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