00001 // ===================================================================== 00002 // $Id: TCrate.cc,v 1.4 2004/03/07 10:30:31 goiwai Exp $ 00003 // $Name: CLDAQ-1-14-03 $ 00004 // $Log: TCrate.cc,v $ 00005 // Revision 1.4 2004/03/07 10:30:31 goiwai 00006 // ROOTに組みこむためのおまじないマクロを埋めこみました。 00007 // 全てにおいて完全に動作するわけではありません。 00008 // 00009 // Revision 1.3 2003/10/06 17:02:40 goiwai 00010 // *** empty log message *** 00011 // 00012 // Revision 1.2 2003/07/30 16:19:10 goiwai 00013 // ファイルにコミットログをつけることにしました. 00014 // 00015 // ===================================================================== 00016 #include "TCrate.hh" 00017 #include "TModule.hh" 00018 00019 TCrate::TCrate() 00020 : theModuleTable() 00021 { 00022 theModuleTable.Clear(); 00023 } 00024 00025 TCrate::~TCrate() 00026 { 00027 ClearCrate(); 00028 } 00029 00030 Tint TCrate::InstallModule( TModule* module, const Tstring& id, const TstringList& groups ) 00031 { 00032 if ( theModuleTable.FindModule( id ) != 0 ) { 00033 Tcerr << "TCrate::InstallModule: already exist Module identified as " << id << "." << Tendl; 00034 } else { 00035 theModuleTable.AddModule( module, id, groups ); 00036 } 00037 return theModuleTable.GetSize(); 00038 } 00039 00040 Tint TCrate::InstallModule( TModule* module, const Tstring& id, const Tstring& group ) 00041 { 00042 TstringList groups; 00043 groups.push_back( group ); 00044 return InstallModule( module, id, groups ); 00045 } 00046 00047 Tint TCrate::RemoveModule( Tint index ) 00048 { 00049 static const Tstring head = "TCrate::RemoveModule: "; 00050 if ( index < 0 || index >= theModuleTable.GetSize() ) { 00051 Tcerr << head << "invalid index " << index << "." << Tendl; 00052 return theModuleTable.GetSize(); 00053 } 00054 Tstring id = theModuleTable[ index ].GetModuleID(); 00055 delete ( theModuleTable[ index ].GetModule() ); 00056 Tcout << head << id << " module was removed." << Tendl; 00057 theModuleTable.RemoveModule( index ); 00058 00059 return theModuleTable.GetSize(); 00060 } 00061 00062 Tint TCrate::RemoveModule( const Tstring& id ) 00063 { 00064 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00065 if ( theModuleTable[ i ].GetModuleID() == id ) { 00066 RemoveModule( i ); 00067 } 00068 } 00069 return theModuleTable.GetSize(); 00070 } 00071 00072 Tint TCrate::RemoveModule( const TstringList& groups ) 00073 { 00074 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00075 if ( theModuleTable[ i ].IsSameGroup( groups ) ) { 00076 RemoveModule( i ); 00077 } 00078 } 00079 return theModuleTable.GetSize(); 00080 } 00081 00082 Tvoid TCrate::ClearCrate() 00083 { 00084 Tstring head = "TCrate::ClearCrate: "; 00085 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00086 if ( theModuleTable[ i ].GetModule() ) { 00087 Tstring id = theModuleTable[ i ].GetModuleID(); 00088 delete ( theModuleTable[ i ].GetModule() ); 00089 Tcout << head << id << " module was removed." << Tendl;; 00090 } 00091 } 00092 theModuleTable.Clear(); 00093 return; 00094 } 00095 00096 TModule* TCrate::FindModule( const Tstring& id ) 00097 { 00098 return theModuleTable.FindModule( id ); 00099 } 00100 00101 TModule* TCrate::GetModule( Tint index ) 00102 { 00103 if ( index < 0 || index >= theModuleTable.GetSize() ) { 00104 Tcerr << "TCrate::GetModule: invalid index " << index << "." << Tendl; 00105 return 0; 00106 } 00107 return theModuleTable[ index ].GetModule(); 00108 } 00109 00110 TModule* TCrate::GetModule( const Tstring& id ) 00111 { 00112 return FindModule( id ); 00113 } 00114 00115 Tvoid TCrate::Clear() 00116 { 00117 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00118 theModuleTable[ i ].GetModule() -> Clear(); 00119 } 00120 return; 00121 } 00122 00123 Tvoid TCrate::Clear( const TstringList& groups ) 00124 { 00125 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00126 if ( theModuleTable[ i ].IsSameGroup( groups ) ) { 00127 theModuleTable[ i ].GetModule() -> Clear(); 00128 } 00129 } 00130 return; 00131 } 00132 00133 Tvoid TCrate::Clear( const Tstring& group ) 00134 { 00135 TstringList groups; 00136 groups.push_back( group ); 00137 Clear( groups ); 00138 return; 00139 } 00140 00141 Tvoid TCrate::Update() 00142 { 00143 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00144 theModuleTable[ i ].GetModule() -> Update(); 00145 } 00146 return; 00147 } 00148 00149 Tvoid TCrate::Update( const TstringList& groups ) 00150 { 00151 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00152 if ( theModuleTable[ i ].IsSameGroup( groups ) ) { 00153 theModuleTable[ i ].GetModule() -> Update(); 00154 } 00155 } 00156 return; 00157 } 00158 00159 Tvoid TCrate::Update( const Tstring& group ) 00160 { 00161 TstringList groups; 00162 groups.push_back( group ); 00163 Update( groups ); 00164 return; 00165 } 00166 00167 Tvoid TCrate::Initialize() 00168 { 00169 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00170 theModuleTable[ i ].GetModule() -> Initialize(); 00171 } 00172 return; 00173 } 00174 00175 Tvoid TCrate::Initialize( const TstringList& groups ) 00176 { 00177 for ( Tint i = 0; i < theModuleTable.GetSize(); i ++ ) { 00178 if ( theModuleTable[ i ].IsSameGroup( groups ) ) { 00179 theModuleTable[ i ].GetModule() -> Initialize(); 00180 } 00181 } 00182 return; 00183 } 00184 00185 Tvoid TCrate::Initialize( const Tstring& group ) 00186 { 00187 TstringList groups; 00188 groups.push_back( group ); 00189 Initialize( groups ); 00190 return; 00191 } 00192 00193 Tvoid TCrate::ClearAllModules() 00194 { 00195 Clear(); 00196 return; 00197 } 00198 00199 Tvoid TCrate::UpdateAllModules() 00200 { 00201 Update(); 00202 return; 00203 } 00204 00205 Tvoid TCrate::InitializeAllModules() 00206 { 00207 Initialize(); 00208 return; 00209 } 00210 00211 Tvoid TCrate::ClearModule( const Tstring& id ) 00212 { 00213 TModule* module = FindModule( id ); 00214 if ( module ) { 00215 module -> Clear(); 00216 } 00217 return; 00218 } 00219 00220 Tvoid TCrate::UpdateModule( const Tstring& id ) 00221 { 00222 TModule* module = FindModule( id ); 00223 if ( module ) { 00224 module -> Update(); 00225 } 00226 return; 00227 } 00228 00229 Tvoid TCrate::InitializeModule( const Tstring& id ) 00230 { 00231 TModule* module = FindModule( id ); 00232 if ( module ) { 00233 module -> Initialize(); 00234 } 00235 return; 00236 } 00237 00238 #ifdef __CLDAQ_ROOT_DLL 00239 ClassImp(TCrate) 00240 #endif