GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4HistogramStatus.cxx
Go to the documentation of this file.
1 // $Id: TGo4HistogramStatus.cxx 999 2013-07-25 11:58:59Z 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 "TGo4HistogramStatus.h"
15 
16 #include "Riostream.h"
17 #include "TH1.h"
18 #include "TH2.h"
19 #include "TH3.h"
20 
21 #include "TGo4Log.h"
22 
23 TGo4HistogramStatus::TGo4HistogramStatus(TH1* his, Bool_t allstatistics)
24 : TGo4ObjectStatus(his, allstatistics),
25 fiDim(0),fiNbinX(0), fiNbinY(0), fiNbinZ(0),
26 fdXmin(0), fdXmax(0), fdYmin(0), fdYmax(0), fdZmin(0), fdZmax(0),
27 fdEntries(0), fdXmean(0), fdYmean(0), fdZmean(0),
28 fdXrms(0), fdYrms(0), fdZrms(0)
29 {
30  GO4TRACE((14,"TGo4HistogramStatus::TGo4HistogramStatus(TH1*)",__LINE__, __FILE__));
31 
32  if(his!=0)
33  {
34  fiDim=his->GetDimension();
35  fiNbinX=his->GetNbinsX();
36  fiNbinY=his->GetNbinsY();
37  fiNbinZ=his->GetNbinsZ();
38  TAxis* xax=his->GetXaxis();
39  if(xax)
40  {
41  fdXmin=xax->GetXmin();
42  fdXmax=xax->GetXmax();
43  }
44  else
45  { // values already initialized as zero
46  }
47  TAxis* yax=his->GetYaxis();
48  if(yax)
49  {
50  fdYmin=yax->GetXmin();
51  fdYmax=yax->GetXmax();
52  }
53  else
54  { // values already initialized as zero
55  }
56  TAxis* zax=his->GetZaxis();
57  if(zax)
58  {
59  fdZmin=zax->GetXmin();
60  fdZmax=zax->GetXmax();
61  }
62  else
63  { // values already initialized as zero
64  }
65  fdEntries = his->GetEntries();
68  Int_t fieldsize=0;
69  // because of multiple inheritance of histogram types, we
70  // must check for all types separately to downcast the correct TArray:
71  if(his->InheritsFrom(TH1D::Class()))
72  {
73  TH1D* dhis=dynamic_cast<TH1D*>(his);
74  fieldsize=sizeof(Double_t)*dhis->GetSize(); // method of TArray baseclass
75  }
76  else if(his->InheritsFrom(TH1F::Class()))
77  {
78  TH1F* fhis=dynamic_cast<TH1F*>(his);
79  fieldsize=sizeof(Float_t)*fhis->GetSize(); // method of TArray baseclass
80  }
81  else if(his->InheritsFrom(TH1I::Class()))
82  {
83  TH1I* ihis=dynamic_cast<TH1I*>(his);
84  fieldsize=sizeof(Int_t)*ihis->GetSize(); // method of TArray baseclass
85  }
86  else if(his->InheritsFrom(TH1S::Class()))
87  {
88  TH1S* shis=dynamic_cast<TH1S*>(his);
89  fieldsize=sizeof(Short_t)*shis->GetSize(); // method of TArray baseclass
90  }
91  else if(his->InheritsFrom(TH1C::Class()))
92  {
93  TH1C* chis=dynamic_cast<TH1C*>(his);
94  fieldsize=sizeof(Char_t)*chis->GetSize(); // method of TArray baseclass
95  }
96  else if(his->InheritsFrom(TH2D::Class()))
97  {
98  TH2D* dhis=dynamic_cast<TH2D*>(his);
99  fieldsize=sizeof(Double_t)*dhis->GetSize(); // method of TArray baseclass
100  }
101  else if(his->InheritsFrom(TH2F::Class()))
102  {
103  TH2F* fhis=dynamic_cast<TH2F*>(his);
104  fieldsize=sizeof(Float_t)*fhis->GetSize(); // method of TArray baseclass
105  }
106  else if(his->InheritsFrom(TH2I::Class()))
107  {
108  TH2I* ihis=dynamic_cast<TH2I*>(his);
109  fieldsize=sizeof(Int_t)*ihis->GetSize(); // method of TArray baseclass
110  }
111  else if(his->InheritsFrom(TH2S::Class()))
112  {
113  TH2S* shis=dynamic_cast<TH2S*>(his);
114  fieldsize=sizeof(Short_t)*shis->GetSize(); // method of TArray baseclass
115  }
116  else if(his->InheritsFrom(TH2C::Class()))
117  {
118  TH2C* chis=dynamic_cast<TH2C*>(his);
119  fieldsize=sizeof(Char_t)*chis->GetSize(); // method of TArray baseclass
120  }
121  else if(his->InheritsFrom(TH3D::Class()))
122  {
123  TH3D* dhis=dynamic_cast<TH3D*>(his);
124  fieldsize=sizeof(Double_t)*dhis->GetSize(); // method of TArray baseclass
125  }
126  else if(his->InheritsFrom(TH3F::Class()))
127  {
128  TH3F* fhis=dynamic_cast<TH3F*>(his);
129  fieldsize=sizeof(Float_t)*fhis->GetSize(); // method of TArray baseclass
130  }
131  else if(his->InheritsFrom(TH3I::Class()))
132  {
133  TH3I* ihis=dynamic_cast<TH3I*>(his);
134  fieldsize=sizeof(Int_t)*ihis->GetSize(); // method of TArray baseclass
135  }
136  else if(his->InheritsFrom(TH3S::Class()))
137  {
138  TH3S* shis=dynamic_cast<TH3S*>(his);
139  fieldsize=sizeof(Short_t)*shis->GetSize(); // method of TArray baseclass
140  }
141  else if(his->InheritsFrom(TH3C::Class()))
142  {
143  TH3C* chis=dynamic_cast<TH3C*>(his);
144  fieldsize=sizeof(Char_t)*chis->GetSize(); // method of TArray baseclass
145  }
146  fiObjectSize+=fieldsize; // add heap field to object stack memory size
148 
149  if(allstatistics)
150  {
151  // note: we do not calculate statistic for nameslist
152  // slows down when processing empty 2d histos!
153  //std::cout <<"\t" <<GetName()<<" calculating mean/rms..." << std::endl;
154  fdXmean=his->GetMean(1);
155  fdYmean=his->GetMean(2);
156  fdZmean=his->GetMean(3);
157  //std::cout <<"\t"<<GetName()<<" finished mean." << std::endl;
158  fdXrms=his->GetRMS(1);
159  fdYrms=his->GetRMS(2);
160  fdZrms=his->GetRMS(3);
161  //std::cout <<"\t"<<GetName()<<" finished rms." << std::endl;
162  }
163  }
164 }
165 
166 
167 
169 fiDim(0),fiNbinX(0), fiNbinY(0), fiNbinZ(0),
170 fdXmin(0), fdXmax(0), fdYmin(0), fdYmax(0), fdZmin(0), fdZmax(0),
171 fdEntries(0), fdXmean(0), fdYmean(0), fdZmean(0),
172 fdXrms(0), fdYrms(0), fdZrms(0)
173 {
174 GO4TRACE((14,"TGo4HistogramStatus::TGo4HistogramStatus()",__LINE__, __FILE__));
175 
176 }
177 
178 
180 {
181 GO4TRACE((14,"TGo4HistogramStatus::TGo4HistogramStatus()",__LINE__, __FILE__));
182 
183 }
184 
185 
186 
187 
188 Int_t TGo4HistogramStatus::PrintStatus(Text_t* buffer, Int_t buflen)
189 {
190  GO4TRACE((12,"TGo4HistogramStatus::PrintStatus()",__LINE__, __FILE__));
191  //
192  if(buflen<=0 && buffer!=0)
193  return 0;
194  Int_t locallen=128000;
195  Text_t localbuf[128000];
196  Int_t size=0;
197  Text_t* current=localbuf;
198  Int_t restlen=locallen;
199  Int_t delta= TGo4ObjectStatus::PrintStatus(current,restlen);
200  restlen-=delta;
201  current+=delta;
202  current=PrintIndent(current,restlen);
203  current=PrintBuffer(current,restlen, "G-OOOO-> Histogram Status Class Printout <-OOOO-G\n");
204  current=PrintIndent(current,restlen);
205  current=PrintBuffer(current,restlen, "G-OOOO-> ---------------------------------------------- <-OOOO-G\n");
206  // put printout of histogram infos here:
207  current=PrintIndent(current,restlen);
208  current=PrintBuffer(current,restlen, " Dimension: \t%d\n",GetDimension());
209  current=PrintIndent(current,restlen);
210  current=PrintBuffer(current,restlen, " Bins X: \t%d\n",GetXbins());
211  current=PrintIndent(current,restlen);
212  current=PrintBuffer(current,restlen, " X min: \t\t%f\n",GetXmin());
213  current=PrintIndent(current,restlen);
214  current=PrintBuffer(current,restlen, " X max: \t\t%f\n",GetXmax());
215  current=PrintIndent(current,restlen);
216  current=PrintBuffer(current,restlen, " X mean: \t%f\n",GetXmean());
217  current=PrintIndent(current,restlen);
218  current=PrintBuffer(current,restlen, " X rms: \t\t%f\n",GetXrms());
219  if(GetDimension()>1)
220  {
221  current=PrintIndent(current,restlen);
222  current=PrintBuffer(current,restlen, " Bins Y: \t%d\n",GetYbins());
223  current=PrintIndent(current,restlen);
224  current=PrintBuffer(current,restlen, " Y min: \t\t%f\n",GetYmin());
225  current=PrintIndent(current,restlen);
226  current=PrintBuffer(current,restlen, " Y max: \t\t%f\n",GetYmax());
227  current=PrintIndent(current,restlen);
228  current=PrintBuffer(current,restlen, " Y mean: \t%f\n",GetYmean());
229  current=PrintIndent(current,restlen);
230  current=PrintBuffer(current,restlen, " Y rms: \t\t%f\n",GetYrms());
231  }
232  else
233  { }
234  if(GetDimension()>2)
235  {
236  current=PrintIndent(current,restlen);
237  current=PrintBuffer(current,restlen, " Bins Z: \t%d\n",GetZbins());
238  current=PrintIndent(current,restlen);
239  current=PrintBuffer(current,restlen, " Z min: \t\t%f\n",GetZmin());
240  current=PrintIndent(current,restlen);
241  current=PrintBuffer(current,restlen, " Z max: \t\t%f\n",GetZmax());
242  current=PrintIndent(current,restlen);
243  current=PrintBuffer(current,restlen, " Z mean: \t%f\n",GetZmean());
244  current=PrintIndent(current,restlen);
245  current=PrintBuffer(current,restlen, " Z rms: \t\t%f\n",GetZrms());
246  }
247  else
248  { }
249  current=PrintIndent(current,restlen);
250  current=PrintBuffer(current,restlen, " N Entries: \t%f\n",GetEntries());
251  current=PrintIndent(current,restlen);
252  current=PrintBuffer(current,restlen, "G-OOOO-> ---------------------------------------------- <-OOOO-G\n");
253  if(buffer==0)
254  {
255  std::cout << localbuf << std::endl;
256  }
257  else
258  {
259  size=locallen-restlen;
260  if(size>buflen-1)
261  size=buflen-1;
262  strncpy(buffer,localbuf,size);
263  }
264  return size;
265 }
static Text_t * PrintIndent(Text_t *buffer, Int_t &buflen)
Definition: TGo4Status.cxx:72
virtual Int_t PrintStatus(Text_t *buffer=0, Int_t buflen=0)
#define GO4TRACE(X)
Definition: TGo4Log.h:26
virtual Int_t PrintStatus(Text_t *buffer=0, Int_t buflen=0)
static Text_t * PrintBuffer(char *buffer, Int_t &buflen, const char *text,...)
Definition: TGo4Status.cxx:85