GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4MbsHist.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 "TGo4MbsHist.h"
15 
16 #include "TGraph.h"
17 #include "TH1.h"
18 #include "TH2.h"
19 #include "TList.h"
20 #include "TFolder.h"
21 #include "TTimeStamp.h"
22 #include "TRegexp.h"
23 
24 #include "TGo4ThreadManager.h"
26 
27 const Int_t TGo4MbsHist::fgiLISTLEN=512;
28 
30  TObject(),
31  fiBufLen(128),
32  fiBuffer(nullptr),
33  fxCursor(nullptr),
34  fiHisNum(0)
35 {
36  fiBuffer = new Int_t[fiBufLen];
37 }
38 
40  TObject(),
41  fiBufLen(1),
42  fiBuffer(nullptr),
43  fxCursor(nullptr),
44  fiHisNum(1)
45 {
46  if (histo) {
47  PrepareHeader(histo, nullptr, &fxHistoHead);
48  if (histo->GetDimension() == 2) {
49  // two dim histo
50  Int_t i = 0;
51  Stat_t value = 0;
52 
53  Int_t maxu = histo->GetNbinsX();
54  Int_t maxv = histo->GetNbinsY();
55  fiBufLen = (maxu) * (maxv); // note: we ignore over + underflow bins
56  fiBuffer = new Int_t[fiBufLen];
57  // test: we swap x and y loops
58  for (Int_t v = 0; v < maxv; v++) {
59  for (Int_t u = 0; u < maxu; u++) {
60  value = histo->GetBinContent(u, v);
61  SetValue((char *)&fiBuffer[i++], value);
62  }
63  } // for
64  } else {
65  // one dim histo and all others
66  Int_t maxu = histo->GetNbinsX();
67  fiBufLen = maxu; // note: we ignore over + underflow bins
68  fiBuffer = new Int_t[fiBufLen];
69  Stat_t value = 0;
70  for (Int_t u = 0; u < maxu; u++) {
71  value = histo->GetBinContent(u);
72  SetValue((char *)&fiBuffer[u], value);
73  }
74  } // if(histo->GetDimension()))
75  } else {
76  // case of dummy object!
77  fiBuffer = new Int_t[fiBufLen];
78  } // if(histo)
79 }
80 
81 TGo4MbsHist::TGo4MbsHist(TFolder *folder, const char *filter) :
82  TObject(),
84  fiBuffer(nullptr),
85  fxCursor(nullptr),
86  fiHisNum(0)
87 {
88  // allocate buffer of total size
89  fiBuffer = new Int_t[fiBufLen];
91  ScanGo4Folder(folder, nullptr, filter);
92 }
93 
95 {
96  delete [] fiBuffer;
97 }
98 
99 void TGo4MbsHist::PrepareHeader(TH1 *source, const char *path, s_his_head* target)
100 {
101  if (!source || !target)
102  return;
103  s_his_head *dest = target; // use local pointer to avoid changes by snprintf
104  dest->l_bins_1 = source->GetNbinsX();
105  dest->l_bins_2 = source->GetNbinsY();
106  // display of path enabled again to test Origin problems JA
107  if (path)
108  snprintf(dest->c_name, 64, "%s%s", path, source->GetName());
109  else
110  snprintf(dest->c_name, 64, "%s", source->GetName());
111  snprintf(dest->c_lettering_1, 64, "%s", source->GetXaxis()->GetTitle());
112  snprintf(dest->c_lettering_2, 64, "%s", source->GetYaxis()->GetTitle());
113  snprintf(dest->c_lettering_res, 64, "%s", source->GetYaxis()->GetTitle());
114  dest->r_limits_low = source->GetXaxis()->GetXmin();
115  dest->r_limits_up = source->GetXaxis()->GetXmax();
116  dest->r_limits_low_2 = source->GetYaxis()->GetXmin();
117  dest->r_limits_up_2 = source->GetYaxis()->GetXmax();
118 
119  if (source->InheritsFrom(TH1D::Class()) || source->InheritsFrom(TH1F::Class()) ||
120  source->InheritsFrom(TH2D::Class()) || source->InheritsFrom(TH2F::Class())) {
121  strcpy(dest->c_dtype, "r");
122  } else {
123  strcpy(dest->c_dtype, "i");
124  }
125  TTimeStamp now;
126  snprintf(dest->c_data_time_cre, 28, "%s", now.AsString("l")); // creation time
127  snprintf(dest->c_clear_date, 28, "%s", now.AsString("l")); // clear time, dummy here
128 }
129 
130 void TGo4MbsHist::SetValue(char *address, Stat_t value)
131 {
132  if (!strcmp(fxHistoHead.c_dtype, "r")) {
133  Float_t *faddress = (Float_t *)address;
134  *faddress = (Float_t)value;
135  } else {
136  Int_t *iaddress = (Int_t *)address;
137  *iaddress = (Int_t)value;
138  }
139 }
140 
141 void TGo4MbsHist::ScanGo4Folder(TFolder *folder, const char *superfolders, const char *filter)
142 {
143  // scan folder for histogram status objects
144 // if(filter)
145 // std::cout <<"ScanGo4Folder with filter "<<filter << std::endl;
146 // else
147 // std::cout <<"ScanGo4Folder with no filter "<< std::endl;
148 //
149 
150  if(!folder)
151  return;
152 
153  TIter iter(folder->GetListOfFolders());
154  while (auto entry = iter()) {
155  char pathbuffer[TGo4ThreadManager::fguTEXTLENGTH];
156  Int_t num = 0;
157  if (superfolders)
158  num = snprintf(pathbuffer, TGo4ThreadManager::fguTEXTLENGTH, "%s/", superfolders);
159  else
160  // num=snprintf(pathbuffer,TGo4ThreadManager::fguTEXTLENGTH,"");
161  strcpy(pathbuffer, "");
162  char *cursor = pathbuffer + num;
163  Int_t edge = TGo4ThreadManager::fguTEXTLENGTH - num;
164  if (entry->InheritsFrom(TFolder::Class())) {
165  // found subfolder, process it recursively
166  const char *foldname = entry->GetName();
167  // filter out folders without histograms or graphs:
168  if (!strcmp(foldname, TGo4AnalysisObjectManager::GetDYNFOLDER())) {
169 
170  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetCONDFOLDER())) {
171 
172  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetPARAFOLDER())) {
173 
174  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetTREEFOLDER())) {
175 
176  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetPICTFOLDER())) {
177 
178  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetCANVFOLDER())) {
179 
180  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetANALYSISFOLDER())) {
181 
182  } else {
183  snprintf(cursor, edge, "%s", foldname);
184  TFolder *subobj = dynamic_cast<TFolder *>(entry);
185  ScanGo4Folder(subobj, pathbuffer, filter);
186  }
187  } else if (entry->InheritsFrom(TH1::Class()) || entry->InheritsFrom(TGraph::Class())) {
188  // first check if filter is ok:
189  Bool_t ismatching = kFALSE;
190  const char *entryname = entry->GetName();
191  TString entrystring = entryname;
192  TRegexp reg(filter, kTRUE);
193  if (!filter)
194  ismatching = kTRUE; // no filter set, take all
195  else if (!strcmp(filter, "*"))
196  ismatching = kTRUE; // take all in this folder
197  // else if (strstr(filter,entryname))
198  // ismatching=kTRUE; // expression just contained in name
199  else if (entrystring.Index(reg, 0) != kNPOS)
200  ismatching = kTRUE; // root regular expression class
201  else
202  ismatching = kFALSE;
203 
204  if (ismatching) {
205  TH1 *hist = dynamic_cast<TH1 *>(entry);
206  if (!hist) {
207  TGraph *graf = dynamic_cast<TGraph *>(entry);
208  if (graf && graf->GetN() > 0) {
209  hist = graf->GetHistogram();
210  }
211  if (!hist)
212  continue;
213  }
214  PrepareHeader(hist, pathbuffer, fxCursor);
215  fxCursor++;
216  fiHisNum++;
217  if ((char *)(fxCursor) > (char *)(fiBuffer) + fiBufLen * sizeof(Int_t) - sizeof(s_his_head)) {
218  Int_t oldbuflen = fiBufLen;
219  fiBufLen += fgiLISTLEN;
220  Int_t *otherbuf = new Int_t[fiBufLen];
221  memcpy(otherbuf, fiBuffer, oldbuflen * sizeof(Int_t));
222  delete[] fiBuffer;
223  fiBuffer = otherbuf;
225  for (Int_t n = 0; n < fiHisNum; ++n)
226  fxCursor++; // set cursor in new buffer
227  // std::cout <<"MMMMMMM Copied buffer, cursor set "<< std::endl;
228  // std::cout <<" hisnum="<< (Int_t) fiHisNum<< std::endl;
229  // std::cout <<" newcr="<< (Int_t) fxCursor<< std::endl;
230  // std::cout <<" buffer="<< (Int_t) fiBuffer<< std::endl;
231  } else {
232  }
233  } // if(ismatching)
234  }
235  } // while
236 }
Int_t fiBufLen
Definition: TGo4MbsHist.h:69
static const Int_t fgiLISTLEN
Definition: TGo4MbsHist.h:53
REAL4 r_limits_up
Definition: s_his_head.h:28
void SetValue(char *address, Stat_t value)
Int_t fiHisNum
Definition: TGo4MbsHist.h:76
CHARS c_clear_date[28]
Definition: s_his_head.h:44
void PrepareHeader(TH1 *source, const char *path, s_his_head *target)
Definition: TGo4MbsHist.cxx:99
CHARS c_lettering_res[64]
Definition: s_his_head.h:45
INTS4 l_bins_2
Definition: s_his_head.h:23
virtual ~TGo4MbsHist()
Definition: TGo4MbsHist.cxx:94
REAL4 r_limits_low
Definition: s_his_head.h:27
REAL4 r_limits_up_2
Definition: s_his_head.h:36
void ScanGo4Folder(TFolder *fold, const char *superfolders=nullptr, const char *filter=nullptr)
s_his_head * fxCursor
Definition: TGo4MbsHist.h:73
CHARS c_data_time_cre[28]
Definition: s_his_head.h:43
CHARS c_name[64]
Definition: s_his_head.h:41
REAL4 r_limits_low_2
Definition: s_his_head.h:35
CHARS c_lettering_1[64]
Definition: s_his_head.h:46
INTS4 l_bins_1
Definition: s_his_head.h:22
CHARS c_lettering_2[64]
Definition: s_his_head.h:47
static const char * GetANALYSISFOLDER()
CHARS c_dtype[4]
Definition: s_his_head.h:42
s_his_head fxHistoHead
Definition: TGo4MbsHist.h:68
Int_t * fiBuffer
Definition: TGo4MbsHist.h:70