00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018 #include <cassert>
00019
00020 #include "TClass.h"
00021 #include "TString.h"
00022
00023 #include "MinosObjectMap/MomNavigator.h"
00024 #include "MessageService/MsgService.h"
00025 #include "Record/RecMinos.h"
00026 #include "Record/RecMinosHdr.h"
00027 #include "Record/RecRecord.h"
00028
00029 CVSID("$Id: MomNavigator.cxx,v 1.18 2010/01/13 23:13:07 rhatcher Exp $");
00030
00031 std::ostream& operator << (std::ostream& os, const MomNavigator& mom)
00032 { return mom.Print(os); }
00033
00034 ClassImp(MomNavigator)
00035
00036
00037 MomNavigator::MomNavigator()
00038 : fFragmentArray(0)
00039 {
00040
00041 MSG("Mom",Msg::kDebug) << "MomNavigator ctor " << this << endl;
00042
00043 fFragmentArray = new TObjArray;
00044 }
00045
00046
00047 MomNavigator::~MomNavigator()
00048 {
00049
00050 MSG("Mom",Msg::kDebug) << "MomNavigator dtor " << this << "\n"
00051 << *this << endl;
00052 if (fFragmentArray) fFragmentArray->Delete();
00053 delete fFragmentArray;
00054 }
00055
00056
00057 void MomNavigator::AdoptFragment(TObject *Fragment)
00058 {
00059
00060
00061 fFragmentArray->Add(Fragment);
00062 }
00063
00064
00065 TObject* MomNavigator::At(Int_t idx) const
00066 {
00067
00068
00069 return fFragmentArray->At(idx);
00070 }
00071
00072
00073 TIter MomNavigator::FragmentIter() const
00074 {
00075
00076
00077 return TIter(fFragmentArray);
00078 }
00079
00080
00081 Int_t MomNavigator::IndexOf(TObject *Fragment)
00082 {
00083
00084
00085 return fFragmentArray->IndexOf(Fragment);
00086 }
00087
00088
00089 TObject* MomNavigator::GetFragment(const char *classname,
00090 const char *username,
00091 const char *streamname) const {
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 TString classtr("");
00107 if (classname)
00108 classtr.Append(TString(classname).Strip(TString::kBoth));
00109 TString userstr("");
00110 if (username)
00111 userstr.Append(TString(username).Strip(TString::kBoth));
00112 TString streamstr("");
00113 if (streamname)
00114 streamstr.Append(TString(streamname).Strip(TString::kBoth));
00115
00116 TIter fiter(fFragmentArray);
00117 TObject* fragment = 0;
00118 while ((fragment = fiter())) {
00119
00120
00121 if (classtr.IsNull() || fragment->IsA()->InheritsFrom(classtr)) {
00122
00123
00124 if (userstr.IsNull() || (userstr == fragment->GetName())) {
00125
00126
00127 if (streamstr.IsNull()) return fragment;
00128
00129
00130 Registry* iotags = 0;
00131 if ( RecMinos* record = dynamic_cast<RecMinos*>(fragment) ) {
00132 iotags = &(record->GetTempTags());
00133 }
00134 else if ( RecRecord* record = dynamic_cast<RecRecord*>(fragment) ) {
00135 iotags = &(record->GetTempTags());
00136 }
00137 if ( iotags ) {
00138 const char* tagstream = 0;
00139 if (iotags -> Get("stream",tagstream)
00140 && strcmp(streamname,tagstream) == 0 ) return fragment;
00141 }
00142 }
00143 }
00144 }
00145 return 0;
00146 }
00147
00148
00149 std::vector<TObject*> MomNavigator::GetFragmentList(const char* classname,
00150 const char *username,
00151 const char *streamname) const {
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 std::vector<TObject*> fragmentList;
00168
00169 TString classtr("");
00170 if (classname)
00171 classtr.Append(TString(classname).Strip(TString::kBoth));
00172 TString userstr("");
00173 if (username)
00174 userstr.Append(TString(username).Strip(TString::kBoth));
00175 TString streamstr("");
00176 if (streamname)
00177 streamstr.Append(TString(streamname).Strip(TString::kBoth));
00178
00179 TIter fiter(fFragmentArray);
00180 TObject* fragment = 0;
00181 while ((fragment = fiter())) {
00182
00183
00184 if (classtr.IsNull() || fragment->IsA()->InheritsFrom(classtr)) {
00185
00186 if (userstr.IsNull() || (userstr == fragment->GetName())) {
00187
00188 if ( streamstr.IsNull() ) {
00189
00190 fragmentList.push_back(fragment);
00191 }
00192 else {
00193
00194 Registry* iotags = 0;
00195 if ( RecMinos* record = dynamic_cast<RecMinos*>(fragment) ) {
00196 iotags = &(record->GetTempTags());
00197 }
00198 else if ( RecRecord* record = dynamic_cast<RecRecord*>(fragment) ) {
00199 iotags = &(record->GetTempTags());
00200 }
00201 if ( iotags ) {
00202 const char* tagstream = 0;
00203 if (iotags -> Get("stream",tagstream)
00204 && strcmp(streamname,tagstream) == 0 ) {
00205 fragmentList.push_back(fragment);
00206 }
00207 }
00208 }
00209 }
00210 }
00211 }
00212 return fragmentList;
00213 }
00214
00215
00216
00217 TObject* MomNavigator::GetFragmentByInputTag(const char *streamname,
00218 const char *treename, int treeindex, const char* filename) const {
00219
00220
00221
00222 TIter fiter(fFragmentArray);
00223 TObject* fragment;
00224 while ((fragment = fiter())) {
00225 Registry* iotags = 0;
00226 if ( RecMinos* record = dynamic_cast<RecMinos*>(fragment) ) {
00227 iotags = &(record->GetTempTags());
00228 }
00229 else if ( RecRecord* record = dynamic_cast<RecRecord*>(fragment) ) {
00230 iotags = &(record->GetTempTags());
00231 }
00232 if ( iotags ) {
00233 const char* tagstream = 0;
00234 if(iotags->Get("stream",tagstream) && strcmp(streamname,tagstream)==0) {
00235 const char* tagtree = 0;
00236 if (iotags -> Get("tree",tagtree) && strcmp(treename,tagtree)==0 ) {
00237 int tagindex = -1;
00238 if (iotags -> Get("index",tagindex) && tagindex == treeindex ) {
00239 const char* tagfile = 0;
00240 if (iotags -> Get("file",tagfile) && strcmp(filename,tagfile)==0){
00241 return fragment;
00242 }
00243 }
00244 }
00245 }
00246 }
00247 }
00248
00249 return 0;
00250 }
00251
00252
00253
00254 void MomNavigator::Clear(Option_t * opt )
00255 {
00256
00257
00258
00259
00260
00261
00262
00263 if ( !fFragmentArray ) return;
00264 MSG("Mom",Msg::kVerbose) << "MomNavigator::Clear. Mom contents at entry:\n"
00265 << *this << endl;
00266
00267
00268
00269
00270 TString optstr(opt);
00271 bool forceTransient = false;
00272 const TString fstring("?forceTransient");
00273 Ssiz_t ipos = optstr.Index(fstring);
00274 if ( ipos >= 0 ) {
00275 forceTransient = true;
00276 optstr.Remove(ipos,fstring.Length());
00277 }
00278
00279 for ( int idx = fFragmentArray->GetEntriesFast()-1; idx >= 0; idx-- ) {
00280 TObject* fragment = fFragmentArray->At(idx);
00281 if ( !fragment ) continue;
00282
00283 RecMinos* recminos = dynamic_cast<RecMinos*>(fragment);
00284 RecRecord* recrecord = dynamic_cast<RecRecord*>(fragment);
00285
00286
00287
00288
00289 if ( optstr != "" ) {
00290 int ismatch = 0;
00291 TString fragClassName(fragment->ClassName());
00292 TString fragUserName(fragment->GetName());
00293
00294 const Registry* reg = 0;
00295 if (recminos) reg = &(recminos->GetTempTags());
00296 else if (recrecord) reg = &(recrecord->GetTempTags());
00297 TString fragStream;
00298 const char* tmp = 0;
00299 if ( reg->Get("stream",tmp)) fragStream = tmp;
00300
00301 if ( optstr == fragClassName ) ismatch = 0x01;
00302 if ( optstr == fragUserName ) ismatch = 0x02;
00303 if ( optstr == fragStream ) ismatch = 0x04;
00304 MSG("Mom",Msg::kDebug) << "MomNavigator::Clear(\"" << optstr << "\") "
00305 << " class=\"" << fragClassName << "\""
00306 << " user=\"" << fragUserName << "\""
00307 << " stream=\"" << fragStream << "\""
00308 << " ismatch=" << ismatch
00309 << endl;
00310 if ( ismatch == 0 ) continue;
00311 MSG("Mom",Msg::kDebug) << "drop the fragment" << endl;
00312 }
00313
00314
00315 bool isTransient = true;
00316 bool isPerOwned = false;
00317 if ( recminos ) {
00318 isTransient = recminos->IsTransient();
00319 }
00320 else if ( recrecord ) {
00321 isTransient = recrecord->IsTransient();
00322 isPerOwned = recrecord->IsPerOwned();
00323 }
00324 if ( isTransient || forceTransient ) {
00325 fFragmentArray->RemoveAt(idx);
00326
00327 if ( fragment && !isPerOwned ) delete fragment;
00328 fragment = 0;
00329 }
00330 }
00331 fFragmentArray->Compress();
00332
00333 MSG("Mom",Msg::kVerbose) << "MomNavigator::Clear. Mom contents at exit:\n"
00334 << *this << endl;
00335
00336 }
00337
00338 std::ostream& MomNavigator::Print(std::ostream& os) const {
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 assert(fFragmentArray);
00350
00351 Int_t nent = fFragmentArray->GetEntriesFast();
00352 if ( nent <= 0 ) {
00353 os << "Mom has no entries." << endl;
00354 return os;
00355 }
00356
00357 os << "Mom contents listed by array index:" << endl;
00358 for (int idx = 0; idx < nent; idx++) {
00359 TObject* fragment = fFragmentArray->At(idx);
00360 if ( !fragment ) {
00361 os << idx << ")No object.";
00362 }
00363 else {
00364 os << idx << ")" << fragment->ClassName();
00365 Registry* iotags = 0;
00366 bool isTransient = true;
00367 bool isPerOwned = false;
00368 if ( RecMinos* record = dynamic_cast<RecMinos*>(fragment) ) {
00369 iotags = &(record->GetTempTags());
00370 isTransient = record -> IsTransient();
00371 const VldContext& vldc = record -> GetHeader() -> GetVldContext();
00372 os << " " << vldc;
00373 }
00374 else if ( RecRecord* record = dynamic_cast<RecRecord*>(fragment) ) {
00375 iotags = &(record->GetTempTags());
00376 isTransient = record -> IsTransient();
00377 isPerOwned = record -> IsPerOwned();
00378 const VldContext& vldc = (record -> GetHeader()).GetVldContext();
00379 os << " " << vldc;
00380 }
00381
00382 if ( strcmp(fragment->GetName(),"") ) {
00383 os << ", TNamed " << fragment->GetName();
00384 }
00385 if ( iotags ) {
00386 const char* tagstream = 0;
00387 if(iotags->Get("stream",tagstream)) {
00388 os << ", InputStream " << tagstream;
00389 }
00390 }
00391 os << (( isTransient ) ? ", isTransient " : ", isNotTransient ");
00392 os << (( isPerOwned ) ? ", isPerOwned " : ", isNotPerOwned ");
00393 }
00394 os << endl;
00395 }
00396
00397 return os;
00398
00399 }
00400
00401 void MomNavigator::Print(Option_t* ) const {
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412 Print(std::cout);
00413 return;
00414
00415 }
00416
00417