KaliVeda
Toolkit for HIC analysis
KVExpSetUpDB.cpp
1 //Created by KVClassFactory on Fri Jul 20 15:49:04 2018
2 //Author: eindra
3 
4 #include "KVExpSetUpDB.h"
5 #include "KVDataSet.h"
6 #include "KVMultiDetArray.h"
7 
8 #include <TKey.h>
9 
11 
12 
13 
17  : KVExpDB()
18 {
19  // Default constructor
20 }
21 
22 
23 
24 
27 
29  : KVExpDB(name)
30 {
31  // Constructor inherited from KVExpDB
32 }
33 
34 
35 
36 
39 
40 KVExpSetUpDB::KVExpSetUpDB(const Char_t* name, const Char_t* title)
41  : KVExpDB(name, title)
42 {
43  // Constructor inherited from KVExpDB
44 }
45 
46 
47 
48 
51 
53 {
54  // Destructor
55 }
56 
57 
58 
65 
67 {
68  // Build the database.
69  // Runs & Systems tables are handled by us, calibrations are handled by each multidetector
70  //
71  // If no run infos are available (perhaps no data yet available for dataset), we make a dummy
72  // database with runs numbered from 1 to 100.
73 
74  try {
75  FillRunsTable();
76  }
77  catch (std::runtime_error& rte) {
78 
79  // an exception may be thrown if a 'bad' runfile is not found,
80  // which indicates an inconsistency in bad_runfiles.dat
81  if(TString(rte.what())!="run infos file not found") throw;
82 
83  Info("Build", "No informations on dataset runs available");
84  Info("Build", "Dummy database runs numbered from 1 to 100 will be created");
85  for (int i = 1; i <= 100; ++i) {
86  AddRun(new KVDBRun(i, "Dummy database run"));
87  }
88  }
89 
90  ReadComments();
93 
95  gMultiDetArray->MakeCalibrationTables(this);
96 }
97 
98 
99 
103 
105 {
106  // Look for file scalers.root and read scalers from it
107  // scalers are assumed to be stored as 64-bit parameters in the list
108 
109  TString runinfos = KVDataSet::GetFullPathToDataSetFile(fDataSet, "scalers.root");
110  if (runinfos == "") return;
111 
112  Info("ReadScalerInfos", "Reading scaler infos from %s", runinfos.Data());
113  TFile runinfos_file(runinfos);
114  TIter it_run(GetRuns());
115  KVDBRun* run;
116  while ((run = (KVDBRun*)it_run())) {
117  KVNameValueList* scalist = (KVNameValueList*)runinfos_file.Get(Form("run_%06d", run->GetNumber()*index_multiplier));
118  if (scalist) {
119  int npar = scalist->GetNpar();
120  for (int i = 0; i < npar; i += 2) {
121  TString parname = scalist->GetParameter(i)->GetName();
122  parname.Remove(parname.Index("_hi"), 3);
123  run->SetScaler64(parname, scalist->GetValue64bit(parname));
124  }
125  }
126  }
127 }
128 
129 
130 
150 
152 {
153  // Fill the Runs table using the informations in file runinfos.root
154  // (which can be generated using KVRunListCreator).
155  //
156  // If there are no run infos available (perhaps because no data yet exists for the dataset),
157  // this method throws an exception and the database will have a dummy list of runs
158  // numbered from 1 to 100
159  //
160  // Any runfiles which are bad i.e. not to be considered for further analysis should
161  // be written in a file bad_runfiles.dat with the given format (TEnv):
162  // - comment lines begin with '#'
163  // - BadFiles.First: first runfile of each run in list is bad
164  // - BadFiles.All: all runfiles for each run in list are bad
165  // - BadFiles.Singles: individual runfiles given as run.index are bad
166  //~~~
167  //BadFiles.First: 17-26 30 35-42 44 52-54 57-63 65-73 76 83-111 123-141
168  //BadFiles.All: 16 27-29 43 46 51 55 56 64 74 75 110 112-122 138
169  //BadFiles.Singles: 26.101 86.8 108.21 109.46 111.31 137.9
170  //~~~
171 
172  TString runinfos = KVDataSet::GetFullPathToDataSetFile(fDataSet, "runinfos.root");
173 
174  if (runinfos == "")
175  throw std::runtime_error("run infos file not found");
176 
177  int run_num{-1}, runfile_index{-1};
178 
179  Info("FillRunsTable", "Reading run infos from %s", runinfos.Data());
180  TFile runinfos_file(runinfos);
181  TIter it(runinfos_file.GetListOfKeys());
182  TKey* run_key;
183  KVList garbage;
184  run_index_t run_index;
185  while ((run_key = (TKey*)it())) {
186  if (TString(run_key->GetClassName()) == "KVNameValueList") {
187  // make sure we only use the highest cycle number of each key
188  if (run_key->GetCycle() == runinfos_file.GetKey(run_key->GetName())->GetCycle()) {
189  KVNameValueList* run = (KVNameValueList*)run_key->ReadObj();
190  garbage.Add(run);
191  if (with_index_multiplier) {
192  run_num = run->GetIntValue("Run") / index_multiplier;
193  runfile_index = run->GetIntValue("Run") % index_multiplier;
194  if (!runfile_index) run_index = run_index_t{run_num, std::nullopt};
195  else run_index = run_index_t{run_num, runfile_index};
196  }
197  else if(HasRawFilesWithIndex())
198  {
199  run_num = run->GetIntValue("Run");
200  KVDBRun* dbrun = GetDBRun(run_num);
201  if (!dbrun) {
202  dbrun = new KVDBRun;
203  dbrun->SetNumber(run_num);
204  AddRun(dbrun);
205  }
206  KVNumberList index_list(run->GetStringValue("IndexList"));
207  for(auto index : index_list)
208  {
209  run_index = index ? run_index_t{run_num, index} : run_index_t{run_num, std::nullopt};
210  auto runfile = new KVDBRunFile("", run_index);
211  runfile->SetStartDate(run->GetStringValue(Form("Start.%d",index)));
212  runfile->SetEndDate(run->GetStringValue(Form("End.%d",index)));
213  if (run->HasValue64bit(Form("Size.%d",index)))
214  runfile->SetSize(run->GetValue64bit(Form("Size.%d",index)) / 1024. / 1024.);
215  else
216  runfile->SetSize(run->GetIntValue(Form("Size.%d",index)) / 1024. / 1024.);
217 
218  if (run->HasValue64bit(Form("Events.%d",index))) {
219  runfile->SetEvents(run->GetValue64bit(Form("Events.%d",index)));
220  }
221  else
222  runfile->SetEvents(run->GetIntValue(Form("Events.%d",index)));
223  dbrun->AddRunFile(runfile);
224  }
225  continue;
226  }
227  else {
228  run_num = run->GetIntValue("Run");
229  run_index = run_index_t{run_num, std::nullopt};
230  }
231  KVDBRun* dbrun = GetDBRun(run_num);
232  if (!dbrun) {
233  dbrun = new KVDBRun;
234  dbrun->SetNumber(run_num);
235  AddRun(dbrun);
236  }
237  auto runfile = new KVDBRunFile("", run_index);
238  runfile->SetStartDate(run->GetStringValue("Start"));
239  runfile->SetEndDate(run->GetStringValue("End"));
240  if (run->HasValue64bit("Size"))
241  runfile->SetSize(run->GetValue64bit("Size") / 1024. / 1024.);
242  else
243  runfile->SetSize(run->GetIntValue("Size") / 1024. / 1024.);
244 
245  if (run->HasValue64bit("Events")) {
246  runfile->SetEvents(run->GetValue64bit("Events"));
247  }
248  else
249  runfile->SetEvents(run->GetIntValue("Events"));
250  dbrun->AddRunFile(runfile);
251  }
252  }
253  }
254  TString badinfos = KVDataSet::GetFullPathToDataSetFile(fDataSet, "bad_runfiles.dat");
255  if (!badinfos.IsNull())
256  {
257  Info("FillRunsTable", "Reading bad runfile infos from %s", badinfos.Data());
258  TEnv badfiles;
259  badfiles.ReadFile(badinfos,kEnvLocal);
260  KVNumberList all(badfiles.GetValue("BadFiles.All",""));
261  all.Begin();
262  while(!all.End())
263  {
264  auto br = all.Next();
265  auto dbrun = GetDBRun(br);
266  if(!dbrun) {
267  Error("FillRunsTable","%s:BadFiles.All contains run number %d which is not in %s",
268  badinfos.Data(), br, runinfos.Data());
269  throw std::runtime_error(Form("inconsistency between %s:BadFiles.All and %s",
270  badinfos.Data(), runinfos.Data()));
271  }
272  dbrun->SetBadAllRunFiles();
273  }
274  KVNumberList first(badfiles.GetValue("BadFiles.First",""));
275  first.Begin();
276  while(!first.End())
277  {
278  auto br = first.Next();
279  auto dbrun = GetDBRun(br);
280  if(!dbrun) {
281  Error("FillRunsTable","%s:BadFiles.First contains run number %d which is not in %s",
282  badinfos.Data(), br, runinfos.Data());
283  throw std::runtime_error(Form("inconsistency between %s:BadFiles.First and %s",
284  badinfos.Data(), runinfos.Data()));
285  }
286  dbrun->GetFirstFile().SetBad();
287  }
288  run_index_list singles(badfiles.GetValue("BadFiles.Singles",""));
289  for(auto& ri : singles)
290  {
291  try {
292  GetDBRunFile(ri).SetBad();
293  } catch (std::exception& e) {
294  Error("FillRunsTable","%s:BadFiles.Singles contains run_index %s which is unknown",
295  badinfos.Data(), ri.as_string().Data());
296  throw;
297  }
298  }
299  }
300 }
301 
302 
303 //____________________________________________________________________________//
304 
305 
#define e(i)
char Char_t
kEnvLocal
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
char name[80]
char * Form(const char *fmt,...)
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:73
A single raw data file associated with an experimental run ,,.
Definition: KVDBRunFile.h:36
void SetBad(Bool_t is_bad=kTRUE)
Declare this runfile to be 'bad', i.e. not to be used for analysis.
Definition: KVDBRunFile.h:196
Description of an experimental run in database ,,.
Definition: KVDBRun.h:40
virtual void SetScaler64(const Char_t *name, ULong64_t val)
Set value for 64-bit scaler with the given name for this run.
Definition: KVDBRun.h:256
void AddRunFile(KVDBRunFile *rf)
Definition: KVDBRun.h:80
void SetNumber(Int_t n) override
Definition: KVDBRun.h:150
TString GetFullPathToDataSetFile(const Char_t *filename)
Definition: KVDataSet.cpp:1926
Base class to describe database of an experiment ,,.
Definition: KVExpDB.h:20
virtual void ReadComments()
Definition: KVExpDB.cpp:705
virtual void ReadSystemList()
Definition: KVExpDB.cpp:248
void AddRun(KVDBRun *r)
Definition: KVExpDB.h:80
KVDBRun * GetDBRun(Int_t number) const
Definition: KVExpDB.h:89
virtual KVSeqCollection * GetRuns() const
Definition: KVExpDB.h:85
bool with_index_multiplier
Definition: KVExpDB.h:31
const KVDBRunFile & GetDBRunFile(const run_index_t &r) const
Definition: KVExpDB.h:93
int index_multiplier
Definition: KVExpDB.h:30
Bool_t HasRawFilesWithIndex() const
Definition: KVExpDB.h:178
TString fDataSet
the name of the dataset to which this database is associated
Definition: KVExpDB.h:23
Calibration database for experiments using coupled detector arrays.
Definition: KVExpSetUpDB.h:17
void FillRunsTable()
KVExpSetUpDB()
Default constructor.
virtual ~KVExpSetUpDB()
Destructor.
void ReadScalerInfos()
void Build() override
Extended TList class which owns its objects by default.
Definition: KVList.h:28
virtual void MakeCalibrationTables(KVExpDB *)
static KVMultiDetArray * MakeMultiDetector(const Char_t *dataset_name, Int_t run=-1, TString classname="KVMultiDetArray")
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Int_t GetIntValue(const Char_t *name) const
Bool_t HasValue64bit(const Char_t *name) const
Int_t GetNpar() const
return the number of stored parameters
ULong64_t GetValue64bit(const Char_t *name) const
const Char_t * GetStringValue(const Char_t *name) const
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
Bool_t End(void) const
Definition: KVNumberList.h:199
void Begin(void) const
Int_t Next(void) const
void Add(TObject *obj) override
T * Get(const char *namecycle)
TKey * GetKey(const char *name, Short_t cycle=9999) const override
TList * GetListOfKeys() const override
virtual const char * GetValue(const char *name, const char *dflt) const
virtual Int_t ReadFile(const char *fname, EEnvLevel level)
virtual const char * GetClassName() const
Short_t GetCycle() const
virtual TObject * ReadObj()
const char * GetName() const override
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
const char * Data() const
Bool_t IsNull() const
TString & Remove(EStripType s, char c)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:33
ClassImp(TPyArg)