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