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