Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "TGo4HistogramEntry.h"
00015
00016 #include "RVersion.h"
00017 #include "Riostream.h"
00018 #include "TH1.h"
00019 #include "TH2.h"
00020 #include "TH3.h"
00021 #include "TDataMember.h"
00022 #include "TDataType.h"
00023 #include "TROOT.h"
00024
00025 #include "TGo4Log.h"
00026 #include "TGo4Status.h"
00027 #include "TGo4Condition.h"
00028 #include "TGo4DynamicListException.h"
00029
00030 const char* TGo4HistogramEntry::fgcNOCONDITION = "No Condition";
00031 const char* TGo4HistogramEntry::fgcNODATA = "No Data";
00032 const char* TGo4HistogramEntry::fgcNOEVENT = "No Event";
00033
00034 TGo4HistogramEntry::TGo4HistogramEntry() :
00035 TGo4DynamicEntry(),
00036 fxHistogram(0),
00037 fxCondition(0),
00038 fbNeedInitialisation(kTRUE)
00039 {
00040 }
00041
00042 TGo4HistogramEntry::TGo4HistogramEntry(const char* name) :
00043 TGo4DynamicEntry(name),
00044 fxHistogram(0),
00045 fxCondition(0),
00046 fbNeedInitialisation(kTRUE)
00047 {
00048 fxHistogramName=fgcNOCONDITION;
00049 for (UInt_t t=0; t<__MAXHISDIM__;++t) {
00050 SetHisEventName(t,fgcNOEVENT);
00051 SetHisVarName(t,fgcNODATA);
00052 }
00053
00054 fxConditionName = fgcNOCONDITION;
00055 for (Int_t t=0; t<__MAXCONDIM__;++t) {
00056 SetConEventName(t,fgcNOEVENT);
00057 SetConVarName(t,fgcNODATA);
00058 }
00059
00060 Reset();
00061 }
00062
00063 TGo4HistogramEntry::~TGo4HistogramEntry()
00064 {
00065 }
00066
00067 void TGo4HistogramEntry::SetHisVarName(Int_t ix, const char* name)
00068 {
00069 if((ix>=0) && (ix<__MAXHISDIM__))
00070 fxHisVarName[ix]=name;
00071 }
00072
00073 const char* TGo4HistogramEntry::GetHistVarName(Int_t ix) const
00074 {
00075 return ((ix>=0) && (ix<__MAXHISDIM__)) ? fxHisVarName[ix].Data() : 0;
00076 }
00077
00078 void TGo4HistogramEntry::SetHisEventName(Int_t ix, const char* name)
00079 {
00080 if((ix>=0) && (ix<__MAXHISDIM__))
00081 fxHisEventName[ix]=name;
00082 }
00083
00084 const char* TGo4HistogramEntry::GetHistEventName(Int_t ix) const
00085 {
00086 return ((ix>=0) && (ix<__MAXHISDIM__)) ? fxHisEventName[ix].Data() : 0;
00087 }
00088
00089 void TGo4HistogramEntry::SetConVarName(Int_t ix, const char* name)
00090 {
00091 GO4TRACE((12,"TGo4DynamicEntry::SetConVarName(UInt_t, char*)",__LINE__, __FILE__));
00092 if((ix>=0) && (ix<__MAXCONDIM__))
00093 fxConVarName[ix]=name;
00094 }
00095
00096 const char* TGo4HistogramEntry::GetConVarName(Int_t ix) const
00097 {
00098 return ((ix>=0) && (ix<__MAXCONDIM__)) ? fxConVarName[ix].Data() : 0;
00099 }
00100
00101 void TGo4HistogramEntry::SetConEventName(Int_t ix, const char* name)
00102 {
00103 GO4TRACE((12,"TGo4DynamicEntry::SetConEventName(UInt_t, char*)",__LINE__, __FILE__));
00104 if((ix>=0) && (ix<__MAXCONDIM__))
00105 fxConEventName[ix]=name;
00106 }
00107
00108 const char* TGo4HistogramEntry::GetConEventName(Int_t ix) const
00109 {
00110 return ((ix>=0) && (ix<__MAXCONDIM__)) ? fxConEventName[ix].Data() : 0;
00111 }
00112
00113
00114 void TGo4HistogramEntry::Reset()
00115 {
00116 fxHistogram=0;
00117 for(Int_t t =0; t<__MAXHISDIM__; ++t) {
00118 fxHisEvents[t] = 0;
00119 fxHistType[t] = 0;
00120 fxHistPtr[t] = 0;
00121 }
00122
00123 fxCondition = 0;
00124 for(Int_t t =0; t<__MAXCONDIM__; ++t) {
00125 fxConEvents[t] = 0;
00126 fxCondType[t] = 0;
00127 fxCondPtr[t] = 0;
00128 }
00129
00130 fbNeedInitialisation = kTRUE;
00131 }
00132
00133 void TGo4HistogramEntry::InitHistPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
00134 {
00135 if ((ix<0) || (ix>=__MAXHISDIM__)) return;
00136 fxHistPtr[ix] = 0;
00137 fxHisEvents[ix] = event;
00138 if ((event==0) || (member==0) || !member->IsBasic()) return;
00139 fxHistPtr[ix] = (char*) event+ offset;
00140 fxHistType[ix] = member->GetDataType()->GetType();
00141 }
00142
00143 void TGo4HistogramEntry::InitCondPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
00144 {
00145 if ((ix<0) || (ix>=__MAXCONDIM__)) return;
00146 fxCondPtr[ix] = 0;
00147 fxConEvents[ix] = event;
00148 if ((event==0) || (member==0) || !member->IsBasic()) return;
00149 fxCondPtr[ix] = (char*) event+ offset;
00150 fxCondType[ix] = member->GetDataType()->GetType();
00151 }
00152
00153 Double_t TGo4HistogramEntry::GetPtrValue(Int_t type, void* ptr)
00154 {
00155 if (ptr==0) return 0.;
00156 switch (type) {
00157 case kUInt_t: return *((UInt_t*)ptr);
00158 case kInt_t: return *((Int_t*)ptr);
00159 case kULong_t: return *((ULong_t*)ptr);
00160 case kLong_t: return *((Long_t*)ptr);
00161 case kULong64_t: return *((ULong64_t*)ptr);
00162 case kLong64_t: return *((Long64_t*)ptr);
00163 case kUShort_t: return *((UShort_t*)ptr);
00164 case kShort_t: return *((Short_t*)ptr);
00165 case kUChar_t: return *((UChar_t*)ptr);
00166 case kChar_t: return *((Char_t*)ptr);
00167 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
00168 case kBool_t: return *((Bool_t*)ptr);
00169 #endif
00170 case kFloat_t: return *((Float_t*)ptr);
00171 case kDouble_t: return *((Double_t*)ptr);
00172 case kDouble32_t: return *((Double32_t*)ptr);
00173 }
00174 return 0.;
00175 }
00176
00177 Bool_t TGo4HistogramEntry::TestConditionNew()
00178 {
00179 if (fxCondition==0) return kTRUE;
00180
00181 Bool_t rev = kTRUE;
00182
00183 Double_t dat[__MAXCONDIM__];
00184
00185 UInt_t j,dimension;
00186
00187
00188
00189 for(dimension=0;dimension<__MAXCONDIM__; ++dimension)
00190 if (fxCondPtr[dimension]==0) break;
00191
00192
00193 for(j=0;j<dimension; ++j)
00194 dat[j] = GetPtrValue(fxCondType[j], fxCondPtr[j]);
00195
00196 switch(dimension) {
00197
00198
00199
00200
00201 case 1:
00202 rev=fxCondition->Test(dat[0]);
00203
00204 break;
00205 case 2:
00206 rev=fxCondition->Test(dat[0], dat[1]);
00207
00208 break;
00209 default:
00210 rev = kTRUE;
00211 break;
00212 }
00213
00214 return rev;
00215 }
00216
00217 void TGo4HistogramEntry::ProcessNew(Bool_t* evvalid)
00218 {
00219 if (fxHistogram==0) return;
00220
00221 if (!TestConditionNew()) return;
00222
00223 Double_t dat[3];
00224 Int_t dimension = fxHistogram->GetDimension();
00225 for(Int_t j=0; j<dimension; ++j)
00226 dat[j] = GetPtrValue(fxHistType[j], fxHistPtr[j]);
00227 switch (dimension) {
00228 case 1:
00229 if(evvalid[0]) fxHistogram->Fill(dat[0]);
00230 break;
00231 case 2:
00232 if(evvalid[0] && evvalid[1]) {
00233 TH2* his2 = dynamic_cast<TH2*>(fxHistogram);
00234 if(his2!=0) his2->Fill(dat[0],dat[1]);
00235 }
00236 break;
00237 case 3:
00238 if(evvalid[0] && evvalid[1] && evvalid[2]) {
00239 TH3* his3 = dynamic_cast<TH3*>(fxHistogram);
00240 if(his3!=0) his3->Fill(dat[0],dat[1],dat[2]);
00241 }
00242 break;
00243 default:
00244 throw TGo4DynamicListException(this,
00245 "Dynamic Histogram Entry %s Process error: Wrong histogram dimension %d !!!",
00246 GetName(), dimension);
00247 }
00248 }
00249
00250 void TGo4HistogramEntry::RecursiveRemove(TObject* obj)
00251 {
00252 if (obj==0) return;
00253
00254 if(fxHistogram==obj) Reset();
00255
00256 if(fxCondition==obj) Reset();
00257
00258 for (Int_t n=0;n<__MAXCONDIM__;n++)
00259 if (fxConEvents[n]==obj) Reset();
00260
00261 for (Int_t n=0;n<__MAXHISDIM__;n++)
00262 if (fxHisEvents[n]==obj) Reset();
00263 }
00264
00265 void TGo4HistogramEntry::Print(Option_t* dummy) const
00266 {
00267
00268 TROOT::IndentLevel();
00269 std::cout <<"-Dynamic Histogram Entry " << GetName()<<" :"<<std::endl;
00270 TROOT::IncreaseDirLevel();
00271 TROOT::IndentLevel();
00272
00273 if(IsEnabledProcessing()) std::cout <<"\t-- Enabled --" << std::endl;
00274 else std::cout <<"\t-- Disabled --" << std::endl;
00275
00276 TROOT::IndentLevel();
00277 std::cout <<"\tCondition: "<< GetConditionName() << std::endl;
00278 for(Int_t i=0;i<__MAXCONDIM__; ++i) {
00279 TROOT::IndentLevel();
00280 std::cout << "\t ConEvent(" << i << "): " << GetConEventName(i)
00281 << "\t ConVar(" << i << "): " << GetConVarName(i) << std::endl;
00282 }
00283 TROOT::IndentLevel();
00284 std::cout <<"\tHistogram: "<< GetHistogramName() << std::endl;
00285 for(Int_t i=0;i<__MAXHISDIM__; ++i) {
00286 TROOT::IndentLevel();
00287 std::cout << "\t HisEvent(" << i<<"): " << GetHistEventName(i)
00288 << "\t HisVar(" << i<< "): " << GetHistVarName(i) << std::endl;
00289 }
00290 TROOT::DecreaseDirLevel();
00291 TROOT::IndentLevel();
00292 std::cout <<"-End "<<GetName()<<"-----------" << std::endl;
00293 }
00294
00295 const char* TGo4HistogramEntry::Get_fgcNOCONDITION()
00296 {
00297 return fgcNOCONDITION;
00298 }
00299
00300 const char* TGo4HistogramEntry::Get_fgcNODATA()
00301 {
00302 return fgcNODATA;
00303 }
00304
00305 const char* TGo4HistogramEntry::Get_fgcNOEVENT()
00306 {
00307 return fgcNOEVENT;
00308 }
00309