GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HistogramEntry.cxx
Go to the documentation of this file.
1 // $Id: TGo4HistogramEntry.cxx 2747 2020-04-16 09:30:36Z 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 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(0),
34  fxCondition(0),
35  fbNeedInitialisation(kTRUE)
36 {
37 }
38 
40  TGo4DynamicEntry(name),
41  fxHistogram(0),
42  fxCondition(0),
43  fbNeedInitialisation(kTRUE)
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() : 0;
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() : 0;
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() : 0;
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() : 0;
108 }
109 
110 
112 {
113  fxHistogram=0;
114  for(Int_t t =0; t<__MAXHISDIM__; ++t) {
115  fxHisEvents[t] = 0;
116  fxHistType[t] = 0;
117  fxHistPtr[t] = 0;
118  }
119 
120  fxCondition = 0;
121  for(Int_t t =0; t<__MAXCONDIM__; ++t) {
122  fxConEvents[t] = 0;
123  fxCondType[t] = 0;
124  fxCondPtr[t] = 0;
125  }
126 
127  fbNeedInitialisation = kTRUE;
128 }
129 
130 void TGo4HistogramEntry::InitHistPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
131 {
132  if ((ix<0) || (ix>=__MAXHISDIM__)) return;
133  fxHistPtr[ix] = 0;
134  fxHisEvents[ix] = event;
135  if ((event==0) || (member==0) || !member->IsBasic()) return;
136  fxHistPtr[ix] = (char*) event+ offset;
137  fxHistType[ix] = member->GetDataType()->GetType();
138 }
139 
140 void TGo4HistogramEntry::InitCondPointer(Int_t ix, TObject* event, TDataMember* member, Long_t offset)
141 {
142  if ((ix<0) || (ix>=__MAXCONDIM__)) return;
143  fxCondPtr[ix] = 0;
144  fxConEvents[ix] = event;
145  if ((event==0) || (member==0) || !member->IsBasic()) return;
146  fxCondPtr[ix] = (char*) event+ offset;
147  fxCondType[ix] = member->GetDataType()->GetType();
148 }
149 
150 Double_t TGo4HistogramEntry::GetPtrValue(Int_t type, void* ptr)
151 {
152  if (ptr==0) return 0.;
153  switch (type) {
154  case kUInt_t: return *((UInt_t*)ptr);
155  case kInt_t: return *((Int_t*)ptr);
156  case kULong_t: return *((ULong_t*)ptr);
157  case kLong_t: return *((Long_t*)ptr);
158  case kULong64_t: return *((ULong64_t*)ptr);
159  case kLong64_t: return *((Long64_t*)ptr);
160  case kUShort_t: return *((UShort_t*)ptr);
161  case kShort_t: return *((Short_t*)ptr);
162  case kUChar_t: return *((UChar_t*)ptr);
163  case kChar_t: return *((Char_t*)ptr);
164  case kBool_t: return *((Bool_t*)ptr);
165  case kFloat_t: return *((Float_t*)ptr);
166  case kDouble_t: return *((Double_t*)ptr);
167  case kDouble32_t: return *((Double32_t*)ptr);
168  }
169  return 0.;
170 }
171 
173 {
174  if (fxCondition==0) return kTRUE;
175 
176  Bool_t rev = kTRUE;
177 
178  Double_t dat[__MAXCONDIM__];
179 
180  UInt_t j,dimension;
181  // find out how many dimensions are set for condition:
182  // maximum condition dimension defined by first index
183  // with all data pointers set to zero.
184  for(dimension=0;dimension<__MAXCONDIM__; ++dimension)
185  if (fxCondPtr[dimension]==0) break;
186 
187  // fill pointers to test variables:
188  for(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 // //std::cout << "found zero dimension for condition" << std::endl;
195 // break;
196  case 1:
197  rev=fxCondition->Test(dat[0]);
198  //std::cout << "found one dimension for condition" << std::endl;
199  break;
200  case 2:
201  rev=fxCondition->Test(dat[0], dat[1]);
202  //std::cout << "found two dimensions for condition" << std::endl;
203  break;
204  default:
205  rev = kTRUE;
206  break;
207  } // switch(maxt)
208 
209  return rev;
210 }
211 
212 void TGo4HistogramEntry::ProcessNew(Bool_t* evvalid)
213 {
214  if (fxHistogram==0) return;
215 
216  if (!TestConditionNew()) return;
217 
218  Double_t dat[3];
219  Int_t dimension = fxHistogram->GetDimension();
220  for(Int_t j=0; j<dimension; ++j)
221  dat[j] = GetPtrValue(fxHistType[j], fxHistPtr[j]);
222  switch (dimension) {
223  case 1:
224  if(evvalid[0]) fxHistogram->Fill(dat[0]);
225  break;
226  case 2:
227  if(evvalid[0] && evvalid[1]) {
228  TH2* his2 = dynamic_cast<TH2*>(fxHistogram);
229  if(his2!=0) his2->Fill(dat[0],dat[1]);
230  }
231  break;
232  case 3:
233  if(evvalid[0] && evvalid[1] && evvalid[2]) {
234  TH3* his3 = dynamic_cast<TH3*>(fxHistogram);
235  if(his3!=0) his3->Fill(dat[0],dat[1],dat[2]);
236  }
237  break;
238  default:
239  throw TGo4DynamicListException(this,
240  Form("Dynamic Histogram Entry %s Process error: Wrong histogram dimension %d !!!", GetName(), dimension));
241  } // switch(dimension)
242 }
243 
245 {
246  if (obj==0) return;
247 
248  if(fxHistogram==obj) Reset();
249 
250  if(fxCondition==obj) Reset();
251 
252  for (Int_t n=0;n<__MAXCONDIM__;n++)
253  if (fxConEvents[n]==obj) Reset();
254 
255  for (Int_t n=0;n<__MAXHISDIM__;n++)
256  if (fxHisEvents[n]==obj) Reset();
257 }
258 
259 void TGo4HistogramEntry::Print(Option_t*) const
260 {
261  // this trick is needed since root defines Print as const function...
262  TROOT::IndentLevel();
263  std::cout <<"-Dynamic Histogram Entry " << GetName()<<" :"<<std::endl;
264  TROOT::IncreaseDirLevel();
265  TROOT::IndentLevel();
266 
267  if(IsEnabledProcessing()) std::cout <<"\t-- Enabled --" << std::endl;
268  else std::cout <<"\t-- Disabled --" << std::endl;
269 
270  TROOT::IndentLevel();
271  std::cout <<"\tCondition: "<< GetConditionName() << std::endl;
272  for(Int_t i=0;i<__MAXCONDIM__; ++i) {
273  TROOT::IndentLevel();
274  std::cout << "\t ConEvent(" << i << "): " << GetConEventName(i)
275  << "\t ConVar(" << i << "): " << GetConVarName(i) << std::endl;
276  }
277  TROOT::IndentLevel();
278  std::cout <<"\tHistogram: "<< GetHistogramName() << std::endl;
279  for(Int_t i=0;i<__MAXHISDIM__; ++i) {
280  TROOT::IndentLevel();
281  std::cout << "\t HisEvent(" << i<<"): " << GetHistEventName(i)
282  << "\t HisVar(" << i<< "): " << GetHistVarName(i) << std::endl;
283  }
284  TROOT::DecreaseDirLevel();
285  TROOT::IndentLevel();
286  std::cout <<"-End "<<GetName()<<"-----------" << std::endl;
287 }
288 
290 {
291  return fgcNOCONDITION;
292 }
293 
295 {
296  return fgcNODATA;
297 }
298 
300 {
301  return fgcNOEVENT;
302 }
303 
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)