00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4AnalysisObjectManager.h"
00015
00016 #include "Riostream.h"
00017 #include "TRegexp.h"
00018 #include "TMultiGraph.h"
00019 #include "TKey.h"
00020 #include "TObjArray.h"
00021 #include "TArrayF.h"
00022 #include "TFolder.h"
00023 #include "TFile.h"
00024 #include "TList.h"
00025 #include "TThread.h"
00026 #include "TH2.h"
00027 #include "TCanvas.h"
00028 #include "TCutG.h"
00029 #include "TROOT.h"
00030 #include "TTree.h"
00031 #include "TDataMember.h"
00032 #include "TBaseClass.h"
00033
00034 #include "TGo4Log.h"
00035 #include "TGo4LockGuard.h"
00036 #include "TGo4ObjectStatus.h"
00037 #include "TGo4BranchStatus.h"
00038 #include "TGo4Parameter.h"
00039 #include "TGo4Condition.h"
00040 #include "TGo4WinCond.h"
00041 #include "TGo4PolyCond.h"
00042 #include "TGo4HistogramEntry.h"
00043 #include "TGo4TreeHistogramEntry.h"
00044 #include "TGo4DynamicListException.h"
00045 #include "TGo4DynamicList.h"
00046 #include "TGo4MainTree.h"
00047 #include "TGo4AnalysisObjectNames.h"
00048 #include "TGo4HistogramStatus.h"
00049 #include "TGo4TreeStructure.h"
00050
00051 #include "TGo4EventStore.h"
00052 #include "TGo4EventSource.h"
00053 #include "TGo4EventProcessor.h"
00054 #include "TGo4BackStore.h"
00055
00056 #include "TGo4Picture.h"
00057 #include "TGo4CompositeEvent.h"
00058 #include "TGo4ParameterStatus.h"
00059 #include "TGo4MemberStatus.h"
00060 #include "TGo4PolyCond.h"
00061 #include "TGo4AnalysisImp.h"
00062
00063 const char* TGo4AnalysisObjectManager::fgcTOPDYNAMICLIST = "Go4DynamicList";
00064 const char* TGo4AnalysisObjectManager::fgcTOPFOLDER = "Go4";
00065 const char* TGo4AnalysisObjectManager::fgcHISTFOLDER = "Histograms";
00066 const char* TGo4AnalysisObjectManager::fgcDYNFOLDER = "DynamicLists";
00067 const char* TGo4AnalysisObjectManager::fgcCONDFOLDER = "Conditions";
00068 const char* TGo4AnalysisObjectManager::fgcPARAFOLDER = "Parameters";
00069 const char* TGo4AnalysisObjectManager::fgcTREEFOLDER = "Trees";
00070 const char* TGo4AnalysisObjectManager::fgcPICTFOLDER = "Pictures";
00071 const char* TGo4AnalysisObjectManager::fgcCANVFOLDER = "Canvases";
00072 const char* TGo4AnalysisObjectManager::fgcANALYSISFOLDER = "EventObjects";
00073 const char* TGo4AnalysisObjectManager::fgcEVENTFOLDER = "Events";
00074 const char* TGo4AnalysisObjectManager::fgcSRCFOLDER = "EventSources";
00075 const char* TGo4AnalysisObjectManager::fgcSTOREFOLDER = "EventStores";
00076 const char* TGo4AnalysisObjectManager::fgcPROCFOLDER = "EventProcessors";
00077 const char* TGo4AnalysisObjectManager::fgcUSRFOLDER = "UserObjects";
00078 const char* TGo4AnalysisObjectManager::fgcTMPFOLDER = "Go4-tmp";
00079
00080 #define fguSUBFOLDERMAXLEN 1024
00081
00082 TGo4AnalysisObjectManager::TGo4AnalysisObjectManager(const char* name) :
00083 TNamed(name,"The Go4 Analysis Object Manager"),
00084 fxGo4Dir(0),fxHistogramDir(0),fxConditionDir(0), fxParameterDir(0),
00085 fxDynListDir(0),fxUserDir(0), fxTreeDir(0), fxPictureDir(0), fxCanvasDir(0),
00086 fxStoreDir(0), fxSourceDir(0), fxProcessorDir(0), fxEventDir(0),
00087 fxAnalysisDir(0), fxTempFolder(0),
00088 fxMatchList(0), fxMatchIterator(0),
00089 fiDynListCount(0), fiDynListInterval(0),
00090 fbCreatedinMake(kFALSE), fbSuppressLoadHistograms(kFALSE)
00091 {
00092 fxDirMutex = new TMutex(kTRUE);
00093 fxGo4Dir = gROOT->GetRootFolder()->AddFolder(fgcTOPFOLDER,"The Go4 Object folder");
00094 fxGo4Dir->SetOwner(kTRUE);
00095 gROOT->GetListOfBrowsables()->Add(fxGo4Dir, fxGo4Dir->GetName());
00096 fxHistogramDir = fxGo4Dir->AddFolder(fgcHISTFOLDER,"All Histogram objects");
00097 fxHistogramDir->SetOwner(kTRUE);
00098 fxConditionDir = fxGo4Dir->AddFolder(fgcCONDFOLDER,"All Condition objects");
00099 fxConditionDir->SetOwner(kTRUE);
00100 fxParameterDir = fxGo4Dir->AddFolder(fgcPARAFOLDER,"All Parameter objects");
00101 fxParameterDir->SetOwner(kTRUE);
00102 fxDynListDir = fxGo4Dir->AddFolder(fgcDYNFOLDER,"Dynamic List Instances");
00103 fxDynListDir->SetOwner(kTRUE);
00104 fxTreeDir = fxGo4Dir->AddFolder(fgcTREEFOLDER,"References to trees");
00105 fxTreeDir->SetOwner(kFALSE);
00106 fxPictureDir = fxGo4Dir->AddFolder(fgcPICTFOLDER,"Picture objects");
00107 fxPictureDir->SetOwner(kTRUE);
00108 fxCanvasDir = fxGo4Dir->AddFolder(fgcCANVFOLDER,"All TCanvases");
00109 fxCanvasDir->SetOwner(kTRUE);
00110 fxAnalysisDir = fxGo4Dir->AddFolder(fgcANALYSISFOLDER,"Event objects of current analysis");
00111 fxAnalysisDir->SetOwner(kTRUE);
00112 fxStoreDir = fxAnalysisDir->AddFolder(fgcSTOREFOLDER,"References to event stores");
00113 fxStoreDir->SetOwner(kFALSE);
00114 fxSourceDir = fxAnalysisDir->AddFolder(fgcSRCFOLDER,"References to event sources");
00115 fxSourceDir->SetOwner(kFALSE);
00116 fxProcessorDir = fxAnalysisDir->AddFolder(fgcPROCFOLDER,"References to event processors");
00117 fxProcessorDir->SetOwner(kFALSE);
00118 fxEventDir = fxAnalysisDir->AddFolder(fgcEVENTFOLDER,"References to event structures");
00119 fxEventDir->SetOwner(kFALSE);
00120 fxUserDir = fxGo4Dir->AddFolder(fgcUSRFOLDER,"For User Objects");
00121
00122
00123 fxGo4Dir->SetOwner(kFALSE);
00124
00125 fxTempFolder = gROOT->GetRootFolder()->AddFolder(fgcTMPFOLDER,"The Go4 temporary object folder");
00126 fxTempFolder->SetOwner(kFALSE);
00127
00128 gROOT->GetListOfCleanups()->Add(this);
00129 }
00130
00131 TGo4AnalysisObjectManager::TGo4AnalysisObjectManager() :
00132 TNamed(),
00133 fxGo4Dir(0),fxHistogramDir(0),fxConditionDir(0),
00134 fxDynListDir(0), fxUserDir(0), fxTreeDir(0), fxPictureDir(0), fxCanvasDir(0),
00135 fxStoreDir(0), fxSourceDir(0), fxProcessorDir(0), fxEventDir(0),
00136 fxAnalysisDir(0), fxTempFolder(0),
00137 fiDynListCount(0), fiDynListInterval(0),
00138 fbCreatedinMake(kFALSE), fbSuppressLoadHistograms(kFALSE)
00139 {
00140
00141
00142 gROOT->GetListOfCleanups()->Add(this);
00143 }
00144
00145
00146 TGo4AnalysisObjectManager::~TGo4AnalysisObjectManager()
00147 {
00148 gROOT->GetListOfCleanups()->Remove(this);
00149
00150 delete fxMatchIterator;
00151 delete fxMatchList;
00152 gROOT->GetListOfBrowsables()->Remove(fxGo4Dir);
00153
00154
00155 gROOT->GetRootFolder()->Remove(fxTempFolder);
00156 gROOT->GetRootFolder()->Remove(fxGo4Dir);
00157
00158
00159 fxCanvasDir->Clear();
00160
00161 fxHistogramDir->Clear();
00162 fxConditionDir->Clear();
00163 fxParameterDir->Clear();
00164 fxDynListDir->Clear();
00165 fxUserDir->Clear();
00166 fxTreeDir->Clear();
00167 fxPictureDir->Clear();
00168
00169 fxEventDir->Clear();
00170 fxProcessorDir->Clear();
00171 fxStoreDir->Clear();
00172 fxSourceDir->Clear();
00173 fxGo4Dir->Clear();
00174 fxTempFolder->Clear();
00175
00176
00177 delete fxTempFolder;
00178
00179 delete fxGo4Dir;
00180
00181
00182 delete fxDirMutex;
00183 }
00184
00185 void TGo4AnalysisObjectManager::RecursiveRemove(TObject* obj)
00186 {
00187 if ((obj!=0) && (obj!=this)) {
00188
00189 if (fxCanvasDir) fxCanvasDir->RecursiveRemove(obj);
00190 }
00191 }
00192
00193
00194 Bool_t TGo4AnalysisObjectManager::AddObject(TNamed * anything, const char* subfolder, Bool_t replace)
00195 {
00196 GO4TRACE((11,"TGo4AnalysisObjectManager::AddObject(TNamed *)",__LINE__, __FILE__));
00197
00198 return (AddObjectToFolder(anything,fxUserDir,subfolder,replace));
00199 }
00200
00201 Bool_t TGo4AnalysisObjectManager::RemoveObject(const char * name, Bool_t del)
00202 {
00203 return RemoveObjectFromFolder(name, fxUserDir, del);
00204 }
00205
00206
00207 TObject* TGo4AnalysisObjectManager::GetAsTObject(const char * name, const char* folder)
00208 {
00209 GO4TRACE((11,"TGo4AnalysisObjectManager::GetAsTObject(const char*, const char*)",__LINE__, __FILE__));
00210
00211 TObject* ob(0);
00212 TFolder* searchfold(fxGo4Dir);
00213 if((folder!=0) && (strcmp(folder,fgcTOPFOLDER)!=0))
00214 searchfold = FindSubFolder(fxGo4Dir, folder, kFALSE);
00215 if(searchfold) {
00216 ob = FindObjectInFolder(searchfold, name);
00217
00218 if(ob && ob->InheritsFrom(TTree::Class())) ob=0;
00219 if(ob && ob->InheritsFrom(TFolder::Class())) ob=0;
00220 if(ob && ob->InheritsFrom(TGo4EventElement::Class())) ob=0;
00221 if(ob && ob->InheritsFrom(TGo4EventSource::Class())) ob=0;
00222 if(ob && ob->InheritsFrom(TGo4EventStore::Class())) ob=0;
00223 if(ob && ob->InheritsFrom(TGo4EventProcessor::Class())) ob=0;
00224 }
00225 if(ob) {
00226 TGo4Analysis::Instance()->Message(0,"AnalysisObjectManager - found object %s of class %s",
00227 ob->GetName(), ob->ClassName());
00228 } else {
00229 TGo4Analysis::Instance()->Message(0,"!!! AnalysisObjectManager - no such object %s !!!",
00230 name);
00231 }
00232 return ob;
00233 }
00234
00235
00236
00237 TNamed * TGo4AnalysisObjectManager::GetObject(const char * name, const char* folder)
00238 {
00239 return dynamic_cast<TNamed*> (GetAsTObject(name, folder));
00240 }
00241
00242
00243 Bool_t TGo4AnalysisObjectManager::ClearObjects(const char * name)
00244 {
00245 GO4TRACE((11,"TGo4AnalysisObjectManager::ClearObject(char *)",__LINE__, __FILE__));
00246 Bool_t rev=kTRUE;
00247 TGo4LockGuard dirguard(fxDirMutex);
00248 TObject* ob = fxGo4Dir->FindObjectAny(name);
00249 if(ob!=0)
00250 {
00251 if(ob->InheritsFrom(TFolder::Class()))
00252 rev=ClearFolder(dynamic_cast<TFolder*>(ob));
00253 else
00254 rev=ClearObject(ob);
00255 }
00256 return rev;
00257 }
00258
00259
00260 Bool_t TGo4AnalysisObjectManager::DeleteObjects(const char * name)
00261 {
00262 Bool_t rev=kFALSE;
00263 TGo4LockGuard dirguard(fxDirMutex);
00264 TObject* ob= fxGo4Dir->FindObjectAny(name);
00265 if(ob!=0)
00266 {
00267 if(ob->InheritsFrom(TFolder::Class()))
00268 rev=DeleteFolder(dynamic_cast<TFolder*>(ob));
00269 else
00270 rev=DeleteObject(ob);
00271 }
00272 return rev;
00273 }
00274
00275 Bool_t TGo4AnalysisObjectManager::ProtectObjects(const char* name, const Option_t* flags)
00276 {
00277 Bool_t rev = kFALSE;
00278 TGo4LockGuard dirguard(fxDirMutex);
00279 TObject* ob= fxGo4Dir->FindObjectAny(name);
00280 if(ob!=0)
00281 {
00282 if(ob->InheritsFrom(TFolder::Class()))
00283 rev=ProtectFolder(dynamic_cast<TFolder*>(ob), flags);
00284 else
00285 rev=ProtectObject(ob, flags);
00286 }
00287 return rev;
00288 }
00289
00290 TFolder * TGo4AnalysisObjectManager::CreateCompositeBranchFolder(TObjArray* branchlist,
00291 TGo4CompositeEvent* compevent,
00292 Int_t startindex, Int_t* skip,
00293 const char* name, const char* title)
00294 {
00295 GO4TRACE((11,"TGo4AnalysisObjectManager::CreateCompositeBranchFolder(TObjArray*,...)",__LINE__, __FILE__));
00296 if (branchlist==0) return 0;
00297
00298 if (compevent==0) return CreateBranchFolder(branchlist,name,title);
00299
00300 Int_t lastindex=0;
00301 if(startindex==1)
00302
00303 lastindex = startindex + branchlist->GetLast();
00304 else
00305
00306 lastindex = startindex + compevent->getNElements();
00307
00308 TFolder* subnames=0;
00309 TList* nameslist = new TList;
00310 TGo4ObjectStatus* state;
00311 TObjArray* csubevents = compevent->getListOfComposites();
00312
00313 Int_t skippedentries=0;
00314 Int_t offset=0;
00315 for(Int_t i=startindex; i<lastindex;i++) {
00316
00317 TClass* cl=0;
00318 TObject* entry=branchlist->At(i+offset);
00319 if((entry!=0) && entry->InheritsFrom(TBranch::Class())) {
00320
00321 TBranch* currentbranch= dynamic_cast<TBranch*> (entry);
00322 TObjArray* currentbranchlist=0;
00323 if (currentbranch!=0) {
00324 currentbranchlist=currentbranch->GetListOfBranches();
00325 cl=gROOT->GetClass(currentbranch->GetClassName());
00326 }
00327 if((cl!=0) && cl->InheritsFrom(TGo4CompositeEvent::Class())) {
00328
00329 TGo4CompositeEvent* subevent=0;
00330 TString branchname(currentbranch->GetName());
00331 Ssiz_t leng = branchname.Length();
00332 branchname.Resize(leng-1);
00333
00334 if(csubevents!=0)
00335 subevent = dynamic_cast<TGo4CompositeEvent *>(csubevents->FindObject(branchname.Data()));
00336
00337 if((subevent!=0) && subevent->getNElements()>0)
00338 {
00339
00340
00341
00342 subnames=CreateCompositeBranchFolder(branchlist,
00343 subevent,
00344 i+offset+1, &skippedentries,
00345 subevent->GetName(),
00346 subevent->GetTitle());
00347 nameslist->AddLast(subnames);
00348 offset+=skippedentries;
00349
00350
00351
00352
00353 TFolder* temp=CreateBranchFolder(currentbranchlist,
00354 "dummy",
00355 "dummy");
00356 subnames->GetListOfFolders()->AddAll(temp->GetListOfFolders());
00357
00358
00359 }
00360 else
00361 {
00362
00363
00364
00365
00366 if(currentbranchlist!=0)
00367 {
00368 if(currentbranchlist->IsEmpty())
00369 {
00370
00371 state=new TGo4BranchStatus(currentbranch);
00372 nameslist->AddLast(state);
00373 }
00374 else
00375 {
00376 subnames=CreateBranchFolder(currentbranchlist,
00377 currentbranch->GetName(),
00378 currentbranch->GetTitle());
00379 nameslist->AddLast(subnames);
00380 }
00381 }
00382 }
00383
00384 }
00385 else
00386 {
00387
00388
00389
00390 if(currentbranchlist!=0)
00391 {
00392 if(currentbranchlist->IsEmpty())
00393 {
00394
00395 state=new TGo4BranchStatus(currentbranch);
00396 nameslist->AddLast(state);
00397 }
00398 else
00399 {
00400 subnames=CreateBranchFolder(currentbranchlist,
00401 currentbranch->GetName(),
00402 currentbranch->GetTitle());
00403 nameslist->AddLast(subnames);
00404 }
00405 }
00406
00407 }
00408 }
00409 else
00410 {
00411 break;
00412
00413
00414
00415
00416
00417 }
00418 }
00419
00420 *skip=lastindex+offset-startindex;
00421 TFolder* fold = fxTempFolder->AddFolder(name,title,nameslist);
00422 fold->SetOwner(kTRUE);
00423 fxTempFolder->Remove(fold);
00424 return fold;
00425 }
00426
00427 TGo4TreeStructure * TGo4AnalysisObjectManager::CreateTreeStructure(TTree* thetree)
00428 {
00429 GO4TRACE((11,"TGo4AnalysisObjectManager::CreateTreeStructure(TTree*)",__LINE__, __FILE__));
00430
00431 TGo4TreeStructure* tstructure=0;
00432 if(thetree)
00433 {
00434 const char* treename=thetree->GetName();
00435 const char* treetitle=thetree->GetTitle();
00436 TGo4Analysis::Instance()->Message(0,"AnalysisObjectManager - creating structure of tree %s",
00437 treename);
00438 TObjArray* branchlist=thetree->GetListOfBranches();
00439 tstructure= new TGo4TreeStructure(treename);
00440 tstructure->fxTopFolder=CreateBranchFolder(branchlist,treename,treetitle, kTRUE);
00441 }
00442 else {}
00443 return tstructure;
00444 }
00445
00446 TGo4TreeStructure * TGo4AnalysisObjectManager::CreateTreeStructure(const char* treename)
00447 {
00448 GO4TRACE((11,"TGo4AnalysisObjectManager::CreateTreeStructure(const char *)",__LINE__, __FILE__));
00449 TTree* thetree=0;
00450 if(fxTreeDir)
00451 {
00452 thetree=dynamic_cast<TTree*> (fxTreeDir->FindObjectAny(treename));
00453 }
00454 else
00455 {
00456 thetree=0;
00457 }
00458 return (CreateTreeStructure(thetree));
00459 }
00460
00461
00462 TFolder* TGo4AnalysisObjectManager::CreateMembersFolder(TObject* obj, const char* membrfoldername, TClass* cl)
00463 {
00464 if(cl==0) return 0;
00465 TList* nameslist= new TList;
00466
00467
00468 TIter biter(cl->GetListOfBases());
00469 TObject* bob=0;
00470 while((bob=biter()) !=0) {
00471 TBaseClass* baseclass = dynamic_cast<TBaseClass*>(bob);
00472 if(baseclass==0) continue;
00473
00474
00475 TClass* bclass=baseclass->GetClassPointer();
00476 if(bclass==0) continue;
00477
00478 if(!strcmp(bclass->GetName(),"TNamed")) continue;
00479
00480
00481 TFolder* subfold = CreateMembersFolder(0, bclass->GetName(), bclass);
00482 if(subfold!=0)
00483 nameslist->AddLast(subfold);
00484 }
00485
00486 TIter miter(cl->GetListOfDataMembers());
00487 TObject* nob=0;
00488
00489 while((nob=miter()) !=0) {
00490 TDataMember* mem = dynamic_cast<TDataMember*>(nob);
00491 if((mem==0) || mem->IsaPointer()) continue;
00492
00493
00494 TString sbuf;
00495
00496 switch(mem->GetArrayDim()) {
00497 case 1:
00498 sbuf = TString::Format("%s[%d]", mem->GetName(), mem->GetMaxIndex(0));
00499 break;
00500
00501 case 2:
00502 sbuf = TString::Format("%s[%d][%d]", mem->GetName(), mem->GetMaxIndex(0), mem->GetMaxIndex(1));
00503 break;
00504
00505 default:
00506 sbuf = mem->GetName();
00507 }
00508
00509 TGo4MemberStatus* state = new TGo4MemberStatus(sbuf.Data(), mem->GetFullTypeName());
00510 nameslist->AddLast(state);
00511 }
00512
00513
00514 if ((obj!=0) && (obj->InheritsFrom(TGo4CompositeEvent::Class()))) {
00515
00516 TObjArray* arr =((TGo4CompositeEvent*)obj)->getElements();
00517
00518 if (arr!=0)
00519 for (Int_t n=0;n<=arr->GetLast();n++) {
00520 TGo4EventElement* elem = (TGo4EventElement*) arr->At(n);
00521 if (elem==0) continue;
00522 TFolder* subfold = CreateMembersFolder(elem, elem->GetName(), elem->IsA());
00523 if(subfold!=0)
00524 nameslist->AddLast(subfold);
00525 }
00526 }
00527
00528 TFolder* memberfolder = fxTempFolder->AddFolder(membrfoldername, TString("Object of class ") + cl->GetName(), nameslist);
00529 fxTempFolder->Remove(memberfolder);
00530 memberfolder->SetOwner(kTRUE);
00531 return memberfolder;
00532 }
00533
00534 Bool_t TGo4AnalysisObjectManager::AddHistogram(TH1 * his, const char* subfolder, Bool_t replace)
00535 {
00536 GO4TRACE((11,"TGo4AnalysisObjectManager::AddHistogram(TH1*)",__LINE__, __FILE__));
00537 Bool_t rev = AddObjectToFolder(his,fxHistogramDir,subfolder,replace,kTRUE);
00538
00539
00540 if(rev && his) his->SetDirectory(gROOT);
00541 return rev;
00542 }
00543
00544 TH1* TGo4AnalysisObjectManager::MakeTH1(const char* histotype,
00545 const char* foldername,
00546 const char* histoname,
00547 Int_t nbinsx,
00548 Axis_t xlow,
00549 Axis_t xup,
00550 const char* title,
00551 const char* xtitle,
00552 const char* ytitle) {
00553
00554 TString htype(histotype);
00555 htype.ToUpper();
00556 if (htype.Length()==0) htype = "I";
00557 TClass* cl = 0;
00558
00559 switch (htype[0]) {
00560 case 'C' : cl = TH1C::Class(); break;
00561 case 'D' : cl = TH1D::Class(); break;
00562 case 'F' : cl = TH1F::Class(); break;
00563 case 'I' : cl = TH1I::Class(); break;
00564 case 'S' : cl = TH1S::Class(); break;
00565 default : cl = TH1I::Class();
00566 }
00567
00568 TH1* histo = (TH1*) TestObject(fxHistogramDir, foldername, histoname, cl);
00569
00570 if (histo) return histo;
00571
00572 switch(htype[0]) {
00573 case 'C' : histo = new TH1C(histoname, histoname, nbinsx, xlow, xup); break;
00574 case 'D' : histo = new TH1D(histoname, histoname, nbinsx, xlow, xup); break;
00575 case 'F' : histo = new TH1F(histoname, histoname, nbinsx, xlow, xup); break;
00576 case 'I' : histo = new TH1I(histoname, histoname, nbinsx, xlow, xup); break;
00577 case 'S' : histo = new TH1S(histoname, histoname, nbinsx, xlow, xup); break;
00578 default : histo = new TH1I(histoname, histoname, nbinsx, xlow, xup);
00579 }
00580
00581 if (title) histo->SetTitle(title);
00582 if (xtitle) histo->SetXTitle(xtitle);
00583 if (ytitle) histo->SetYTitle(ytitle);
00584 AddHistogram(histo, foldername);
00585 return histo;
00586 }
00587
00588 TH2* TGo4AnalysisObjectManager::MakeTH2(const char* histotype,
00589 const char* foldername,
00590 const char* histoname,
00591 Int_t nbinsx,
00592 Axis_t xlow,
00593 Axis_t xup,
00594 Int_t nbinsy,
00595 Axis_t ylow,
00596 Axis_t yup,
00597 const char* title,
00598 const char* xtitle,
00599 const char* ytitle) {
00600 TString htype(histotype);
00601 htype.ToUpper();
00602 if (htype.Length()==0) htype = "I";
00603
00604 TClass* cl = 0;
00605
00606 switch (htype[0]) {
00607 case 'C' : cl = TH2C::Class(); break;
00608 case 'D' : cl = TH2D::Class(); break;
00609 case 'F' : cl = TH2F::Class(); break;
00610 case 'I' : cl = TH2I::Class(); break;
00611 case 'S' : cl = TH2S::Class(); break;
00612 default : cl = TH2I::Class();
00613 }
00614
00615 TH2* histo = (TH2*) TestObject(fxHistogramDir, foldername, histoname, cl);
00616
00617 if (histo) return histo;
00618
00619 switch(htype[0]) {
00620 case 'C' : histo = new TH2C(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00621 case 'D' : histo = new TH2D(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00622 case 'F' : histo = new TH2F(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00623 case 'I' : histo = new TH2I(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00624 case 'S' : histo = new TH2S(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00625 default : histo = new TH2I(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup);
00626 }
00627
00628 if (title) histo->SetTitle(title);
00629 if (xtitle) histo->SetXTitle(xtitle);
00630 if (ytitle) histo->SetYTitle(ytitle);
00631 AddHistogram(histo, foldername);
00632 return histo;
00633 }
00634
00635 TFolder * TGo4AnalysisObjectManager::CreateBranchFolder(TObjArray* branchlist,
00636 const char* name,
00637 const char* title,
00638 Bool_t istopbranch)
00639 {
00640 GO4TRACE((11,"TGo4AnalysisObjectManager::CreateBranchFolder(TObjArray*)",__LINE__, __FILE__));
00641 if (branchlist==0) return 0;
00642
00643 TList* nameslist= new TList;
00644 TGo4ObjectStatus* state;
00645 Int_t cursor=0;
00646 TObject* entry = 0;
00647 TIter iter(branchlist);
00648 while((entry=iter()) !=0) {
00649 if(entry->InheritsFrom(TBranch::Class())) {
00650
00651 TBranch* subbranch= dynamic_cast<TBranch*> (entry);
00652 TObjArray* subbranchlist = subbranch->GetListOfBranches();
00653 if(subbranchlist!=0) {
00654 if(subbranchlist->IsEmpty()) {
00655
00656 state=new TGo4BranchStatus(subbranch);
00657 nameslist->AddLast(state);
00658 } else {
00659
00660
00661
00662 TFolder* subnames = 0;
00663
00664 TClass* cl = gROOT->GetClass(subbranch->GetClassName());
00665 if((cl!=0) && cl->InheritsFrom(TGo4CompositeEvent::Class()) && istopbranch) {
00666
00667 TGo4CompositeEvent* cevent=0;
00668 TString branchname(subbranch->GetName());
00669 Ssiz_t leng = branchname.Length();
00670 branchname.Resize(leng-1);
00671
00672 cevent = dynamic_cast<TGo4CompositeEvent*> (GetEventStructure(branchname.Data()));
00673 if(cevent!=0) {
00674
00675 Int_t skippedentries=0;
00676
00677 subnames = CreateCompositeBranchFolder(
00678 branchlist,cevent,cursor+1,
00679 &skippedentries,
00680 cevent->GetName(),
00681 cevent->GetTitle());
00682
00683
00684
00685
00686 TFolder* temp = CreateBranchFolder(subbranchlist, "dummy","dummy");
00687 subnames->GetListOfFolders()->AddAll(temp->GetListOfFolders());
00688 for(Int_t t=0;t<skippedentries;++t) {
00689 iter();
00690 cursor++;
00691 }
00692 } else {
00693
00694 subnames=CreateBranchFolder(subbranchlist,
00695 subbranch->GetName(),
00696 subbranch->GetTitle());
00697 }
00698 } else {
00699
00700 subnames=CreateBranchFolder(subbranchlist,
00701 subbranch->GetName(), subbranch->GetTitle());
00702 }
00703 nameslist->AddLast(subnames);
00704 }
00705 } else {
00706
00707
00708 state=new TGo4BranchStatus(subbranch);
00709 nameslist->AddLast(state);
00710 }
00711 }
00712 cursor++;
00713 }
00714
00715 TFolder* fold = fxTempFolder->AddFolder(name,title,nameslist);
00716 fold->SetOwner(kTRUE);
00717 fxTempFolder->Remove(fold);
00718 return fold;
00719 }
00720
00721 Bool_t TGo4AnalysisObjectManager::AddTree(TTree* tree, const char* subfolder)
00722 {
00723 GO4TRACE((11,"TGo4AnalysisObjectManager::AddTree(TTree*, char*)",__LINE__, __FILE__));
00724 return (AddObjectToFolder(tree,fxTreeDir,subfolder,kFALSE));
00725 }
00726
00727 Bool_t TGo4AnalysisObjectManager::RemoveTree(TTree * tree, const char* stepname)
00728 {
00729 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveTree(TTree*, const char*)",__LINE__, __FILE__));
00730 if (tree==0) return kFALSE;
00731
00732 TGo4LockGuard listguard(fxDirMutex);
00733 fxTreeDir->Remove(tree);
00734 return kTRUE;
00735 }
00736
00737 TH1* TGo4AnalysisObjectManager::GetHistogram(const char * name)
00738 {
00739 GO4TRACE((11,"TGo4AnalysisObjectManager::GetHistogram(char *)",__LINE__, __FILE__));
00740 TH1* rev = dynamic_cast<TH1*> (FindObjectInFolder(fxHistogramDir, name));
00741 if(rev==0) rev = dynamic_cast<TH1*> (FindObjectInFolder(fxUserDir, name));
00742 return rev;
00743 }
00744
00745 TTree * TGo4AnalysisObjectManager::GetTree(const char * name)
00746 {
00747 GO4TRACE((11,"TGo4AnalysisObjectManager::GetTree(char *)",__LINE__, __FILE__));
00748 return dynamic_cast<TTree*> (FindObjectInFolder(fxTreeDir, name));
00749 }
00750
00751 Bool_t TGo4AnalysisObjectManager::RemoveHistogram(const char * name, Bool_t del)
00752 {
00753 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveHistogram(char*)",__LINE__, __FILE__));
00754
00755 return RemoveObjectFromFolder(name, fxHistogramDir, del);
00756 }
00757
00758
00759 Bool_t TGo4AnalysisObjectManager::AddAnalysisCondition(TGo4Condition * con, const char* subfolder)
00760 {
00761 GO4TRACE((11,"TGo4AnalysisObjectManager::AddAnalysisCondition(TGo4Condition *)",__LINE__, __FILE__));
00762 return(AddObjectToFolder(con,fxConditionDir,subfolder,kTRUE));
00763 }
00764
00765 Bool_t TGo4AnalysisObjectManager::SetAnalysisCondition(const char * name, TGo4Condition* con,
00766 Bool_t counter, TFolder* parent)
00767 {
00768 GO4TRACE((11,"TGo4AnalysisObjectManager::SetAnalysisCondition(char*, TGo4Condition*, Bool_t)",__LINE__, __FILE__));
00769
00770 if(con==0) return kFALSE;
00771
00772 TGo4LockGuard listguard(fxDirMutex);
00773 Bool_t rev(kFALSE);
00774 TFolder* topfolder=0;
00775 if(parent)
00776 topfolder=parent;
00777 else
00778 topfolder=fxConditionDir;
00779
00780 TObject* searchresult=topfolder->FindObjectAny(name);
00781 if(searchresult==0)
00782 searchresult=fxUserDir->FindObjectAny(name);
00783
00784 TGo4Condition* oldcon(0);
00785 if(searchresult && searchresult->InheritsFrom(TGo4Condition::Class())) {
00786 oldcon= dynamic_cast<TGo4Condition *> (searchresult);
00787 } else
00788 if (searchresult && searchresult->InheritsFrom(TFolder::Class())) {
00789
00790 TFolder* subf=dynamic_cast<TFolder*>(searchresult);
00791 searchresult=subf->FindObjectAny(name);
00792 oldcon= dynamic_cast<TGo4Condition *> (searchresult);
00793 }
00794 if(oldcon!=0) {
00795
00796 rev = oldcon->UpdateFrom(con,counter);
00797
00798
00799 } else {
00800
00801 TGo4Condition* clonedcon = dynamic_cast<TGo4Condition*>(con->Clone());
00802
00803 TGo4PolyCond::CleanupSpecials();
00804
00805 const char* separ = strrchr(name, '/');
00806 if (separ!=0) {
00807 TString fname(name, separ-name);
00808 rev=AddObjectToFolder(clonedcon,topfolder,fname.Data(),kTRUE,kFALSE,kFALSE);
00809 } else
00810 rev=AddObjectToFolder(clonedcon,topfolder,0,kTRUE,kFALSE,kFALSE);
00811
00812 }
00813 return rev;
00814 }
00815
00816 TGo4Condition * TGo4AnalysisObjectManager::GetAnalysisCondition(const char * name, const char* cond_cl)
00817 {
00818 GO4TRACE((11,"TGo4AnalysisObjectManager::GetAnalysisCondition(char*)",__LINE__, __FILE__));
00819 TGo4Condition* cond = dynamic_cast<TGo4Condition*> (FindObjectInFolder(fxConditionDir, name));
00820
00821 if(cond==0) cond = dynamic_cast<TGo4Condition*> (FindObjectInFolder(fxUserDir, name));
00822
00823 if ((cond!=0) && (cond_cl!=0))
00824 if(!cond->InheritsFrom(cond_cl)) cond = 0;
00825
00826 return cond;
00827 }
00828
00829 TGo4WinCond* TGo4AnalysisObjectManager::MakeWindowCond(const char* foldername,
00830 const char* conditionname,
00831 Double_t xlow,
00832 Double_t xup,
00833 const char* bindhistogram,
00834 Bool_t invert)
00835 {
00836 TGo4WinCond* wcond = (TGo4WinCond*)
00837 TestObject(fxConditionDir, foldername, conditionname, TGo4WinCond::Class());
00838
00839 if (wcond) return wcond;
00840
00841 wcond = new TGo4WinCond(conditionname);
00842 wcond->SetValues(xlow, xup);
00843 if (bindhistogram!=0)
00844 wcond->SetHistogram(bindhistogram);
00845 if (invert) wcond->Invert(invert);
00846 AddAnalysisCondition(wcond, foldername);
00847 return wcond;
00848 }
00849
00850 TGo4WinCond* TGo4AnalysisObjectManager::MakeWindowCond(const char* foldername,
00851 const char* conditionname,
00852 Double_t xlow,
00853 Double_t xup,
00854 Double_t ylow,
00855 Double_t yup,
00856 const char* bindhistogram,
00857 Bool_t invert)
00858 {
00859 TGo4WinCond* wcond = (TGo4WinCond*)
00860 TestObject(fxConditionDir, foldername, conditionname, TGo4WinCond::Class());
00861
00862 if (wcond) return wcond;
00863
00864 wcond = new TGo4WinCond(conditionname);
00865 wcond->SetValues(xlow, xup, ylow, yup);
00866 if (bindhistogram!=0)
00867 wcond->SetHistogram(bindhistogram);
00868 if (invert) wcond->Invert(invert);
00869 AddAnalysisCondition(wcond, foldername);
00870 return wcond;
00871 }
00872
00873 TGo4PolyCond* TGo4AnalysisObjectManager::MakePolyCond(const char* foldername,
00874 const char* conditionname,
00875 Int_t size,
00876 Float_t (*points)[2],
00877 const char* bindhistogram,
00878 Bool_t invert)
00879 {
00880 TGo4PolyCond* pcond = (TGo4PolyCond*)
00881 TestObject(fxConditionDir, foldername, conditionname, TGo4PolyCond::Class());
00882
00883 if (pcond) return pcond;
00884
00885 TArrayF fullx(size+1), fully(size+1);
00886 int numpoints = size;
00887
00888 for (int i=0;i<numpoints;i++) {
00889 fullx[i] = points[i][0];
00890 fully[i] = points[i][1];
00891 }
00892
00893
00894 if ((fullx[0]!=fullx[numpoints-1]) || (fully[0]!=fully[numpoints-1])) {
00895 fullx[numpoints] = fullx[0];
00896 fully[numpoints] = fully[0];
00897 numpoints++;
00898 }
00899
00900 TCutG mycat("initialcut", numpoints, fullx.GetArray(), fully.GetArray());
00901 pcond = new TGo4PolyCond(conditionname);
00902 pcond->SetValues(&mycat);
00903 if (bindhistogram!=0)
00904 pcond->SetHistogram(bindhistogram);
00905 if (invert) pcond->Invert(invert);
00906 AddAnalysisCondition(pcond, foldername);
00907 return pcond;
00908 }
00909
00910
00911 Bool_t TGo4AnalysisObjectManager::RemoveAnalysisCondition(const char * name)
00912 {
00913 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveAnalysisCondition(char*)",__LINE__, __FILE__));
00914 return RemoveObjectFromFolder(name, fxConditionDir, kTRUE);
00915 }
00916
00917 TGo4ObjectStatus * TGo4AnalysisObjectManager::CreateObjectStatus(const char * name, const char* folder)
00918 {
00919 TNamed* object=GetObject(name, folder);
00920 return CreateObjectStatus(object);
00921 }
00922
00923 TGo4ObjectStatus * TGo4AnalysisObjectManager::CreateObjectStatus(TObject* obj, Bool_t fullinfo)
00924 {
00925 if(obj==0) return 0;
00926
00927 if(obj->InheritsFrom(TH1::Class()))
00928 return new TGo4HistogramStatus(dynamic_cast<TH1*> (obj),fullinfo);
00929
00930 if(obj->InheritsFrom(TGo4Parameter::Class()))
00931 return new TGo4ParameterStatus(dynamic_cast<TGo4Parameter*> (obj), fullinfo);
00932
00933 return new TGo4ObjectStatus(obj);
00934 }
00935
00936 TGo4AnalysisObjectNames * TGo4AnalysisObjectManager::CreateNamesList()
00937 {
00938 GO4TRACE((11,"TGo4AnalysisObjectManager::CreateNamesList()",__LINE__, __FILE__));
00939 TGo4LockGuard listguard(fxDirMutex);
00940 TGo4AnalysisObjectNames* namesobject=0;
00941
00942 const char* name = TGo4Analysis::Instance()->GetName();
00943 if ((name==0) || (strlen(name)==0)) name = "Go4NamesList";
00944 namesobject= new TGo4AnalysisObjectNames(name);
00945 namesobject->fxTopFolder=CreateNamesFolder(fxGo4Dir);
00946 TGo4PolyCond::CleanupSpecials();
00947 return namesobject;
00948 }
00949
00950 TFolder * TGo4AnalysisObjectManager::CreateNamesFolder(TFolder * objectfolder)
00951 {
00952 GO4TRACE((11,"TGo4AnalysisObjectManager::CreateNamesFolder(TFolder*)",__LINE__, __FILE__));
00953 if (objectfolder==0) return 0;
00954
00955 TList* nameslist= new TList;
00956 TIter listiter(objectfolder->GetListOfFolders());
00957 TObject* entry;
00958 while((entry=listiter())!=0) {
00959 if(entry->InheritsFrom(TFolder::Class())) {
00960
00961
00962 TFolder* subobj= dynamic_cast<TFolder*> (entry);
00963 TFolder* subnames = CreateNamesFolder(subobj);
00964 nameslist->AddLast(subnames);
00965 } else
00966
00967 if (entry->InheritsFrom(TTree::Class())) {
00968
00969 TTree* subobj= dynamic_cast<TTree*> (entry);
00970 TGo4TreeStructure* treestruct=CreateTreeStructure(subobj);
00971 nameslist->AddLast(treestruct);
00972 } else
00973
00974 if(entry->InheritsFrom(TGo4EventElement::Class())) {
00975 TFolder* evfolder = CreateMembersFolder(entry, entry->GetName(), entry->IsA());
00976 if (evfolder!=0)
00977 nameslist->AddLast(evfolder);
00978 } else {
00979
00980 TGo4ObjectStatus*state = CreateObjectStatus(entry,kFALSE);
00981 if(state!=0)
00982 nameslist->AddLast(state);
00983 }
00984 }
00985
00986 TFolder* namesfolder = fxTempFolder->AddFolder(objectfolder->GetName(),objectfolder->GetTitle(),nameslist);
00987 fxTempFolder->Remove(namesfolder);
00988 namesfolder->SetOwner(kTRUE);
00989
00990 return namesfolder;
00991 }
00992
00993 TFolder * TGo4AnalysisObjectManager::GetObjectFolder()
00994 {
00995 return fxGo4Dir;
00996 }
00997
00998 Bool_t TGo4AnalysisObjectManager::AddEventStore(TGo4EventStore * store)
00999 {
01000 GO4TRACE((11,"TGo4AnalysisObjectManager::AddEventStore(TGo4EventStore*)",__LINE__, __FILE__));
01001 return (AddObjectToFolder(store,fxStoreDir,0,kFALSE));
01002 }
01003
01004 Bool_t TGo4AnalysisObjectManager::RemoveEventStore(TGo4EventStore * store)
01005 {
01006 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveEventStore(TGo4EventStore*)",__LINE__, __FILE__));
01007 Bool_t rev=kFALSE;
01008 if(store)
01009 {
01010 TGo4LockGuard listguard(fxDirMutex);
01011 fxStoreDir->Remove(store);
01012 rev=kTRUE;
01013 }
01014 else
01015 {
01016 rev=kFALSE;
01017 }
01018 return rev;
01019 }
01020
01021 Bool_t TGo4AnalysisObjectManager::AddEventSource(TGo4EventSource * source)
01022 {
01023 GO4TRACE((11,"TGo4AnalysisObjectManager::AddEventSource(TGo4EventSource*)",__LINE__, __FILE__));
01024 return (AddObjectToFolder(source,fxSourceDir,0,kFALSE));
01025 }
01026
01027 Bool_t TGo4AnalysisObjectManager::RemoveEventSource(TGo4EventSource* source)
01028 {
01029 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveEventSource(TGo4EventSource*)",__LINE__, __FILE__));
01030 Bool_t rev=kFALSE;
01031 if(source)
01032 {
01033 TGo4LockGuard listguard(fxDirMutex);
01034 fxSourceDir->Remove(source);
01035 rev=kTRUE;
01036 }
01037 else
01038 {
01039 rev=kFALSE;
01040 }
01041 return rev;
01042 }
01043 Bool_t TGo4AnalysisObjectManager::AddEventProcessor(TGo4EventProcessor * pro)
01044 {
01045 GO4TRACE((11,"TGo4AnalysisObjectManager::AddEventProcessor(TGo4EventProcessor*)",__LINE__, __FILE__));
01046 return (AddObjectToFolder(pro,fxProcessorDir,0,kFALSE));
01047 }
01048
01049 Bool_t TGo4AnalysisObjectManager::RemoveEventProcessor(TGo4EventProcessor * pro)
01050 {
01051 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveEventProcessor(TGo4EventProcessr*)",__LINE__, __FILE__));
01052 Bool_t rev=kFALSE;
01053 if(pro)
01054 {
01055 TGo4LockGuard listguard(fxDirMutex);
01056 fxProcessorDir->Remove(pro);
01057 rev=kTRUE;
01058 }
01059 else
01060 {
01061 rev=kFALSE;
01062 }
01063 return rev;
01064 }
01065 Bool_t TGo4AnalysisObjectManager::AddEventStructure(TGo4EventElement * ev)
01066 {
01067 GO4TRACE((11,"TGo4AnalysisObjectManager::AddEventStructure(TGo4EventElement*)",__LINE__, __FILE__));
01068 return (AddObjectToFolder(ev,fxEventDir,0,kFALSE));
01069 }
01070
01071 Bool_t TGo4AnalysisObjectManager::RemoveEventStructure(TGo4EventElement * ev)
01072 {
01073 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveEventStructure(TGo4EventElement*)",__LINE__, __FILE__));
01074 Bool_t rev=kFALSE;
01075 if(ev!=0) {
01076 TGo4LockGuard listguard(fxDirMutex);
01077 fxEventDir->Remove(ev);
01078
01079 CleanupDynamicLists(ev);
01080 rev=kTRUE;
01081 }
01082 return rev;
01083 }
01084
01085 TGo4EventElement * TGo4AnalysisObjectManager::GetEventStructure(const char * name)
01086 {
01087 GO4TRACE((11,"TGo4AnalysisObjectManager::GetEvenStructure(char *)",__LINE__, __FILE__));
01088
01089 if ((name==0) || (strlen(name)==0)) return 0;
01090
01091 TString path(name);
01092 TGo4EventElement* curr(0);
01093
01094 while (path.Length()>0) {
01095 Int_t pos = path.Index("/");
01096 if (pos==0) { path.Remove(0, 1); continue; }
01097
01098 TString sub = path;
01099 if (pos>0) { sub.Resize(pos); path.Remove(0, pos+1); }
01100 else { path.Clear(); }
01101
01102 if (curr==0)
01103 curr = dynamic_cast<TGo4EventElement*> (FindObjectInFolder(fxEventDir, sub.Data()));
01104 else {
01105 TGo4EventElement* chld = curr->GetChild(sub.Data());
01106
01107
01108
01109
01110 if ((chld==0) && curr->InheritsFrom(sub.Data())) return curr;
01111 curr = chld;
01112 }
01113
01114 if (curr==0) return 0;
01115 }
01116
01117 return curr;
01118 }
01119
01120 Bool_t TGo4AnalysisObjectManager::AddDynamicEntry(TGo4DynamicEntry* entry)
01121 {
01122 if(entry) entry->Reset();
01123 return AddObjectToFolder(entry, fxDynListDir, 0, kTRUE, kFALSE, kFALSE);
01124 }
01125
01126 Bool_t TGo4AnalysisObjectManager::ResetBackStores(Bool_t clearflag)
01127 {
01128 GO4TRACE((11,"TGo4AnalysisObjectManager::ResetBackStores()",__LINE__, __FILE__));
01129 Bool_t rev=kTRUE;
01130 TIter iter(fxStoreDir->GetListOfFolders());
01131 TObject* entry = 0;
01132 while((entry=iter()) !=0) {
01133 TGo4BackStore* bs= dynamic_cast<TGo4BackStore*>(entry);
01134 if(bs!=0) bs->Reset(clearflag);
01135 }
01136 return rev;
01137 }
01138
01139 void TGo4AnalysisObjectManager::CloseAnalysis()
01140 {
01141 GO4TRACE((14,"TGo4AnalysisObjectManager::CloseAnalysis()",__LINE__, __FILE__));
01142 ResetCurrentDynList();
01143 fiDynListCount=0;
01144 TGo4Analysis::Instance()->Message(0,"Analysis Object Manager -- Dynamic List was reset.");
01145 }
01146
01147 void TGo4AnalysisObjectManager::SaveObjects(TFile* file)
01148 {
01149 if(!file) return;
01150 TGo4Analysis::Instance()->Message(0,"Analysis Object Manager -- Saving objects to file %s",file->GetName());
01151 fxGo4Dir->RecursiveRemove(fxTreeDir);
01152 fxGo4Dir->RecursiveRemove(fxAnalysisDir);
01154
01157 TDirectory* savdir=gDirectory;
01158 file->cd();
01159
01160
01161 SaveFolder(fxGo4Dir);
01162 file->Write(0,TObject::kOverwrite);
01163 savdir->cd();
01164 RemoveFromDir(fxGo4Dir,file);
01166 fxGo4Dir->Add(fxTreeDir);
01167 fxGo4Dir->Add(fxAnalysisDir);
01168 }
01169 Bool_t TGo4AnalysisObjectManager::AddParameter(TGo4Parameter * par, const char* subfolder)
01170 {
01171 GO4TRACE((11,"TGo4AnalysisObjectManager::AddParameter(TGo4Parameter *)",__LINE__, __FILE__));
01172 return (AddObjectToFolder(par,fxParameterDir,subfolder,kTRUE));
01173 }
01174
01175 Bool_t TGo4AnalysisObjectManager::SetParameter(const char* name, TGo4Parameter * par, TFolder* parent)
01176 {
01177 GO4TRACE((11,"TGo4AnalysisObjectManager::SetParameter(const char*, TGo4Parameter*)",__LINE__, __FILE__));
01178
01179 if (par==0) return kFALSE;
01180
01181 Bool_t rev(kFALSE);
01182 TFolder* topfolder = parent ? parent : fxParameterDir;
01183 TGo4Parameter* oldpar= dynamic_cast<TGo4Parameter*> (topfolder->FindObjectAny(name));
01184 if(oldpar!=0) {
01185
01186 rev = oldpar->UpdateFrom(par);
01187 TGo4Log::Info("Updated parameter %s from parameter %s", name, par->GetName());
01188
01189 } else {
01190
01191 TGo4Parameter* clonedpar=dynamic_cast<TGo4Parameter*>(par->Clone());
01192
01193 const char* separ = strrchr(name, '/');
01194 if (separ!=0) {
01195 TString fname(name, separ-name);
01196 rev=AddObjectToFolder(clonedpar,topfolder, fname.Data(), kTRUE);
01197 TGo4Log::Info("Added new parameter %s to folder %s/%s", clonedpar->GetName(), topfolder->GetName(), fname.Data());
01198 } else
01199 rev=AddObjectToFolder(clonedpar,topfolder,0,kTRUE);
01200 }
01201 return rev;
01202 }
01203
01204 Bool_t TGo4AnalysisObjectManager::SetParameterStatus(const char* name, TGo4ParameterStatus* status, TFolder* parent)
01205 {
01206 GO4TRACE((11,"TGo4AnalysisObjectManager::SetParameter(char*, TGo4Parameter*)",__LINE__, __FILE__));
01207
01208 if (status==0) return kFALSE;
01209
01210 Bool_t rev (kFALSE);
01211 TFolder* topfolder = (parent!=0) ? parent : fxParameterDir;
01212
01213 TGo4Parameter* oldpar= dynamic_cast<TGo4Parameter*> (topfolder->FindObjectAny(name));
01214 if(oldpar!=0) {
01215
01216 rev = status->UpdateParameterValues(oldpar);
01217 } else {
01218
01219 TGo4Parameter* clonedpar = status->CreateParameter();
01220
01221
01222 const char* separ = strrchr(name, '/');
01223 if (separ!=0) {
01224 TString fname(name, separ-name);
01225 rev=AddObjectToFolder(clonedpar,topfolder, fname.Data(), kTRUE);
01226 } else {
01227 rev=AddObjectToFolder(clonedpar,topfolder,0,kTRUE);
01228 }
01229 }
01230 return rev;
01231 }
01232
01233
01234
01235 TGo4Parameter * TGo4AnalysisObjectManager::GetParameter(const char * name, const char* parameter_class)
01236 {
01237 GO4TRACE((11,"TGo4AnalysisObjectManager::GetParameter(char*)",__LINE__, __FILE__));
01238 TGo4Parameter* rev=dynamic_cast<TGo4Parameter *> (FindObjectInFolder(fxParameterDir,name));
01239 if(rev==0) rev= dynamic_cast<TGo4Parameter *> (FindObjectInFolder(fxUserDir,name));
01240 if ((rev!=0) && (parameter_class!=0))
01241 if (!rev->InheritsFrom(parameter_class)) rev=0;
01242 return rev;
01243 }
01244
01245 Bool_t TGo4AnalysisObjectManager::RemoveParameter(const char * name)
01246 {
01247 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveParameter(char*)",__LINE__, __FILE__));
01248 return RemoveObjectFromFolder(name, fxParameterDir, kTRUE);
01249 }
01250
01251 Bool_t TGo4AnalysisObjectManager::AddPicture(TGo4Picture * pic, const char* subfolder)
01252 {
01253 GO4TRACE((11,"TGo4AnalysisObjectManager::AddPicture(TGo4Picture *)",__LINE__, __FILE__));
01254 if(!pic) return kFALSE;
01255
01256
01257 return (AddObjectToFolder(pic,fxPictureDir,subfolder,kTRUE));
01258 }
01259
01260 Bool_t TGo4AnalysisObjectManager::SetPicture(const char* name, TGo4Picture * pic, TFolder* parent)
01261 {
01262 GO4TRACE((11,"TGo4AnalysisObjectManager::SetPicture(char*, TGo4Picture*)",__LINE__, __FILE__));
01263
01264 if (pic==0) return kFALSE;
01265
01266 Bool_t rev(kTRUE);
01267 TFolder* topfolder=0;
01268 if(parent)
01269 topfolder=parent;
01270 else
01271 topfolder=fxPictureDir;
01272
01273 TGo4Picture* oldpic = dynamic_cast<TGo4Picture *> (topfolder->FindObjectAny(name));
01274 if(oldpic!=0) {
01275
01276 oldpic->UpdateFrom(pic);
01277
01278 } else {
01279
01280 TGo4Picture* clonedpic = dynamic_cast<TGo4Picture*>(pic->Clone());
01281
01282
01283 const char* separ = strrchr(name, '/');
01284 if (separ!=0) {
01285 TString fname(name, separ-name);
01286 rev = AddObjectToFolder(clonedpic, topfolder, fname.Data(),kTRUE);
01287 } else
01288 rev = AddObjectToFolder(clonedpic, topfolder, 0, kTRUE);
01289 }
01290 return rev;
01291 }
01292
01293 TGo4Picture * TGo4AnalysisObjectManager::GetPicture(const char * name)
01294 {
01295 GO4TRACE((11,"TGo4AnalysisObjectManager::GetPicture(char*)",__LINE__, __FILE__));
01296 TGo4Picture* rev=dynamic_cast<TGo4Picture *> (FindObjectInFolder(fxPictureDir, name));
01297 if(rev==0) rev=dynamic_cast<TGo4Picture *> (FindObjectInFolder(fxUserDir, name));
01298 return rev;
01299 }
01300
01301 Bool_t TGo4AnalysisObjectManager::RemovePicture(const char * name)
01302 {
01303 GO4TRACE((11,"TGo4AnalysisObjectManager::RemovePicture(char*)",__LINE__, __FILE__));
01304 return RemoveObjectFromFolder(name, fxPictureDir, kTRUE);
01305 }
01306
01307 Bool_t TGo4AnalysisObjectManager::AddCanvas(TCanvas * can, const char* subfolder)
01308 {
01309 GO4TRACE((11,"TGo4AnalysisObjectManager::AddCanvas(TCanvas *)",__LINE__, __FILE__));
01310
01311 Bool_t rev = AddObjectToFolder(can,fxCanvasDir,subfolder,kFALSE);
01312
01313 if (rev && can) can->SetBit(kMustCleanup);
01314
01315
01316
01317
01318 return rev;
01319 }
01320
01321 TCanvas * TGo4AnalysisObjectManager::GetCanvas(const char * name)
01322 {
01323 GO4TRACE((11,"TGo4AnalysisObjectManager::GetPicture(char*)",__LINE__, __FILE__));
01324 TCanvas* rev=dynamic_cast<TCanvas*> (FindObjectInFolder(fxCanvasDir, name));
01325 if(rev==0) rev=dynamic_cast<TCanvas*> (FindObjectInFolder(fxCanvasDir, name));
01326 return rev;
01327 }
01328
01329 Bool_t TGo4AnalysisObjectManager::RemoveCanvas(const char * name)
01330 {
01331 GO4TRACE((11,"TGo4AnalysisObjectManager::RemovePicture(char*)",__LINE__, __FILE__));
01332 return RemoveObjectFromFolder(name, fxCanvasDir, kTRUE);
01333 }
01334
01335
01336 Bool_t TGo4AnalysisObjectManager::LoadObjects(TFile* obfile)
01337 {
01338 GO4TRACE((11,"TGo4AnalysisObjectManager::LoadObjects(TFile*)",__LINE__, __FILE__));
01339 Bool_t rev=kFALSE;
01340 if(obfile)
01341 {
01342 TObject* ob=obfile->Get(TGo4AnalysisObjectManager::fgcTOPFOLDER);
01343 TFolder* top= dynamic_cast<TFolder*>(ob);
01344 if(top)
01345 {
01346
01347
01348 rev=LoadFolder(top,fxGo4Dir,kFALSE);
01349 }
01350 else
01351 {
01352
01353
01354 rev=LoadFolder(obfile,fxGo4Dir,kFALSE);
01355 }
01356 TGo4PolyCond::CleanupSpecials();
01357 ResetCurrentDynList();
01358 }
01359
01360 return rev;
01361 }
01362
01363 void TGo4AnalysisObjectManager::ResetCurrentDynList()
01364 {
01365 TGo4DynamicList::ResetEntries(fxDynListDir);
01366 }
01367
01368 void TGo4AnalysisObjectManager::ProcessDynamicList()
01369 {
01370 fiDynListCount++;
01371
01372
01373 Bool_t processtrees = (fiDynListCount % fiDynListInterval)==0;
01374 TGo4DynamicList::ProcessEntries(fxDynListDir, processtrees, GetDynListInterval());
01375 if(processtrees) ResetBackStores();
01376 }
01377
01378 void TGo4AnalysisObjectManager::PrintDynamicList()
01379 {
01380 TGo4DynamicList::PrintEntries(fxDynListDir);
01381 }
01382
01383 Bool_t TGo4AnalysisObjectManager::AddDynamicHistogram(const char* name,
01384 const char* histo,
01385 const char* hevx, const char* hmemx,
01386 const char* hevy, const char* hmemy,
01387 const char* hevz, const char* hmemz,
01388 const char* condition,
01389 const char* cevx, const char* cmemx,
01390 const char* cevy, const char* cmemy)
01391 {
01392 if(name==0 || histo==0 || hevx==0 || hmemx==0) return kFALSE;
01393 TGo4HistogramEntry* entry = new TGo4HistogramEntry(name);
01394
01395 entry->SetHistogramName(histo);
01396
01397 if ((hevx!=0) && (hmemx!=0)) {
01398 entry->SetHisEventName(0, hevx);
01399 entry->SetHisVarName(0, hmemx);
01400 }
01401
01402 if ((hevy!=0) && (hmemy!=0)) {
01403 entry->SetHisEventName(1, hevy);
01404 entry->SetHisVarName(1, hmemy);
01405 }
01406
01407 if ((hevz!=0) && (hmemz!=0)) {
01408 entry->SetHisEventName(2, hevz);
01409 entry->SetHisVarName(2, hmemz);
01410 }
01411
01412 if((condition!=0) && (cevx!=0) && (cmemx!=0)) {
01413 entry->SetConditionName(condition);
01414 entry->SetConEventName(0, cevx);
01415 entry->SetConVarName(0, cmemx);
01416 if((cevy!=0) && (cmemy!=0)) {
01417 entry->SetConEventName(1, cevy);
01418 entry->SetConVarName(1, cmemy);
01419 }
01420 }
01421
01422 return AddDynamicEntry(entry);
01423 }
01424
01425 Bool_t TGo4AnalysisObjectManager::AddTreeHistogram(const char* hisname, const char* treename, const char* varexp, const char* cutexp)
01426 {
01427 GO4TRACE((11,"TGo4AnalysisObjectManager::AddTreeHistogram(char*,...)",__LINE__, __FILE__));
01428
01429 Bool_t rev=kFALSE;
01430 TGo4TreeHistogramEntry* tentry =
01431 new TGo4TreeHistogramEntry(hisname, treename, varexp, cutexp);
01432 if(AddDynamicEntry(tentry)) {
01433 TGo4Analysis::Instance()->Message(0,"Analysis added tree histogram %s to dynamic list", tentry->GetName());
01434 rev=kTRUE;
01435 } else {
01436 TGo4Analysis::Instance()->Message(0,"!!! Analysis AddTreeHistogram- ERROR: entry %s already exists !!!", tentry->GetName());
01437 delete tentry;
01438 }
01439 return rev;
01440 }
01441
01442
01443 Bool_t TGo4AnalysisObjectManager::RemoveDynamicEntry(const char* entryname)
01444 {
01445 return RemoveObjectFromFolder(entryname, fxDynListDir, kTRUE);
01446 }
01447
01448
01449 TFolder* TGo4AnalysisObjectManager::FindSubFolder(TFolder* parent, const char* subfolder, Bool_t create)
01450 {
01451 GO4TRACE((11,"TGo4AnalysisObjectManager::FindSubFolder(TFolder*, const char*, Bool_t)",__LINE__, __FILE__));
01452 TGo4LockGuard dirguard(fxDirMutex);
01453 TFolder* result=0;
01454 if(parent==0) return 0;
01455 if(subfolder==0) return parent;
01456 const char* separ = strchr(subfolder,'/');
01457 if(separ!=0) {
01458
01459 TString subname(subfolder, separ - subfolder);
01460
01461
01462 TFolder* nextsubfolder = FindSubFolder(parent, subname.Data(), create);
01463 result = FindSubFolder(nextsubfolder, separ+1,create);
01464 } else {
01465
01466 TIter listiter(parent->GetListOfFolders());
01467 TObject* entry;
01468 while((entry=listiter()) !=0)
01469 if(entry->InheritsFrom(TFolder::Class()))
01470 if(!strcmp(subfolder,entry->GetName())) {
01471 result= dynamic_cast<TFolder*>(entry);
01472 break;
01473 }
01474 if(result==0 && create)
01475 result=parent->AddFolder(subfolder,"UserFolder");
01476 }
01477 return result;
01478 }
01479
01480
01481 Bool_t TGo4AnalysisObjectManager::AddObjectToFolder(TObject * ob,
01482 TFolder* fold,
01483 const char* subfolder,
01484 Bool_t replace,
01485 Bool_t uniquename,
01486 Bool_t resetbits)
01487 {
01488 GO4TRACE((11,"TGo4AnalysisObjectManager::AddObjectToFolder(TObject *, TFolder*, const char*, Bool_t)",__LINE__, __FILE__));
01489
01490 TGo4LockGuard dirguard(fxDirMutex);
01491 if(fold==0) return kFALSE;
01492
01493 if (ob==0) {
01494 GO4TRACE((12,"TGo4AnalysisObjectManager::AddObjectToFolder - zero object",__LINE__, __FILE__));
01495 return kFALSE;
01496 }
01497
01498 if(resetbits) {
01499 ob->ResetBit(TGo4Status::kGo4NoReset);
01500 ob->ResetBit(TGo4Status::kGo4CanDelete);
01501 }
01502
01503 TString subname;
01504 if (subfolder && (strlen(subfolder)!=0)) {
01505 subname = subfolder;
01506 if (subname[subname.Length()-1] == '/')
01507 subname.Resize(subname.Length()-1);
01508 }
01509
01510 TObject* oldob=0;
01511 if(uniquename) {
01512
01513 oldob=fold->FindObjectAny( ob->GetName() );
01514 } else {
01515 TString obname;
01516
01517 if (subname.Length()>0)
01518 obname = subname + "/" + ob->GetName();
01519 else
01520 obname = ob->GetName();
01521
01522
01523 oldob = fold->FindObjectAny(obname.Data());
01524 }
01525
01526
01527 if(oldob) {
01528
01529 if(replace && ob!=oldob) {
01530
01531 fold->RecursiveRemove(oldob);
01532 CleanupDynamicLists(oldob);
01533
01534
01535
01536 delete oldob;
01537 } else {
01538
01539
01540
01541 return kFALSE;
01542 }
01543 }
01544
01545 TFolder* addDir(0);
01546 if(subfolder)
01547 addDir = FindSubFolder(fold, subname, kTRUE);
01548 if(addDir==0) addDir = fold;
01549
01550 addDir->Add(ob);
01551
01552 return kTRUE;
01553 }
01554
01555
01556 Bool_t TGo4AnalysisObjectManager::RemoveObjectFromFolder(const char* fullname, TFolder* fold, Bool_t isDel)
01557 {
01558 GO4TRACE((11,"TGo4AnalysisObjectManager::RemoveObjectFromFolder(const char*, TFolder*, Bool_t)",__LINE__, __FILE__));
01559
01560 if(fold==0) return kFALSE;
01561 TGo4LockGuard dirguard(fxDirMutex);
01562 TObject* obj = 0;
01563 Int_t buflen = fguSUBFOLDERMAXLEN;
01564 char buffer[fguSUBFOLDERMAXLEN];
01565 if(fullname) {
01566 strncpy(buffer,fullname,buflen-10);
01567 obj = fold->FindObjectAny(buffer);
01568 }
01569
01570 if(obj!=0) {
01571 fold->RecursiveRemove(obj);
01572 CleanupDynamicLists(obj);
01573 if (isDel) delete obj;
01574 TGo4Analysis::Instance()->Message(0,"Analysis: removed object %s",buffer);
01575 return kTRUE;
01576 }
01577
01578 TGo4Analysis::Instance()->Message(0,"!!! Analysis: removing object %s FAILED !!!",buffer);
01579 return kFALSE;
01580 }
01581
01582 Bool_t TGo4AnalysisObjectManager::LoadFolder(TFolder* source, TFolder* destination, Bool_t replace)
01583 {
01584 if (source==0) return kFALSE;
01585 GO4TRACE((11,"TGo4AnalysisObjectManager::LoadFolder(TFolder*, TFolder*, Bool_t replace)",__LINE__, __FILE__));
01586 TGo4LockGuard dirguard(fxDirMutex);
01587 Bool_t rev=kTRUE;
01588 TIter folderiter(source->GetListOfFolders());
01589 TObject* ob=0;
01590 while(( ob=folderiter() ) !=0)
01591 {
01592 if(ob->InheritsFrom(TFolder::Class()))
01593 {
01594 TFolder* subfolder =dynamic_cast<TFolder*> (ob);
01595 if(subfolder)
01596 {
01597
01598 TFolder* subdest=FindSubFolder(destination,subfolder->GetName(), kTRUE);
01599 LoadFolder(subfolder,subdest,replace);
01600 }
01601 }
01602 else
01603 {
01604 rev=PutToFolder(ob,destination,replace);
01605 }
01606 }
01607 return rev;
01608 }
01609
01610 Bool_t TGo4AnalysisObjectManager::LoadFolder(TDirectory* source, TFolder* destination, Bool_t replace)
01611 {
01612 GO4TRACE((11,"TGo4AnalysisObjectManager::LoadFolder(TDirectory*, TFolder*, Bool_t replace)",__LINE__, __FILE__));
01613 if(!source || !destination) return kFALSE;
01614 TGo4LockGuard dirguard(fxDirMutex);
01615 Bool_t rev=kTRUE;
01616 TDirectory* savdir=gDirectory;
01617 source->cd();
01618 source->ReadKeys();
01619 TIter keyiter(source->GetListOfKeys());
01620 TObject* keyob=0;
01621 TKey* key=0;
01622 while(( keyob=keyiter() ) !=0)
01623 {
01624 key=dynamic_cast<TKey*>(keyob);
01625 if(key==0)
01626 {
01627 TGo4Analysis::Instance()->Message(3,"Analysis LoadFolder: ZERO key in directory %s",
01628 source->GetName());
01629 return kFALSE;
01630 }
01631
01632 TObject* ob = key->ReadObj();
01633 if(ob==0)
01634 {
01635 TGo4Analysis::Instance()->Message(2,"Analysis LoadFolder: Retrying to read key %s ...",
01636 key->GetName());
01637 ob=source->Get(key->GetName());
01638 if(ob==0)
01639 {
01640 TGo4Analysis::Instance()->Message(3,"Analysis LoadFolder: Failed to read key %s !",
01641 key->GetName());
01642 return kFALSE;
01643 }
01644 }
01645
01646 if(ob->InheritsFrom(TDirectory::Class()))
01647 {
01648 TDirectory* subdir =dynamic_cast<TDirectory*> (ob);
01649 if(subdir)
01650 {
01651
01652 Bool_t inpicturefolder=kFALSE;
01653 if(!strcmp(subdir->GetName(),fgcPICTFOLDER)) inpicturefolder=kTRUE;
01654 if(inpicturefolder) fbSuppressLoadHistograms=kTRUE;
01655 TFolder* subdest=FindSubFolder(destination,subdir->GetName(), kTRUE);
01656 rev=LoadFolder(subdir,subdest,replace);
01657 if(inpicturefolder) fbSuppressLoadHistograms=kFALSE;
01658 }
01659 }
01660 else
01661 {
01662 rev=PutToFolder(ob,destination,replace);
01663 }
01664 }
01665 savdir->cd();
01666 return rev;
01667 }
01668
01669 Bool_t TGo4AnalysisObjectManager::PutToFolder(TObject* ob, TFolder* destination, Bool_t replace)
01670 {
01671 if(!ob || !destination) return kFALSE;
01672 Bool_t rev=kTRUE;
01673
01674 if (ob->InheritsFrom(TGo4DynamicEntry::Class())) {
01675
01676 TGo4DynamicEntry* dentry =dynamic_cast<TGo4DynamicEntry*> ( ob->Clone() );
01677 AddDynamicEntry(dentry);
01678
01679 } else
01680 if(ob->InheritsFrom(TGo4Parameter::Class())) {
01681
01682 TGo4Parameter* par = dynamic_cast<TGo4Parameter*>(ob);
01683 SetParameter(ob->GetName(),par,destination);
01684 } else
01685 if(ob->InheritsFrom(TGo4Picture::Class())) {
01686
01687 TGo4Picture* pic =dynamic_cast<TGo4Picture*>(ob);
01688
01689 SetPicture(ob->GetName(),pic,destination);
01690 } else
01691 if(ob->InheritsFrom(TGo4Condition::Class())) {
01692
01693 TGo4Condition* con =dynamic_cast<TGo4Condition*>(ob);
01694 SetAnalysisCondition(ob->GetName(),con,kTRUE, destination);
01695 } else
01696 if(ob->InheritsFrom(TH1::Class())) {
01697 if(fbSuppressLoadHistograms) return kFALSE;
01698
01699 TH1* his = dynamic_cast<TH1*>(ob);
01700 if(AddObjectToFolder(his,destination,0,replace,kFALSE,kFALSE)) {
01701 his->SetDirectory(gROOT);
01702 TGo4Analysis::Instance()->Message(0,"Analysis LoadFolder: Histogram %s was loaded.",
01703 his->GetName());
01704
01705 }
01706 } else
01707 if(ob->InheritsFrom(TCanvas::Class())) {
01708 TObject* addob = ob->Clone();
01709 if(AddObjectToFolder(addob, destination, 0, replace)) {
01710 TGo4Analysis::Instance()->Message(0,"Analysis LoadFolder: Object %s was loaded.", addob->GetName());
01711 } else {
01712
01713 delete addob;
01714 if (gPad==addob) gPad = 0;
01715 }
01716 } else {
01717
01718
01719 TObject* addob = ob->Clone();
01720 if(AddObjectToFolder(addob,destination,0,replace)) {
01721 TGo4Analysis::Instance()->Message(0,"Analysis LoadFolder: Object %s was loaded.", addob->GetName());
01722 } else {
01723 delete addob;
01724 }
01725 }
01726 return rev;
01727 }
01728
01729
01730
01731 Bool_t TGo4AnalysisObjectManager::SaveFolder(TFolder* source)
01732 {
01733 if (source==0) return kFALSE;
01734 TGo4LockGuard dirguard(fxDirMutex);
01735 Bool_t rev=kTRUE;
01736 TIter folderiter(source->GetListOfFolders());
01737 TObject* ob=0;
01738 while(( ob=folderiter() ) !=0) {
01739 if(ob->InheritsFrom(TFolder::Class())) {
01740 TFolder* subfolder =dynamic_cast<TFolder*> (ob);
01741 if(subfolder)
01742 {
01743 TDirectory* currentdir=gDirectory;
01744 const char* subfoldername=subfolder->GetName();
01745 TDirectory* subdir=dynamic_cast<TDirectory*>(currentdir->Get(subfoldername));
01746 if(subdir==0)
01747 {
01748 subdir=currentdir->mkdir(subfoldername,"subdir");
01749
01750 }
01751 else
01752 {
01753
01754 }
01755
01756 if(subdir)
01757 {
01758 subdir->cd();
01759
01760 SaveFolder(subfolder);
01761 }
01762 else
01763 {
01764 TGo4Analysis::Instance()->Message(2,"Analysis SaveFolder: Could not assign subdirectory %s to folder.",
01765 subfoldername);
01766 }
01767 currentdir->cd();
01768 }
01769 } else
01770 AppendToDir(ob,gDirectory);
01771 }
01772 return rev;
01773 }
01774
01775 void TGo4AnalysisObjectManager::AppendToDir(TObject* ob, TDirectory* dir)
01776 {
01777 if(!ob || !dir) return;
01778
01779
01780
01781
01782
01785
01786 dir->Append(ob);
01787 }
01788
01789 void TGo4AnalysisObjectManager::RemoveFromDir(TFolder* fold, TDirectory* dir)
01790 {
01791 if((fold==0) || (dir==0)) return;
01792
01793 TIter iter(fold->GetListOfFolders());
01794 TObject* ob = 0;
01795 while((ob = iter()) !=0) {
01796 if(ob->InheritsFrom(TFolder::Class())) {
01797 TFolder* subfolder =dynamic_cast<TFolder*> (ob);
01798 if(subfolder!=0)
01799 RemoveFromDir(subfolder,dir);
01800 } else
01801 dir->RecursiveRemove(ob);
01802 }
01803 }
01804
01805 Int_t TGo4AnalysisObjectManager::PrintFolder(TFolder* fold, Option_t* opt, const char* expression)
01806 {
01807 if(fold==0) return 0;
01808
01809 GO4TRACE((11,"TGo4AnalysisObjectManager::PrintFolder(TFolder*, Option_t*)",__LINE__, __FILE__));
01810 TGo4LockGuard dirguard(fxDirMutex);
01811 Int_t totalsize=0;
01812 TROOT::IndentLevel();
01813 TROOT::IncreaseDirLevel();
01814 std::cout <<"+Folder "<<fold->GetName()<<" content:" << std::endl;
01815 TIter listiter(fold->GetListOfFolders());
01816 TObject* ob=0;
01817 while((ob=listiter())!=0) {
01818 if(ob->InheritsFrom(TFolder::Class()))
01819 totalsize+=PrintFolder(dynamic_cast<TFolder*>(ob),opt,expression);
01820 else
01821 if(IsMatching(ob->GetName(),expression)) {
01822 TROOT::IndentLevel();
01823 ob->Print(opt);
01824 TGo4ObjectStatus* temp = CreateObjectStatus(ob);
01825 if(temp!=0) totalsize += temp->GetObjectSize();
01826 delete temp;
01827 }
01828 }
01829 TROOT::DecreaseDirLevel();
01830 TROOT::IndentLevel();
01831 std::cout <<"++++End "<<fold->GetName()<<"++++++++++" << std::endl;
01832 return totalsize;
01833 }
01834
01835 Bool_t TGo4AnalysisObjectManager::ClearFolder(TFolder* fold)
01836 {
01837 GO4TRACE((11,"TGo4AnalysisObjectManager::ClearFolder(TFolder*, Option_t*)",__LINE__, __FILE__));
01838 if(fold==0) return kFALSE;
01839 TGo4LockGuard dirguard(fxDirMutex);
01840 TIter iter(fold->GetListOfFolders());
01841 TObject* ob=0;
01842 while((ob=iter())!=0)
01843 if(ob->InheritsFrom(TFolder::Class()))
01844 ClearFolder(dynamic_cast<TFolder*>(ob));
01845 else
01846 ClearObject(ob);
01847 return kTRUE;
01848 }
01849
01850 Bool_t TGo4AnalysisObjectManager::ClearObject(TObject* ob)
01851 {
01852 GO4TRACE((11,"TGo4AnalysisObjectManager::ClearObject(TObject*)",__LINE__, __FILE__));
01853 Bool_t rev=kFALSE;
01854 if(ob)
01855 {
01856 if(ob->TestBit(TGo4Status::kGo4NoReset)) return kFALSE;
01857 rev=kTRUE;
01858 if(ob->InheritsFrom(TH1::Class()))
01859 {
01860 TH1* his= dynamic_cast<TH1*>(ob);
01861 if (his) his->Reset();
01862 }
01863 else if(ob->InheritsFrom(TGo4DynamicEntry::Class()))
01864 {
01865 TGo4DynamicEntry* entry = dynamic_cast<TGo4DynamicEntry*>(ob);
01866 if (entry!=0) entry->Reset();
01867 }
01868 else if(ob->InheritsFrom(TGo4Picture::Class()))
01869 {
01870 TGo4Picture* pic = dynamic_cast<TGo4Picture*>(ob);
01871 if (pic) pic->Reset();
01872 }
01873 else if(ob->InheritsFrom(TGraph::Class()))
01874 {
01875 TGraph* gr= dynamic_cast<TGraph*>(ob);
01876 if (gr) {
01877
01878 gr->Set(0);
01879
01880 }
01881 }
01882 else if(ob->InheritsFrom(TMultiGraph::Class()))
01883 {
01884 TMultiGraph* mg= dynamic_cast<TMultiGraph*>(ob);
01885 if (mg) {
01886 TIter liter(mg->GetListOfGraphs());
01887 TObject* ob=0;
01888 while((ob=liter())!=0)
01889 ClearObject(ob);
01890 }
01891 }
01892 else if(ob->InheritsFrom(TGo4EventElement::Class()))
01893 {
01894
01895
01896 rev=kFALSE;
01897 }
01898 else if(ob->InheritsFrom(TTree::Class()))
01899 {
01900
01901
01902 rev=kFALSE;
01903 }
01904 else
01905 {
01906 ob->Clear();
01907
01908
01909 }
01910 }
01911 return rev;
01912 }
01913
01914
01915 Bool_t TGo4AnalysisObjectManager::DeleteFolder(TFolder* fold)
01916 {
01917 GO4TRACE((11,"TGo4AnalysisObjectManager::DeleteFolder(TFolder*, Option_t*)",__LINE__, __FILE__));
01918 if (fold==0) return kFALSE;
01919
01920 TGo4LockGuard dirguard(fxDirMutex);
01921 TIter iter(fold->GetListOfFolders());
01922 TObject* ob=0;
01923 while((ob=iter())!=0)
01924 if(ob->InheritsFrom(TFolder::Class()))
01925 DeleteFolder(dynamic_cast<TFolder*>(ob));
01926 else
01927 DeleteObject(ob);
01928 return kTRUE;
01929 }
01930
01931 Bool_t TGo4AnalysisObjectManager::DeleteObject(TObject* ob)
01932 {
01933 GO4TRACE((11,"TGo4AnalysisObjectManager::DeleteObject(TObject*)",__LINE__, __FILE__));
01934 if(ob==0 || !ob->TestBit(TGo4Status::kGo4CanDelete) ) return kFALSE;
01935 fxGo4Dir->RecursiveRemove(ob);
01936 CleanupDynamicLists(ob);
01937 delete ob;
01938 return kTRUE;;
01939 }
01940
01941
01942
01943 Bool_t TGo4AnalysisObjectManager::ProtectFolder(TFolder* fold, const Option_t* flags)
01944 {
01945 if(fold==0) return kFALSE;
01946 TGo4LockGuard dirguard(fxDirMutex);
01947 TIter listiter(fold->GetListOfFolders());
01948 TObject* ob=0;
01949 while((ob=listiter.Next())!=0)
01950 if(ob->InheritsFrom(TFolder::Class()))
01951 ProtectFolder(dynamic_cast<TFolder*>(ob), flags);
01952 else
01953 ProtectObject(ob, flags);
01954 return kTRUE;
01955 }
01956
01957 Bool_t TGo4AnalysisObjectManager::ProtectObject(TObject* ob, const Option_t* flags)
01958 {
01959 if((ob==0) || (flags==0)) return kFALSE;
01960 TString opt=flags;
01961 if(opt.Contains("+D")) ob->ResetBit(TGo4Status::kGo4CanDelete);
01962 if(opt.Contains("-D")) ob->SetBit(TGo4Status::kGo4CanDelete);
01963 if(opt.Contains("+C")) ob->SetBit(TGo4Status::kGo4NoReset);
01964 if(opt.Contains("-C")) ob->ResetBit(TGo4Status::kGo4NoReset);
01965 return kTRUE;
01966 }
01967
01968 void TGo4AnalysisObjectManager::CleanupDynamicLists(TObject* oldobject)
01969 {
01970 GO4TRACE((11,"TGo4AnalysisObjectManager::CleanupDynamicLists(TNamed*)",__LINE__, __FILE__));
01971 TGo4LockGuard dirguard(fxDirMutex);
01972 if (oldobject==0) return;
01973
01974 if(oldobject->InheritsFrom(TH1::Class()) ||
01975 oldobject->InheritsFrom(TGo4Condition::Class()) ||
01976 oldobject->InheritsFrom(TGo4EventElement::Class()))
01977 TGo4DynamicList::CleanupPointerInEntries(fxDynListDir, oldobject);
01978 }
01979
01980
01981 void TGo4AnalysisObjectManager::PrintConditions(const char* expression)
01982 {
01983 GO4TRACE((11,"TGo4AnalysisObjectManager::PrintConditions(const char*)",__LINE__, __FILE__));
01984 Int_t totalsize = PrintFolder(fxConditionDir, "*", expression);
01985 std::cout << "___________________________________________________________" << std::endl;
01986 std::cout << "Total size of all conditions is: " << totalsize << " bytes." << std::endl;
01987 }
01988
01989 void TGo4AnalysisObjectManager::PrintHistograms(const char* expression)
01990 {
01991 GO4TRACE((11,"TGo4AnalysisObjectManager::PrintHistograms(const char*)",__LINE__, __FILE__));
01992 Int_t totalsize = PrintFolder(fxHistogramDir, "*", expression);
01993 std::cout << "___________________________________________________________" << std::endl;
01994 std::cout << "Total size of all histograms is: " << totalsize << " bytes." << std::endl;
01995 }
01996
01997 void TGo4AnalysisObjectManager::PrintParameters(const char* expression)
01998 {
01999 GO4TRACE((11,"TGo4AnalysisObjectManager::PrintParameters(const char*)",__LINE__, __FILE__));
02000 Int_t totalsize = PrintFolder(fxParameterDir, "*", expression);
02001 std::cout << "___________________________________________________________" << std::endl;
02002 std::cout << "Total size of all parameters is: " << totalsize << " bytes." << std::endl;
02003 }
02004
02005
02006 TObject* TGo4AnalysisObjectManager::NextMatchingObject(const char* expr,
02007 const char* folder,
02008 Bool_t reset)
02009 {
02010 if(reset) {
02011 delete fxMatchIterator;
02012 delete fxMatchList;
02013 fxMatchList=CreateObjectList(expr,folder);
02014 fxMatchIterator=fxMatchList->MakeIterator();
02015 }
02016 return fxMatchIterator->Next();
02017 }
02018
02019 TList* TGo4AnalysisObjectManager::CreateObjectList(const char* expr, const char* folder)
02020 {
02021 TGo4LockGuard dirguard(fxDirMutex);
02022 TFolder* searchfold;
02023 if(folder==0 || !strcmp(folder,fgcTOPFOLDER))
02024 searchfold=fxGo4Dir;
02025 else
02026 searchfold=FindSubFolder(fxGo4Dir, folder, kFALSE);
02027 return (CreateObjectList(expr, searchfold));
02028 }
02029
02030
02031 TList* TGo4AnalysisObjectManager::CreateObjectList(const char* expr, TFolder* fold)
02032 {
02033 TList* result = new TList;
02034 if(fold!=0) {
02035 TIter iter(fold->GetListOfFolders());
02036 TObject* entry=0;
02037 while((entry = iter())!=0) {
02038 if(entry->InheritsFrom(TFolder::Class())) {
02039 TFolder* subfold=dynamic_cast<TFolder*>(entry);
02040 TList* sublist=CreateObjectList(expr,subfold);
02041
02042 result->AddAll(sublist);
02043 } else
02044 if(entry->InheritsFrom(TTree::Class())) {
02045 } else
02046 if(entry->InheritsFrom(TGo4EventElement::Class())) {
02047 } else
02048 if(entry->InheritsFrom(TGo4EventSource::Class())) {
02049 } else
02050 if(entry->InheritsFrom(TGo4EventStore::Class())) {
02051 } else
02052 if(entry->InheritsFrom(TGo4EventProcessor::Class())) {
02053 } else {
02054 if(IsMatching(entry->GetName(),expr))
02055 result->AddLast(entry);
02056 }
02057 }
02058 }
02059 return result;
02060 }
02061
02062 Bool_t TGo4AnalysisObjectManager::IsMatching(const char* string, const char* expression)
02063 {
02064 if(expression==0) return kTRUE;
02065 Bool_t ismatching=kFALSE;
02066 TString entrystring=string;
02067 TRegexp reg(expression,kTRUE);
02068 if(!strcmp(expression,"*"))
02069 ismatching=kTRUE;
02070
02071
02072 else if (entrystring.Index(reg,0)!=kNPOS)
02073 ismatching=kTRUE;
02074 else
02075 ismatching=kFALSE;
02076 return ismatching;
02077 }
02078
02079
02080 TObject* TGo4AnalysisObjectManager::FindObjectInFolder(TFolder* folder, const char* fullname)
02081 {
02082 GO4TRACE((12,"TGo4AnalysisObjectManager::FindObjectInFolder(TFolder*, const char*)",__LINE__, __FILE__));
02083 TGo4LockGuard listguard(fxDirMutex);
02084
02085 return folder ? folder->FindObjectAny(fullname) : 0;
02086 }
02087
02088
02089 TObject* TGo4AnalysisObjectManager::TestObject(TFolder* folder,
02090 const char* &pathname,
02091 const char* objectname,
02092 const TClass* cl)
02093 {
02094 TString fullname;
02095 if ((pathname!=0) && (strlen(pathname)==0)) pathname = 0;
02096 if (pathname) {
02097 fullname = pathname;
02098 fullname += "/";
02099 }
02100 fullname += objectname;
02101
02102 TObject* obj = FindObjectInFolder(folder, fullname);
02103
02104 if ((obj!=0) && (!obj->InheritsFrom(cl))) {
02105 RemoveObjectFromFolder(fullname, folder, kTRUE);
02106 obj = 0;
02107 }
02108
02109 fbCreatedinMake = (obj==0);
02110 return obj;
02111 }
02112
02113 Bool_t TGo4AnalysisObjectManager::FindObjectPathName(TObject* obj, TString& pathname, TFolder* fold)
02114 {
02115 if (obj==0) return kFALSE;
02116
02117 if (fold==0) fold = fxGo4Dir;
02118
02119 if (fold->GetListOfFolders()->FindObject(obj)==obj) {
02120 pathname = "";
02121 return kTRUE;
02122 }
02123
02124 TIter iter(fold->GetListOfFolders());
02125 TObject* sub = 0;
02126
02127 while ((sub = iter())!=0) {
02128 if (!sub->InheritsFrom(TFolder::Class())) continue;
02129 if (FindObjectPathName(obj, pathname, (TFolder*) sub)) {
02130 if (pathname.Length()==0)
02131 pathname = sub->GetName();
02132 else
02133 pathname = TString(sub->GetName()) + "/" + pathname;
02134 return kTRUE;
02135 }
02136 }
02137
02138 return kFALSE;
02139 }