Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4BackStore.h"
00015
00016 #include "TTree.h"
00017 #include "TDirectory.h"
00018 #include "TROOT.h"
00019
00020 #include "TGo4Log.h"
00021 #include "TGo4Status.h"
00022 #include "TGo4BackStoreParameter.h"
00023 #include "TGo4EventElement.h"
00024 #include "TGo4CompositeEvent.h"
00025
00026 const char* TGo4BackStore::fgcTREESUF = "xTree";
00027 const char* TGo4BackStore::fgcEVBRANCHNAME = "Go4EventBranch.";
00028
00029 const Int_t TGo4BackStore::fgiMAXAUTOBYTES = 100000000;
00030
00031 TGo4BackStore::TGo4BackStore() :
00032 TGo4EventStore("Go4 Default Back Store"),
00033 fxTree(0),
00034 fbBranchExists(kFALSE),
00035 fxEvent(0),
00036 fiSplit(1),
00037 fiBufsize(0),
00038 fiFillCount(0)
00039 {
00040 GO4TRACE((15,"TGo4BackStore::TGo4BackStore()", __LINE__, __FILE__));
00041
00042 }
00043
00044 TGo4BackStore::TGo4BackStore(TGo4BackStoreParameter* par) :
00045 TGo4EventStore("dummy"),
00046 fxTree(0),
00047 fbBranchExists(kFALSE),
00048 fxEvent(0),
00049 fiSplit(1),
00050 fiBufsize(0),
00051 fiFillCount(0)
00052 {
00053 GO4TRACE((15,"TGo4BackStore::TGo4BackStore(TGo4BackStoreParameter* par)", __LINE__, __FILE__));
00054
00055 if (par==0) {
00056 TGo4Log::Error("TGo4BackStoreParameter is not specified in TGo4BackStore constructor");
00057 return;
00058 }
00059
00060 fiSplit = par->GetSplitlevel();
00061 fiBufsize = par->GetBufsize();
00062
00063 SetName(par->GetName());
00064
00065 const char* lastname = par->GetTitle();
00066 const char* oldname = lastname;
00067 lastname=strstr(oldname,"/");
00068 while(lastname!=0)
00069 {
00070 oldname=lastname+1;
00071 lastname=strstr(oldname,"/");
00072 }
00073 TString buffer = oldname;
00074 buffer+=fgcTREESUF;
00075 TDirectory *dirsav = gDirectory;
00076 gROOT->cd();
00077 fxTree = new TTree(buffer.Data(), "Go4BackStore");
00078 fxTree->SetBit(TGo4Status::kGo4BackStoreReset);
00079 fxTree->SetAutoSave(TGo4BackStore::fgiMAXAUTOBYTES);
00080 TGo4Log::Debug(" Tree %s has been created in memory ",buffer.Data());
00081 dirsav->cd();
00082 }
00083
00084 TGo4BackStore::~TGo4BackStore()
00085 {
00086 GO4TRACE((15,"TGo4BackStore::~TGo4BackStore()", __LINE__, __FILE__));
00087 delete fxTree;
00088
00089 }
00090
00091 void TGo4BackStore::Reset(Bool_t onlyclearflag)
00092 {
00093 if(fxTree!=0) {
00094
00095 if(!onlyclearflag)
00096 {
00097 fxTree->Reset();
00098 fxTree->SetBit(TGo4Status::kGo4BackStoreReset);
00099 }
00100 else
00101 {
00102 fxTree->ResetBit(TGo4Status::kGo4BackStoreReset);
00103 }
00104 }
00105 }
00106
00107 Int_t TGo4BackStore::Store(TGo4Parameter* cali)
00108 {
00109 return 0;
00110 }
00111
00112 Int_t TGo4BackStore::Store(TGo4Condition* conny)
00113 {
00114 return 0;
00115 }
00116
00117 Int_t TGo4BackStore::Store(TGo4Fitter* fitty)
00118 {
00119 return 0;
00120 }
00121
00122 Int_t TGo4BackStore::Store(TFolder* foldy)
00123 {
00124 return 0;
00125 }
00126
00127
00128 Int_t TGo4BackStore::Store(TGo4EventElement* event)
00129 {
00130 GO4TRACE((12,"TGo4BackStore::Store(TGo4EventElement*)", __LINE__, __FILE__));
00131
00132 fxEvent=event;
00133 if(!fbBranchExists)
00134 {
00135
00136
00137 if(fxEvent)
00138 {
00139 TString topbranchname(fxEvent->GetName());
00140 topbranchname+=".";
00141 TBranch* go4branch= fxTree->GetBranch(topbranchname.Data());
00142 if(go4branch)
00143 {
00144
00145 TGo4Log::Debug(" BackStore: Found existing branch %s , continue filling ",topbranchname.Data() );
00146
00147 go4branch->SetAddress(&fxEvent);
00148 fbBranchExists=kTRUE;
00149
00150 }
00151 else
00152 {
00153
00154 TBranch *topbranch=
00155 fxTree->Branch(topbranchname.Data(), fxEvent->ClassName(), &fxEvent, fiBufsize, fiSplit);
00156 TGo4Log::Debug(" BackStore: Created new branch %s ", topbranchname.Data());
00157 fbBranchExists=kTRUE;
00158 if (fxEvent->InheritsFrom(TGo4CompositeEvent::Class()))
00159 dynamic_cast<TGo4CompositeEvent*> (fxEvent)->makeBranch(topbranch);
00160 }
00161 }
00162 else
00163 {
00164
00165 return 1;
00166 }
00167 }
00168 else
00169 {
00170
00171 }
00172
00173 Double_t totbytes=fxTree->GetTotBytes();
00174 if(totbytes>TGo4BackStore::fgiMAXAUTOBYTES)
00175 {
00176 fxTree->Reset();
00177 TGo4Log::Debug(" BackStore: Tree %s was Reset after %f bytes ",
00178 fxTree->GetName(), totbytes);
00179 }
00180 fxTree->Fill();
00181 return 0;
00182 }
00183
00184
00185
00186