KaliVeda
Toolkit for HIC analysis
KVDBRun.h
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 #ifndef KV_DB_RUN_H
10 #define KV_DB_RUN_H
11 
12 #include "KVDBRecord.h"
13 #include "KVDBSystem.h"
14 #include "KVTarget.h"
15 #include "KVString.h"
16 #include "TDatime.h"
17 #include "KVNameValueList.h"
18 #include "KVDBRunFile.h"
19 #include "run_index_list.h"
20 #include <RQ_OBJECT.h>
21 
41 class KVDBRun: public KVDBRecord {
42 
43  RQ_OBJECT("KVDBRun")
45 
47  std::map<int, int> fRunIndexMap;
48  mutable run_index_list fRunIndexList;
49 
51 
53  {
55  return static_cast<KVDBRunFile*>(fRunFiles[fRunIndexMap[run_index.index()]]);
56  }
57  const KVDBRunFile* get_run_file(const run_index_t& run_index) const
58  {
60  if (fRunIndexMap.find(run_index.index()) != fRunIndexMap.end())
61  return static_cast<const KVDBRunFile*>(fRunFiles[fRunIndexMap.at(run_index.index())]);
62  return nullptr;
63  }
64 public:
65 
66  KVDBRun();
67  KVDBRun(Int_t number, const Char_t* title);
68 
69  Bool_t HasRunFile(const run_index_t& run_index) const
70  {
71  return GetRunIndexList().Contains(run_index);
72  }
73  KVDBRunFile& GetRunFile(const run_index_t& run_index)
74  {
77  auto rf = get_run_file(run_index);
78  if (!rf)
79  throw std::runtime_error(Form("<KVDBRun::GetRunFile>: no file for run_index_t %s", run_index.as_string().Data()));
80  return *rf;
81  }
82  const KVDBRunFile& GetRunFile(const run_index_t& run_index) const
83  {
86  auto rf = get_run_file(run_index);
87  if (!rf)
88  throw std::runtime_error(Form("<KVDBRun::GetRunFile>: no file for run_index_t %s", run_index.as_string().Data()));
89  return *rf;
90  }
92  {
94  fRunIndexList.Add(rf->GetRunIndex());
95  fRunFiles.Add(rf);
96  }
98  {
99  return fRunFiles.GetEntries();
100  }
101  const run_index_list& GetRunIndexList() const
102  {
104  if (!fRunIndexList.GetEntries()) {
105  TIter it(&fRunFiles);
106  KVDBRunFile* rf;
107  while ((rf = (KVDBRunFile*)it()))
108  fRunIndexList.Add(rf->GetRunIndex());
109  }
110  return fRunIndexList;
111  }
113  {
114  return GetNRunFiles() > 1;
115  }
117  {
118  return GetRunFile(GetRunIndexList().First());
119  }
120  const KVDBRunFile& GetFirstFile() const
121  {
122  return GetRunFile(GetRunIndexList().Last());
123  }
124  std::optional<std::reference_wrapper<const KVDBRunFile>> GetFirstGoodFile() const
125  {
127  for (auto& ri : GetRunIndexList()) {
128  auto& rf = GetRunFile(ri);
129  if (!rf.IsBad()) return rf;
130  }
131  return {};
132  }
134  {
135  return GetRunFile(GetRunIndexList().Last());
136  }
137  const KVDBRunFile& GetLastFile() const
138  {
139  return GetRunFile(GetRunIndexList().Last());
140  }
141  std::optional<std::reference_wrapper<const KVDBRunFile>> GetLastGoodFile() const
142  {
144  for (auto it = std::rbegin(GetRunIndexList()); it != std::rend(GetRunIndexList()); ++it) {
145  auto& rf = GetRunFile(*it);
146  if (!rf.IsBad()) return rf;
147  }
148  return {};
149  }
151  {
154  TIter next(&fRunFiles);
155  KVDBRunFile* rf;
156  while ((rf = (KVDBRunFile*)next()))
157  rf->SetBad();
158  }
160  {
162  Int_t not_bad(0);
163  TIter next(&fRunFiles);
164  KVDBRunFile* rf;
165  while ((rf = (KVDBRunFile*)next()))
166  not_bad += !rf->IsBad();
167  return not_bad;
168  }
169 
170  void Modified() // *SIGNAL*
171  {
173  if (!fBlockSignals) Emit("Modified()");
174  }
175  void BlockSignals(Bool_t yes = kTRUE)
176  {
179  fBlockSignals = yes;
180  }
181 
182  Bool_t Has(const Char_t* param, Bool_t check_whitespace = kTRUE) const
183  {
186  if (check_whitespace && fParameters.HasStringParameter(param)) {
187  return !(fParameters.GetTStringValue(param).IsWhitespace());
188  }
190  }
191 
192  void SetNumber(Int_t n) override
193  {
195  Modified();
196  }
198  {
202  ULong64_t tot = 0;
203  TIter it(&fRunFiles);
204  while (KVDBRunFile* dbr = (KVDBRunFile*)it()) {
205  if (!dbr->IsBad()) tot += dbr->GetEvents();
206  }
207  return tot;
208  }
209  const Char_t* GetStartDate() const
210  {
212  return GetFirstFile().GetStartDate();
213  }
214  const Char_t* GetEndDate() const
215  {
217  return GetLastFile().GetEndDate();
218  }
220  {
224  Double_t tot = 0;
225  TIter it(&fRunFiles);
226  while (KVDBRunFile* dbr = (KVDBRunFile*)it()) {
227  if (!dbr->IsBad()) tot += dbr->GetSize();
228  }
229  return tot;
230  }
232  {
236  Double_t tot = 0;
237  TIter it(&fRunFiles);
238  while (KVDBRunFile* dbr = (KVDBRunFile*)it()) {
239  if (!dbr->IsBad()) tot += dbr->GetTime();
240  }
241  return tot;
242  }
243 
244  void SetTrigger(Int_t trig)
245  {
246  SetScaler("Trigger multiplicity", trig);
247  }
248 
250  {
251  return GetScaler("Trigger multiplicity");
252  }
253  const Char_t* GetTriggerString() const
254  {
255  if (GetTrigger() > 0) return Form("M>=%d", GetTrigger());
256  else return Form("xxx");
257  }
258  KVDBSystem* GetSystem() const;
259  const Char_t* GetSystemName() const
260  {
261  return (GetSystem() ? GetSystem()->GetName() : "");
262  }
263  const Char_t* GetComments() const
264  {
265  return GetString("Comments");
266  }
269  {
270  return (GetSystem() ? GetSystem()->GetTarget() : 0);
271  }
272  void SetComments(const KVString& comments)
273  {
274  Set("Comments", comments);
275  }
276 
277  virtual void SetSystem(KVDBSystem* system);
278  virtual void UnsetSystem();
279 
280  void Print(Option_t* option = "") const override;
281 
282  virtual void WriteRunListLine(std::ostream&, Char_t delim = '|') const;
283  virtual void ReadRunListLine(const KVString&);
284  virtual void WriteRunListHeader(std::ostream&, Char_t delim = '|') const;
285 
286  virtual void SetScaler(const Char_t* name, Int_t val)
287  {
289  KV__SET_INT(name, val)
290  Modified();
291  }
292  virtual Int_t GetScaler(const Char_t* name) const
293  {
295  KV__GET_INT(name)
296  }
297  virtual void SetScaler64(const Char_t* name, ULong64_t val)
298  {
300  KV__SET_ULONG(name, val)
301  Modified();
302  }
303  virtual ULong64_t GetScaler64(const Char_t* name) const
304  {
306  KV__GET_ULONG(name)
307  }
308  void Set(const Char_t* param, Double_t val)
309  {
311  KV__SET_DBL(param, val)
312  Modified();
313  }
314  Double_t Get(const Char_t* param) const
315  {
317  KV__GET_DBL(param)
318  }
319  void Set(const Char_t* param, const KVString& val)
320  {
322  KV__SET_STR(param, val)
323  Modified();
324  }
325  const Char_t* GetString(const Char_t* param) const
326  {
328  KV__GET_STR(param)
329  }
330 
331  ClassDefOverride(KVDBRun, 11) //Base class for an experiment run
332 };
333 #endif
int Int_t
#define RQ_OBJECT(sender_class)
bool Bool_t
char Char_t
double Double_t
const char Option_t
#define ClassDefOverride(name, id)
char name[80]
char * Form(const char *fmt,...)
Record folder for the database.
Definition: KVDBRecord.h:43
virtual void SetNumber(Int_t n)
Definition: KVDBRecord.h:77
A single raw data file associated with an experimental run ,,.
Definition: KVDBRunFile.h:39
const Char_t * GetStartDate() const
Definition: KVDBRunFile.h:170
run_index_t GetRunIndex() const
Definition: KVDBRunFile.h:73
void SetBad(Bool_t is_bad=kTRUE)
Definition: KVDBRunFile.h:230
const Char_t * GetEndDate() const
Definition: KVDBRunFile.h:178
Bool_t IsBad() const
Definition: KVDBRunFile.h:235
Description of an experimental run in database ,,.
Definition: KVDBRun.h:41
void Print(Option_t *option="") const override
Definition: KVDBRun.cpp:61
virtual void SetSystem(KVDBSystem *system)
Set system for run. Any previous system is unassociated (run will be removed from system's list)
Definition: KVDBRun.cpp:253
virtual void SetScaler64(const Char_t *name, ULong64_t val)
Definition: KVDBRun.h:297
void SetBadAllRunFiles()
Definition: KVDBRun.h:150
KVNameValueList fParameters
cannot write run_index_list objects to disk!
Definition: KVDBRun.h:50
ULong64_t GetEvents() const
Definition: KVDBRun.h:197
virtual ULong64_t GetScaler64(const Char_t *name) const
Definition: KVDBRun.h:303
const Char_t * GetSystemName() const
Definition: KVDBRun.h:259
KVTarget * GetTarget() const
Return target used for this run (actually target of KVDBSystem associated to run)
Definition: KVDBRun.h:268
std::optional< std::reference_wrapper< const KVDBRunFile > > GetFirstGoodFile() const
Definition: KVDBRun.h:124
std::optional< std::reference_wrapper< const KVDBRunFile > > GetLastGoodFile() const
Definition: KVDBRun.h:141
void AddRunFile(KVDBRunFile *rf)
Definition: KVDBRun.h:91
const KVDBRunFile & GetRunFile(const run_index_t &run_index) const
Definition: KVDBRun.h:82
void SetComments(const KVString &comments)
Definition: KVDBRun.h:272
KVDBSystem * GetSystem() const
Definition: KVDBRun.cpp:239
virtual void WriteRunListLine(std::ostream &, Char_t delim='|') const
Definition: KVDBRun.cpp:93
const Char_t * GetEndDate() const
Definition: KVDBRun.h:214
TObjArray fRunFiles
Definition: KVDBRun.h:46
void SetNumber(Int_t n) override
Definition: KVDBRun.h:192
Bool_t Has(const Char_t *param, Bool_t check_whitespace=kTRUE) const
Definition: KVDBRun.h:182
Bool_t fBlockSignals
Definition: KVDBRun.h:44
void Set(const Char_t *param, Double_t val)
Definition: KVDBRun.h:308
const run_index_list & GetRunIndexList() const
Definition: KVDBRun.h:101
Bool_t IsMultiFile() const
Definition: KVDBRun.h:112
Bool_t HasRunFile(const run_index_t &run_index) const
Definition: KVDBRun.h:69
Int_t GetNGoodRunFiles() const
Definition: KVDBRun.h:159
Double_t Get(const Char_t *param) const
Definition: KVDBRun.h:314
const KVDBRunFile & GetFirstFile() const
Definition: KVDBRun.h:120
const Char_t * GetTriggerString() const
Definition: KVDBRun.h:253
Int_t GetTrigger() const
Definition: KVDBRun.h:249
Double_t GetSize() const
Definition: KVDBRun.h:219
void BlockSignals(Bool_t yes=kTRUE)
Definition: KVDBRun.h:175
std::map< int, int > fRunIndexMap
Definition: KVDBRun.h:47
const Char_t * GetStartDate() const
Definition: KVDBRun.h:209
void SetTrigger(Int_t trig)
Definition: KVDBRun.h:244
const KVDBRunFile * get_run_file(const run_index_t &run_index) const
Definition: KVDBRun.h:57
KVDBRunFile & GetLastFile()
Definition: KVDBRun.h:133
virtual void ReadRunListLine(const KVString &)
Definition: KVDBRun.cpp:140
const KVDBRunFile & GetLastFile() const
Definition: KVDBRun.h:137
Int_t GetNRunFiles() const
Definition: KVDBRun.h:97
void Modified()
Definition: KVDBRun.h:170
void Set(const Char_t *param, const KVString &val)
Definition: KVDBRun.h:319
KVDBRunFile & GetFirstFile()
Definition: KVDBRun.h:116
virtual void UnsetSystem()
Definition: KVDBRun.cpp:222
KVDBRunFile * get_run_file(const run_index_t &run_index)
Definition: KVDBRun.h:52
virtual Int_t GetScaler(const Char_t *name) const
Definition: KVDBRun.h:292
const Char_t * GetString(const Char_t *param) const
Definition: KVDBRun.h:325
KVDBRun()
default ctor
Definition: KVDBRun.cpp:33
const Char_t * GetComments() const
Definition: KVDBRun.h:263
run_index_list fRunIndexList
Definition: KVDBRun.h:48
Double_t GetTime() const
Definition: KVDBRun.h:231
virtual void SetScaler(const Char_t *name, Int_t val)
Definition: KVDBRun.h:286
KVDBRunFile & GetRunFile(const run_index_t &run_index)
Definition: KVDBRun.h:73
virtual void WriteRunListHeader(std::ostream &, Char_t delim='|') const
Write the version flag.
Definition: KVDBRun.cpp:208
Database class used to store information on different colliding systems studied during an experiment....
Definition: KVDBSystem.h:52
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Bool_t HasStringParameter(const Char_t *name) const
Bool_t HasIntParameter(const Char_t *name) const
Bool_t HasDoubleParameter(const Char_t *name) const
TString GetTStringValue(const Char_t *name) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
Calculation/correction of energy losses of particles through an experimental target.
Definition: KVTarget.h:128
const char * GetName() const override
Int_t GetEntries() const override
void Add(TObject *obj) override
const char * Data() const
Bool_t IsWhitespace() const
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:31
TString as_string() const
Definition: run_index.h:95
int index(int no_index=-1) const
Definition: run_index.h:55
unsigned long long ULong64_t
const Int_t n