00001 // ===================================================================== 00002 // $Id: TRunInformationTable.cc,v 1.4 2004/03/07 10:30:34 goiwai Exp $ 00003 // $Name: CLDAQ-1-14-03 $ 00004 // $Log: TRunInformationTable.cc,v $ 00005 // Revision 1.4 2004/03/07 10:30:34 goiwai 00006 // ROOTに組みこむためのおまじないマクロを埋めこみました。 00007 // 全てにおいて完全に動作するわけではありません。 00008 // 00009 // Revision 1.3 2003/10/06 17:02:45 goiwai 00010 // *** empty log message *** 00011 // 00012 // Revision 1.2 2003/07/30 16:20:30 goiwai 00013 // ファイルにコミットログをつけることにしました. 00014 // 00015 // ===================================================================== 00016 #include "TRunInformationTable.hh" 00017 #include "TRunInformation.hh" 00018 #include "TOutputHtmlFileStream.hh" 00019 00020 TRunInformationTable::TRunInformationTable() 00021 : theRunInformationList() 00022 { 00023 theRunInformationList.clear(); 00024 } 00025 00026 TRunInformationTable::TRunInformationTable( const TRunInformationList& infolist ) 00027 : theRunInformationList( infolist ) 00028 {;} 00029 00030 TRunInformationTable::TRunInformationTable( const TRunInformationTable& right ) 00031 : theRunInformationList( right.theRunInformationList ) 00032 {;} 00033 00034 TRunInformationTable::~TRunInformationTable() 00035 {;} 00036 00037 const TRunInformationTable& TRunInformationTable::operator=( const TRunInformationTable& right ) 00038 { 00039 theRunInformationList = right.theRunInformationList; 00040 return *this; 00041 } 00042 00043 Tbool TRunInformationTable::operator==( const TRunInformationTable& right ) const 00044 { 00045 if ( theRunInformationList == right.theRunInformationList ) { 00046 return Ttrue; 00047 } else { 00048 return Tfalse; 00049 } 00050 } 00051 00052 Tbool TRunInformationTable::operator!=( const TRunInformationTable& right ) const 00053 { 00054 if ( theRunInformationList != right.theRunInformationList ) { 00055 return Ttrue; 00056 } else { 00057 return Tfalse; 00058 } 00059 } 00060 00061 TRunInformationTable operator+( const TRunInformationList& left, const TRunInformationTable& right ) 00062 { 00063 TRunInformationTable table = left + right; 00064 return table; 00065 } 00066 00067 TRunInformationTable operator+( const TRunInformation& left, const TRunInformationTable& right ) 00068 { 00069 TRunInformationTable table = left + right; 00070 return table; 00071 } 00072 00073 TRunInformationTable TRunInformationTable::operator+( const TRunInformationTable& right ) const 00074 { 00075 TRunInformationTable table( *this ); 00076 const TRunInformationList infolist = right.GetRunInformationList(); 00077 for ( Tsize_t i = 0; i < infolist.size(); i ++ ) { 00078 table.AddRunInformation( infolist[ i ] ); 00079 } 00080 return table; 00081 } 00082 00083 TRunInformationTable TRunInformationTable::operator+( const TRunInformationList& right ) const 00084 { 00085 TRunInformationTable table( *this ); 00086 for ( Tsize_t i = 0; i < right.size(); i ++ ) { 00087 table.AddRunInformation( right[ i ] ); 00088 } 00089 return table; 00090 } 00091 00092 TRunInformationTable TRunInformationTable::operator+( const TRunInformation& right ) const 00093 { 00094 TRunInformationTable table( *this ); 00095 table.AddRunInformation( right ); 00096 return table; 00097 } 00098 00099 TRunInformationTable& TRunInformationTable::operator+=( const TRunInformationTable& right ) 00100 { 00101 *this = *this + right; 00102 return *this; 00103 } 00104 00105 TRunInformationTable& TRunInformationTable::operator+=( const TRunInformationList& right ) 00106 { 00107 *this = *this + right; 00108 return *this; 00109 } 00110 00111 TRunInformationTable& TRunInformationTable::operator+=( const TRunInformation& right ) 00112 { 00113 *this = *this + right; 00114 return *this; 00115 } 00116 00117 Tostream& operator<<( Tostream& tos, const TRunInformationTable& right ) 00118 { 00119 Tsize_t nrow = right.theRunInformationList.size(); 00120 for ( Tsize_t i = 0; i < nrow; i ++ ) { 00121 tos << right.theRunInformationList[ i ]; 00122 if ( i != nrow - 1 ) { 00123 tos << Tendl; 00124 } 00125 } 00126 return tos; 00127 } 00128 00129 TOutputHtmlFileStream& operator<<( TOutputHtmlFileStream& html, const TRunInformationTable& right ) 00130 { 00131 if ( html.IsOpen() ) { 00132 if ( !html.OpenTable() ) { 00133 html.OpenTable(); 00134 } 00135 for ( Tsize_t i = 0; i < right.theRunInformationList.size(); i ++ ) { 00136 html << "<tr><td><b>" << right.theRunInformationList[ i ].GetItem() << "</b></td>" << Tflush; 00137 html << "<td>" << right.theRunInformationList[ i ].GetValue() << "</td></tr>" << Tendl; 00138 } 00139 if ( !html.CloseTable() ) { 00140 html.CloseTable(); 00141 } 00142 } 00143 return html; 00144 } 00145 00146 Tint TRunInformationTable::GetNumberOfRows() const 00147 { 00148 return (Tint)theRunInformationList.size(); 00149 } 00150 00151 Tvoid TRunInformationTable::SetRunInformation( const Tstring& item ) 00152 { 00153 if ( !HasItem( item ) ) { 00154 AddRunInformation( item ); 00155 return; 00156 } 00157 SetInformation( theRunInformationList[ FindItem( item ) ] ); 00158 return; 00159 } 00160 00161 Tvoid TRunInformationTable::SetRunInformation( const Tstring& item, const Tstring& value ) 00162 { 00163 if ( !HasItem( item ) ) { 00164 AddRunInformation( item, value ); 00165 return; 00166 } 00167 theRunInformationList[ FindItem( item ) ].SetValue( value ); 00168 return; 00169 } 00170 00171 Tvoid TRunInformationTable::SetRunInformation( const TRunInformation& runinfo ) 00172 { 00173 Tstring item = runinfo.GetItem(); 00174 if ( !HasItem( item ) ) { 00175 AddRunInformation( runinfo ); 00176 return; 00177 } 00178 theRunInformationList[ FindItem( item ) ] = runinfo; 00179 return; 00180 } 00181 00182 Tvoid TRunInformationTable::SetRunInformation() 00183 { 00184 for ( Tsize_t i = 0; i < theRunInformationList.size(); i ++ ) { 00185 SetInformation( theRunInformationList[ i ] ); 00186 } 00187 return; 00188 } 00189 00190 Tvoid TRunInformationTable::AddRunInformation( const Tstring& item ) 00191 { 00192 if ( HasItem( item ) ) { 00193 Tstring head = "TRunInformationTable::AddRunInformation: "; 00194 Tcerr << head << item << " already exist." << Tendl; 00195 return; 00196 } 00197 TRunInformation runinfo( item ); 00198 theRunInformationList.push_back( runinfo ); 00199 return; 00200 } 00201 00202 Tvoid TRunInformationTable::AddRunInformation( const Tstring& item, const Tstring& value ) 00203 { 00204 if ( HasItem( item ) ) { 00205 Tstring head = "TRunInformationTable::AddRunInformation: "; 00206 Tcerr << head << item << " already exist." << Tendl; 00207 return; 00208 } 00209 TRunInformation runinfo( item, value ); 00210 theRunInformationList.push_back( runinfo ); 00211 return; 00212 } 00213 00214 Tvoid TRunInformationTable::AddRunInformation( const TRunInformation& runinfo ) 00215 { 00216 Tstring item = runinfo.GetItem(); 00217 if ( HasItem( item ) ) { 00218 Tstring head = "TRunInformationTable::AddRunInformation: "; 00219 Tcerr << head << item << " already exist." << Tendl; 00220 return; 00221 } 00222 theRunInformationList.push_back( runinfo ); 00223 return; 00224 } 00225 00226 Tvoid TRunInformationTable::AddRunInformation() 00227 { 00228 TRunInformation runinfo; 00229 SetInformation( runinfo ); 00230 return; 00231 } 00232 00233 Tstring TRunInformationTable::GetItem( const Tstring& value ) const 00234 { 00235 Tstring retitem = ""; 00236 Tint pos = FindValue( value ); 00237 if ( pos >= 0 && pos < (Tint)theRunInformationList.size() ) { 00238 retitem = theRunInformationList[ pos ].GetItem(); 00239 } else { 00240 Tstring head = "TRunInformationTable::GetItem: "; 00241 Tcerr << head << value << " doesn't exist." << Tendl; 00242 } 00243 return retitem; 00244 } 00245 00246 Tstring TRunInformationTable::GetItem( Tint nrow ) const 00247 { 00248 Tstring retitem = ""; 00249 if ( nrow >= 0 && nrow < (Tint)theRunInformationList.size() ) { 00250 retitem = theRunInformationList[ nrow ].GetItem(); 00251 } 00252 return retitem; 00253 } 00254 00255 Tstring TRunInformationTable::GetValue( const Tstring& item ) const 00256 { 00257 Tstring retval = ""; 00258 Tint pos = FindItem( item ); 00259 if ( pos >= 0 && pos < (Tint)theRunInformationList.size() ) { 00260 retval = theRunInformationList[ pos ].GetValue(); 00261 } else { 00262 Tstring head = "TRunInformationTable::GetValue: "; 00263 Tcerr << head << item << " doesn't exist." << Tendl; 00264 } 00265 return retval; 00266 } 00267 00268 Tstring TRunInformationTable::GetValue( Tint nrow ) const 00269 { 00270 Tstring retval = ""; 00271 if ( nrow >= 0 && nrow < (Tint)theRunInformationList.size() ) { 00272 retval = theRunInformationList[ nrow ].GetValue(); 00273 } 00274 return retval; 00275 } 00276 00277 Tint TRunInformationTable::FindItem( const Tstring& item ) const 00278 { 00279 for ( Tint i = 0; i < (Tint)theRunInformationList.size(); i ++ ) { 00280 if ( theRunInformationList[ i ].GetItem() == item ) { 00281 return i; 00282 } 00283 } 00284 return tNotFound; 00285 } 00286 00287 Tint TRunInformationTable::FindValue( const Tstring& value ) const 00288 { 00289 for ( Tint i = 0; i < (Tint)theRunInformationList.size(); i ++ ) { 00290 if ( theRunInformationList[ i ].GetValue() == value ) { 00291 return i; 00292 } 00293 } 00294 return tNotFound; 00295 } 00296 00297 Tint TRunInformationTable::FindRunInformation( const TRunInformation& runinfo ) const 00298 { 00299 for ( Tint i = 0; i < (Tint)theRunInformationList.size(); i ++ ) { 00300 if ( theRunInformationList[ i ] == runinfo ) { 00301 return i; 00302 } 00303 } 00304 return tNotFound; 00305 } 00306 00307 Tbool TRunInformationTable::HasItem( const Tstring& item ) const 00308 { 00309 if ( FindItem( item ) == tNotFound ) { 00310 return Tfalse; 00311 } 00312 return Ttrue; 00313 } 00314 00315 Tbool TRunInformationTable::HasRunInformation( const TRunInformation& runinfo ) const 00316 { 00317 if ( FindRunInformation( runinfo ) == tNotFound ) { 00318 return Tfalse; 00319 } 00320 return Ttrue; 00321 } 00322 00323 Tvoid TRunInformationTable::Remove( const Tstring& item ) 00324 { 00325 if ( !HasItem( item ) ) { 00326 Tstring head = "TRunInformationTable::Remove: "; 00327 Tcerr << head << item << " doesn't exist." << Tendl; 00328 return; 00329 } 00330 theRunInformationList.erase( theRunInformationList.begin() + FindItem( item ) ); 00331 return; 00332 } 00333 00334 Tvoid TRunInformationTable::Remove( const TRunInformation& runinfo ) 00335 { 00336 if ( !HasRunInformation( runinfo ) ) { 00337 Tstring head = "TRunInformationTable::Remove: "; 00338 Tcerr << head << runinfo << " doesn't exist in the table." << Tendl; 00339 return; 00340 } 00341 theRunInformationList.erase( theRunInformationList.begin() + FindRunInformation( runinfo ) ); 00342 return; 00343 } 00344 00345 Tvoid TRunInformationTable::Clear() 00346 { 00347 for ( Tsize_t i = 0; i < theRunInformationList.size(); i ++ ) { 00348 theRunInformationList[ i ].Clear(); 00349 } 00350 return; 00351 } 00352 00353 #ifdef __CLDAQ_ROOT_DLL 00354 ClassImp(TRunInformationTable) 00355 #endif