GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4MbsHist.cxx
Go to the documentation of this file.
1 // $Id: TGo4MbsHist.cxx 2857 2020-05-18 14:01:48Z 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 "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(0),
33  fxCursor(0),
34  fiHisNum(0)
35 {
36  fiBuffer = new Int_t[fiBufLen];
37 }
38 
40  TObject(),
41  fiBufLen(1),
42  fiBuffer(0),
43  fxCursor(0),
44  fiHisNum(1)
45 {
46  if (histo) {
47  PrepareHeader(histo, 0, &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(),
83  fiBufLen(fgiLISTLEN),
84  fiBuffer(0),
85  fxCursor(0),
86  fiHisNum(0)
87 {
88  // allocate buffer of total size
89  //std::cout <<"Init buflen with "<< fiBufLen << std::endl;
90  fiBuffer=new Int_t[fiBufLen];
92  ScanGo4Folder(folder,0,filter);
93 }
94 
95 
97 {
98  delete [] fiBuffer;
99 }
100 
101 void TGo4MbsHist::PrepareHeader(TH1* source, const char* path, s_his_head* target)
102 {
103  if (source == 0 || target == 0)
104  return;
105  // std::cout <<"MMMMMMMM Preparing header for histogram "<< source->GetName() << std::endl;
106  s_his_head *dest = target; // use local pointer to avoid changes by snprintf
107  dest->l_bins_1 = source->GetNbinsX();
108  dest->l_bins_2 = source->GetNbinsY();
109  // std::cout <<" \tMMMMMMMM Prepare header - bins1="<< dest->l_bins_1 << std::endl;
110  // std::cout <<"\tMMMMMMMM Prepare header - bins2="<< dest->l_bins_2 << std::endl;
111  // display of path enabled again to test Origin problems JA
112  if (path)
113  snprintf(dest->c_name, 64, "%s%s", path, source->GetName());
114  else
115  snprintf(dest->c_name, 64, "%s", source->GetName());
116  snprintf(dest->c_lettering_1, 64, "%s", source->GetXaxis()->GetTitle());
117  snprintf(dest->c_lettering_2, 64, "%s", source->GetYaxis()->GetTitle());
118  snprintf(dest->c_lettering_res, 64, "%s", source->GetYaxis()->GetTitle());
119  dest->r_limits_low = source->GetXaxis()->GetXmin();
120  dest->r_limits_up = source->GetXaxis()->GetXmax();
121  dest->r_limits_low_2 = source->GetYaxis()->GetXmin();
122  dest->r_limits_up_2 = source->GetYaxis()->GetXmax();
123  // std::cout <<" \tMMMMMMMM Prepare header - 1low="<< dest->r_limits_low << std::endl;
124  // std::cout <<"\tMMMMMMMM Prepare header - 1up ="<< dest->r_limits_up << std::endl;
125  // std::cout <<" \tMMMMMMMM Prepare header - 2low="<< dest->r_limits_low_2 << std::endl;
126  // std::cout <<"\tMMMMMMMM Prepare header - 2up ="<< dest->r_limits_up_2 << std::endl;
127 
128  if (source->InheritsFrom(TH1D::Class()) || source->InheritsFrom(TH1F::Class()) ||
129  source->InheritsFrom(TH2D::Class()) || source->InheritsFrom(TH2F::Class())) {
130  // std::cout <<" \tMMMMMMMM Prepare header has float histo" << std::endl;
131  strcpy(dest->c_dtype, "r");
132  } else {
133  // std::cout <<" \tMMMMMMMM Prepare header has int histo" << std::endl;
134  strcpy(dest->c_dtype, "i");
135  }
136  TTimeStamp now;
137  snprintf(dest->c_data_time_cre, 28, "%s", now.AsString("l")); // creation time
138  snprintf(dest->c_clear_date, 28, "%s", now.AsString("l")); // clear time, dummy here
139 }
140 
141 void TGo4MbsHist::SetValue(char *address, Stat_t value)
142 {
143  if (!strcmp(fxHistoHead.c_dtype, "r")) {
144  Float_t *faddress = (Float_t *)address;
145  *faddress = (Float_t)value;
146  } else {
147  Int_t *iaddress = (Int_t *)address;
148  *iaddress = (Int_t)value;
149  }
150 }
151 
152 void TGo4MbsHist::ScanGo4Folder(TFolder* folder, const char* superfolders, const char* filter)
153 {
154  // scan folder for histogram status objects
155 // if(filter)
156 // std::cout <<"ScanGo4Folder with filter "<<filter << std::endl;
157 // else
158 // std::cout <<"ScanGo4Folder with no filter "<< std::endl;
159 //
160 
161  if(folder==0)
162  return;
163 
164  TIter iter(folder->GetListOfFolders());
165  TObject *entry = 0;
166  while ((entry = iter()) != 0) {
167  char pathbuffer[TGo4ThreadManager::fguTEXTLENGTH];
168  Int_t num = 0;
169  if (superfolders)
170  num = snprintf(pathbuffer, TGo4ThreadManager::fguTEXTLENGTH, "%s/", superfolders);
171  else
172  // num=snprintf(pathbuffer,TGo4ThreadManager::fguTEXTLENGTH,"");
173  strcpy(pathbuffer, "");
174  char *cursor = pathbuffer + num;
175  Int_t edge = TGo4ThreadManager::fguTEXTLENGTH - num;
176  if (entry->InheritsFrom(TFolder::Class())) {
177  // found subfolder, process it recursively
178  const char *foldname = entry->GetName();
179  // filter out folders without histograms or graphs:
180  if (!strcmp(foldname, TGo4AnalysisObjectManager::GetDYNFOLDER())) {
181 
182  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetCONDFOLDER())) {
183 
184  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetPARAFOLDER())) {
185 
186  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetTREEFOLDER())) {
187 
188  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetPICTFOLDER())) {
189 
190  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetCANVFOLDER())) {
191 
192  } else if (!strcmp(foldname, TGo4AnalysisObjectManager::GetANALYSISFOLDER())) {
193 
194  } else {
195  // std::cout <<"##### parsing folder "<< foldname << std::endl;
196  snprintf(cursor, edge, "%s", foldname);
197  TFolder *subobj = dynamic_cast<TFolder *>(entry);
198  ScanGo4Folder(subobj, pathbuffer, filter);
199  }
200  } else if (entry->InheritsFrom(TH1::Class()) || entry->InheritsFrom(TGraph::Class())) {
201  // first check if filter is ok:
202  Bool_t ismatching = kFALSE;
203  const char *entryname = entry->GetName();
204  TString entrystring = entryname;
205  TRegexp reg(filter, kTRUE);
206  if (filter == 0)
207  ismatching = kTRUE; // no filter set, take all
208  else if (!strcmp(filter, "*"))
209  ismatching = kTRUE; // take all in this folder
210  // else if (strstr(filter,entryname))
211  // ismatching=kTRUE; // expression just contained in name
212  else if (entrystring.Index(reg, 0) != kNPOS)
213  ismatching = kTRUE; // root regular expression class
214  else
215  ismatching = kFALSE;
216 
217  if (ismatching) {
218  // std::cout <<"found matching:" << entryname << std::endl;
219  TH1 *hist = dynamic_cast<TH1 *>(entry);
220  if (hist == 0) {
221  TGraph *graf = dynamic_cast<TGraph *>(entry);
222  if (graf && graf->GetN() > 0) {
223  hist = graf->GetHistogram();
224  }
225  if (hist == 0)
226  continue;
227  } // if(hist==0)
228  PrepareHeader(hist, pathbuffer, fxCursor);
229  fxCursor++;
230  fiHisNum++;
231  // std::cout <<"MMMMMMMM found histogram "<< entry->GetName()<<" cr="<<(Int_t) fxCursor<< std::endl;
232  if ((char *)(fxCursor) > (char *)(fiBuffer) + fiBufLen * sizeof(Int_t) - sizeof(s_his_head)) {
233  // std::cout <<"MMMMMMM Realloc buffer cursor "<< (Int_t) fxCursor << std::endl;
234  Int_t oldbuflen = fiBufLen;
235  fiBufLen += fgiLISTLEN;
236  Int_t *otherbuf = new Int_t[fiBufLen];
237  memcpy(otherbuf, fiBuffer, oldbuflen * sizeof(Int_t));
238  delete[] fiBuffer;
239  fiBuffer = otherbuf;
241  for (Int_t n = 0; n < fiHisNum; ++n)
242  fxCursor++; // set cursor in new buffer
243  // std::cout <<"MMMMMMM Copied buffer, cursor set "<< std::endl;
244  // std::cout <<" hisnum="<< (Int_t) fiHisNum<< std::endl;
245  // std::cout <<" newcr="<< (Int_t) fxCursor<< std::endl;
246  // std::cout <<" buffer="<< (Int_t) fiBuffer<< std::endl;
247  } else {
248  }
249  } // if(ismatching)
250  }
251  } // while
252 }
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)
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:96
REAL4 r_limits_low
Definition: s_his_head.h:27
REAL4 r_limits_up_2
Definition: s_his_head.h:36
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
void ScanGo4Folder(TFolder *fold, const char *superfolders=0, const char *filter=0)
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