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 (...) {
78  Info("Build", "No informations on dataset runs available");
79  Info("Build", "Dummy database runs numbered from 1 to 100 will be created");
80  for (int i = 1; i <= 100; ++i) {
81  AddRun(new KVDBRun(i, "Dummy database run"));
82  }
83  }
84 
85  ReadComments();
88 
90  gMultiDetArray->MakeCalibrationTables(this);
91 }
92 
93 
94 
98 
100 {
101  // Look for file scalers.root and read scalers from it
102  // scalers are assumed to be stored as 64-bit parameters in the list
103 
104  TString runinfos = KVDataSet::GetFullPathToDataSetFile(fDataSet, "scalers.root");
105  if (runinfos == "") return;
106 
107  Info("ReadScalerInfos", "Reading scaler infos from %s", runinfos.Data());
108  TFile runinfos_file(runinfos);
109  TIter it_run(GetRuns());
110  KVDBRun* run;
111  while ((run = (KVDBRun*)it_run())) {
112  KVNameValueList* scalist = (KVNameValueList*)runinfos_file.Get(Form("run_%06d", run->GetNumber()));
113  if (scalist) {
114  int npar = scalist->GetNpar();
115  for (int i = 0; i < npar; i += 2) {
116  TString parname = scalist->GetParameter(i)->GetName();
117  parname.Remove(parname.Index("_hi"), 3);
118  run->SetScaler64(parname, scalist->GetValue64bit(parname));
119  }
120  }
121  }
122 }
123 
124 
125 
133 
135 {
136  // Fill the Runs table using the informations in file runinfos.root
137  // (which can be generated using KVRunListCreator).
138  //
139  // If there are no run infos available (perhaps because no data yet exists for the dataset),
140  // this method throws an exception and the database will have a dummy list of runs
141  // numbered from 1 to 100
142 
143  TString runinfos = KVDataSet::GetFullPathToDataSetFile(fDataSet, "runinfos.root");
144 
145  if (runinfos == "")
146  throw std::runtime_error("run infos file not found");
147 
148  Info("FillRunsTable", "Reading run infos from %s", runinfos.Data());
149  TFile runinfos_file(runinfos);
150  TIter it(runinfos_file.GetListOfKeys());
151  TKey* run_key;
152  KVList garbage;
153  while ((run_key = (TKey*)it())) {
154  if (TString(run_key->GetClassName()) == "KVNameValueList") {
155  // make sure we only use the highest cycle number of each key
156  if (run_key->GetCycle() == runinfos_file.GetKey(run_key->GetName())->GetCycle()) {
157  KVNameValueList* run = (KVNameValueList*)run_key->ReadObj();
158  garbage.Add(run);
159  KVDBRun* dbrun = new KVDBRun;
160  dbrun->SetNumber(run->GetIntValue("Run"));
161  dbrun->SetStartDate(run->GetStringValue("Start"));
162  dbrun->SetEndDate(run->GetStringValue("End"));
163  if (run->HasValue64bit("Size"))
164  dbrun->SetSize(run->GetValue64bit("Size") / 1024. / 1024.);
165  else
166  dbrun->SetSize(run->GetIntValue("Size") / 1024. / 1024.);
167 
168  if (run->HasValue64bit("Events")) {
169  dbrun->SetEvents(run->GetValue64bit("Events"));
170  }
171  else
172  dbrun->SetEvents(run->GetIntValue("Events"));
173  AddRun(dbrun);
174  }
175  }
176  }
177 }
178 
179 
180 //____________________________________________________________________________//
181 
182 
char Char_t
char name[80]
char * Form(const char *fmt,...)
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:73
Description of an experimental run in database ,,.
Definition: KVDBRun.h:36
void SetEvents(ULong64_t evt_number)
Definition: KVDBRun.h:170
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:220
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
void SetNumber(Int_t n)
Definition: KVDBRun.h:93
TString GetFullPathToDataSetFile(const Char_t *filename)
Definition: KVDataSet.cpp:1898
Base class to describe database of an experiment ,,.
Definition: KVExpDB.h:20
virtual void ReadComments()
Definition: KVExpDB.cpp:706
virtual void ReadSystemList()
Definition: KVExpDB.cpp:249
void AddRun(KVDBRun *r)
Definition: KVExpDB.h:67
virtual KVSeqCollection * GetRuns() const
Definition: KVExpDB.h:72
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()
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
virtual void Add(TObject *obj)
T * Get(const char *namecycle)
TKey * GetKey(const char *name, Short_t cycle=9999) const override
TList * GetListOfKeys() const override
virtual const char * GetClassName() const
Short_t GetCycle() const
virtual TObject * ReadObj()
const char * GetName() const override
virtual void Info(const char *method, const char *msgfmt,...) const
const char * Data() const
TString & Remove(EStripType s, char c)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
ClassImp(TPyArg)