KaliVeda
Toolkit for HIC analysis
KVINDRARunSheetReader.cpp
1 /*******************************************************************************
2 $Id: KVINDRARunSheetReader.cpp,v 1.13 2008/12/08 14:07:37 franklan Exp $
3 $Revision: 1.13 $
4 $Date: 2008/12/08 14:07:37 $
5 $Author: franklan $
6 *******************************************************************************/
7 
8 #include "KVINDRARunSheetReader.h"
9 #include "KVINDRADBRun.h"
10 #include "KVExpDB.h"
11 #include "Riostream.h"
12 #include "KVDatime.h"
13 #include "TSystem.h"
14 #include "TObjString.h"
15 #include "TROOT.h"
16 
17 using namespace std;
18 
20 
21 
22 
27 {
28  //Default ctor. If make_tree = kTRUE, a TTree will be created and filled with
29  //data from runsheets.
30  SetMakeTree(make_tree);
31  fTree = 0;
32  init_vars();
33  fTIME_START = 0;
34 }
35 
36 
37 
40 
42 {
43  //Set values of all runsheet/TTree variables to 0
44  len_run = size = data_rate = acq_rate = trait_rate = ctrl_rate =
45  rempli_dlt_pc = temps_mort = 0.;
46  run_num = buf_sav = eve_sav = eve_lus = buf_ctrl = eve_ctrl =
47  rempli_dlt_blocs = 0;
48  for (int i = 0; i < 100; i++) fScalers[i] = 0;
49 }
50 
51 
52 
56 
58 {
59  //Uses directory path and file format to create full path to runsheet
60  //file for run number 'run'.
61 
63  filename.Form(fFileFormat.Data(), run);
64  char* dirname =
65  gSystem->ConcatFileName(fRunSheetDir.Data(), filename.Data());
66  fFilePath = dirname;
67  delete[]dirname;
68  return fFilePath.Data();
69 }
70 
71 
72 
74 
76 {
77  if (fTree) delete fTree;
78  fTree =
79  new TTree("RunInfoScalerTree",
80  "Data from INDRA runsheets. Created by KVINDRARunSheetReader.");
81  fTree->SetDirectory(gROOT);
82  fTree->Branch("run", &run_num, "run/I");
83  fTree->Branch("start", &istart, "start/I");
84  fTree->Branch("end", &iend, "end/I");
85  fTree->Branch("buf_sav", &buf_sav, "buf_sav/I");
86  fTree->Branch("eve_sav", &eve_sav, "eve_sav/I");
87  fTree->Branch("eve_lus", &eve_lus, "eve_lus/I");
88  fTree->Branch("buf_ctrl", &buf_ctrl, "buf_ctrl/I");
89  fTree->Branch("eve_ctrl", &eve_ctrl, "eve_ctrl/I");
90  fTree->Branch("rempli_dlt_blocs", &rempli_dlt_blocs,
91  "rempli_dlt_blocs/I");
92  fTree->Branch("len_run", &len_run, "len_run/D");
93  fTree->Branch("size", &size, "size/D");
94  fTree->Branch("data_rate", &data_rate, "data_rate/D");
95  fTree->Branch("acq_rate", &acq_rate, "acq_rate/D");
96  fTree->Branch("trait_rate", &trait_rate, "trait_rate/D");
97  fTree->Branch("ctrl_rate", &ctrl_rate, "ctrl_rate/D");
98  fTree->Branch("rempli_dlt_pc", &rempli_dlt_pc, "rempli_dlt_pc/D");
99  fTree->Branch("temps_mort", &temps_mort, "temps_mort/D");
100 }
101 
102 
103 
109 
111 {
112  //Read runsheet corresponding to run number 'run'
113  //Store the informations we read in the runsheet in the run database.
114  //Create TTree if required and if not already done
115  //Return kTRUE if all goes well.
116 
117  cout <<
118  "<KVINDRARunSheetReader::ReadRunSheet> : Reading runsheet for new run, Run "
119  << run << endl;
120  KVINDRADBRun* indra_db_run = (KVINDRADBRun*)gExpDB->GetDBRun(run);
121  if (!indra_db_run) {
122  //create new run and add it to the database
123  indra_db_run = new KVINDRADBRun(run);
124  gExpDB->AddRun(indra_db_run);
125  }
126 
127  //open runsheet file
128  ifstream read_file(GetRunSheetFileName(run));
129  if (!read_file.good()) {
130  cout << "Error opening file : " << fFilePath.Data() << endl;
131  return kFALSE;
132  }
133  //reset runsheet/TTree variables
134  init_vars();
135 
136  KVString line, dumstr;
137 
138  line.ReadLine(read_file);
139 
140  //read all infos up to list of scalers (which begins with the line "*** Impression des Echelles :"
141  while (read_file.good() && !line.Contains("Echelles")) {
142 
143  if (line.Contains("Run numero"))
144  run_num = (Int_t) GetNumberField(line);
145  if (line.Contains("Debut")) {
146  start_run.SetGanacqDate(GetDateField(line));
147  istart = start_run.Convert();
148  if (!fTIME_START) {
149  //we put the "time origin" at the start of the first run we read
150  fTIME_START = start_run.Convert();
151  }
152  indra_db_run->SetStartDate(start_run.AsGanacqDateString());
153  }
154  if (line.Contains("Fin")) {
155  endrun.SetGanacqDate(GetDateField(line));
156  iend = endrun.Convert();
157  indra_db_run->SetEndDate(endrun.AsGanacqDateString());
158  }
159  if (line.Contains("Length of run")) {
160  sscanf(line.Data(),
161  "Length of run: %lf seconds, Size : %lf MB ( %lf MB/sec)",
162  &len_run, &size, &data_rate);
163  indra_db_run->SetTime(len_run / 60.);
164  indra_db_run->SetSize(size);
165  }
166  if (line.Contains("Stat_eve")) {
167  dumstr = GetStringField(line);
168  stat_eve = GetStringField(dumstr, " ", 0);
169  }
170  if (line.Contains("Buffers sauves")) {
171  dumstr = GetStringField(line);
172  buf_sav = (Int_t) GetNumberField(dumstr, " ", 0);
173  eve_sav = (Int_t) GetNumberField(line, ":", 2);
174  indra_db_run->SetScaler("Buffers", buf_sav);
175  indra_db_run->SetEvents(eve_sav);
176  }
177  if (line.Contains("Evenements lus"))
178  eve_lus = (Int_t) GetNumberField(line);
179  if (line.Contains("Buffers ctrl")) {
180  dumstr = GetStringField(line);
181  buf_ctrl = (Int_t) GetNumberField(dumstr, " ", 0);
182  eve_ctrl = (Int_t) GetNumberField(line, ":", 2);
183  }
184  if (line.Contains("Taux d'acquisition")) {
185  dumstr = GetStringField(line);
186  acq_rate = GetNumberField(dumstr, " ", 0);
187  }
188  if (line.Contains("Taux de traitement")) {
189  dumstr = GetStringField(line);
190  trait_rate = GetNumberField(dumstr, " ", 0);
191  }
192  if (line.Contains("Taux de controle")) {
193  dumstr = GetStringField(line);
194  ctrl_rate = GetNumberField(dumstr, " ", 0);
195  }
196  if (line.Contains("Remplissage")) {
197  dumstr = GetStringField(line);
198  rempli_dlt_pc = GetNumberField(dumstr, " ", 0);
199  rempli_dlt_blocs = (Int_t) GetNumberField(dumstr, " ", 3);
200  }
201 
202  //read next line
203  line.ReadLine(read_file);
204  }
205  if (line.Contains("Echelles")) {
206  //found beginning of scalers
207  line.ReadLine(read_file);
208  //find first scaler line
209  while (read_file.good() && !line.Contains(":")) line.ReadLine(read_file);
210  //now read all scalers
211  while (read_file.good() && line.Contains(":")) {
212  dumstr = GetStringField(line, ":", 0);
213  dumstr.Remove(TString::kBoth, ' ');
214  Int_t scaler = (Int_t)GetNumberField(line);
215  //cout << "SCALER: \"" << dumstr.Data() << "\" = " << scaler << endl;
216  indra_db_run->SetScaler(dumstr.Data(), scaler);
217  line.ReadLine(read_file);
218  if (fMakeTree) {
219  dumstr.ReplaceAll(" ", "_");
220  dumstr.ReplaceAll("-", "_");
221  TBranch* br_sca = fTree->FindBranch(dumstr.Data());
222  Int_t index;
223  //do we need to add a branch for this scaler ?
224  if (!br_sca) {
225  index = fTree->GetListOfBranches()->GetEntries();
226  br_sca = fTree->Branch(dumstr.Data(), &fScalers[index], Form("%s/I", dumstr.Data()));
227  //cout << "br_sca = fTree->Branch( \"" <<dumstr.Data()<<"\", &fScalers["<<index<<"], "<<Form("%s/I", dumstr.Data())<<");"<<endl;
228  }
229  else {
230  index = fTree->GetListOfBranches()->IndexOf(br_sca);
231  }
232  //fill tableau with value
233  fScalers[index] = scaler;
234  //cout << "fScalers["<<index<<"] = "<<scaler<<";"<<endl;
235  }
236  }
237  }
238  //in case events sauves = buffers sauves = 0, we use events lus & buffers ctrl
239  if (eve_sav == 0)
240  indra_db_run->SetEvents(eve_lus);
241  if (buf_sav == 0) {
242  indra_db_run->SetScaler("Buffers", buf_ctrl);
243  indra_db_run->SetSize(buf_ctrl * 16384. / 1024. / 1024.);
244  }
245 
246  temps_mort = 100. * indra_db_run->GetTempsMort();
247  indra_db_run->SetTMpercent(temps_mort);
248 
249  istart -= fTIME_START;
250  iend -= fTIME_START;
251 
252  if (fMakeTree)
253  fTree->Fill();
254 
255  return kTRUE;
256 }
257 
258 
259 
260 
264 
266  const Char_t* delim,
267  int index)
268 {
269  //Split line according to delimiter.
270  //Return the index-th element (index = 0, 1, 2, ...) as a Double_t
271  TObjArray* toks = line.Tokenize(delim);
272  KVString val = ((TObjString*) toks->At(index))->GetString();
273  delete toks;
274  return val.Atof();
275 }
276 
277 
278 
279 
283 
285  const Char_t* delim,
286  int index)
287 {
288  //Split line according to delimiter.
289  //Return the index-th element (index = 0, 1, 2, ...) as a string
290  TObjArray* toks = line.Tokenize(delim);
291  TString val = ((TObjString*) toks->At(index))->GetString();
292  delete toks;
293  return val;
294 }
295 
296 
297 
298 
302 
304  const Char_t* delim)
305 {
306  //Special case of GetStringField for date-strings with ':' used in between hours, minutes, seconds.
307  //If ':' is also the delimiter of the string, we need to stick the time back together.
308  TObjArray* toks = line.Tokenize(delim);
309 
310  TString date =
311  ((TObjString*) toks->At(1))->GetString().Strip(TString::kLeading,
312  ' ');
313  if (!strcmp(delim, ":")) {
314  for (int i = 2; i < toks->GetEntries(); i++) {
315  date += ":";
316  date += ((TObjString*) toks->At(i))->GetString();
317  }
318  }
319  delete toks;
320  date = date.Strip(TString::kTrailing, ' ');
321  return date;
322 }
323 
324 
325 
326 
331 
333 {
334  //Read all run sheets in the directory fRunSheetDir from run number 'first' to 'last'
335  //(default values are 1 and 9999).
336  //Returns the number of run sheets actually read.
337 
338  Int_t n_lus = 0; //number of run sheets read
339 
340  if (fMakeTree) CreateTree();
341 
342  for (int run = first; run <= last; run++) {
343 
344  //Check run sheet file exists - if not, skip run
345  if (gSystem->AccessPathName(GetRunSheetFileName(run)))
346  continue;
347 
348  n_lus += (Int_t) ReadRunSheet(run);
349  }
350 
351  if (fMakeTree) fTree->Print();
352  return n_lus;
353 }
354 
355 
int Int_t
size_t size(const MatrixT &matrix)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
#define gROOT
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
void SetEvents(ULong64_t evt_number)
Definition: KVDBRun.h:170
void SetTime(Double_t time)
Definition: KVDBRun.h:174
void SetSize(Double_t s)
Definition: KVDBRun.h:178
void SetStartDate(const KVString &date)
Definition: KVDBRun.h:186
void SetEndDate(const KVString &d)
Definition: KVDBRun.h:194
virtual void SetScaler(const Char_t *name, Int_t val)
Set value for the scaler with the given name for this run.
Definition: KVDBRun.h:209
void AddRun(KVDBRun *r)
Definition: KVExpDB.h:67
KVDBRun * GetDBRun(Int_t number) const
Definition: KVExpDB.h:76
Database entry for each run of an INDRA experiment.
Definition: KVINDRADBRun.h:30
Double_t GetTempsMort() const
void SetTMpercent(Float_t tmp)
Definition: KVINDRADBRun.h:55
Read the run sheets produced by the standard INDRA acquisition control program.
TString GetDateField(TString &, const Char_t *delim=":")
void init_vars()
Set values of all runsheet/TTree variables to 0.
Double_t GetNumberField(TString &, const Char_t *delim=":", int index=1)
const Char_t * GetRunSheetFileName(Int_t run)
Int_t ReadAllRunSheets(Int_t first=1, Int_t last=9999)
TString GetStringField(TString &, const Char_t *delim=":", int index=1)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
virtual TBranch * FindBranch(const char *name)
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Double_t Atof() const
const char * Data() const
TString & Remove(EStripType s, char c)
TString & ReplaceAll(const char *s1, const char *s2)
virtual char * ConcatFileName(const char *dir, const char *name)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
TLine * line
ClassImp(TPyArg)