Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4Analysis/TGo4AnalysisObjectManager.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4AnalysisObjectManager.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TCanvas.h"
00021 #include "TRegexp.h"
00022 #include "TMultiGraph.h"
00023 #include "TKey.h"
00024 #include "TObjArray.h"
00025 #include "TFolder.h"
00026 #include "TList.h"
00027 #include "TThread.h"
00028 #include "TH2.h"
00029 #include "TCanvas.h"
00030 #include "TTree.h"
00031 
00032 #include "Go4ThreadManager/TGo4LockGuard.h"
00033 #include "Go4StatusBase/TGo4ObjectStatus.h"
00034 #include "Go4StatusBase/TGo4BranchStatus.h"
00035 #include "Go4StatusBase/TGo4Parameter.h"
00036 #include "Go4ConditionsBase/TGo4Condition.h"
00037 #include "Go4ConditionsBase/TGo4WinCond.h"
00038 #include "Go4ConditionsBase/TGo4PolyCond.h"
00039 #include "Go4DynamicList/TGo4TreeHistogramEntry.h"
00040 #include "Go4DynamicList/TGo4DynamicList.h"
00041 #include "Go4EventServer/TGo4MainTree.h"
00042 #include "Go4StatusAnalysis/TGo4AnalysisObjectNames.h"
00043 #include "Go4StatusAnalysis/TGo4HistogramStatus.h"
00044 #include "Go4StatusAnalysis/TGo4TreeStructure.h"
00045 
00046 
00047 #include "Go4StatusBase/TGo4Parameter.h"
00048 #include "Go4StatusBase/TGo4Picture.h"
00049 #include "Go4Event/TGo4CompositeEvent.h"
00050 #include "Go4EventServer/Go4EventServer.h"
00051 #include "Go4StatusAnalysis/TGo4ConditionStatus.h"
00052 #include "Go4StatusAnalysis/TGo4ParameterStatus.h"
00053 #include "Go4StatusAnalysis/TGo4PictureStatus.h"
00054 #include "Go4StatusAnalysis/TGo4CanvasStatus.h"
00055 #include "Go4StatusAnalysis/TGo4EventStatus.h"
00056 #include "Go4StatusAnalysis/TGo4EventSourceStatus.h"
00057 #include "Go4StatusAnalysis/TGo4EventStoreStatus.h"
00058 #include "Go4StatusAnalysis/TGo4EventProcStatus.h"
00059 #include "Go4ConditionsBase/TGo4PolyCond.h"
00060 #include "Go4DynamicList/TGo4DynamicList.h"
00061 #include "Go4DynamicList/TGo4DynamicListException.h"
00062 #include "Go4DynamicList/TGo4DynamicListStatus.h"
00063 #include "Go4DynamicList/TGo4HistogramEntryStatus.h"
00064 #include "Go4DynamicList/TGo4TreeHistogramEntryStatus.h"
00065 #include "Go4Analysis/TGo4AnalysisImp.h"
00066 
00067 //#include "Go4HistogramServer/TGo4MbsHist.h"
00068 
00069 const Text_t TGo4AnalysisObjectManager::fgcTOPDYNAMICLIST[]="Go4DynamicList";
00070 const Text_t TGo4AnalysisObjectManager::fgcTOPFOLDER[]="Go4";
00071 const Text_t TGo4AnalysisObjectManager::fgcHISTFOLDER[]="Histograms";
00072 const Text_t TGo4AnalysisObjectManager::fgcDYNFOLDER[]="DynamicLists";
00073 const Text_t TGo4AnalysisObjectManager::fgcCONDFOLDER[]="Conditions";
00074 const Text_t TGo4AnalysisObjectManager::fgcPARAFOLDER[]="Parameters";
00075 const Text_t TGo4AnalysisObjectManager::fgcTREEFOLDER[]="Trees";
00076 const Text_t TGo4AnalysisObjectManager::fgcPICTFOLDER[]="Pictures";
00077 const Text_t TGo4AnalysisObjectManager::fgcCANVFOLDER[]="Canvases";
00078 const Text_t TGo4AnalysisObjectManager::fgcANALYSISFOLDER[]="EventObjects";
00079 const Text_t TGo4AnalysisObjectManager::fgcEVENTFOLDER[]="Events";
00080 const Text_t TGo4AnalysisObjectManager::fgcSRCFOLDER[]="EventSources";
00081 const Text_t TGo4AnalysisObjectManager::fgcSTOREFOLDER[]="EventStores";
00082 const Text_t TGo4AnalysisObjectManager::fgcPROCFOLDER[]="EventProcessors";
00083 const Text_t TGo4AnalysisObjectManager::fgcUSRFOLDER[]="UserObjects";
00084 const Text_t TGo4AnalysisObjectManager::fgcTMPFOLDER[]="Go4-tmp";
00085 
00086 const UInt_t TGo4AnalysisObjectManager::fguSUBFOLDERMAXLEN=1024;
00087 
00088 TGo4AnalysisObjectManager::TGo4AnalysisObjectManager(const Text_t* name)
00089 :TNamed(name,"The Go4 Analysis Object Manager"),
00090       fxGo4Dir(0),fxHistogramDir(0),fxConditionDir(0), fxParameterDir(0),
00091       fxDynListDir(0),fxUserDir(0), fxAnalysisDir(0), fxTempFolder(0),
00092       fxMatchList(0), fxMatchIterator(0),
00093       fxDynamicList(0), fiDynListCount(0), fiDynListInterval(0),
00094       fbCreatedinMake(kFALSE), fbSuppressLoadHistograms(kFALSE)
00095 {
00096          fxDirMutex=new TMutex(kTRUE);
00097          fxGo4Dir=gROOT->GetRootFolder()->AddFolder(fgcTOPFOLDER,"The Go4 Object folder");
00098          fxGo4Dir->SetOwner(kTRUE); // top go4 dir owns subfolders
00099          gROOT->GetListOfBrowsables()->Add(fxGo4Dir, fxGo4Dir->GetName());
00100          fxHistogramDir=fxGo4Dir->AddFolder(fgcHISTFOLDER,"All Histogram objects");
00101          fxHistogramDir->SetOwner(kTRUE);
00102          fxConditionDir=fxGo4Dir->AddFolder(fgcCONDFOLDER,"All Condition objects");
00103          fxConditionDir->SetOwner(kTRUE);
00104          fxParameterDir=fxGo4Dir->AddFolder(fgcPARAFOLDER,"All Parameter objects");
00105          fxParameterDir->SetOwner(kTRUE);
00106          fxDynListDir=fxGo4Dir->AddFolder(fgcDYNFOLDER,"Dynamic List Instances");
00107          fxDynListDir->SetOwner(kTRUE);
00108          fxTreeDir=fxGo4Dir->AddFolder(fgcTREEFOLDER,"References to trees");
00109          fxTreeDir->SetOwner(kFALSE); // tree dir does not own objects,
00110          fxPictureDir=fxGo4Dir->AddFolder(fgcPICTFOLDER,"Picture objects");
00111          fxPictureDir->SetOwner(kTRUE);
00112          fxCanvasDir=fxGo4Dir->AddFolder(fgcCANVFOLDER,"All TCanvases");
00113          fxCanvasDir->SetOwner(kTRUE);
00114          fxAnalysisDir=fxGo4Dir->AddFolder(fgcANALYSISFOLDER,"Event objects of current analysis");
00115          fxAnalysisDir->SetOwner(kTRUE); // owns folders, but not objects in folders
00116          fxStoreDir=fxAnalysisDir->AddFolder(fgcSTOREFOLDER,"References to event stores");
00117          fxStoreDir->SetOwner(kFALSE); // event  classes dir does not own objects,
00118          fxSourceDir=fxAnalysisDir->AddFolder(fgcSRCFOLDER,"References to event sources");
00119          fxSourceDir->SetOwner(kFALSE); // event  classes dir does not own objects,
00120          fxProcessorDir=fxAnalysisDir->AddFolder(fgcPROCFOLDER,"References to event processors");
00121          fxProcessorDir->SetOwner(kFALSE); // event  classes dir does not own objects,
00122          fxEventDir=fxAnalysisDir->AddFolder(fgcEVENTFOLDER,"References to event structures");
00123          fxEventDir->SetOwner(kFALSE); // event  classes dir does not own objects,
00124          fxUserDir=fxGo4Dir->AddFolder(fgcUSRFOLDER,"For User Objects");
00125          fxGo4Dir->SetOwner(kFALSE);
00126          fxTempFolder=gROOT->GetRootFolder()->AddFolder(fgcTMPFOLDER,"The Go4 temporary object folder");
00127          fxTempFolder->SetOwner(kFALSE);
00128 }
00129 
00130 TGo4AnalysisObjectManager::TGo4AnalysisObjectManager()
00131 :fxGo4Dir(0),fxHistogramDir(0),fxConditionDir(0),
00132 fxDynListDir(0),fxUserDir(0), fxAnalysisDir(0), fxTempFolder(0),
00133 fxDynamicList(0), fiDynListCount(0), fiDynListInterval(0),
00134 fbCreatedinMake(kFALSE), fbSuppressLoadHistograms(kFALSE)
00135 {
00136 // ctor for streamer only!
00137 }
00138 
00139 
00140 TGo4AnalysisObjectManager::~TGo4AnalysisObjectManager()
00141 {
00142 
00143 delete fxMatchIterator;
00144 delete fxMatchList;
00145 //delete fxDirMutex;
00146 gROOT->GetListOfBrowsables()->Remove(fxGo4Dir);
00147 //cout <<"Removed all folders from list of browsables" << endl;
00148 
00149 gROOT->GetRootFolder()->Remove(fxTempFolder);
00150 gROOT->GetRootFolder()->Remove(fxGo4Dir);
00151 
00152 fxHistogramDir->Clear();
00153 fxConditionDir->Clear();
00154 fxParameterDir->Clear();
00155 fxDynListDir->Clear();
00156 fxUserDir->Clear();
00157 fxTreeDir->Clear();
00158 fxPictureDir->Clear();
00159 fxCanvasDir->Clear();
00160 fxEventDir->Clear();
00161 fxProcessorDir->Clear();
00162 fxStoreDir->Clear();
00163 fxSourceDir->Clear();
00164 fxGo4Dir->Clear();
00165 fxTempFolder->Clear();
00166 //cout <<"Cleared all folders" << endl;
00167 delete fxTempFolder;
00168 //cout <<"deleted temporary folder" << endl;
00169 delete fxGo4Dir;
00170 //cout <<"deleted top folder" << endl;
00171 }
00172 
00173 
00174 Bool_t TGo4AnalysisObjectManager::AddObject(TNamed * anything, const Text_t* subfolder, Bool_t replace)
00175 {
00176 TRACE((11,"TGo4AnalysisObjectManager::AddObject(TNamed *)",__LINE__, __FILE__));
00177    // unspecified objects are only allowed to put into userdir
00178  return (AddObjectToFolder(anything,fxUserDir,subfolder,replace));
00179 }
00180 
00181 Bool_t TGo4AnalysisObjectManager::RemoveObject(const Text_t * name, Bool_t del)
00182 {
00183    return RemoveObjectFromFolder(name, fxUserDir, del);
00184 }
00185 
00186 
00187 
00188 TNamed * TGo4AnalysisObjectManager::GetObject(const Text_t * name, const Text_t* folder)
00189 {
00190 TRACE((11,"TGo4AnalysisObjectManager::GetObject(Text_t *)",__LINE__, __FILE__));
00191    //
00192    TNamed* ob=0;
00193    TFolder* searchfold;
00194    if(folder==0 || !strcmp(folder,fgcTOPFOLDER))
00195       searchfold=fxGo4Dir; // default: search topfolder
00196    else
00197       searchfold=FindSubFolder(fxGo4Dir, folder, kFALSE);
00198    if(searchfold)
00199       {
00200       ob= dynamic_cast<TNamed*> (FindObjectInFolder(searchfold, name));
00201       //cout << "found object in top folder :" << ob  <<endl;
00202       if(ob && ob->InheritsFrom("TTree")) ob=0; // disable sending tree to gui!
00203       if(ob && ob->InheritsFrom("TFolder")) ob=0; // disable sending complete folder
00204       if(ob && ob->InheritsFrom("TGo4EventElement")) ob=0; // disable events
00205       if(ob && ob->InheritsFrom("TGo4EventSource")) ob=0; // disable events
00206       if(ob && ob->InheritsFrom("TGo4EventStore")) ob=0; // disable events
00207       if(ob && ob->InheritsFrom("TGo4EventProcessor")) ob=0; // disable events
00208       }
00209    else
00210       {
00211          ob=0;
00212       }
00213    if(ob)
00214       {
00215          TGo4Analysis::Instance()->Message(0,"AnalysisObjectManager - found object %s of class %s",
00216                ob->GetName(), ob->ClassName());
00217       }
00218    else
00219       {
00220          TGo4Analysis::Instance()->Message(0,"!!! AnalysisObjectManager - no such object %s !!!",
00221                name);
00222       }
00223    return ob;
00224 }
00225 
00226 
00227 
00228 Bool_t TGo4AnalysisObjectManager::ClearObjects(const Text_t * name)
00229 {
00230 TRACE((11,"TGo4AnalysisObjectManager::ClearObject(Text_t *)",__LINE__, __FILE__));
00231 Bool_t rev=kTRUE;
00232 TGo4LockGuard  dirguard(fxDirMutex);
00233 TObject* ob= fxGo4Dir->FindObjectAny(name);
00234 if(ob==0)
00235    {
00236       //if not found in folder, try to find dynamic entry in list:
00237       TGo4DynamicEntry* ent=fxDynamicList->GetEntry(name);
00238       if(ent) 
00239          {
00240             ent->Reset();
00241             rev=kTRUE;
00242          }
00243       else
00244          {
00245             rev=kFALSE;
00246          }
00247    }
00248 else
00249    {
00250       if(ob->InheritsFrom("TFolder"))
00251          {
00252              TFolder* fold=dynamic_cast<TFolder*>(ob);
00253              rev=ClearFolder(fold);
00254          }
00255       else
00256          {
00257              rev=ClearObject(ob);
00258           }//if(ob->InheritsFrom("TFolder"))
00259    } // if(ob==0)
00260 return rev;
00261 }
00262 
00263 
00264 Bool_t TGo4AnalysisObjectManager::DeleteObjects(const Text_t * name)
00265 {
00266 Bool_t rev=kTRUE;
00267 TGo4LockGuard  dirguard(fxDirMutex);
00268 TObject* ob= fxGo4Dir->FindObjectAny(name);
00269 if(ob==0)
00270    {
00271       rev=kFALSE;
00272    }
00273 else
00274    {
00275       if(ob->InheritsFrom("TFolder"))
00276          {
00277              TFolder* fold=dynamic_cast<TFolder*>(ob);
00278              rev=DeleteFolder(fold);
00279          }
00280       else
00281          {
00282              rev=DeleteObject(ob);
00283           }//if(ob->InheritsFrom("TFolder"))
00284    } // if(ob==0)
00285 return rev;
00286 
00287 
00288 
00289 }
00290 
00291 
00292 Bool_t TGo4AnalysisObjectManager::ProtectObjects(const Text_t* name, const Option_t* flags)
00293 {
00294 Bool_t rev=kTRUE;
00295 TGo4LockGuard  dirguard(fxDirMutex);
00296 TObject* ob= fxGo4Dir->FindObjectAny(name);
00297 if(ob==0)
00298    {
00299       rev=kFALSE;
00300    }
00301 else
00302    {
00303       if(ob->InheritsFrom("TFolder"))
00304          {
00305              TFolder* fold=dynamic_cast<TFolder*>(ob);
00306              rev=ProtectFolder(fold, flags);
00307          }
00308       else
00309          {
00310              rev=ProtectObject(ob, flags);
00311           }//if(ob->InheritsFrom("TFolder"))
00312    } // if(ob==0)
00313 return rev;      
00314 }
00315 
00316 
00317 
00318 TFolder * TGo4AnalysisObjectManager::CreateBranchFolder(TObjArray* branchlist, const Text_t* name, const Text_t* title, Bool_t istopbranch)
00319 {
00320    TRACE((11,"TGo4AnalysisObjectManager::CreateBranchFolder(TObjArray*)",__LINE__, __FILE__));
00321    TFolder* fold=0;
00322    if(branchlist)
00323       {
00324          TFolder* subnames=0;
00325          TList* nameslist= new TList;
00326          TIterator* listiter=branchlist->MakeIterator();
00327          TObject* entry;
00328          TGo4ObjectStatus* state;
00329          Int_t cursor=0;
00330          while((entry=listiter->Next()) !=0)
00331             {
00332                if(entry->InheritsFrom("TBranch"))
00333                   {
00334                       // found subfolder, process it recursively
00335                       TBranch* subbranch= dynamic_cast<TBranch*> (entry);
00336                       TObjArray* subbranchlist=subbranch->GetListOfBranches();
00337                       if(subbranchlist)
00338                          {
00339                             if(subbranchlist->IsEmpty())
00340                                {
00341                                  // subbranchlist is empty, add status object to folder
00342                                     state=new TGo4BranchStatus(subbranch);
00343                                     nameslist->AddLast(state);
00344                                }
00345                             else
00346                                {
00347                                   // found subbranchlist
00348                                   // test for composite event:
00349                                    TClass* cl=gROOT->GetClass(subbranch->GetClassName());
00350                                    if(cl  && cl->InheritsFrom("TGo4CompositeEvent") && istopbranch)
00351                                     {
00352                                        // search for composite event of that name in Go4 (only if top level call)
00353                                        TGo4CompositeEvent* cevent=0;
00354                                        TString branchname(subbranch->GetName());
00355                                        Ssiz_t leng = branchname.Length();
00356                                        branchname.Resize(leng-1); // strip dot from branchname
00357                                        //cout <<"searching for composite event "<< branchname.Data() << endl;
00358                                        cevent = dynamic_cast<TGo4CompositeEvent*> (GetEventStructure(branchname.Data()));
00359 
00360                                        if(cevent)
00361                                         {
00362                                            //cout <<"found top comp event" << endl;
00363                                            Int_t skippedentries=0;
00364                                            // we pass complete top branchlist to method
00365                                            subnames=CreateCompositeBranchFolder(
00366                                                 branchlist,cevent,cursor+1,
00367                                                      &skippedentries,
00368                                                     cevent->GetName(),
00369                                                     cevent->GetTitle());
00370                                            // skip comp subelements in iterator:
00371                                             //cout <<"top skipped:"<<skippedentries<< endl;
00372                                            // now process subbranchlist  of top compevent,
00373                                            // add members of this folder to existing folder subnames!
00374                                            TFolder* temp=CreateBranchFolder(subbranchlist,
00375                                                     "dummy",
00376                                                     "dummy");
00377                                            subnames->GetListOfFolders()->AddAll(temp->GetListOfFolders());
00378 
00379                                            for(Int_t t=0;t<skippedentries;++t)
00380                                               {
00381                                                  listiter->Next();
00382                                                  cursor++;
00383                                               }
00384 
00385                                         }
00386                                        else
00387                                         {
00388                                            //cout <<"not found top comp event" << endl;
00389                                            subnames=CreateBranchFolder(subbranchlist,
00390                                                     subbranch->GetName(),
00391                                                     subbranch->GetTitle());
00392                                         }
00393                                     } // if (cl  && cl->InheritsFrom("TGo4CompositeEvent"))
00394                                   else
00395                                      {
00396                                         //cout <<"no class or not top branch" << endl;
00397                                         subnames=CreateBranchFolder(subbranchlist,
00398                                                     subbranch->GetName(),
00399                                                     subbranch->GetTitle());
00400                                      }
00401                                   nameslist->AddLast(subnames);
00402                                } // if(subbranchlist->IsEmpty())
00403                          }
00404                      else
00405                         {
00406                            // no subbranchlist, should not happen...
00407                            // add status object to folder
00408                            state=new TGo4BranchStatus(subbranch);
00409                            nameslist->AddLast(state);
00410                         } // if(subbranchlist)
00411                   }
00412                else
00413                   {
00414 
00415                   } //if(entry->InheritsFrom("TBranch"))
00416                 cursor++;
00417             } // while((entry=listiter->Next()) !=0)
00418          fold=fxTempFolder->AddFolder(name,title,nameslist);
00419          fold->SetOwner(kTRUE);
00420          fxTempFolder->Remove(fold);
00421          delete listiter;
00422         }
00423       else
00424          {   } // if(branchlist)
00425 
00426    return fold;
00427 }
00428 TFolder * TGo4AnalysisObjectManager::CreateCompositeBranchFolder(TObjArray* branchlist,
00429                                            TGo4CompositeEvent* compevent,
00430                                            Int_t startindex, Int_t* skip,
00431                                            const Text_t* name, const Text_t* title)
00432 {
00433    TRACE((11,"TGo4AnalysisObjectManager::CreateCompositeBranchFolder(TObjArray*,...)",__LINE__, __FILE__));
00434    TFolder* fold=0;
00435    TFolder* subnames=0;
00436    if(branchlist)
00437       {
00438          TList* nameslist= new TList;
00439          TGo4ObjectStatus* state;
00440          TObjArray* csubevents=0;
00441          Int_t lastindex=0;
00442          if(compevent)
00443             {
00444                csubevents=compevent->getListOfComposites();
00445                if(startindex==1)
00446                   {
00447                      lastindex=startindex+branchlist->GetLast(); // top event: scan everything
00448 
00449                   }
00450                else
00451                   {
00452                      lastindex=startindex+compevent->getNElements(); // subevent: scan only own members
00453                   }
00454                 //cout <<"startindex:"<<startindex <<" lastindex:"<<lastindex << endl;
00455             }
00456          else
00457             {
00458                //cout <<"CreateCompsositeBranchFolder Error: no composite event" << endl;
00459                return (CreateBranchFolder(branchlist,name,title));
00460             }
00461          Int_t skippedentries=0;
00462          Int_t offset=0;
00463          for(Int_t i=startindex; i<lastindex;i++)
00464             {
00465             //cout <<"i+offset="<<i+offset << endl;
00466             TClass* cl=0;
00467             TObject* entry=branchlist->At(i+offset);
00468             if(entry && entry->InheritsFrom("TBranch"))
00469                {
00470                          // found subfolder, process it recursively
00471                TBranch* currentbranch= dynamic_cast<TBranch*> (entry);
00472                TObjArray* currentbranchlist=0;
00473                if (currentbranch)
00474                   {
00475                      currentbranchlist=currentbranch->GetListOfBranches();
00476                      cl=gROOT->GetClass(currentbranch->GetClassName());
00477                   }
00478                else {}
00479                if(cl  && cl->InheritsFrom("TGo4CompositeEvent"))
00480                   {
00481                   // subevent is also composite event, treat next n branches as subbranches:
00482                   TGo4CompositeEvent* subevent=0;
00483                   TString branchname(currentbranch->GetName());
00484                   Ssiz_t leng = branchname.Length();
00485                   branchname.Resize(leng-1); // strip dot from branchname
00486                   //cout <<"searching for composite sub event "<< branchname.Data() << endl;
00487                   if(csubevents)
00488                      {
00489                         subevent = dynamic_cast<TGo4CompositeEvent *>(csubevents->FindObject(branchname.Data()));
00490                      }
00491                   else
00492                      {   }
00493                   if(subevent && subevent->getNElements()>0)
00494                      {
00495                          //cout <<"found composite subevent "<< subevent->GetName() << endl;
00496                          // found subbranch, add it to folder struct
00497 
00498                          subnames=CreateCompositeBranchFolder(branchlist,
00499                                                           subevent,
00500                                                           i+offset+1, &skippedentries,
00501                                                           subevent->GetName(),
00502                                                           subevent->GetTitle());
00503                          nameslist->AddLast(subnames);
00504                          offset+=skippedentries;
00505                          //cout <<"skipped:"<<skippedentries<<", i:"<<i << endl;
00506                          //cout <<"offset:"<<offset<< endl;
00507                          // now process subbranchlist currentbranchlist of compevent,
00508                          // add members of this folder to existing folder subnames!
00509                          TFolder* temp=CreateBranchFolder(currentbranchlist,
00510                                                     "dummy",
00511                                                     "dummy");
00512                          subnames->GetListOfFolders()->AddAll(temp->GetListOfFolders());
00513 
00514 
00515                      }
00516                   else
00517                      {
00518                          //cout <<"composite subevent is basic member..." << endl;
00519                          // subevent not in list, normal operation:
00520                         //state=new TGo4ObjectStatus(dynamic_cast<TNamed*> (entry) );
00521                         //nameslist->AddLast(state);
00522                         if(currentbranchlist)
00523                          {
00524                             if(currentbranchlist->IsEmpty())
00525                                {
00526                                  // subbranchlist is empty, add status object to folder
00527                                     state=new TGo4BranchStatus(currentbranch);
00528                                     nameslist->AddLast(state);
00529                                }
00530                             else
00531                                {
00532                                  subnames=CreateBranchFolder(currentbranchlist,
00533                                                     currentbranch->GetName(),
00534                                                     currentbranch->GetTitle());
00535                                  nameslist->AddLast(subnames);
00536                                }
00537                          } // if(currentbranchlist)
00538                      } //if(subevent && subevent->getNElements()>0)
00539 
00540                }   //  if(cl  && cl->InheritsFrom("TGo4CompositeEvent"))
00541             else
00542                {
00543                   // subevent is not a composite event, normal operation:
00544 //                  state=new TGo4ObjectStatus(dynamic_cast<TNamed*> (entry) );
00545 //                  nameslist->AddLast(state);
00546                   if(currentbranchlist)
00547                          {
00548                             if(currentbranchlist->IsEmpty())
00549                                {
00550                                  // subbranchlist is empty, add status object to folder
00551                                     state=new TGo4BranchStatus(currentbranch);
00552                                     nameslist->AddLast(state);
00553                                }
00554                             else
00555                                {
00556                                  subnames=CreateBranchFolder(currentbranchlist,
00557                                                     currentbranch->GetName(),
00558                                                     currentbranch->GetTitle());
00559                                  nameslist->AddLast(subnames);
00560                                }
00561                      }
00562                   //cout <<"added entry"<< entry->GetName() << endl;
00563                }
00564             }
00565             else
00566                {
00567                   break;
00568 //                  if(entry)
00569 //                     cout <<"ERROR: no branch in branchlist, class:"<< entry->ClassName() << endl;
00570 //                  else
00571 //                     cout << "ZERO entry in branchlist"<< endl;
00572 
00573                } //if(entry->InheritsFrom("TBranch"))
00574          } // for()
00575          *skip=lastindex+offset-startindex;
00576          fold=fxTempFolder->AddFolder(name,title,nameslist);
00577          fold->SetOwner(kTRUE);
00578          fxTempFolder->Remove(fold);
00579         }
00580       else
00581          {   } // if(branchlist)
00582 
00583    return fold;
00584 
00585 }
00586 TGo4TreeStructure * TGo4AnalysisObjectManager::CreateTreeStructure(TTree* thetree)
00587 {
00588 TRACE((11,"TGo4AnalysisObjectManager::CreateTreeStructure(TTree*)",__LINE__, __FILE__));
00589    //
00590    TGo4TreeStructure* tstructure=0;
00591    if(thetree)
00592       {
00593          const Text_t* treename=thetree->GetName();
00594          const Text_t* treetitle=thetree->GetTitle();
00595          TGo4Analysis::Instance()->Message(0,"AnalysisObjectManager - creating structure of tree %s",
00596                 treename);
00597          TObjArray* branchlist=thetree->GetListOfBranches();
00598          tstructure= new TGo4TreeStructure(treename);
00599          tstructure->fxTopFolder=CreateBranchFolder(branchlist,treename,treetitle, kTRUE);
00600       }
00601    else {}
00602    return tstructure;
00603 }
00604 
00605 TGo4TreeStructure * TGo4AnalysisObjectManager::CreateTreeStructure(const Text_t* treename)
00606 {
00607 TRACE((11,"TGo4AnalysisObjectManager::CreateTreeStructure(const Text_t *)",__LINE__, __FILE__));
00608    TTree* thetree=0;
00609    if(fxTreeDir)
00610       {
00611          thetree=dynamic_cast<TTree*> (fxTreeDir->FindObjectAny(treename));
00612       }
00613    else
00614       {
00615          thetree=0;
00616       }
00617    return (CreateTreeStructure(thetree));
00618 
00619 }
00620 
00621 
00622 Bool_t TGo4AnalysisObjectManager::AddHistogram(TH1 * his, const Text_t* subfolder, Bool_t replace)
00623 {
00624 TRACE((11,"TGo4AnalysisObjectManager::AddHistogram(TH1*)",__LINE__, __FILE__));
00625    Bool_t rev=AddObjectToFolder(his,fxHistogramDir,subfolder,replace,kTRUE);
00626    // for histograms: add with unique object names within histogramdir
00627    // to avoid errors in TTree::Draw()
00628    if(rev && his) his->SetDirectory(gROOT); // assign histo to the top dir, no file!
00629    return rev;
00630 }
00631 
00632 TH1* TGo4AnalysisObjectManager::MakeH1(const Text_t* histotype,
00633                                        const Text_t* foldername,
00634                                        const Text_t* histoname,
00635                                        Int_t         nbinsx,
00636                                        Axis_t        xlow,
00637                                        Axis_t        xup,
00638                                        const Text_t* title,
00639                                        const Text_t* xtitle,
00640                                        const Text_t* ytitle) {
00641 
00642    TString htype(histotype);
00643    htype.ToUpper();
00644    if (htype.Length()==0) htype = "I";
00645    TClass* cl = 0;
00646 
00647    switch (htype[0]) {
00648      case 'C' : cl = TH1C::Class(); break;
00649      case 'D' : cl = TH1D::Class(); break;
00650      case 'F' : cl = TH1F::Class(); break;
00651      case 'I' : cl = TH1I::Class(); break;
00652      case 'S' : cl = TH1S::Class(); break;
00653      default : cl = TH1I::Class();
00654    }
00655 
00656    TH1* histo = (TH1*) TestObject(fxHistogramDir, foldername, histoname, cl);
00657 
00658    if (histo) return histo;
00659 
00660    switch(htype[0]) {
00661       case 'C' : histo = new TH1C(histoname, histoname, nbinsx, xlow, xup); break;
00662       case 'D' : histo = new TH1D(histoname, histoname, nbinsx, xlow, xup); break;
00663       case 'F' : histo = new TH1F(histoname, histoname, nbinsx, xlow, xup); break;
00664       case 'I' : histo = new TH1I(histoname, histoname, nbinsx, xlow, xup); break;
00665       case 'S' : histo = new TH1S(histoname, histoname, nbinsx, xlow, xup); break;
00666       default :  histo = new TH1I(histoname, histoname, nbinsx, xlow, xup);
00667    }
00668 
00669    if (title) histo->SetTitle(title);
00670    if (xtitle) histo->SetXTitle(xtitle);
00671    if (ytitle) histo->SetYTitle(ytitle);
00672    AddHistogram(histo, foldername);
00673    return histo;
00674 }
00675 
00676 TH2* TGo4AnalysisObjectManager::MakeH2(const Text_t* histotype,
00677                                        const Text_t* foldername,
00678                                        const Text_t* histoname,
00679                                        Int_t         nbinsx,
00680                                        Axis_t        xlow,
00681                                        Axis_t        xup,
00682                                        Int_t         nbinsy,
00683                                        Axis_t        ylow,
00684                                        Axis_t        yup,
00685                                        const Text_t* title,
00686                                        const Text_t* xtitle,
00687                                        const Text_t* ytitle) {
00688    TString htype(histotype);
00689    htype.ToUpper();
00690    if (htype.Length()==0) htype = "I";
00691 
00692    TClass* cl = 0;
00693 
00694    switch (htype[0]) {
00695      case 'C' : cl = TH2C::Class(); break;
00696      case 'D' : cl = TH2D::Class(); break;
00697      case 'F' : cl = TH2F::Class(); break;
00698      case 'I' : cl = TH2I::Class(); break;
00699      case 'S' : cl = TH2S::Class(); break;
00700      default : cl = TH2I::Class();
00701    }
00702 
00703    TH2* histo = (TH2*) TestObject(fxHistogramDir, foldername, histoname, cl);
00704 
00705    if (histo) return histo;
00706 
00707    switch(htype[0]) {
00708       case 'C' : histo = new TH2C(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00709       case 'D' : histo = new TH2D(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00710       case 'F' : histo = new TH2F(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00711       case 'I' : histo = new TH2I(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00712       case 'S' : histo = new TH2S(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup); break;
00713       default :  histo = new TH2I(histoname, histoname, nbinsx, xlow, xup, nbinsy, ylow, yup);
00714    }
00715 
00716    if (title) histo->SetTitle(title);
00717    if (xtitle) histo->SetXTitle(xtitle);
00718    if (ytitle) histo->SetYTitle(ytitle);
00719    AddHistogram(histo, foldername);
00720    return histo;
00721 }
00722 
00723 Bool_t TGo4AnalysisObjectManager::AddTree(TTree* tree, const Text_t* subfolder)
00724 {
00725 TRACE((11,"TGo4AnalysisObjectManager::AddTree(TTree*, Text_t*)",__LINE__, __FILE__));
00726   return (AddObjectToFolder(tree,fxTreeDir,subfolder,kFALSE));
00727 }
00728 
00729 Bool_t TGo4AnalysisObjectManager::RemoveTree(TTree * tree, const Text_t* stepname)
00730 {
00731 TRACE((11,"TGo4AnalysisObjectManager::RemoveTree(TTree*, Text_t*)",__LINE__, __FILE__));
00732    Bool_t rev=kFALSE;
00733    if(tree)
00734       {
00735                TGo4LockGuard listguard(fxDirMutex);
00736                   fxTreeDir->Remove(tree);
00737                   // later: we use directory with name stepname to put tree in
00738       }
00739    else
00740       {
00741          rev=kFALSE;
00742       }
00743    return rev;
00744 }
00745 TH1* TGo4AnalysisObjectManager::GetHistogram(const Text_t * name)
00746 {
00747 TRACE((11,"TGo4AnalysisObjectManager::GetHistogram(Text_t *)",__LINE__, __FILE__));
00748    TH1* rev= dynamic_cast<TH1*> (FindObjectInFolder(fxHistogramDir, name));
00749    if(rev==0) rev= dynamic_cast<TH1*> (FindObjectInFolder(fxUserDir, name)); // also check user objects dir
00750    return rev;
00751 }
00752 
00753 TTree * TGo4AnalysisObjectManager::GetTree(const Text_t * name)
00754 {
00755 TRACE((11,"TGo4AnalysisObjectManager::GetTree(Text_t *)",__LINE__, __FILE__));
00756   return dynamic_cast<TTree*> (FindObjectInFolder(fxTreeDir, name));
00757 }
00758 
00759 Bool_t TGo4AnalysisObjectManager::RemoveHistogram(const Text_t * name, Bool_t del)
00760 {
00761 TRACE((11,"TGo4AnalysisObjectManager::RemoveHistogram(Text_t*)",__LINE__, __FILE__));
00762    //
00763    return RemoveObjectFromFolder(name, fxHistogramDir, del);
00764 }
00765 
00766 
00767 Bool_t TGo4AnalysisObjectManager::AddAnalysisCondition(TGo4Condition * con, const Text_t* subfolder)
00768 {
00769 TRACE((11,"TGo4AnalysisObjectManager::AddAnalysisCondition(TGo4Condition *)",__LINE__, __FILE__));
00770 return(AddObjectToFolder(con,fxConditionDir,subfolder,kTRUE));
00771 }
00772 
00773 Bool_t TGo4AnalysisObjectManager::SetAnalysisCondition(const Text_t * name, TGo4Condition* con,
00774                                    Bool_t counter, TFolder* parent)
00775 {
00776 TRACE((11,"TGo4AnalysisObjectManager::SetAnalysisCondition(Text_t*, TGo4Condition*, Bool_t)",__LINE__, __FILE__));
00777 TGo4LockGuard   listguard(fxDirMutex);
00778 Bool_t rev=kFALSE;
00779 TFolder* topfolder=0;
00780 if(parent)
00781    topfolder=parent;
00782 else
00783    topfolder=fxConditionDir;
00784 if(con)
00785    {
00786       TObject* searchresult=topfolder->FindObjectAny(name);
00787       if(searchresult==0)
00788          searchresult=fxUserDir->FindObjectAny(name);
00789          // condition may be under user objects folder if not found in topfolder
00790       TGo4Condition* oldcon;
00791       if(searchresult && searchresult->InheritsFrom("TGo4Condition"))
00792          {
00793             oldcon= dynamic_cast<TGo4Condition *> (searchresult);
00794          }
00795       else if (searchresult && searchresult->InheritsFrom("TFolder"))
00796          {
00797             // this is for the case that condition has same name as its folder!
00798             TFolder* subf=dynamic_cast<TFolder*>(searchresult);
00799             searchresult=subf->FindObjectAny(name);
00800             oldcon= dynamic_cast<TGo4Condition *> (searchresult);
00801          }
00802       else
00803          {
00804              oldcon=0;
00805          }
00806       if(oldcon!=0)
00807          {
00808             // update existing condition of given name
00809             rev=oldcon->UpdateFrom(con,counter);
00810             //cout << "++++ Updated condition "<< name<<" from condition "<< con->GetName() << endl;
00811             //oldcon->PrintCondition(true);
00812          }
00813       else
00814          {
00815             // condition not yet exisiting, add external condition
00816              TGo4Condition* clonedcon= dynamic_cast<TGo4Condition*>(con->Clone());
00817              TGo4PolyCond::CleanupSpecials(); // remove reference to cloned cut
00818              // find out destination folder for new condition from name:
00819             Text_t subfolder[fguSUBFOLDERMAXLEN];
00820             size_t fnamelen=0;
00821             const char* endname = name;
00822             const char* foldername = name;
00823             while (endname!=0)
00824                {
00825                   endname=strstr(foldername,"/");
00826                   if(endname==0) break;
00827                   clonedcon->SetName(endname+1);
00828                   fnamelen= endname-name; // length of path string
00829                   //cout <<"SetAnalysiscondition: namelen="<< (Int_t) fnamelen << endl;
00830                   foldername=endname+1;
00831                }
00832 
00833              if(fnamelen>0)
00834                 {
00835                    // we have a subfolder for condition
00836                    if(fnamelen>fguSUBFOLDERMAXLEN) fnamelen=fguSUBFOLDERMAXLEN;
00837                    snprintf(subfolder,fnamelen+1,"%s",name);
00838                    rev=AddObjectToFolder(clonedcon,topfolder,subfolder,kTRUE,kFALSE,kFALSE);
00839                    //cout << "++++ Added new condition "<< clonedcon->GetName()<<" to folder "<<topfolder->GetName()<<"/"<< subfolder << endl;
00840                 }
00841              else
00842                 {
00843                    // no subfolder, condition is directly under topfolder
00844                    rev=AddObjectToFolder(clonedcon,topfolder,0,kTRUE,kFALSE,kFALSE);
00845                    //cout << "++++ Added new condition "<< clonedcon->GetName()<<" to folder "<<topfolder->GetName()<<", no subfolder!!!"<< endl;
00846                 }
00847          }
00848    }
00849 else
00850    {
00851       rev=kFALSE;
00852    }
00853 return rev;
00854 }
00855 
00856 TGo4Condition * TGo4AnalysisObjectManager::GetAnalysisCondition(const Text_t * name)
00857 {
00858 TRACE((11,"TGo4AnalysisObjectManager::GetAnalysisCondition(Text_t*)",__LINE__, __FILE__));
00859    TGo4Condition* cond = dynamic_cast<TGo4Condition *> (FindObjectInFolder(fxConditionDir, name));
00860    if(cond==0) cond=dynamic_cast<TGo4Condition *> (FindObjectInFolder(fxUserDir, name));
00861       // some users have their conditions rather in user folder...
00862    return cond;
00863 }
00864 
00865 TGo4WinCond* TGo4AnalysisObjectManager::MakeWindowCond(const Text_t* foldername,
00866                                                        const Text_t* conditionname,
00867                                                        Double_t      xlow,
00868                                                        Double_t      xup,
00869                                                        const Text_t* bindhistogram,
00870                                                        Bool_t        invert) {
00871    TGo4WinCond* wcond = (TGo4WinCond*)
00872      TestObject(fxConditionDir, foldername, conditionname, TGo4WinCond::Class());
00873 
00874    if (wcond) return wcond;
00875 
00876    wcond = new TGo4WinCond(conditionname);
00877    wcond->SetValues(xlow, xup);
00878    if (bindhistogram!=0)
00879      wcond->SetHistogram(bindhistogram);
00880    if (invert) wcond->Invert(invert);
00881    AddAnalysisCondition(wcond, foldername);
00882    return wcond;
00883 }
00884 
00885 TGo4WinCond* TGo4AnalysisObjectManager::MakeWindowCond(const Text_t* foldername,
00886                                                        const Text_t* conditionname,
00887                                                        Double_t      xlow,
00888                                                        Double_t      xup,
00889                                                        Double_t      ylow,
00890                                                        Double_t      yup,
00891                                                        const Text_t* bindhistogram,
00892                                                        Bool_t      invert) {
00893    TGo4WinCond* wcond = (TGo4WinCond*)
00894      TestObject(fxConditionDir, foldername, conditionname, TGo4WinCond::Class());
00895 
00896    if (wcond) return wcond;
00897 
00898    wcond = new TGo4WinCond(conditionname);
00899    wcond->SetValues(xlow, xup, ylow, yup);
00900    if (bindhistogram!=0)
00901      wcond->SetHistogram(bindhistogram);
00902    if (invert) wcond->Invert(invert);
00903    AddAnalysisCondition(wcond, foldername);
00904    return wcond;
00905 }
00906 
00907 TGo4PolyCond* TGo4AnalysisObjectManager::MakePolyCond(const Text_t* foldername,
00908                                                       const Text_t* conditionname,
00909                                                       Int_t         size,
00910                                                       Float_t      (*points)[2],
00911                                                       const Text_t* bindhistogram,
00912                                                       Bool_t        invert)
00913 {
00914    TGo4PolyCond* pcond = (TGo4PolyCond*)
00915       TestObject(fxConditionDir, foldername, conditionname, TGo4PolyCond::Class());
00916 
00917    if (pcond) return pcond;
00918 
00919    Float_t fullx[size+1], fully[size+1];
00920    int numpoints = size;
00921 
00922    for (int i=0;i<numpoints;i++) {
00923      fullx[i] = points[i][0];
00924      fully[i] = points[i][1];
00925    }
00926 
00927    // connect first and last points
00928    if ((fullx[0]!=fullx[numpoints-1]) || (fully[0]!=fully[numpoints-1])) {
00929       fullx[numpoints] = fullx[0];
00930       fully[numpoints] = fully[0];
00931       numpoints++;
00932    }
00933 
00934    TCutG mycat("initialcut", numpoints, fullx, fully);
00935    pcond = new TGo4PolyCond(conditionname);
00936    pcond->SetValues(&mycat);
00937    if (bindhistogram!=0)
00938      pcond->SetHistogram(bindhistogram);
00939    if (invert) pcond->Invert(invert);
00940    AddAnalysisCondition(pcond, foldername);
00941    return pcond;
00942 }
00943 
00944 
00945 Bool_t TGo4AnalysisObjectManager::RemoveAnalysisCondition(const Text_t * name)
00946 {
00947 TRACE((11,"TGo4AnalysisObjectManager::RemoveAnalysisCondition(Text_t*)",__LINE__, __FILE__));
00948    return RemoveObjectFromFolder(name, fxConditionDir, kTRUE);
00949 }
00950 
00951 TGo4ObjectStatus * TGo4AnalysisObjectManager::CreateObjectStatus(const Text_t * name, const Text_t* folder)
00952 {
00953    TNamed* object=GetObject(name, folder);
00954    return CreateObjectStatus(object);
00955 }
00956 
00957 TGo4ObjectStatus * TGo4AnalysisObjectManager::CreateObjectStatus(TObject* ob, Bool_t fullinfo)
00958 {
00959 if(ob==0) return 0;
00960 TGo4ObjectStatus* state=0;
00961 if(ob->InheritsFrom("TH1"))
00962    {
00963        // found histogram
00964        TH1* his= dynamic_cast<TH1*> (ob);
00965        state=new TGo4HistogramStatus(his,fullinfo);
00966   }
00967  else if(ob->InheritsFrom("TGo4Condition"))
00968    {
00969        TGo4Condition* cond= dynamic_cast<TGo4Condition*> (ob);
00970        state=new TGo4ConditionStatus(cond);
00971    }
00972 else if(ob->InheritsFrom("TGo4Parameter"))
00973    {
00974        TGo4Parameter* par= dynamic_cast<TGo4Parameter*> (ob);
00975        state=new TGo4ParameterStatus(par);
00976    }
00977 else if(ob->InheritsFrom("TGo4Picture"))
00978    {
00979        TGo4Picture* par= dynamic_cast<TGo4Picture*> (ob);
00980        state=new TGo4PictureStatus(par);
00981    }
00982  else if(ob->InheritsFrom("TCanvas"))
00983    {
00984        TCanvas* can= dynamic_cast<TCanvas*> (ob);
00985        state=new TGo4CanvasStatus(can,kTRUE);
00986    }
00987  else if(ob->InheritsFrom("TGo4EventElement"))
00988    {
00989        TGo4EventElement* ev= dynamic_cast<TGo4EventElement*> (ob);
00990        state=new TGo4EventStatus(ev);
00991    }
00992 else if(ob->InheritsFrom("TGo4EventSource"))
00993    {
00994        TGo4EventSource* ev= dynamic_cast<TGo4EventSource*> (ob);
00995        state=new TGo4EventSourceStatus(ev);
00996    }
00997 else if(ob->InheritsFrom("TGo4EventStore"))
00998    {
00999        TGo4EventStore* ev= dynamic_cast<TGo4EventStore*> (ob);
01000        state=new TGo4EventStoreStatus(ev);
01001    }
01002 else if(ob->InheritsFrom("TGo4EventProcessor"))
01003    {
01004        TGo4EventProcessor* ev= dynamic_cast<TGo4EventProcessor*> (ob);
01005        state=new TGo4EventProcStatus(ev);
01006    }
01007 else
01008    {
01009       state=new TGo4ObjectStatus(dynamic_cast<TNamed*> (ob) );
01010    }
01011 return state;
01012 }
01013 
01014 TGo4AnalysisObjectNames * TGo4AnalysisObjectManager::CreateNamesList()
01015 {
01016 TRACE((11,"TGo4AnalysisObjectManager::CreateNamesList()",__LINE__, __FILE__));
01017    TGo4LockGuard   listguard(fxDirMutex);
01018    TGo4AnalysisObjectNames* namesobject=0;
01019    //fxTempFolder->Clear();
01020    namesobject= new TGo4AnalysisObjectNames("Go4NamesList");
01021    namesobject->fxTopFolder=CreateNamesFolder(fxGo4Dir);
01022    TGo4PolyCond::CleanupSpecials(); // remove references to cloned TCutG in status
01023    return namesobject;
01024 }
01025 TFolder * TGo4AnalysisObjectManager::CreateNamesFolder(TFolder * objectfolder)
01026 {
01027    TRACE((11,"TGo4AnalysisObjectManager::CreateNamesFolder(TFolder*)",__LINE__, __FILE__));
01028    TFolder* namesfolder=0;
01029    if(objectfolder)
01030       {
01031          TList* nameslist= new TList;
01032          TList* objectlist=dynamic_cast<TList*> (objectfolder->GetListOfFolders());
01033          TIterator* listiter=objectlist->MakeIterator();
01034          TObject* entry;
01035          TGo4ObjectStatus* state;
01036          while((entry=listiter->Next()) !=0)
01037             {
01038                if(entry->InheritsFrom("TFolder"))
01039                   {
01040                       // found subfolder, process it recursively
01041                       //cout <<"##### parsing folder "<< entry->GetName() << endl;
01042                       TFolder* subobj= dynamic_cast<TFolder*> (entry);
01043                       TFolder* subnames=CreateNamesFolder(subobj);
01044                       nameslist->AddLast(subnames);
01045                   }
01046                 else if (entry->InheritsFrom("TTree"))
01047                    {
01048                       // treestructure should be ObjectStatus?
01049                       TTree* subobj= dynamic_cast<TTree*> (entry);
01050                       TGo4TreeStructure* treestruct=CreateTreeStructure(subobj);
01051                       nameslist->AddLast(treestruct);
01052                    }
01053                  else if (entry->InheritsFrom("TGo4DynamicList"))
01054                    {
01055                       TGo4DynamicList* subobj= dynamic_cast<TGo4DynamicList*> (entry);
01056                       TGo4DynamicListStatus* dynstat=
01057                             dynamic_cast<TGo4DynamicListStatus*> ( subobj->CreateStatus() );
01058                       nameslist->AddLast(dynstat->GetTopFolder(kTRUE));
01059                       delete dynstat;
01060                       // after the top folder is adopted by the nameslist,
01061                       // we do not need the dynmic list status object itself, avoid leak!
01062                    }
01063                 else
01064                    {
01065                      state=CreateObjectStatus(entry,kFALSE); // do not use full status info for nameslist
01066                      if(state==0) continue;
01067                      if(state->InheritsFrom("TGo4EventStatus"))
01068                         {
01069                            TGo4EventStatus* evstate=dynamic_cast<TGo4EventStatus*>(state);
01070                            nameslist->AddLast(evstate->GetTopFolder(kTRUE));
01071                            delete evstate;
01072                         }
01073                      else
01074                         {
01075                            nameslist->AddLast(state);
01076                         }
01077                   }
01078             } // while
01079          namesfolder=fxTempFolder->AddFolder(objectfolder->GetName(),objectfolder->GetTitle(),nameslist);
01080          fxTempFolder->Remove(namesfolder);
01081          namesfolder->SetOwner(kTRUE);
01082          delete listiter;
01083       }
01084    else
01085       {
01086          namesfolder=0;
01087       }
01088 
01089    return namesfolder;
01090 }
01091 
01092 TFolder * TGo4AnalysisObjectManager::GetObjectFolder()
01093 {
01094    return fxGo4Dir;
01095 }
01096 
01097 
01098 
01099 
01100 Bool_t TGo4AnalysisObjectManager::AddEventStore(TGo4EventStore * store)
01101 {
01102 TRACE((11,"TGo4AnalysisObjectManager::AddEventStore(TGo4EventStore*)",__LINE__, __FILE__));
01103  return (AddObjectToFolder(store,fxStoreDir,0,kFALSE));
01104 }
01105 Bool_t TGo4AnalysisObjectManager::RemoveEventStore(TGo4EventStore * store)
01106 {
01107 TRACE((11,"TGo4AnalysisObjectManager::RemoveEventStore(TGo4EventStore*)",__LINE__, __FILE__));
01108    Bool_t rev=kFALSE;
01109    if(store)
01110       {
01111          TGo4LockGuard listguard(fxDirMutex);
01112             fxStoreDir->Remove(store);
01113             rev=kTRUE;
01114       }
01115    else
01116       {
01117          rev=kFALSE;
01118       }
01119    return rev;
01120 }
01121 
01122 Bool_t TGo4AnalysisObjectManager::AddEventSource(TGo4EventSource * source)
01123 {
01124 TRACE((11,"TGo4AnalysisObjectManager::AddEventSource(TGo4EventSource*)",__LINE__, __FILE__));
01125  return (AddObjectToFolder(source,fxSourceDir,0,kFALSE));
01126 }
01127 
01128 Bool_t TGo4AnalysisObjectManager::RemoveEventSource(TGo4EventSource* source)
01129 {
01130 TRACE((11,"TGo4AnalysisObjectManager::RemoveEventSource(TGo4EventSource*)",__LINE__, __FILE__));
01131    Bool_t rev=kFALSE;
01132    if(source)
01133       {
01134          TGo4LockGuard listguard(fxDirMutex);
01135             fxSourceDir->Remove(source);
01136             rev=kTRUE;
01137       }
01138    else
01139       {
01140          rev=kFALSE;
01141       }
01142    return rev;
01143 }
01144 Bool_t TGo4AnalysisObjectManager::AddEventProcessor(TGo4EventProcessor * pro)
01145 {
01146 TRACE((11,"TGo4AnalysisObjectManager::AddEventProcessor(TGo4EventProcessor*)",__LINE__, __FILE__));
01147   return (AddObjectToFolder(pro,fxProcessorDir,0,kFALSE));
01148 }
01149 
01150 Bool_t TGo4AnalysisObjectManager::RemoveEventProcessor(TGo4EventProcessor * pro)
01151 {
01152 TRACE((11,"TGo4AnalysisObjectManager::RemoveEventProcessor(TGo4EventProcessr*)",__LINE__, __FILE__));
01153    Bool_t rev=kFALSE;
01154    if(pro)
01155       {
01156          TGo4LockGuard listguard(fxDirMutex);
01157             fxProcessorDir->Remove(pro);
01158             rev=kTRUE;
01159       }
01160    else
01161       {
01162          rev=kFALSE;
01163       }
01164    return rev;
01165 }
01166 Bool_t TGo4AnalysisObjectManager::AddEventStructure(TGo4EventElement * ev)
01167 {
01168 TRACE((11,"TGo4AnalysisObjectManager::AddEventStructure(TGo4EventElement*)",__LINE__, __FILE__));
01169   return (AddObjectToFolder(ev,fxEventDir,0,kFALSE));
01170 }
01171 
01172 Bool_t TGo4AnalysisObjectManager::RemoveEventStructure(TGo4EventElement * ev)
01173 {
01174 TRACE((11,"TGo4AnalysisObjectManager::RemoveEventStructure(TGo4EventElement*)",__LINE__, __FILE__));
01175    Bool_t rev=kFALSE;
01176    if(ev) {
01177       TGo4LockGuard listguard(fxDirMutex);
01178       fxEventDir->Remove(ev);
01179       // remove pointers to event data from all dynamic lists:
01180       TObject* dl=0;
01181       TIter iter(fxDynListDir->GetListOfFolders());
01182       while((dl=iter())!=0) {
01183          TGo4DynamicList* dynlist= dynamic_cast<TGo4DynamicList*>(dl);
01184          if(dynlist)
01185             dynlist->CleanupEvent(ev);
01186       }
01187       rev=kTRUE;
01188    } else {
01189       rev=kFALSE;
01190    }
01191    return rev;
01192 }
01193 TGo4EventElement * TGo4AnalysisObjectManager::GetEventStructure(const Text_t * name)
01194 {
01195 TRACE((11,"TGo4AnalysisObjectManager::GetEvenStructure(Text_t *)",__LINE__, __FILE__));
01196    return dynamic_cast<TGo4EventElement*> (FindObjectInFolder(fxEventDir, name));
01197 }
01198 
01199 Bool_t TGo4AnalysisObjectManager::AddDynamicList(TGo4DynamicList * list)
01200 {
01201 TRACE((11,"TGo4AnalysisObjectManager::AddDynamicList(TGo4DynamicList *)",__LINE__, __FILE__));
01202   return (AddObjectToFolder(list,fxDynListDir,0,kTRUE));
01203 
01204 }
01205 
01206 void TGo4AnalysisObjectManager::RemoveDynamicList(TGo4DynamicList* list)
01207 {
01208 TRACE((11,"TGo4AnalysisObjectManager::RemoveDynamicList(TGo4DynamicList*)",__LINE__, __FILE__));
01209    fxDynListDir->Remove(list);
01210 }
01211 
01212 Bool_t TGo4AnalysisObjectManager::RemoveDynamicList(const Text_t * name)
01213 {
01214 TRACE((11,"TGo4AnalysisObjectManager::RemoveDynamicList(Text_t*)",__LINE__, __FILE__));
01215    return RemoveObjectFromFolder(name, fxDynListDir, kTRUE);
01216 }
01217 
01218 TGo4DynamicList * TGo4AnalysisObjectManager::GetDynamicList(const Text_t * name)
01219 {
01220 TRACE((11,"TGo4AnalysisObjectManager::GetDynamicList(Text_t*)",__LINE__, __FILE__));
01221    return dynamic_cast<TGo4DynamicList *> (FindObjectInFolder(fxDynListDir, name));
01222 }
01223 
01224 Bool_t TGo4AnalysisObjectManager::ResetBackStores()
01225 {
01226 TRACE((11,"TGo4AnalysisObjectManager::ResetBackStores()",__LINE__, __FILE__));
01227    Bool_t rev=kTRUE;
01228 // now reset all backstore instances:
01229    TList* objectlist=dynamic_cast<TList*> (fxStoreDir->GetListOfFolders());
01230    TIterator* listiter=objectlist->MakeIterator();
01231    TObject* entry;
01232    while((entry=listiter->Next()) !=0)
01233       {
01234          if(entry->InheritsFrom("TGo4BackStore"))
01235             {
01236                TGo4BackStore* bs= dynamic_cast<TGo4BackStore*>(entry);
01237                if(bs)
01238                   {
01239                      bs->Reset();
01240                      //
01241                      //TGo4Log::Debug(" Analysis Object Manager has reset backstore %s",bs->GetName());
01242                   }
01243                else   {}
01244             }
01245          else {}
01246       } // while
01247    delete listiter;
01248    return rev;
01249 }
01250 
01251 void TGo4AnalysisObjectManager::CloseAnalysis()
01252 {
01253 TRACE((14,"TGo4AnalysisObjectManager::CloseAnalysis()",__LINE__, __FILE__));
01254    fxDynamicList->Reset();
01255    fiDynListCount=0;
01256    TGo4Analysis::Instance()->Message(0,"Analysis Object Manager  --  Dynamic List was reset.");
01257 }
01258 
01259 void TGo4AnalysisObjectManager::SaveObjects(TFile* file)
01260 {
01261    if(!file) return;
01262    TGo4Analysis::Instance()->Message(0,"Analysis Object Manager  --  Saving objects to file %s",file->GetName());
01263    fxGo4Dir->RecursiveRemove(fxTreeDir); // do not save the trees twice!
01264    fxGo4Dir->RecursiveRemove(fxAnalysisDir); // do not save eventclass refs
01266    //fxGo4Dir->Write(0, TObject::kOverwrite);
01269    TDirectory* savdir=gDirectory;
01270    file->cd();
01271    // file->Delete("T*;*"); // remove old contents (get rid of deleted dynamic objects)
01272    // note: we always use RECREATE option on saving now. No need to cleanup old file!
01273    SaveFolder(fxGo4Dir);
01274    file->Write(0,TObject::kOverwrite); // write all appended objects and subdirs
01275    savdir->cd();
01276    RemoveFromDir(fxGo4Dir,file); // prevent object deletion on closing the file
01278    fxGo4Dir->Add(fxTreeDir);
01279    fxGo4Dir->Add(fxAnalysisDir);
01280 }
01281 Bool_t TGo4AnalysisObjectManager::AddParameter(TGo4Parameter * par, const Text_t* subfolder)
01282 {
01283 TRACE((11,"TGo4AnalysisObjectManager::AddParameter(TGo4Parameter *)",__LINE__, __FILE__));
01284    return (AddObjectToFolder(par,fxParameterDir,subfolder,kTRUE));
01285 }
01286 
01287 Bool_t TGo4AnalysisObjectManager::SetParameter(const Text_t * name, TGo4Parameter * par, TFolder* parent)
01288 {
01289 TRACE((11,"TGo4AnalysisObjectManager::SetParameter(Text_t*, TGo4Parameter*)",__LINE__, __FILE__));
01290 Bool_t rev=kFALSE;
01291 TFolder* topfolder=0;
01292 if(parent)
01293    topfolder=parent;
01294 else
01295    topfolder=fxParameterDir;
01296 if(par)
01297    {
01298       TGo4Parameter* oldpar= dynamic_cast<TGo4Parameter *> (topfolder->FindObjectAny(name));
01299       if(oldpar!=0)
01300          {
01301             // update existing parameter of given name
01302             rev=oldpar->UpdateFrom(par);
01303             //cout << "++++ Updated parameter "<< name<<" from parameter "<< par->GetName() << endl;
01304             //oldpar->PrintParameter();
01305          }
01306       else
01307          {
01308             // parameter not yet exisiting, add external paramter as a copy:
01309              TGo4Parameter* clonedpar=dynamic_cast<TGo4Parameter*>(par->Clone());
01310               // find out destination folder for new parameter from name:
01311             Text_t subfolder[fguSUBFOLDERMAXLEN];
01312             size_t fnamelen=0;
01313             const char* endname = name;
01314             const char* foldername = name;
01315             while (endname!=0)
01316                {
01317                   endname=strstr(foldername,"/");
01318                   if(endname==0) break;
01319                   fnamelen= endname-name; // length of path string
01320                   foldername=endname+1;
01321                }
01322             if(fnamelen>0)
01323                 {
01324                    // we have a subfolder for condition
01325                    if(fnamelen>fguSUBFOLDERMAXLEN) fnamelen=fguSUBFOLDERMAXLEN;
01326                    snprintf(subfolder,fnamelen,"%s",name);
01327                    rev=AddObjectToFolder(clonedpar,topfolder,subfolder,kTRUE);
01328                    //cout << "++++ Added new parameter "<< clonedpar->GetName()<<" to folder "<<topfolder->GetName()<<"/"<< subfolder << endl;
01329                 }
01330              else
01331                 {
01332                    // no subfolder, condition is directly under topfolder
01333                    rev=AddObjectToFolder(clonedpar,topfolder,0,kTRUE);
01334                    //cout << "++++ Added new parameter "<< clonedpar->GetName()<<" to folder "<<topfolder->GetName()<<", no subfolder!!!"<< endl;
01335                 }
01336          }
01337    }
01338 else
01339    {
01340       rev=kFALSE;
01341    }
01342 return rev;
01343 }
01344 
01345 TGo4Parameter * TGo4AnalysisObjectManager::GetParameter(const Text_t * name)
01346 {
01347 TRACE((11,"TGo4AnalysisObjectManager::GetParameter(Text_t*)",__LINE__, __FILE__));
01348    TGo4Parameter* rev=dynamic_cast<TGo4Parameter *> (FindObjectInFolder(fxParameterDir,name));
01349    if(rev==0) rev= dynamic_cast<TGo4Parameter *> (FindObjectInFolder(fxUserDir,name));
01350    return rev;
01351 }
01352 
01353 Bool_t TGo4AnalysisObjectManager::RemoveParameter(const Text_t * name)
01354 {
01355 TRACE((11,"TGo4AnalysisObjectManager::RemoveParameter(Text_t*)",__LINE__, __FILE__));
01356    return RemoveObjectFromFolder(name, fxParameterDir, kTRUE);
01357 }
01358 
01359 Bool_t TGo4AnalysisObjectManager::AddPicture(TGo4Picture * pic, const Text_t* subfolder)
01360 {
01361 TRACE((11,"TGo4AnalysisObjectManager::AddPicture(TGo4Picture *)",__LINE__, __FILE__));
01362 if(pic)
01363 {
01364    pic->LocateObjectsFrom(fxGo4Dir);
01365    return (AddObjectToFolder(pic,fxPictureDir,subfolder,kTRUE));
01366 }
01367 else
01368    return kFALSE;
01369 }
01370 
01371 Bool_t TGo4AnalysisObjectManager::SetPicture(const Text_t * name, TGo4Picture * pic, TFolder* parent)
01372 {
01373 TRACE((11,"TGo4AnalysisObjectManager::SetPicture(Text_t*, TGo4Picture*)",__LINE__, __FILE__));
01374 Bool_t rev=kFALSE;
01375 TFolder* topfolder=0;
01376 if(parent)
01377    topfolder=parent;
01378 else
01379    topfolder=fxPictureDir;
01380 if(pic)
01381    {
01382       TGo4Picture* oldpic= dynamic_cast<TGo4Picture *> (topfolder->FindObjectAny(name));
01383       if(oldpic!=0)
01384          {
01385             // update existing picture of given name
01386             oldpic->UpdateFrom(pic);
01387 //            cout << "++++ Updated picture "<< name<<" from picture "<< pic->GetName() << endl;
01388          }
01389       else
01390          {
01391             // picture not yet exisiting, add external as a copy:
01392              TGo4Picture* clonedpic=dynamic_cast<TGo4Picture*>(pic->Clone());
01393               // find out destination folder for new pic from name:
01394             Text_t subfolder[fguSUBFOLDERMAXLEN];
01395             size_t fnamelen=0;
01396             const char* endname = name;
01397             const char* foldername = name;
01398             while (endname!=0)
01399                {
01400                   endname=strstr(foldername,"/");
01401                   if(endname==0) break;
01402                   fnamelen= endname-name; // length of path string
01403                   foldername=endname+1;
01404                }
01405             if(fnamelen>0)
01406                 {
01407                    // we have a subfolder for condition
01408                    if(fnamelen>fguSUBFOLDERMAXLEN) fnamelen=fguSUBFOLDERMAXLEN;
01409                    snprintf(subfolder,fnamelen,"%s",name);
01410                    rev=AddObjectToFolder(clonedpic,topfolder,subfolder,kTRUE);
01411                 }
01412              else
01413                 {
01414                    // no subfolder, condition is directly under topfolder
01415                    rev=AddObjectToFolder(clonedpic,topfolder,0,kTRUE);
01416                 }
01417          }
01418    }
01419 else
01420    {
01421       rev=kFALSE;
01422    }
01423 return rev;
01424 }
01425 
01426 TGo4Picture * TGo4AnalysisObjectManager::GetPicture(const Text_t * name)
01427 {
01428 TRACE((11,"TGo4AnalysisObjectManager::GetPicture(Text_t*)",__LINE__, __FILE__));
01429    TGo4Picture* rev=dynamic_cast<TGo4Picture *> (FindObjectInFolder(fxPictureDir, name));
01430    if(rev==0) rev=dynamic_cast<TGo4Picture *> (FindObjectInFolder(fxUserDir, name));
01431    return rev;
01432 }
01433 
01434 Bool_t TGo4AnalysisObjectManager::RemovePicture(const Text_t * name)
01435 {
01436 TRACE((11,"TGo4AnalysisObjectManager::RemovePicture(Text_t*)",__LINE__, __FILE__));
01437    return RemoveObjectFromFolder(name, fxPictureDir, kTRUE);
01438 }
01439 
01440 
01441 void TGo4AnalysisObjectManager::InitPictures(TFolder* fold) {
01442 TFolder* workfolder;
01443 if(fold)
01444    workfolder=fold;
01445 else
01446    workfolder=fxPictureDir;
01447 
01448 TGo4LockGuard  dirguard(fxDirMutex);
01449 
01450 TIter iter(workfolder->GetListOfFolders());
01451 TObject* ob=0;
01452 while(( ob=iter() ) !=0)
01453    {
01454       if(ob->InheritsFrom(TFolder::Class()))
01455          {
01456             TFolder* subfolder =dynamic_cast<TFolder*> (ob);
01457             if(subfolder)
01458                {
01459                   InitPictures(subfolder); // recursively scan all subfolders
01460                }
01461          }
01462       else if(ob->InheritsFrom(TGo4Picture::Class()))
01463          {
01464             TGo4Picture* pic=dynamic_cast<TGo4Picture*> (ob);
01465             pic->LocateObjectsFrom(fxGo4Dir);
01466             //cout<< "PPPPPPP init of picture "<<pic->GetName() <<endl;
01467          }
01468    } // while
01469 }
01470 
01471 
01472 
01473 Bool_t TGo4AnalysisObjectManager::AddCanvas(TCanvas * can, const Text_t* subfolder)
01474 {
01475 TRACE((11,"TGo4AnalysisObjectManager::AddCanvas(TCanvas *)",__LINE__, __FILE__));
01476 Bool_t rev=AddObjectToFolder(can,fxCanvasDir,subfolder,kFALSE);
01477 if(rev && can) gROOT->GetListOfCanvases()->Remove(can);
01478    // make sure that root has no other reference to our canvas
01479 return rev;
01480 }
01481 
01482 Bool_t TGo4AnalysisObjectManager::SetCanvas(const Text_t * name, TGo4CanvasStatus * stat, TFolder* parent)
01483 {
01484 TRACE((11,"TGo4AnalysisObjectManager::SetCanvas(Text_t*, TGo4CanvasStat*)",__LINE__, __FILE__));
01485 Bool_t rev=kFALSE;
01486 TFolder* topfolder=0;
01487 if(parent)
01488    topfolder=parent;
01489 else
01490    topfolder=fxCanvasDir;
01491 if(stat)
01492    {
01493        TCanvas* can=stat->CreateCanvas();
01494        if(can)  gROOT->GetListOfCanvases()->Remove(can);
01495        //can->SetName(name); // override original canvas name
01496         // find out destination folder for canvas from name:
01497       Text_t subfolder[fguSUBFOLDERMAXLEN];
01498       size_t fnamelen=0;
01499       const char* endname = name;
01500       const char* foldername = name;
01501       while (endname!=0)
01502          {
01503             endname=strstr(foldername,"/");
01504             if(endname==0) break;
01505             fnamelen= endname-name; // length of path string
01506             foldername=endname+1;
01507          }
01508       if(fnamelen>0)
01509           {
01510              // we have a subfolder for condition
01511              if(fnamelen>fguSUBFOLDERMAXLEN) fnamelen=fguSUBFOLDERMAXLEN;
01512              snprintf(subfolder,fnamelen,"%s",name);
01513              rev=AddObjectToFolder(can,topfolder,subfolder,kTRUE);
01514              //cout << "++++ Added new parameter "<< clonedpar->GetName()<<" to folder "<<topfolder->GetName()<<"/"<< subfolder << endl;
01515           }
01516        else
01517           {
01518              // no subfolder, condition is directly under topfolder
01519              rev=AddObjectToFolder(can,topfolder,0,kTRUE);
01520              //cout << "++++ Added new parameter "<< clonedpar->GetName()<<" to folder "<<topfolder->GetName()<<", no subfolder!!!"<< endl;
01521           }
01522 
01523    }
01524 else
01525    {
01526       rev=kFALSE;
01527    }
01528 return rev;
01529 }
01530 
01531 TCanvas * TGo4AnalysisObjectManager::GetCanvas(const Text_t * name)
01532 {
01533 TRACE((11,"TGo4AnalysisObjectManager::GetPicture(Text_t*)",__LINE__, __FILE__));
01534    TCanvas* rev=dynamic_cast<TCanvas*> (FindObjectInFolder(fxCanvasDir, name));
01535    if(rev==0) rev=dynamic_cast<TCanvas*> (FindObjectInFolder(fxCanvasDir, name));
01536    return rev;
01537 }
01538 
01539 Bool_t TGo4AnalysisObjectManager::RemoveCanvas(const Text_t * name)
01540 {
01541 TRACE((11,"TGo4AnalysisObjectManager::RemovePicture(Text_t*)",__LINE__, __FILE__));
01542    return RemoveObjectFromFolder(name, fxCanvasDir, kTRUE);
01543 }
01544 
01545 
01546 
01547 
01548 
01549 Bool_t TGo4AnalysisObjectManager::LoadObjects(TFile* obfile)
01550 {
01551    TRACE((11,"TGo4AnalysisObjectManager::LoadObjects(TFile*)",__LINE__, __FILE__));
01552    Bool_t rev=kFALSE;
01553    if(obfile)
01554       {
01555          TObject* ob=obfile->Get(TGo4AnalysisObjectManager::fgcTOPFOLDER);
01556          TFolder* top= dynamic_cast<TFolder*>(ob);
01557          if(top)
01558             {
01559                // kept for backward compatibility: read folder struct directly
01560                //cout << "found top go4 folder "<< endl;
01561                rev=LoadFolder(top,fxGo4Dir,kFALSE);
01562             }
01563          else
01564             {
01565                // new: convert directory structure of file into folders
01566                //cout <<"LoadObjects with Dirscan..." << endl;
01567                rev=LoadFolder(obfile,fxGo4Dir,kFALSE);
01568             }
01569          TGo4PolyCond::CleanupSpecials(); // remove references to file cuts
01570          InitPictures(); // initialize pointers to histos
01571          if(fxDynamicList) fxDynamicList->Reset(); // reset loaded entries
01572       
01573       }
01574    return rev;
01575 }
01576 
01577 void TGo4AnalysisObjectManager::ResetCurrentDynList()
01578 {
01579    if(fxDynamicList)
01580       fxDynamicList->Reset();
01581 }
01582 
01583 Int_t TGo4AnalysisObjectManager::ProcessDynamicList()
01584 {
01585 TRACE((11,"TGo4AnalysisObjectManager::ProcessDynamicList()",__LINE__, __FILE__));
01586 //
01587    Int_t rev=-1;
01588    if(fxDynamicList)
01589       {
01590          if(fxDynamicList->IsEmpty()) return 0;
01591          fiDynListCount++;
01592          rev=fxDynamicList->Process(); // normally, all entries are processed eventwise
01593                                        // except for treehistogramentries; these
01594                                        // check the dynlistinterval internally now!
01595          if(CheckDynListInterval()) ResetBackStores();
01596             // after dynlistinterval treehistogram entries are processed, reset trees for them
01597       }
01598    else
01599       {
01600          throw TGo4DynamicListException(0,
01601                "AnalysisObjectManager::ProcessDynamicList: No current dynamic list set  !!!");
01602       }
01603    return rev;
01604 }
01605 
01606 Bool_t TGo4AnalysisObjectManager::SetDynamicEntryStatus(const Text_t* name, TGo4DynamicEntryStatus* state, const Text_t* listname)
01607 {
01608 TRACE((11,"TGo4AnalysisObjectManager::SetDynamicEntryStatus(Text_t*, TGo4DynamicEntryStatus*)",__LINE__, __FILE__));
01609    if(state==0) return kFALSE;
01610    TGo4DynamicList* thelist=0;
01611    if(listname==0)
01612       {
01613          thelist=GetCurrentDynList(); // default behaviour: work on current dynlist
01614       }
01615    else
01616       {
01617          thelist= GetDynamicList(listname); // later: more than one dynamic list?
01618       } //   if(listname==0)
01619    if(thelist)
01620       return (thelist->SetEntryStatus(name,state));
01621    else
01622       return kFALSE;
01623    return kFALSE;
01624 }
01625 
01626 Bool_t TGo4AnalysisObjectManager::AddDynamicHistogram(const Text_t* name,
01627                                                       const Text_t* histo,
01628                                                       const Text_t* hevx, const Text_t* hmemx,
01629                                                       const Text_t* hevy, const Text_t* hmemy,
01630                                                       const Text_t* hevz, const Text_t* hmemz,
01631                                                       const Text_t* condition,
01632                                                       const Text_t* cevx, const Text_t* cmemx,
01633                                                       const Text_t* cevy, const Text_t* cmemy)
01634 {
01635 TRACE((11,"TGo4AnalysisObjectManager::AddDynamicHistogram(Text_t*,...)",__LINE__, __FILE__));
01636    if(name==0 || histo==0 || hevx==0 || hmemx==0) return kFALSE;
01637    TGo4HistogramEntryStatus* settings= new TGo4HistogramEntryStatus;
01638    settings->ResetNames();
01639    settings->SetName(name);
01640    settings->SetHistogramName(histo);
01641    TString hevents[__MAXHISDIM__];
01642    TString hmembers[__MAXHISDIM__];
01643    for (UInt_t t=0; t<TGo4HistogramEntry::fguMAXHISDIMENSION;++t)
01644       {
01645           // set names to defaults.
01646           hevents[t]=TGo4DynamicEntry::fgcNOEVENT;
01647           hmembers[t]=TGo4DynamicEntry::fgcNODATA;
01648       }
01649    hevents[0]=hevx;
01650    hmembers[0]=hmemx;
01651    if(hevy!=0 && hmemy!=0 && TGo4HistogramEntry::fguMAXHISDIMENSION>1)
01652       {
01653          hevents[1]=hevy;
01654          hmembers[1]=hmemy;
01655          if(hevz!=0 && hmemz!=0 && TGo4HistogramEntry::fguMAXHISDIMENSION>2)
01656             {
01657                 hevents[2]=hevz;
01658                 hmembers[2]=hmemz;
01659             }
01660          else {}
01661       }
01662    else {}
01663    settings->SetHisEventNames(hevents);
01664    settings->SetHisVarNames(hmembers);
01665    if(condition!=0 && cevx!=0 && cmemx!=0 )
01666       {
01667           settings->SetConditionName(condition);
01668           TString cevents[__MAXCONDIM__];
01669           TString cmembers[__MAXCONDIM__];
01670           for (UInt_t t=0; t<TGo4DynamicEntry::fguMAXCONDIMENSION;++t)
01671             {
01672                 // set names to defaults.
01673                 cevents[t]=TGo4DynamicEntry::fgcNOEVENT;
01674                 cmembers[t]=TGo4DynamicEntry::fgcNODATA;
01675             }
01676           cevents[0]=cevx;
01677           cmembers[0]=cmemx;
01678           if(cevy!=0 && cmemy!=0 && TGo4DynamicEntry::fguMAXCONDIMENSION>1)
01679             {
01680                cevents[1]=cevy;
01681                cmembers[1]=cmemy;
01682             }
01683           settings->SetConEventNames(cevents);
01684           settings->SetConVarNames(cmembers);
01685        } // if (condition...)
01686     else {}
01687 
01688    Bool_t rev=AddDynamicHistogram(settings);
01689    delete settings;
01690    return rev;
01691 }
01692 
01693 Bool_t TGo4AnalysisObjectManager::AddDynamicHistogram(TGo4HistogramEntryStatus* settings)
01694 {
01695 TRACE((11,"TGo4AnalysisObjectManager::AddDynamicHistogram(TGo4HistogramEntryStatus**,...)",__LINE__, __FILE__));
01696    Bool_t rev=kFALSE;
01697    if(settings==0) return kFALSE;
01698    const Text_t* name=settings->GetName();
01699    TGo4DynamicList* thelist=GetCurrentDynList();
01700    if(thelist)
01701       {
01702          TGo4HistogramEntry* hisentry= new TGo4HistogramEntry(name);
01703          hisentry->SetStatus(settings);
01704          if(thelist->AddEntry(hisentry))
01705             {
01706                rev=kTRUE;
01707             }
01708          else
01709             {
01710                // adding failed, name already exists
01711                delete hisentry;
01712                rev=kFALSE;
01713             }
01714       }
01715    else
01716       {
01717          rev=kFALSE;
01718       }  //  if(thelist)
01719    return rev;
01720 }
01721 
01722 Bool_t TGo4AnalysisObjectManager::AddTreeHistogram(const Text_t * hisname, const Text_t * treename, const Text_t* varexp, TCut selection)
01723 {
01724 TRACE((11,"TGo4AnalysisObjectManager::AddTreeHistogram(Text_t*,...)",__LINE__, __FILE__));
01725   //
01726    Bool_t rev=kFALSE;
01727    TGo4TreeHistogramEntry* hisentry= new TGo4TreeHistogramEntry(hisname,
01728                                                              treename,
01729                                                              varexp,
01730                                                              selection);
01731    TGo4DynamicList* curlist=GetCurrentDynList();
01732    if(curlist)
01733       {
01734 
01735          if(curlist->AddEntry(hisentry))
01736             {
01737                TGo4Analysis::Instance()->Message(0,"Analysis added tree histogram %s to dynamic list",
01738                hisentry->GetName() );
01739                //UpdateNamesList();
01740                rev=kTRUE;
01741             }
01742          else
01743             {
01744                TGo4Analysis::Instance()->Message(0,"!!! Analysis AddTreeHistogram- ERROR: entry %s already exists !!!",
01745                      hisentry->GetName());
01746                rev=kFALSE;
01747             }
01748       }
01749   else
01750       {
01751           TGo4Analysis::Instance()->Message(3,"!!! Analysis AddTreeHistogram- ERROR: no dynamic list !!!");
01752           delete hisentry;
01753           rev=kFALSE;
01754       } // if(fxDynamicList)
01755    return rev;
01756 }
01757 
01758 
01759 
01760 
01761 Bool_t TGo4AnalysisObjectManager::RemoveDynamicEntry(const Text_t * entryname, const Text_t* listname)
01762 {
01763 TRACE((11,"TGo4AnalysisObjectManager::RemoveDynamicEntry(const Text_t *, const Text_t* )",__LINE__, __FILE__));
01764    Bool_t rev=kFALSE;
01765    TGo4DynamicList* thelist=0;
01766    if(listname==0)
01767       {
01768          thelist=GetCurrentDynList();
01769       }
01770    else
01771       {
01772          thelist= GetDynamicList(listname);
01773       } //   if(listname==0)
01774    if(thelist)
01775       {
01776          thelist->DeleteEntry(entryname);
01777          rev=kTRUE;
01778       }
01779    else
01780       {
01781          // no such dynamic list
01782          rev=kFALSE;
01783       }  //  if(thelist)
01784    return rev;
01785 }
01786 
01787 
01788 TFolder* TGo4AnalysisObjectManager::FindSubFolder(TFolder* parent, const Text_t* subfolder, Bool_t create)
01789 {
01790 TRACE((11,"TGo4AnalysisObjectManager::FindSubFolder(TFolder*, const Text_t*, Bool_t)",__LINE__, __FILE__));
01791 TGo4LockGuard  dirguard(fxDirMutex);
01792    TFolder* result=0;
01793    if(parent==0) return 0;
01794    if(subfolder==0) return parent;
01795    Text_t subname[fguSUBFOLDERMAXLEN];
01796    size_t fnamelen=0;
01797    const char* endname = subfolder;
01798    const char* searchname = subfolder;
01799    endname=strstr(searchname,"/"); // find end of first subfolder string
01800    if(endname!=0)
01801       {
01802          // we have subfolder of subfolder, process recursively
01803          endname+=1;
01804          fnamelen= endname-searchname; // length of first subfolder name
01805          if(fnamelen>fguSUBFOLDERMAXLEN) fnamelen=fguSUBFOLDERMAXLEN;
01806          snprintf(subname,fnamelen,"%s",searchname);
01807          //cout <<" fffffff Searching for subfolder "<< subname << endl;
01808          TFolder* nextsubfolder=FindSubFolder(parent,subname,create); // get folder directly under parent
01809          result=FindSubFolder(nextsubfolder,endname,create); // search rest of path in this folder
01810       }
01811    else
01812       {
01813          // only one level of subfolder, find it directly
01814          TList* folderlist=dynamic_cast<TList*> (parent->GetListOfFolders());
01815          TIterator* listiter=folderlist->MakeIterator();
01816          TObject* entry;
01817          while((entry=listiter->Next()) !=0)
01818             {
01819                if(entry->InheritsFrom("TFolder"))
01820                   {
01821                      if(!strcmp(subfolder,entry->GetName()))
01822                         {
01823                             result= dynamic_cast<TFolder*>(entry);
01824                             //cout <<" fffffff Found subfolder "<<subfolder << endl;
01825                             break;
01826                         }
01827                   }
01828             }
01829          if(result==0 && create)
01830             {
01831                result=parent->AddFolder(subfolder,"UserFolder"); // create new subfolder if not found
01832             }
01833          delete listiter;
01834       } // if (endname!=0)
01835    return result;
01836 }
01837 
01838 
01839 Bool_t TGo4AnalysisObjectManager::AddObjectToFolder(TObject * ob, TFolder* fold, const Text_t* subfolder, Bool_t replace, Bool_t uniquename, Bool_t resetbits)
01840 {
01841 TRACE((11,"TGo4AnalysisObjectManager::AddObjectToFolder(TObject *, TFolder*, const Text_t*, Bool_t)",__LINE__, __FILE__));
01842 
01843 Bool_t rev=kTRUE;
01844 TGo4LockGuard  dirguard(fxDirMutex);
01845 if(fold==0) return kFALSE;
01846 if(ob)
01847    {
01848       if(resetbits)
01849          {
01850             ob->ResetBit(TGo4Status::kGo4NoReset);
01851             ob->ResetBit(TGo4Status::kGo4CanDelete); // default behaviour: allow reset, disable delete   
01852          }
01853       Text_t obname[fguSUBFOLDERMAXLEN];
01854       Text_t subname[fguSUBFOLDERMAXLEN];
01855       if(subfolder)
01856          {
01857             // prepare given name of subfolder:
01858             snprintf(subname,fguSUBFOLDERMAXLEN,"%s",subfolder);
01859             Text_t* lastchar=subname + strlen(subname)-1;
01860             if (*lastchar=='/')
01861                *lastchar = 0;
01862 /*            if(!strcmp("/",lastchar))
01863                {
01864                   // last character of foldername is slash, ignore it!
01865                   snprintf(lastchar,1,"\0");
01866                }
01867 */
01868             snprintf(obname,fguSUBFOLDERMAXLEN,"%s/%s",subname,ob->GetName());
01869          }
01870       else
01871          {
01872             snprintf(obname,fguSUBFOLDERMAXLEN,"%s",ob->GetName());
01873          }
01874 
01875       TObject* oldob=0;
01876       if(uniquename)
01877          {
01878             // look for object of identical name anywhere in top folder
01879             oldob=fold->FindObjectAny( ob->GetName() );
01880          }
01881       else
01882          {
01883             // only check for objects that are in given subfolder
01884             oldob= fold->FindObjectAny(obname);
01885          }
01886       if(oldob)
01887          // is object already in folder?
01888          {
01889                //yes, shall we replace? check if pointers are identical first!
01890             if(replace && ob!=oldob)
01891                {
01892                   // remove old reference before adding new one:
01893                   fold->RecursiveRemove(oldob);
01894                   CleanupDynamicLists(oldob);
01895                   delete oldob;
01896                }
01897             else
01898                {
01899                   return kFALSE; // do not overwrite old one
01900                }
01901          }
01902       else   {}
01903     TFolder* addDir=0;
01904     if(subfolder)
01905        {
01906          addDir=FindSubFolder(fold,subname,kTRUE);
01907          if(addDir==0)
01908             {
01909             // should not happen: all specified subfolders should be created!
01910             addDir=fold;
01911             }
01912        }
01913     else
01914        {
01915           addDir=fold;
01916        } // if(subfolder)
01917     addDir->Add(ob);
01918     rev=kTRUE;
01919    }
01920 else
01921    {
01922       TRACE((12,"TGo4AnalysisObjectManager::AddObjectToFolder - zero object",__LINE__, __FILE__));
01923       rev=kFALSE;
01924    } // if(his)
01925 
01926 
01927 
01928 return rev;
01929 }
01930 
01931 
01932 Bool_t TGo4AnalysisObjectManager::RemoveObjectFromFolder(const Text_t* fullname, TFolder* fold, Bool_t isDel)
01933 {
01934 TRACE((11,"TGo4AnalysisObjectManager::RemoveObjectFromFolder(const Text_t*, TFolder*, Bool_t)",__LINE__, __FILE__));
01935 //
01936    if(fold==0) return kFALSE;
01937    TGo4LockGuard  dirguard(fxDirMutex);
01938    TNamed* obj = 0;
01939    Int_t buflen=fguSUBFOLDERMAXLEN;
01940    Text_t buffer[buflen];
01941    if(fullname) {
01942       strncpy(buffer,fullname,buflen-10);
01943       obj = dynamic_cast<TNamed*> (fold->FindObjectAny(buffer));
01944    }
01945 
01946    if(obj!=0) {
01947       fold->RecursiveRemove(obj);
01948       CleanupDynamicLists(obj);
01949       if (isDel) delete obj;
01950       TGo4Analysis::Instance()->Message(0,"Analysis: removed object %s",buffer);
01951       return kTRUE;
01952    }
01953 
01954    TGo4Analysis::Instance()->Message(0,"!!! Analysis: removing object %s FAILED !!!",buffer);
01955    return kFALSE;
01956 }
01957 
01958 Bool_t TGo4AnalysisObjectManager::LoadFolder(TFolder* source, TFolder* destination, Bool_t replace)
01959 {
01960 TRACE((11,"TGo4AnalysisObjectManager::LoadFolder(TFolder*, TFolder*, Bool_t replace)",__LINE__, __FILE__));
01961 TGo4LockGuard  dirguard(fxDirMutex);
01962 Bool_t rev=kTRUE;
01963 TCollection* folderlist=source->GetListOfFolders();
01964 TIterator* folderiter=folderlist->MakeIterator();
01965 TObject* ob=0;
01966 while(( ob=folderiter->Next() ) !=0)
01967    {
01968       if(ob->InheritsFrom("TFolder"))
01969          {
01970             TFolder* subfolder =dynamic_cast<TFolder*> (ob);
01971             if(subfolder)
01972                {
01973                   //cout <<"LLLLLL Load folder scanning subfolder "<< subfolder->GetName() << endl;
01974                   TFolder* subdest=FindSubFolder(destination,subfolder->GetName(), kTRUE);
01975                   LoadFolder(subfolder,subdest,replace); // recursively scan all subfolders
01976                }
01977          }
01978       else
01979          {
01980             rev=PutToFolder(ob,destination,replace);
01981          }
01982 } // while(..)
01983 delete folderiter;
01984 return rev;
01985 }
01986 
01987 Bool_t TGo4AnalysisObjectManager::LoadFolder(TDirectory* source, TFolder* destination, Bool_t replace)
01988 {
01989 TRACE((11,"TGo4AnalysisObjectManager::LoadFolder(TDirectory*, TFolder*, Bool_t replace)",__LINE__, __FILE__));
01990 if(!source || !destination) return kFALSE;
01991 TGo4LockGuard  dirguard(fxDirMutex);
01992 Bool_t rev=kTRUE;
01993 TDirectory* savdir=gDirectory;
01994 source->cd(); // this is necessary to let the TKey::ReadObj work!
01995 source->ReadKeys();
01996 TCollection* keylist=source->GetListOfKeys();
01997 TIterator* keyiter=keylist->MakeIterator();
01998 TObject* keyob=0;
01999 TKey* key=0;
02000 while(( keyob=keyiter->Next() ) !=0)
02001    {
02002       key=dynamic_cast<TKey*>(keyob);
02003       if(key==0)
02004         {
02005            TGo4Analysis::Instance()->Message(3,"Analysis LoadFolder: ZERO key in directory %s",
02006                           source->GetName());
02007            delete keyiter;               
02008            return kFALSE;
02009         }
02010       //cout <<"Reading key "<<key->GetName() << endl;
02011       TObject* ob=key->ReadObj();
02012       if(ob==0)
02013          {
02014              TGo4Analysis::Instance()->Message(2,"Analysis LoadFolder: Retrying to read key %s ...",
02015                           key->GetName());
02016             ob=source->Get(key->GetName());
02017             if(ob==0)
02018                {
02019                   TGo4Analysis::Instance()->Message(3,"Analysis LoadFolder: Failed to read key %s !",
02020                           key->GetName());
02021                   return kFALSE;
02022                }
02023          }
02024 
02025       if(ob->InheritsFrom("TDirectory"))
02026          {
02027             TDirectory* subdir =dynamic_cast<TDirectory*> (ob);
02028             if(subdir)
02029                {
02030                   //cout <<"LLLLLL Load folder dir scanning for subdir "<< subdir->GetName() << endl;
02031                   Bool_t inpicturefolder=kFALSE;
02032                   if(!strcmp(subdir->GetName(),fgcPICTFOLDER)) inpicturefolder=kTRUE;
02033                   if(inpicturefolder) fbSuppressLoadHistograms=kTRUE;   
02034                   TFolder* subdest=FindSubFolder(destination,subdir->GetName(), kTRUE);
02035                   rev=LoadFolder(subdir,subdest,replace); // recursively scan all subfolders
02036                   if(inpicturefolder) fbSuppressLoadHistograms=kFALSE;
02037                }
02038          }
02039       else
02040          {
02041             rev=PutToFolder(ob,destination,replace);
02042          }
02043 } // while(..)
02044 delete keyiter;
02045 savdir->cd();
02046 return rev;
02047 }
02048 
02049 Bool_t TGo4AnalysisObjectManager::PutToFolder(TObject* ob, TFolder* destination, Bool_t replace)
02050 {
02051 if(!ob || !destination) return kFALSE;
02052 Bool_t rev=kTRUE;
02053 //cout <<"put to folder for "<<ob->GetName() << endl;
02054 if(ob->InheritsFrom("TGo4DynamicList"))
02055    {
02056       // this case only happens for old autosave file structure
02057       // take care for global dynamic list pointer
02058      RemoveDynamicList(fxDynamicList);
02059      TGo4DynamicList* list =dynamic_cast<TGo4DynamicList*> ( ob->Clone() ); // deep copy of source object!
02060       if(AddObjectToFolder(list,destination,0,replace))
02061          {
02062            //cout <<"put to folder added dynamic list "<<list->GetName()<<" "<< list << endl;
02063            //cout <<"put to folder deleted old list "<<fxDynamicList << endl;
02064            delete fxDynamicList; // discard previous list
02065            fxDynamicList=list;
02066            TGo4Analysis::Instance()->Message(0,"Analysis LoadFolder: Dynamiclist %s was loaded and set.",
02067                           list->GetName());
02068          }
02069       else
02070          {
02071             //cout <<"put to folder 2. try: added dynamic list "<<list->GetName()<<" "<< ob << endl;
02072             // object already there and noreplace set: delete clone
02073             delete list;
02074             AddDynamicList(fxDynamicList); // we continue with old list
02075          } // if(AddObjectToFolder(addob,destination,0,replace))
02076                      fxDynamicList->Reset();
02077    }
02078 else if (ob->InheritsFrom("TGo4DynamicEntry"))
02079 {
02080    // new autosave file structure will save dynamic entries independently:
02081    if(fxDynamicList==0)
02082       {
02083          fxDynamicList= new TGo4DynamicList( TGo4Analysis::fgcTOPDYNAMICLIST );
02084          AddDynamicList(fxDynamicList);
02085       }
02086    TGo4DynamicEntry* dentry =dynamic_cast<TGo4DynamicEntry*> ( ob->Clone() ); // deep copy of source object!
02087    fxDynamicList->DeleteEntry(dentry->GetName());
02088    fxDynamicList->AddEntry(dentry);
02089    //cout <<"Added dynamic entry from file: "<<dentry->GetName() << endl;
02090 }
02091 
02092 else if(ob->InheritsFrom("TGo4Parameter"))
02093    {
02094       // parameters never replaced, but updated
02095       TGo4Parameter* par =dynamic_cast<TGo4Parameter*>(ob);
02096       SetParameter(ob->GetName(),par,destination);
02097    }
02098 else if(ob->InheritsFrom("TGo4Picture"))
02099    {
02100       // pictures never replaced, but updated
02101       TGo4Picture* pic =dynamic_cast<TGo4Picture*>(ob);
02102       //cout <<"LLLLLoad Folder SetsPicture!!!!!" << endl;
02103       SetPicture(ob->GetName(),pic,destination);
02104    }
02105 else if(ob->InheritsFrom("TGo4Condition"))
02106    {
02107       // conditions not replaced, but updated
02108       TGo4Condition* con =dynamic_cast<TGo4Condition*>(ob);
02109       SetAnalysisCondition(ob->GetName(),con,kTRUE, destination);
02110    }
02111 else if(ob->InheritsFrom("TH1")) 
02112    {
02113       if(fbSuppressLoadHistograms) return kFALSE;
02114       // test: do not clone histos, but change dir from asf file to memory
02115       TH1* his =dynamic_cast<TH1*>(ob);
02116        if(AddObjectToFolder(his,destination,0,replace,kFALSE,kFALSE))
02117          {
02118             his->SetDirectory(gROOT); // set directory for histos, needed for TTree::Draw
02119             TGo4Analysis::Instance()->Message(0,"Analysis LoadFolder: Histogram %s was loaded.",
02120                           his->GetName());
02121             //cout <<"Changed directory of histo "<<his->GetName() << endl;
02122          }
02123        else
02124         {
02125             // object already there and noreplace set: do not change dir
02126         }
02127    }
02128 else
02129    {
02130       TObject* addob =ob->Clone(); // deep copy of source object!
02131       if(AddObjectToFolder(addob,destination,0,replace))
02132          {
02133 
02134             TGo4Analysis::Instance()->Message(-1,"Analysis LoadFolder: Object %s was loaded.",
02135                           addob->GetName());
02136          }
02137       else
02138          {
02139             // object already there and noreplace set: delete clone
02140             delete addob;
02141          } // if(AddObjectToFolder(addob,destination,0,replace))
02142    }
02143 return rev;
02144 }
02145 
02146 
02147 
02148 Bool_t TGo4AnalysisObjectManager::SaveFolder(TFolder* source)
02149 {
02150 TGo4LockGuard  dirguard(fxDirMutex);
02151 Bool_t rev=kTRUE;
02152 TCollection* folderlist=source->GetListOfFolders();
02153 TIterator* folderiter=folderlist->MakeIterator();
02154 TObject* ob=0;
02155 while(( ob=folderiter->Next() ) !=0)
02156    {
02157       if(ob->InheritsFrom("TFolder"))
02158          {
02159             TFolder* subfolder =dynamic_cast<TFolder*> (ob);
02160             if(subfolder)
02161                {
02162                   TDirectory* currentdir=gDirectory;
02163                   const Text_t* subfoldername=subfolder->GetName();
02164                   TDirectory* subdir=subdir=dynamic_cast<TDirectory*>(currentdir->Get(subfoldername));
02165                   if(subdir==0)
02166                      {
02167                         subdir=currentdir->mkdir(subfoldername,"subdir");
02168                         //cout <<"SSSS Save folder created subdir "<<subfoldername << endl;
02169                      }
02170                   else
02171                      {
02172                          //cout <<"SSSS Save folder found existing subdir "<<subfoldername << endl;
02173                      }
02174 
02175                   if(subdir)
02176                      {
02177                         subdir->cd();
02178                         //cout <<"SSSS Save folder scanning subfolder "<< subfolder->GetName() << endl;
02179                         SaveFolder(subfolder); // recursively scan all subfolders
02180                      }
02181                   else
02182                      {
02183                           TGo4Analysis::Instance()->Message(2,"Analysis SaveFolder: Could not assign subdirectory %s to folder.",
02184                                 subfoldername);
02185                      }
02186                   currentdir->cd();
02187                }
02188          }
02189       else
02190          {
02191 
02192 
02193             if(ob->InheritsFrom("TGo4DynamicList"))
02194                {
02195                    TGo4DynamicList* dlist=dynamic_cast<TGo4DynamicList*>(ob);
02196                    dlist->ResetIterator();
02197                    TGo4DynamicEntry* dentry=0;
02198                    while((dentry= dlist->NextEntry()) !=0)
02199                      {
02200                         AppendToDir(dentry,gDirectory);
02201                         //cout <<"Appending dynamic list entry "<<dentry->GetName()<<" "<< ob << endl;
02202                      }
02203                }
02204             else
02205                {
02206                     AppendToDir(ob,gDirectory);
02207                     //cout <<"Appended "<<ob->GetName()<<" to subdir "<< gDirectory->GetName() <<endl;
02208                }
02209          }
02210 } // while(..)
02211 delete folderiter;
02212 return rev;
02213 }
02214 
02215 void TGo4AnalysisObjectManager::AppendToDir(TObject* ob, TDirectory* dir)
02216 {
02217 if(!ob || !dir) return;
02218 // note: we do not check for old objects anymore, because
02219 // file is generally cleaned up before writing now JA
02220 //TObject* oldob=dir->Get(ob->GetName());
02221 //if(oldob)
02222 //   {
02225 //   }
02226 dir->Append(ob);
02227 }
02228 
02229 void TGo4AnalysisObjectManager::RemoveFromDir(TFolder* fold, TDirectory* dir)
02230 {
02231 if(!fold || !dir) return;
02232 TCollection* folderlist=fold->GetListOfFolders();
02233 TIterator* folderiter=folderlist->MakeIterator();
02234 TObject* ob=0;
02235 while(( ob=folderiter->Next() ) !=0)
02236    {
02237       if(ob->InheritsFrom("TFolder"))
02238          {
02239             TFolder* subfolder =dynamic_cast<TFolder*> (ob);
02240             if(subfolder)
02241                {
02242                   RemoveFromDir(subfolder,dir); // recursively scan all subfolders
02243                }
02244          }
02245       else if (ob->InheritsFrom("TGo4DynamicList"))
02246          {
02247             TGo4DynamicList* dlist=dynamic_cast<TGo4DynamicList*>(ob);
02248             dlist->ResetIterator();
02249             TGo4DynamicEntry* dentry=0;
02250             while((dentry=dlist->NextEntry() ) !=0)
02251                {
02252                   dir->RecursiveRemove(dentry);
02253                   //cout <<"Removing dynamic list entry "<<dentry->GetName()<<" "<< dentry << endl;
02254                }
02255          }
02256       else
02257          {
02258             dir->RecursiveRemove(ob);
02259          }
02260    }
02261 delete folderiter;
02262 }
02263 
02264 Int_t TGo4AnalysisObjectManager::PrintFolder(TFolder* fold, Option_t* opt, const Text_t* expression)
02265 {
02266 TRACE((11,"TGo4AnalysisObjectManager::PrintFolder(TFolder*, Option_t*)",__LINE__, __FILE__));
02267 TGo4LockGuard  dirguard(fxDirMutex);
02268 Int_t totalsize=0;
02269 if(fold)
02270    {
02271       TROOT::IndentLevel();
02272       TROOT::IncreaseDirLevel();
02273       cout <<"+Folder "<<fold->GetName()<<" content:" << endl;
02274       TCollection* list=fold->GetListOfFolders();
02275       TIterator* listiter=list->MakeIterator();
02276       TObject* ob=0;
02277       while((ob=listiter->Next())!=0)
02278          {
02279             if(ob->InheritsFrom("TFolder"))
02280                {
02281                    totalsize+=PrintFolder(dynamic_cast<TFolder*>(ob),opt,expression);
02282                }
02283             else
02284                {
02285                    if(IsMatching(ob->GetName(),expression))
02286                       {
02287                          TROOT::IndentLevel();
02288                          ob->Print(opt);
02289                          TGo4ObjectStatus* temp=CreateObjectStatus(ob);
02290                          if(temp) totalsize+=temp->GetObjectSize();
02291                          delete temp;
02292                       }
02293                }
02294       }// while
02295    TROOT::DecreaseDirLevel();
02296    TROOT::IndentLevel();
02297    cout <<"++++End "<<fold->GetName()<<"++++++++++" << endl;
02298    delete listiter;
02299    } else {}
02300 return totalsize;
02301 }
02302 
02303 Bool_t TGo4AnalysisObjectManager::ClearFolder(TFolder* fold)
02304 {
02305 TRACE((11,"TGo4AnalysisObjectManager::ClearFolder(TFolder*, Option_t*)",__LINE__, __FILE__));
02306 TGo4LockGuard  dirguard(fxDirMutex);
02307 Bool_t rev=kFALSE;
02308 if(fold)
02309    {
02310       rev=kTRUE;
02311       TCollection* list=fold->GetListOfFolders();
02312       TIterator* listiter=list->MakeIterator();
02313       TObject* ob=0;
02314       while((ob=listiter->Next())!=0)
02315          {
02316             if(ob->InheritsFrom("TFolder"))
02317                {
02318                    ClearFolder(dynamic_cast<TFolder*>(ob));
02319                }
02320             else
02321                {
02322                    ClearObject(ob);
02323                }
02324       }// while
02325    delete listiter;
02326    }
02327 return rev;
02328 }
02329 
02330 Bool_t TGo4AnalysisObjectManager::ClearObject(TObject* ob)
02331 {
02332 TRACE((11,"TGo4AnalysisObjectManager::ClearObject(TObject*)",__LINE__, __FILE__));
02333 Bool_t rev=kFALSE;
02334 if(ob)
02335    {
02336       if(ob->TestBit(TGo4Status::kGo4NoReset)) return kFALSE;
02337       rev=kTRUE;
02338       if(ob->InheritsFrom("TH1"))
02339          {
02340              TH1* his= dynamic_cast<TH1*>(ob);
02341              his->Reset(); // histogram has no Clear implementation!
02342          }
02343       else if(ob->InheritsFrom("TGo4Picture"))
02344          {
02345              TGo4Picture* pic= dynamic_cast<TGo4Picture*>(ob);
02346              pic->Reset(); // picture has no Clear implementation!
02347          }
02348       else if(ob->InheritsFrom("TGraph"))
02349          {
02350             TGraph* gr= dynamic_cast<TGraph*>(ob);
02351             Int_t pn=gr->GetN();
02352             gr->Set(0); // clear array of points
02353             gr->Set(pn); // this should set all to 0
02354          }
02355      else if(ob->InheritsFrom("TMultiGraph"))
02356          {
02357             TMultiGraph* mg= dynamic_cast<TMultiGraph*>(ob);
02358             TList* glist=mg->GetListOfGraphs();
02359             TIterator* liter=glist->MakeIterator();
02360             TObject* ob=0;
02361             while((ob=liter->Next())!=0)
02362                {
02363                   ClearObject(ob);
02364                }
02365             delete liter;
02366          }
02367       else if(ob->InheritsFrom("TGo4EventElement"))
02368          {
02369             // nop, we do not allow a user clear from gui
02370             // on any event
02371             rev=kFALSE;
02372          }
02373       else if(ob->InheritsFrom("TTree"))
02374          {
02375             // nop, we do not allow a user clear from gui
02376             // on any tree
02377             rev=kFALSE;
02378          }
02379       else
02380          {
02381              ob->Clear();
02382              // use virtual Clear of all objects
02383              // make sure that TNamed::Clear is overwritten in subclasses
02384          }
02385    }
02386 return rev;
02387 }
02388 
02389 
02390 Bool_t TGo4AnalysisObjectManager::DeleteFolder(TFolder* fold)
02391 {
02392 TRACE((11,"TGo4AnalysisObjectManager::DeleteFolder(TFolder*, Option_t*)",__LINE__, __FILE__));
02393 TGo4LockGuard  dirguard(fxDirMutex);
02394 Bool_t rev=kFALSE;
02395 if(fold)
02396    {
02397       rev=kTRUE;
02398       TCollection* list=fold->GetListOfFolders();
02399       TIterator* listiter=list->MakeIterator();
02400       TObject* ob=0;
02401       while((ob=listiter->Next())!=0)
02402          {
02403             if(ob->InheritsFrom("TFolder"))
02404                {
02405                    DeleteFolder(dynamic_cast<TFolder*>(ob));
02406                }
02407             else
02408                {
02409                    DeleteObject(ob);
02410                }
02411       }// while
02412    delete listiter;
02413    }
02414 return rev;
02415 }
02416 
02417 Bool_t TGo4AnalysisObjectManager::DeleteObject(TObject* ob)
02418 {
02419 TRACE((11,"TGo4AnalysisObjectManager::DeleteObject(TObject*)",__LINE__, __FILE__));
02420 if(ob==0 || !ob->TestBit(TGo4Status::kGo4CanDelete) ) return kFALSE;
02421 fxGo4Dir->RecursiveRemove(ob);
02422 CleanupDynamicLists(ob);
02423 delete ob;
02424 return kTRUE;;
02425 }
02426 
02427 
02428 
02429 Bool_t TGo4AnalysisObjectManager::ProtectFolder(TFolder* fold, const Option_t* flags)
02430 {
02431 if(fold==0) return kFALSE;
02432 TGo4LockGuard  dirguard(fxDirMutex);
02433 TCollection* list=fold->GetListOfFolders();
02434 TIter listiter(list);
02435 TObject* ob=0;
02436 while((ob=listiter.Next())!=0)
02437    {
02438       if(ob->InheritsFrom("TFolder"))
02439          {
02440              ProtectFolder(dynamic_cast<TFolder*>(ob), flags);
02441          }
02442       else
02443          {
02444              ProtectObject(ob, flags);
02445          }
02446    }// while
02447 return kTRUE;
02448 }
02449 
02450 Bool_t TGo4AnalysisObjectManager::ProtectObject(TObject* ob, const Option_t* flags)
02451 {
02452 if(ob==0 || flags==0) return kFALSE;
02453 TString opt=flags;
02454 if(opt.Contains("+D")) ob->ResetBit(TGo4Status::kGo4CanDelete);
02455 if(opt.Contains("-D")) ob->SetBit(TGo4Status::kGo4CanDelete);
02456 if(opt.Contains("+C")) ob->SetBit(TGo4Status::kGo4NoReset);
02457 if(opt.Contains("-C")) ob->ResetBit(TGo4Status::kGo4NoReset);
02458 return kTRUE;
02459 }
02460 
02461 
02462 
02463 
02464 void TGo4AnalysisObjectManager::CleanupDynamicLists(TObject* oldobject)
02465 {
02466 TRACE((11,"TGo4AnalysisObjectManager::CleanupDynamicLists(TNamed*)",__LINE__, __FILE__));
02467 TGo4LockGuard  dirguard(fxDirMutex);
02468 // scan all dynamic lists for this object:
02469 TCollection* dynlistlist=fxDynListDir->GetListOfFolders();
02470 TIterator* dyniter=dynlistlist->MakeIterator();
02471 TObject* dl=0;
02472 while((dl=dyniter->Next())!=0)
02473    {
02474      TGo4DynamicList* dynlist= dynamic_cast<TGo4DynamicList*>(dl);
02475      if(dynlist)
02476       {
02477           if(oldobject->InheritsFrom("TH1"))
02478              {
02479                 TH1* his=dynamic_cast<TH1*>(oldobject);
02480                 dynlist->CleanupHistogram(his);
02481              }
02482           else if (oldobject->InheritsFrom("TGo4Condition"))
02483              {
02484                 TGo4Condition* con=dynamic_cast<TGo4Condition*>(oldobject);
02485                 dynlist->CleanupCondition(con);
02486              }
02487           else if (oldobject->InheritsFrom("TGo4EventElement"))
02488              {
02489                 TGo4EventElement* eve=dynamic_cast<TGo4EventElement*>(oldobject);
02490                 dynlist->CleanupEvent(eve);
02491              }
02492           else { }
02493       }
02494    }// while()
02495 delete dyniter;
02496 }
02497 
02498 
02499 void TGo4AnalysisObjectManager::PrintConditions(const Text_t* expression)
02500 {
02501 TRACE((11,"TGo4AnalysisObjectManager::PrintConditions()",__LINE__, __FILE__));
02502 Int_t totalsize=PrintFolder(fxConditionDir,"*",expression);
02503 cout<<"___________________________________________________________"<<endl;
02504 cout << "Total size of all conditions is: "<<totalsize<<" bytes."<<endl;
02505 }
02506 
02507 void TGo4AnalysisObjectManager::PrintHistograms(const Text_t* expression)
02508 {
02509 TRACE((11,"TGo4AnalysisObjectManager::PrintHistograms()",__LINE__, __FILE__));
02510 Int_t totalsize=PrintFolder(fxHistogramDir,"*",expression);
02511 cout<<"___________________________________________________________"<<endl;
02512 cout << "Total size of all histograms is: "<<totalsize<<" bytes."<<endl;
02513 
02514 }
02515 
02516 void TGo4AnalysisObjectManager::PrintDynamicList()
02517 {
02518 if(fxDynamicList)
02519    {
02520    TGo4DynamicListStatus* dynstat=
02521                  dynamic_cast<TGo4DynamicListStatus*> ( fxDynamicList->CreateStatus() );
02522    dynstat->Print("*");
02523    delete dynstat;
02524    }
02525 else
02526    {
02527       cout <<"No current dynamic list object." << endl;
02528    }
02529 }
02530 
02531 TObject* TGo4AnalysisObjectManager::NextMatchingObject(const Text_t* expr,
02532                         const Text_t* folder,
02533                         Bool_t reset)
02534 {
02535 if(reset)
02536    {
02537        delete fxMatchIterator;
02538        delete fxMatchList;
02539        fxMatchList=CreateObjectList(expr,folder);
02540        fxMatchIterator=fxMatchList->MakeIterator();
02541    }
02542 else {}
02543 return (fxMatchIterator->Next());
02544 }
02545 
02546 TList* TGo4AnalysisObjectManager::CreateObjectList(const Text_t* expr, const Text_t* folder)
02547 {
02548 TGo4LockGuard  dirguard(fxDirMutex);
02549 TFolder* searchfold;
02550 if(folder==0 || !strcmp(folder,fgcTOPFOLDER))
02551    searchfold=fxGo4Dir; // default: search topfolder
02552 else
02553    searchfold=FindSubFolder(fxGo4Dir, folder, kFALSE);
02554 return (CreateObjectList(expr, searchfold));
02555 }
02556 
02557 
02558 TList* TGo4AnalysisObjectManager::CreateObjectList(const Text_t* expr, TFolder* fold)
02559 {
02560  TList* result=new TList;
02561  if(fold) {
02562    TIter iter(fold->GetListOfFolders());
02563    TObject* entry=0;
02564    while((entry = iter())!=0) {
02565        if(entry->InheritsFrom("TFolder")) {
02566            TFolder* subfold=dynamic_cast<TFolder*>(entry);
02567            TList* sublist=CreateObjectList(expr,subfold);
02568            // add sublist contents to our result list:
02569            result->AddAll(sublist);
02570        } else
02571        if(entry->InheritsFrom("TTree")) {
02572        } else  // disable sending tree to gui!
02573        if(entry->InheritsFrom("TGo4EventElement")) {
02574        } else // disable events
02575        if(entry->InheritsFrom("TGo4EventSource")) {
02576        } else  // disable events
02577        if(entry->InheritsFrom("TGo4EventStore")) {
02578        } else // disable events
02579        if(entry->InheritsFrom("TGo4EventProcessor")) {
02580        } else { // disable events
02581          if(IsMatching(entry->GetName(),expr))
02582             result->AddLast(entry);
02583        } // if(entry->InheritsFrom("TFolder"))
02584    } // while
02585  } // if(fold)
02586  return result;
02587 }
02588 
02589 Bool_t TGo4AnalysisObjectManager::IsMatching(const Text_t* string, const Text_t* expression)
02590 {
02591 if(expression==0) return kTRUE;
02592 Bool_t ismatching=kFALSE;
02593 TString entrystring=string;
02594 TRegexp reg(expression,kTRUE);
02595 if(!strcmp(expression,"*"))
02596    ismatching=kTRUE; // take all in this folder
02597 //               else if (strstr(expression,string))
02598 //                  ismatching=kTRUE; // expression just contained in name
02599 else if (entrystring.Index(reg,0)!=kNPOS)
02600    ismatching=kTRUE; // root regular expression class
02601 else
02602    ismatching=kFALSE;
02603 return ismatching;
02604 }
02605 
02606 
02607 TObject* TGo4AnalysisObjectManager::FindObjectInFolder(TFolder*      folder,
02608                                                        const Text_t* fullname)
02609 {
02610    TRACE((12,"TGo4AnalysisObjectManager::FindObjectInFolder(TFolder*, const Text_t*)",__LINE__, __FILE__));
02611    TGo4LockGuard  listguard(fxDirMutex);
02612    return folder ? folder->FindObjectAny(fullname) : 0;
02613 }
02614 
02615 
02616 TObject* TGo4AnalysisObjectManager::TestObject(TFolder*     folder,
02617                                                const Text_t* &pathname,
02618                                                const Text_t* objectname,
02619                                                const TClass* cl)
02620 {
02621    TString fullname;
02622    if ((pathname!=0) && (strlen(pathname)==0)) pathname = 0;
02623    if (pathname) {
02624      fullname = pathname;
02625      fullname += "/";
02626    }
02627    fullname += objectname;
02628 
02629    TObject* obj = FindObjectInFolder(folder, fullname);
02630 
02631    if ((obj!=0) && (!obj->InheritsFrom(cl))) {
02632       RemoveObjectFromFolder(fullname, folder, kTRUE);
02633       obj = 0;
02634    }
02635 
02636    fbCreatedinMake = (obj==0);
02637    return obj;
02638 }
02639 
02640 
02641 
02642 
02643 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:49 2005 for Go4-v2.10-5 by doxygen1.2.15