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  auto file_list = run->GetRunIndexList();
118  for(auto& rf : file_list)
119  {
120  auto scalist = (KVNameValueList*)runinfos_file.Get(Form("run%s", rf.as_string().Data()));
121  if(!scalist) scalist = (KVNameValueList*)runinfos_file.Get(Form("run_%06d", run->GetNumber()*index_multiplier));
122  if (scalist) {
123  int npar = scalist->GetNpar();
124  for (int i = 0; i < npar; i += 2) {
125  TString parname = scalist->GetParameter(i)->GetName();
126  parname.Remove(parname.Length()-3, 3);
127  run->GetRunFile(rf).SetScaler64(parname, scalist->GetValue64bit(parname));
128  }
129  }
130  }
131  }
132 }
133 
134 
135 
155 
157 {
158  // Fill the Runs table using the informations in file runinfos.root
159  // (which can be generated using KVRunListCreator).
160  //
161  // If there are no run infos available (perhaps because no data yet exists for the dataset),
162  // this method throws an exception and the database will have a dummy list of runs
163  // numbered from 1 to 100
164  //
165  // Any runfiles which are bad i.e. not to be considered for further analysis should
166  // be written in a file bad_runfiles.dat with the given format (TEnv):
167  // - comment lines begin with '#'
168  // - BadFiles.First: first runfile of each run in list is bad
169  // - BadFiles.All: all runfiles for each run in list are bad
170  // - BadFiles.Singles: individual runfiles given as run.index are bad
171  //~~~
172  //BadFiles.First: 17-26 30 35-42 44 52-54 57-63 65-73 76 83-111 123-141
173  //BadFiles.All: 16 27-29 43 46 51 55 56 64 74 75 110 112-122 138
174  //BadFiles.Singles: 26.101 86.8 108.21 109.46 111.31 137.9
175  //~~~
176 
177  TString runinfos = KVDataSet::GetFullPathToDataSetFile(fDataSet, "runinfos.root");
178 
179  if (runinfos == "")
180  throw std::runtime_error("run infos file not found");
181 
182  int run_num{-1}, runfile_index{-1};
183 
184  Info("FillRunsTable", "Reading run infos from %s", runinfos.Data());
185  TFile runinfos_file(runinfos);
186  TIter it(runinfos_file.GetListOfKeys());
187  TKey* run_key;
188  KVList garbage;
189  run_index_t run_index;
190  while ((run_key = (TKey*)it())) {
191  if (TString(run_key->GetClassName()) == "KVNameValueList") {
192  // make sure we only use the highest cycle number of each key
193  if (run_key->GetCycle() == runinfos_file.GetKey(run_key->GetName())->GetCycle()) {
194  KVNameValueList* run = (KVNameValueList*)run_key->ReadObj();
195  garbage.Add(run);
196  if (with_index_multiplier) {
197  run_num = run->GetIntValue("Run") / index_multiplier;
198  runfile_index = run->GetIntValue("Run") % index_multiplier;
199  if (!runfile_index) run_index = run_index_t{run_num, std::nullopt};
200  else run_index = run_index_t{run_num, runfile_index};
201  }
202  else if(HasRawFilesWithIndex())
203  {
204  run_num = run->GetIntValue("Run");
205  KVDBRun* dbrun = GetDBRun(run_num);
206  if (!dbrun) {
207  dbrun = new KVDBRun;
208  dbrun->SetNumber(run_num);
209  AddRun(dbrun);
210  }
211  KVNumberList index_list(run->GetStringValue("IndexList"));
212  for(auto index : index_list)
213  {
214  run_index = index ? run_index_t{run_num, index} : run_index_t{run_num, std::nullopt};
215  auto runfile = new KVDBRunFile("", run_index);
216  runfile->SetStartDate(run->GetStringValue(Form("Start.%d",index)));
217  runfile->SetEndDate(run->GetStringValue(Form("End.%d",index)));
218  if (run->HasValue64bit(Form("Size.%d",index)))
219  runfile->SetSize(run->GetValue64bit(Form("Size.%d",index)) / 1024. / 1024.);
220  else
221  runfile->SetSize(run->GetIntValue(Form("Size.%d",index)) / 1024. / 1024.);
222 
223  if (run->HasValue64bit(Form("Events.%d",index))) {
224  runfile->SetEvents(run->GetValue64bit(Form("Events.%d",index)));
225  }
226  else
227  runfile->SetEvents(run->GetIntValue(Form("Events.%d",index)));
228  dbrun->AddRunFile(runfile);
229  }
230  continue;
231  }
232  else {
233  run_num = run->GetIntValue("Run");
234  run_index = run_index_t{run_num, std::nullopt};
235  }
236  KVDBRun* dbrun = GetDBRun(run_num);
237  if (!dbrun) {
238  dbrun = new KVDBRun;
239  dbrun->SetNumber(run_num);
240  AddRun(dbrun);
241  }
242  auto runfile = new KVDBRunFile("", run_index);
243  runfile->SetStartDate(run->GetStringValue("Start"));
244  runfile->SetEndDate(run->GetStringValue("End"));
245  if (run->HasValue64bit("Size"))
246  runfile->SetSize(run->GetValue64bit("Size") / 1024. / 1024.);
247  else
248  runfile->SetSize(run->GetIntValue("Size") / 1024. / 1024.);
249 
250  if (run->HasValue64bit("Events")) {
251  runfile->SetEvents(run->GetValue64bit("Events"));
252  }
253  else
254  runfile->SetEvents(run->GetIntValue("Events"));
255  dbrun->AddRunFile(runfile);
256  }
257  }
258  }
259  TString badinfos = KVDataSet::GetFullPathToDataSetFile(fDataSet, "bad_runfiles.dat");
260  if (!badinfos.IsNull())
261  {
262  Info("FillRunsTable", "Reading bad runfile infos from %s", badinfos.Data());
263  TEnv badfiles;
264  badfiles.ReadFile(badinfos,kEnvLocal);
265  KVNumberList all(badfiles.GetValue("BadFiles.All",""));
266  all.Begin();
267  while(!all.End())
268  {
269  auto br = all.Next();
270  auto dbrun = GetDBRun(br);
271  if(!dbrun) {
272  Error("FillRunsTable","%s:BadFiles.All contains run number %d which is not in %s",
273  badinfos.Data(), br, runinfos.Data());
274  throw std::runtime_error(Form("inconsistency between %s:BadFiles.All and %s",
275  badinfos.Data(), runinfos.Data()));
276  }
277  dbrun->SetBadAllRunFiles();
278  }
279  KVNumberList first(badfiles.GetValue("BadFiles.First",""));
280  first.Begin();
281  while(!first.End())
282  {
283  auto br = first.Next();
284  auto dbrun = GetDBRun(br);
285  if(!dbrun) {
286  Error("FillRunsTable","%s:BadFiles.First contains run number %d which is not in %s",
287  badinfos.Data(), br, runinfos.Data());
288  throw std::runtime_error(Form("inconsistency between %s:BadFiles.First and %s",
289  badinfos.Data(), runinfos.Data()));
290  }
291  dbrun->GetFirstFile().SetBad();
292  }
293  run_index_list singles(badfiles.GetValue("BadFiles.Singles",""));
294  for(auto& ri : singles)
295  {
296  try {
297  GetDBRunFile(ri).SetBad();
298  } catch (std::exception& e) {
299  Error("FillRunsTable","%s:BadFiles.Singles contains run_index %s which is unknown",
300  badinfos.Data(), ri.as_string().Data());
301  throw;
302  }
303  }
304  }
305 }
306 
307 
308 //____________________________________________________________________________//
309 
310 
#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:38
void SetScaler64(const Char_t *name, ULong64_t val)
Set value for 64-bit scaler with the given name for this run.
Definition: KVDBRunFile.h:90
void SetBad(Bool_t is_bad=kTRUE)
Definition: KVDBRunFile.h:217
Description of an experimental run in database ,,.
Definition: KVDBRun.h:40
KVDBRunFile * GetRunFile(int index)
Definition: KVDBRun.h:48
void AddRunFile(KVDBRunFile *rf)
Definition: KVDBRun.h:80
void SetNumber(Int_t n) override
Definition: KVDBRun.h:160
run_index_list GetRunIndexList() const
Definition: KVDBRun.h:88
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.
Int_t GetIntValue(const Char_t *name) const
Bool_t HasValue64bit(const Char_t *name) const
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
Ssiz_t Length() const
const char * Data() const
Bool_t IsNull() const
TString & Remove(EStripType s, char c)
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:33
ClassImp(TPyArg)