00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4EventElement.h"
00015
00016 #include "TTree.h"
00017
00018 #include "TGo4Log.h"
00019 #include "TGo4EventSource.h"
00020
00023 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,34,19)
00024 R__EXTERN TTree *gTree;
00025 #endif
00026
00027 TGo4EventElement::TGo4EventElement() :
00028 TNamed("Go4Element","This is a Go4 EventElement"),
00029 fbIsValid(kTRUE),
00030 fxParent(0),
00031 fxEventSource(0),
00032 fIdentifier(-1),
00033 fDebug(kFALSE),
00034 fbKeepContents(kFALSE)
00035 {
00036
00037 GO4TRACE((15,"TGo4EventElement::TGo4EventElement()",__LINE__, __FILE__));
00038 }
00039
00040 TGo4EventElement::TGo4EventElement(const char* name) :
00041 TNamed(name,"This is a Go4 EventElement"),
00042 fbIsValid(kTRUE),
00043 fxParent(0),
00044 fxEventSource(0),
00045 fIdentifier(-1),
00046 fDebug(kFALSE),
00047 fbKeepContents(kFALSE)
00048 {
00049 GO4TRACE((15,"TGo4EventElement::TGo4EventElement(const char*)",__LINE__, __FILE__));
00050 }
00051
00052 TGo4EventElement::TGo4EventElement(const char* aName, const char* aTitle, Short_t aBaseCat) :
00053 TNamed(aName,aTitle),
00054 fbIsValid(kTRUE),
00055 fxParent(0),
00056 fxEventSource(0),
00057 fIdentifier(aBaseCat),
00058 fDebug(kFALSE)
00059 {
00060 }
00061
00062 TGo4EventElement::~TGo4EventElement()
00063 {
00064 GO4TRACE((15,"TGo4EventElement::~TGo4EventElement()",__LINE__, __FILE__));
00065 }
00066
00067 Bool_t TGo4EventElement::CheckEventSource(const char* classname)
00068 {
00069 GO4TRACE((12,"TGo4EventElement::CheckEventSource(const char*)",__LINE__, __FILE__));
00070 if(fxEventSource==0) return kFALSE;
00071 return fxEventSource->InheritsFrom(classname);
00072 }
00073
00074 void TGo4EventElement::PrintEvent()
00075 {
00076 GO4TRACE((12,"TGo4EventElement::PrintEvent()",__LINE__, __FILE__));
00077
00078 TGo4Log::Debug( " EventElement printout: ");
00079 TGo4Log::Debug( "\tIsValid=%d ",fbIsValid);
00080 if(fxEventSource)
00081 TGo4Log::Debug( "\tEventSource: %s of class %s",
00082 fxEventSource->GetName(), fxEventSource->ClassName() );
00083 else
00084 TGo4Log::Debug( "\tNO EventSource");
00085 }
00086
00087 void TGo4EventElement::Print(Option_t* option) const
00088 {
00089 ((TGo4EventElement*)this) -> PrintEvent();
00090 }
00091
00092 void TGo4EventElement::makeBranch(TBranch *parent)
00093 {
00094
00095 }
00096
00097 TGo4EventElement* TGo4EventElement::GetChild(const char* name)
00098 {
00099 if ((name==0) || (strlen(name)==0)) return this;
00100
00101 if (strcmp(name,".")==0) return this;
00102
00103 if (strcmp(name,"..")==0) return GetParent();
00104
00105 return 0;
00106 }
00107
00108
00109 void TGo4EventElement::synchronizeWithTree(TTree *tree, TGo4EventElement** var_ptr)
00110 {
00111 if (tree==0) return;
00112
00113 TBranch* topb = 0;
00114 TString searchname = GetName();
00115 if (searchname.Length()>0) {
00116 searchname += ".";
00117 topb = tree->FindBranch(searchname.Data());
00118 }
00119
00120
00121
00122 if (topb==0) topb = (TBranch*) tree->GetListOfBranches()->First();
00123
00124 Int_t index = tree->GetListOfBranches()->IndexOf(topb);
00125
00126
00127
00128
00129
00130 activateBranch(topb, index, var_ptr);
00131 }
00132
00133 Int_t TGo4EventElement::activateBranch(TBranch *branch, Int_t init, TGo4EventElement** var_ptr)
00134 {
00135 if (branch==0) return 0;
00136
00137 TString cad = branch->GetName();
00138
00139 TTree* tree = branch->GetTree();
00140
00141 if (var_ptr!=0) {
00142
00143
00144
00145
00146
00147
00148
00149 TClass* cl = *var_ptr ? (*var_ptr)->IsA() : 0;
00150 tree->SetBranchAddress(cad.Data(), var_ptr, 0, cl, kOther_t, true);
00151
00152 }
00153
00154 tree->SetBranchStatus(cad.Data(), 1);
00155 cad+="*";
00156 tree->SetBranchStatus(cad.Data(), 1);
00157
00158 return 0;
00159 }
00160
00161 void TGo4EventElement::deactivate()
00162 {
00163 TString name = GetName();
00164 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,34,19)
00165 name+=".";
00166 gTree->SetBranchStatus(name.Data(), 0);
00167 name+="*";
00168 gTree->SetBranchStatus(name.Data(), 0);
00169 TGo4Log::Info("-I- Deactivating elements at location : %s", name.Data());
00170 #else
00171 TGo4Log::Warn("-W- Could not deactivate() event element %s in this ROOT Version, do not use!", name.Data());
00172 #endif
00173 }
00174
00175 void TGo4EventElement::activate()
00176 {
00177 TString name=GetName();
00178 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,34,19)
00179 name+=".";
00180 gTree->SetBranchStatus(name.Data(), 1);
00181 name+="*";
00182 gTree->SetBranchStatus(name.Data(), 1);
00183 TGo4Log::Info("-I- Activating elements at location : %s", name.Data());
00184 #else
00185 TGo4Log::Warn("-W- Could not activate() element %s in this ROOT Version, do not use!", name.Data());
00186 #endif
00187
00188 }
00189
00190 void TGo4EventElement::Clear(Option_t *)
00191 {
00192 }
00193
00194 Int_t TGo4EventElement::Init()
00195 {
00196 Int_t res(0);
00197 Clear();
00198 SetValid(kTRUE);
00199 if (fxEventSource) {
00200 TGo4Log::Info("Event %s has source %s class: %s", GetName(), fxEventSource->GetName(), fxEventSource->ClassName());
00201 if (!fxEventSource->CheckEventClass(IsA())) {
00202 TGo4Log::Error("Event %s, mismatch between event source and event class", GetName());
00203 res = 1;
00204 }
00205 } else {
00206 TGo4Log::Error("Event %s has no data source", GetName());
00207 res = 1;
00208 }
00209 return res;
00210 }
00211
00212 Int_t TGo4EventElement::Fill()
00213 {
00214 if (!fbKeepContents) Clear();
00215 fbKeepContents = kFALSE;
00216 if (fxEventSource==0) { SetValid(kFALSE); return 1; }
00217
00218 if (fxEventSource->BuildEvent(this)) {
00219
00220 return 0;
00221 }
00222
00223 Int_t res = fxEventSource->GetEventStatus();
00224
00225 SetValid(kFALSE);
00226
00227 return res==0 ? 1 : res;
00228 }