00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "TGo4TreeStore.h"
00017
00018 #include "TFile.h"
00019 #include "TTree.h"
00020 #include "snprintf.h"
00021
00022 #include "TGo4Log.h"
00023 #include "TGo4EventElement.h"
00024 #include "TGo4EventCalibration.h"
00025 #include "TGo4Parameter.h"
00026 #include "TGo4TreeStoreParameter.h"
00027 #include "TGo4MainTree.h"
00028
00029 const Text_t TGo4TreeStore::fgcFILESUF[] = ".root";
00030
00031 TGo4TreeStore::TGo4TreeStore(const char* name,
00032 TGo4EventElement* event,
00033 Int_t splitlevel,
00034 Int_t bufsize,
00035 Text_t* filename,
00036 Int_t compression)
00037 : TGo4EventStore(name),
00038 fxBranch(0), fxEvent(event), fiSplit(splitlevel), fiBufsize(bufsize)
00039 {
00040 TRACE((15,"TGo4TreeStore::TGo4TreeStore(Text_t*,...)", __LINE__, __FILE__));
00041
00042 Text_t buffer [TGo4EventStore::fguTXTLEN];
00043 snprintf(buffer, TGo4EventStore::fguTXTLEN-5,"%s", name);
00044 strcat(buffer,".");
00045 fxSingletonTree=TGo4MainTree::Instance();
00046 if(fxEvent)
00047 {
00048 strncpy(fcEventClass, fxEvent->ClassName(), TGo4EventStore::fguTXTLEN-1);
00049 fxTree=fxSingletonTree->GetTree();
00050 fxBranch= fxTree->GetBranch(buffer);
00051 if(fxBranch)
00052 {
00053
00054 TGo4Log::Debug(" TreeStore: Found existing branch %s , reset it ", name);
00055 fxBranch->Reset();
00056 }
00057 else
00058 {
00059
00060 fxBranch=fxTree->Branch(buffer, fcEventClass, &fxEvent, fiBufsize, fiSplit);
00061 TGo4Log::Debug(" TreeStore: Created new branch %s ", name);
00062 }
00063 if(filename)
00064 {
00065 snprintf(buffer, TGo4EventStore::fguTXTLEN -10, "%s", filename);
00066 strcat(buffer,fgcFILESUF);
00067 fxFile = new TFile(buffer, "UPDATE");
00068 fxFile->SetCompressionLevel(compression);
00069 fxBranch->SetFile(fxFile);
00070 TGo4Log::Debug(" TreeStore: Set branch to file %s ", filename);
00071 }
00072 else
00073 {
00074 fxFile=0;
00075 }
00076
00077 }
00078 else
00079 {
00080 TGo4Log::Debug(" !!! TreeStore creation ERROR: no event structure !!! ");
00081 }
00082
00083
00084 }
00085
00086 TGo4TreeStore::TGo4TreeStore(TGo4TreeStoreParameter* par, TGo4EventElement* event)
00087 : TGo4EventStore("dummy"),
00088 fxBranch(0), fxEvent(event), fiSplit(par->fiSplit), fiBufsize(par->fiBufsize)
00089 {
00090 TRACE((15,"TGo4TreeStore::TGo4TreeStore(Text_t*,...)", __LINE__, __FILE__));
00091
00092 Text_t buffer [TGo4EventStore::fguTXTLEN];
00093 snprintf(buffer, TGo4EventStore::fguTXTLEN -5, "%s", par->GetName());
00094 SetName(buffer);
00095 strcat(buffer,".");
00096 fxSingletonTree=TGo4MainTree::Instance();
00097 if(fxEvent)
00098 {
00099 strncpy(fcEventClass, fxEvent->ClassName(),TGo4EventStore::fguTXTLEN-1);
00100 fxTree=fxSingletonTree->GetTree();
00101 fxBranch= fxTree->GetBranch(buffer);
00102 if(fxBranch)
00103 {
00104
00105 TGo4Log::Debug(" TreeStore: Found existing branch %s , reset it ", buffer);
00106 fxBranch->Reset();
00107 }
00108 else
00109 {
00110
00111 fxBranch=fxTree->Branch(buffer, fcEventClass, &fxEvent, fiBufsize, fiSplit);
00112 TGo4Log::Debug(" TreeStore: Created new branch %s ", buffer);
00113 }
00114 if(!par->fxBranchFile.IsNull())
00115 {
00116 snprintf(buffer, TGo4EventStore::fguTXTLEN -10, "%s", par->fxBranchFile.Data());
00117 strcat(buffer,fgcFILESUF);
00118 fxFile = new TFile(buffer, "UPDATE");
00119 fxFile->SetCompressionLevel(par->fiCompression);
00120 fxBranch->SetFile(fxFile);
00121 TGo4Log::Debug(" TreeStore: Set branch to file %s ", buffer);
00122 }
00123 else
00124 {
00125 fxFile=0;
00126 }
00127
00128 }
00129 else
00130 {
00131 TGo4Log::Debug(" !!! TreeStore creation ERROR: no event structure !!! ");
00132 }
00133 }
00134
00135 TGo4TreeStore::TGo4TreeStore()
00136 :TGo4EventStore("Go4 Default Tree Store"),
00137 fxBranch(0), fxEvent(0), fiSplit(0), fiBufsize(0)
00138 {
00139 TRACE((15,"TGo4TreeStore::TGo4TreeStore()", __LINE__, __FILE__));
00140
00141 }
00142
00143
00144 TGo4TreeStore::~TGo4TreeStore()
00145 {
00146 TRACE((15,"TGo4TreeStore::~TGo4TreeStore()", __LINE__, __FILE__));
00147
00148 }
00149
00150
00151
00152 Int_t TGo4TreeStore::Store(TGo4EventElement* event)
00153 {
00154 TRACE((12,"TGo4TreeStore::Store(TGo4EventElement*)", __LINE__, __FILE__));
00155
00156 Int_t rev=-1;
00157
00158 if(!strcmp( event->ClassName(), fcEventClass) )
00159 {
00160
00161 fxEvent=event;
00162 fxBranch->SetAddress(&fxEvent);
00163 fxBranch->Fill();
00164 rev=0;
00165 }
00166 else
00167 {
00168
00169 TGo4Log::Debug(" !!! TreeStore::Store ERROR: this event does not match !!! ");
00170 fxEvent->Clear();
00171 fxEvent->SetValid(kFALSE);
00172 fxBranch->SetAddress(&fxEvent);
00173 fxBranch->Fill();
00174 rev=1;
00175 }
00176
00177 return rev;
00178 }
00179
00180
00181 Int_t TGo4TreeStore::Store(TGo4Parameter* cali)
00182 {
00183 TRACE((12,"TGo4TreeStore::Store(TGo4EventCalibration*)", __LINE__, __FILE__));
00184 if(cali)
00185 {
00186 Text_t buf[256];
00187 Text_t oldname[256];
00188 strncpy(oldname,cali->GetName(),255);
00189 snprintf(buf,255,"%s_%d" , oldname, fxSingletonTree->GetCurrentIndex());
00190 cali->SetName(buf);
00191 fxSingletonTree->fxFile->cd();
00192 cali->Write(0, TObject::kOverwrite);
00193 cali->SetName(oldname);
00194 }
00195 else
00196 {
00197
00198 }
00199
00200 return 0;
00201 }
00202
00203 void TGo4TreeStore::SetCompression(Int_t comp)
00204 {
00205 TRACE((12,"TGo4TreeStore::SetCompression(Int_t)", __LINE__, __FILE__));
00206 fxFile->SetCompressionLevel(comp);
00207 }
00208
00209