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