GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HistogramEntry.cxx
Go to the documentation of this file.
1 // $Id: TGo4HistogramEntry.cxx 1494 2015-06-08 15:33:53Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4HistogramEntry.h"
15 
16 #include "RVersion.h"
17 #include "Riostream.h"
18 #include "TH1.h"
19 #include "TH2.h"
20 #include "TH3.h"
21 #include "TDataMember.h"
22 #include "TDataType.h"
23 #include "TROOT.h"
24 
25 #include "TGo4Log.h"
26 #include "TGo4Status.h"
27 #include "TGo4Condition.h"
29 
30 const char* TGo4HistogramEntry::fgcNOCONDITION = "No Condition";
31 const char* TGo4HistogramEntry::fgcNODATA = "No Data";
32 const char* TGo4HistogramEntry::fgcNOEVENT = "No Event";
33 
36  fxHistogram(0),
37  fxCondition(0),
38  fbNeedInitialisation(kTRUE)
39 {
40 }
41 
43  TGo4DynamicEntry(name),
44  fxHistogram(0),
45  fxCondition(0),
46  fbNeedInitialisation(kTRUE)
47 {
49  for (UInt_t t=0; t<__MAXHISDIM__;++t) {
52  }
53 
55  for (Int_t t=0; t<__MAXCONDIM__;++t) {
58  }
59 
60  Reset();
61 }
62 
64 {
65 }
66 
67 void TGo4HistogramEntry::SetHisVarName(Int_t ix, const char* name)
68 {
69  if((ix>=0) && (ix<__MAXHISDIM__))
70  fxHisVarName[ix]=name;
71 }
72 
73 const char* TGo4HistogramEntry::GetHistVarName(Int_t ix) const
74 {
75  return ((ix>=0) && (ix<__MAXHISDIM__)) ? fxHisVarName[ix].Data() : 0;
76 }
77 
78 void TGo4HistogramEntry::SetHisEventName(Int_t ix, const char* name)
79 {
80  if((ix>=0) && (ix<__MAXHISDIM__))
81  fxHisEventName[ix]=name;
82 }
83 
84 const char* TGo4HistogramEntry::GetHistEventName(Int_t ix) const
85 {
86  return ((ix>=0) && (ix<__MAXHISDIM__)) ? fxHisEventName[ix].Data() : 0;
87 }
88 
89 void TGo4HistogramEntry::SetConVarName(Int_t ix, const char* name)
90 {
91  GO4TRACE((12,"TGo4DynamicEntry::SetConVarName(UInt_t, char*)",__LINE__, __FILE__));
92  if((ix>=0) && (ix<__MAXCONDIM__))
93  fxConVarName[ix]=name;
94 }
95 
96 const char* TGo4HistogramEntry::GetConVarName(Int_t ix) const
97 {
98  return ((ix>=0) && (ix<__MAXCONDIM__)) ? fxConVarName[ix].Data() : 0;
99 }
100 
101 void TGo4HistogramEntry::SetConEventName(Int_t ix, const char* name)
102 {
103  GO4TRACE((12,"TGo4DynamicEntry::SetConEventName(UInt_t, char*)",__LINE__, __FILE__));
104  if((ix>=0) && (ix<__MAXCONDIM__))
105  fxConEventName[ix]=name;
106 }
107 
108 const char* TGo4HistogramEntry::GetConEventName(Int_t ix) const
109 {
110  return ((ix>=0) && (ix<__MAXCONDIM__)) ? fxConEventName[ix].Data() : 0;
111 }
112 
113 
115 {
116  fxHistogram=0;
117  for(Int_t t =0; t<__MAXHISDIM__; ++t) {
118  fxHisEvents[t] = 0;
119  fxHistType[t] = 0;
120  fxHistPtr[t] = 0;
121  }
122 
123  fxCondition = 0;
124  for(Int_t t =0; t<__MAXCONDIM__; ++t) {
125  fxConEvents[t] = 0;
126  fxCondType[t] = 0;
127  fxCondPtr[t] = 0;
128  }
129 
130  fbNeedInitialisation = kTRUE;
131 }
132 
133 void TGo4HistogramEntry::InitHistPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
134 {
135  if ((ix<0) || (ix>=__MAXHISDIM__)) return;
136  fxHistPtr[ix] = 0;
137  fxHisEvents[ix] = event;
138  if ((event==0) || (member==0) || !member->IsBasic()) return;
139  fxHistPtr[ix] = (char*) event+ offset;
140  fxHistType[ix] = member->GetDataType()->GetType();
141 }
142 
143 void TGo4HistogramEntry::InitCondPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
144 {
145  if ((ix<0) || (ix>=__MAXCONDIM__)) return;
146  fxCondPtr[ix] = 0;
147  fxConEvents[ix] = event;
148  if ((event==0) || (member==0) || !member->IsBasic()) return;
149  fxCondPtr[ix] = (char*) event+ offset;
150  fxCondType[ix] = member->GetDataType()->GetType();
151 }
152 
153 Double_t TGo4HistogramEntry::GetPtrValue(Int_t type, void* ptr)
154 {
155  if (ptr==0) return 0.;
156  switch (type) {
157  case kUInt_t: return *((UInt_t*)ptr);
158  case kInt_t: return *((Int_t*)ptr);
159  case kULong_t: return *((ULong_t*)ptr);
160  case kLong_t: return *((Long_t*)ptr);
161  case kULong64_t: return *((ULong64_t*)ptr);
162  case kLong64_t: return *((Long64_t*)ptr);
163  case kUShort_t: return *((UShort_t*)ptr);
164  case kShort_t: return *((Short_t*)ptr);
165  case kUChar_t: return *((UChar_t*)ptr);
166  case kChar_t: return *((Char_t*)ptr);
167 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,3,2)
168  case kBool_t: return *((Bool_t*)ptr);
169 #endif
170  case kFloat_t: return *((Float_t*)ptr);
171  case kDouble_t: return *((Double_t*)ptr);
172  case kDouble32_t: return *((Double32_t*)ptr);
173  }
174  return 0.;
175 }
176 
178 {
179  if (fxCondition==0) return kTRUE;
180 
181  Bool_t rev = kTRUE;
182 
183  Double_t dat[__MAXCONDIM__];
184 
185  UInt_t j,dimension;
186  // find out how many dimensions are set for condition:
187  // maximum condition dimension defined by first index
188  // with all data pointers set to zero.
189  for(dimension=0;dimension<__MAXCONDIM__; ++dimension)
190  if (fxCondPtr[dimension]==0) break;
191 
192  // fill pointers to test variables:
193  for(j=0;j<dimension; ++j)
194  dat[j] = GetPtrValue(fxCondType[j], fxCondPtr[j]);
195 
196  switch(dimension) {
197 // case 0:
198 // rev = fxCondition->GetLast(); // no own variables: last result
199 // //std::cout << "found zero dimension for condition" << std::endl;
200 // break;
201  case 1:
202  rev=fxCondition->Test(dat[0]);
203  //std::cout << "found one dimension for condition" << std::endl;
204  break;
205  case 2:
206  rev=fxCondition->Test(dat[0], dat[1]);
207  //std::cout << "found two dimensions for condition" << std::endl;
208  break;
209  default:
210  rev = kTRUE;
211  break;
212  } // switch(maxt)
213 
214  return rev;
215 }
216 
217 void TGo4HistogramEntry::ProcessNew(Bool_t* evvalid)
218 {
219  if (fxHistogram==0) return;
220 
221  if (!TestConditionNew()) return;
222 
223  Double_t dat[3];
224  Int_t dimension = fxHistogram->GetDimension();
225  for(Int_t j=0; j<dimension; ++j)
226  dat[j] = GetPtrValue(fxHistType[j], fxHistPtr[j]);
227  switch (dimension) {
228  case 1:
229  if(evvalid[0]) fxHistogram->Fill(dat[0]);
230  break;
231  case 2:
232  if(evvalid[0] && evvalid[1]) {
233  TH2* his2 = dynamic_cast<TH2*>(fxHistogram);
234  if(his2!=0) his2->Fill(dat[0],dat[1]);
235  }
236  break;
237  case 3:
238  if(evvalid[0] && evvalid[1] && evvalid[2]) {
239  TH3* his3 = dynamic_cast<TH3*>(fxHistogram);
240  if(his3!=0) his3->Fill(dat[0],dat[1],dat[2]);
241  }
242  break;
243  default:
244  throw TGo4DynamicListException(this,
245  "Dynamic Histogram Entry %s Process error: Wrong histogram dimension %d !!!",
246  GetName(), dimension);
247  } // switch(dimension)
248 }
249 
251 {
252  if (obj==0) return;
253 
254  if(fxHistogram==obj) Reset();
255 
256  if(fxCondition==obj) Reset();
257 
258  for (Int_t n=0;n<__MAXCONDIM__;n++)
259  if (fxConEvents[n]==obj) Reset();
260 
261  for (Int_t n=0;n<__MAXHISDIM__;n++)
262  if (fxHisEvents[n]==obj) Reset();
263 }
264 
265 void TGo4HistogramEntry::Print(Option_t*) const
266 {
267  // this trick is needed since root defines Print as const function...
268  TROOT::IndentLevel();
269  std::cout <<"-Dynamic Histogram Entry " << GetName()<<" :"<<std::endl;
270  TROOT::IncreaseDirLevel();
271  TROOT::IndentLevel();
272 
273  if(IsEnabledProcessing()) std::cout <<"\t-- Enabled --" << std::endl;
274  else std::cout <<"\t-- Disabled --" << std::endl;
275 
276  TROOT::IndentLevel();
277  std::cout <<"\tCondition: "<< GetConditionName() << std::endl;
278  for(Int_t i=0;i<__MAXCONDIM__; ++i) {
279  TROOT::IndentLevel();
280  std::cout << "\t ConEvent(" << i << "): " << GetConEventName(i)
281  << "\t ConVar(" << i << "): " << GetConVarName(i) << std::endl;
282  }
283  TROOT::IndentLevel();
284  std::cout <<"\tHistogram: "<< GetHistogramName() << std::endl;
285  for(Int_t i=0;i<__MAXHISDIM__; ++i) {
286  TROOT::IndentLevel();
287  std::cout << "\t HisEvent(" << i<<"): " << GetHistEventName(i)
288  << "\t HisVar(" << i<< "): " << GetHistVarName(i) << std::endl;
289  }
290  TROOT::DecreaseDirLevel();
291  TROOT::IndentLevel();
292  std::cout <<"-End "<<GetName()<<"-----------" << std::endl;
293 }
294 
296 {
297  return fgcNOCONDITION;
298 }
299 
301 {
302  return fgcNODATA;
303 }
304 
306 {
307  return fgcNOEVENT;
308 }
309 
Double_t GetPtrValue(Int_t type, void *ptr)
static const char * Get_fgcNOCONDITION()
static const char * fgcNOEVENT
void * fxCondPtr[__MAXCONDIM__]
virtual void Print(Option_t *="") const
static const char * fgcNODATA
Int_t fxCondType[__MAXCONDIM__]
#define __MAXHISDIM__
TString fxConVarName[__MAXCONDIM__]
void SetConEventName(Int_t ix, const char *name)
const char * GetConVarName(Int_t ix) const
static const char * fgcNOCONDITION
void InitCondPointer(Int_t ix, TObject *event, TDataMember *member, Long_t offset)
virtual void RecursiveRemove(TObject *obj)
TObject * fxConEvents[__MAXCONDIM__]
const char * GetHistVarName(Int_t ix) const
void SetHisEventName(Int_t ix, const char *name)
Bool_t IsEnabledProcessing() const
void * fxHistPtr[__MAXHISDIM__]
const char * GetHistogramName() const
Int_t fxHistType[__MAXHISDIM__]
TString fxHisVarName[__MAXHISDIM__]
#define __MAXCONDIM__
static const char * Get_fgcNODATA()
virtual Bool_t Test()
#define GO4TRACE(X)
Definition: TGo4Log.h:26
TString fxConEventName[__MAXCONDIM__]
const char * GetConditionName() const
TObject * fxHisEvents[__MAXHISDIM__]
void SetConVarName(Int_t ix, const char *name)
void InitHistPointer(Int_t ix, TObject *event, TDataMember *member, Long_t offset)
const char * GetConEventName(Int_t ix) const
const char * GetHistEventName(Int_t ix) const
void ProcessNew(Bool_t *evvalid)
TString fxHisEventName[__MAXHISDIM__]
static const char * Get_fgcNOEVENT()
TGo4Condition * fxCondition
void SetHisVarName(Int_t ix, const char *name)