KaliVeda
Toolkit for HIC analysis
KVExpDB.cpp
1 //Created by KVClassFactory on Tue Jul 12 11:43:52 2016
2 //Author: bonnet,,,
3 
4 #include "KVExpDB.h"
5 #include "KVDBSystem.h"
6 #include "KVNumberList.h"
7 #include "TSystem.h"
8 #include <KVFileReader.h>
9 #include <KVNucleus.h>
10 #include <iostream>
11 #include "KVUnownedList.h"
12 #include "KVEnv.h"
13 using namespace std;
14 
15 KVExpDB* gExpDB = nullptr;
16 
18 
19 
20 
23 void KVExpDB::init()
24 {
25  //default initialisations
26 
27  fRuns = AddTable("Runs", "List of available runs");
28  fRuns->SetDefaultFormat("Run %d"); // default format for run names
29  fSystems = AddTable("Systems", "List of available systems");
30  index_multiplier = KVBase::GetDataSetEnv(fDataSet, "DataSet.RunFileIndexMultiplier.raw", 1);
31  with_index_multiplier = index_multiplier != 1;
32  raw_files_have_index = KVBase::GetDataSetEnv<KVString>(fDataSet, "DataSet.RunFileName.raw").Contains("%I");
33 }
34 
35 
36 
90 
92 {
93  // Read infos on beams, targets, and reactions in files
94  //~~~
95  //Beams.dat
96  //Targets.dat
97  //Reactions.dat
98  //~~~
99  //(default filenames defined by config variables `EXPDB.Beams`, `EXPDB.Targets`, `EXPDB.Reactions`)
100  //and set up the corresponding KVTarget and KVDBSystem objects, adding to the database
101  //table `Systems`.
102  //
103  //###Beams
104  //Format of file is
105  //~~~
106  //Beams: B1 B2 [...]
107  //
108  //B1.Ion: 129Xe [nature of accelerated ion]
109  //B1.Energy: 49.9976 [energy in MeV/A]
110  //
111  //B2.Ion: [...]
112  //~~~
113  //
114  //###Targets
115  //Format of file is
116  //~~~
117  //Targets: T1 T2 [...]
118  //
119  //T1.Material: 197Au
120  //T1.AreaDensity: 0.66 [in mg/cm2]
121  //[T1.Angle: 45] [angle to beam in degrees, if != 0]
122  //[T1.Name: Au-660] [optional name]
123  //
124  //T2.Layers: 2
125  //T2.Layer.1.Material: 12C
126  //T2.Layer.1.AreaDensity: 0.02 [in mg/cm2]
127  //T2.Layer.2.Material: 238U
128  //T2.Layer.2.AreaDensity: 0.4 [in mg/cm2]
129  //T2.TargetNucleus: 238U [used for reaction kinematics]
130  //~~~
131  //
132  //###Reactions
133  //Format of file is
134  //~~~
135  //Reactions: R1 R2 [...]
136  //
137  //R1.Name: Alpha source
138  //R1.Runlist: 1-12
139  //
140  //R2.Beam: B1 [beam defined in Beams.dat]
141  //R2.Target: T1 [target defined in Targets.dat]
142  //R2.Runlist: 13-25
143  //R2.UseBeamEnergyIn: MeV [optional; default is to use MeV/A]
144  //~~~
145 
146  TString beam_fp, target_fp, reaction_fp;
147  if (!(FindCalibFile("Beams", beam_fp) && FindCalibFile("Targets", target_fp) && FindCalibFile("Reactions", reaction_fp))) {
148  Error("read_beams_targets_reactions",
149  "One or more files not found:\nFull path to %s = %s\nFull path to %s = %s\nFull path to %s = %s",
150  GetCalibFileName("Beams").Data(), beam_fp.Data(),
151  GetCalibFileName("Targets").Data(), target_fp.Data(),
152  GetCalibFileName("Reactions").Data(), reaction_fp.Data());
153  return;
154  }
155 
156  Info("read_beams_targets_reactions", "Reading files:\nFull path to %s = %s\nFull path to %s = %s\nFull path to %s = %s",
157  GetCalibFileName("Beams").Data(), beam_fp.Data(),
158  GetCalibFileName("Targets").Data(), target_fp.Data(),
159  GetCalibFileName("Reactions").Data(), reaction_fp.Data());
160 
161  KVEnv beams_v(beam_fp), targets_v(target_fp), reactions_v(reaction_fp);
162 
163  auto make_target = [&](const KVString & react) -> KVTarget * {
164  if (!reactions_v.HasValue(react, "Target"))
165  return nullptr;
166 
167  auto targ = reactions_v.GetValueOf(react, "Target").Default<KVString>();
168 
169  auto nlayers = targets_v.GetValueOf(targ, "Layers").Default(1);
170 
171  auto T = new KVTarget;
172  if (nlayers > 1)
173  {
174  for (int ilay = 1; ilay <= nlayers; ++ilay) {
175  T->AddLayer(targets_v.GetValueOf(targ, "Layer", ilay, "Material").Default<KVString>(),
176  targets_v.GetValueOf(targ, "Layer", ilay, "AreaDensity").Default(0.));
177  }
178  }
179  else if (targets_v.HasValue(targ, "Material"))
180  {
181  T->AddLayer(targets_v.GetValueOf(targ, "Material").Default<KVString>(),
182  targets_v.GetValueOf(targ, "AreaDensity").Default(0.));
183  }
184 
185  T->SetAngleToBeam(targets_v.GetValueOf(targ, "Angle").Default(0.));
186  if (targets_v.HasValue(targ, "Name"))
187  T->SetName(targets_v.GetValueOf(targ, "Name").Default<KVString>());
188 
189  return T;
190  };
191  auto get_beam_properties = [&](const KVString & react) {
192  auto beam = reactions_v.GetValueOf(react, "Beam").Default<KVString>();
193  return KVNucleus(beams_v.GetValueOf(beam, "Ion").Default<KVString>(),
194  beams_v.GetValueOf(beam, "Energy").Default(0.));
195  };
196  auto get_beam_units = [&](const KVString & react) {
197  return reactions_v.GetValueOf(react, "UseBeamEnergyIn").Default<KVString>("MeV/A");
198  };
199  auto get_target_properties = [&](const KVString & react) {
200  auto targ = reactions_v.GetValueOf(react, "Target").Default<KVString>();
201  if (targets_v.HasValue(targ, "TargetNucleus"))
202  return KVNucleus(targets_v.GetValueOf(targ, "TargetNucleus").Default<KVString>());
203  return KVNucleus(targets_v.GetValueOf(targ, "Material").Default<KVString>());
204  };
205  auto get_target_name = [&](const KVString & react) {
206  auto targ = reactions_v.GetValueOf(react, "Target").Default<KVString>();
207  return targets_v.GetValueOf(targ, "Name").Default<KVString>("");
208  };
209 
210  KVString reactions = reactions_v.GetValue("Reactions", "");
211  reactions.Begin(" ");
212  while (!reactions.End()) {
213  auto R = reactions.Next();
214 
215  KVDBSystem* sys = nullptr;
216 
217  if (!reactions_v.HasValue(R, "Beam") && !reactions_v.HasValue(R, "Target"))
218  sys = new KVDBSystem(reactions_v.GetValueOf(R, "Name").Default<KVString>());
219  else
220  sys = new KVDBSystem(get_beam_properties(R), get_target_properties(R), get_target_name(R), get_beam_units(R));
221 
222  // system with a defined target?
223  auto targ = make_target(R);
224  if (targ)
225  sys->SetTarget(targ);
226 
227  AddSystem(sys);
228 
229  sys->SetRuns(reactions_v.GetValueOf(R, "Runlist").Default<KVNumberList>(), index_multiplier);
230  }
231 }
232 
233 
234 
237 
239  : KVDataBase()
240 {
241  // Default constructor
242 }
243 
244 
245 
246 
249 
251  : KVDataBase(name), fDataSet(name)
252 {
253  // Constructor inherited from KVDataBase
254  init();
255 }
256 
257 
258 
259 
262 
263 KVExpDB::KVExpDB(const Char_t* name, const Char_t* title)
264  : KVDataBase(name, title), fDataSet(name)
265 {
266  // Constructor inherited from KVDataBase
267  init();
268 }
269 
270 
271 
272 
275 
277 {
278  // Destructor
279  if (gExpDB == this) gExpDB = nullptr;
280 }
281 
282 
283 
289 
291  UInt_t last_run)
292 {
293  //If the KVDBRecord 'rec' (i.e. set of calibration parameters, reaction system, etc.) is
294  //associated to, or valid for, a range of runs, we use this method in order to link the record
295  //and the runs. The list of associated runs will be kept with the record, and each of the runs
296  //will have a link to the record.
297 
298  std::map<int, int> one_shot; //make sure each run is only linked once
299  for (UInt_t ii = first_run; ii <= last_run; ii++) {
300  Int_t rr = ii;
301  if (rr > index_multiplier) rr /= index_multiplier;
302  if (!one_shot[rr]) LinkRecordToRun(rec, ii);
303  ++one_shot[rr];
304  }
305 }
306 
307 
313 
315 {
316  //If the KVDBRecord 'rec' (i.e. set of calibration parameters, reaction system, etc.) is
317  //associated to, or valid for, a range of runs, we use this method in order to link the record
318  //and the runs. The list of associated runs will be kept with the record, and each of the runs
319  //will have a link to the record.
320  nl.Begin();
321  std::map<int, int> one_shot; //make sure each run is only linked once
322  while (!nl.End()) {
323  Int_t rr = nl.Next();
324  if (rr > index_multiplier) rr /= index_multiplier;
325  if (!one_shot[rr]) LinkRecordToRun(rec, rr);
326  ++one_shot[rr];
327  }
328 }
329 
330 
331 
333 
335 {
336 
337  KVDBRecord* run = 0;
338  if ((run = fRuns->GetRecord(rnumber)))
339  rec->AddLink("Runs", run);
340 
341 }
342 
343 
344 
352 
354  UInt_t run_ranges[][2])
355 {
356  //Call LinkRecordToRunRange for a set of run ranges stored in the two-dimensional array
357  //in the following way:
358  // run_ranges[0][0] = first run of first run range
359  // run_ranges[0][1] = last run of first run range
360  // run_ranges[1][0] = first run of second run range etc. etc.
361  //rr_number is the number of run ranges in the array
362 
363  for (UInt_t i = 0; i < rr_number; i++) {
364  LinkRecordToRunRange(rec, run_ranges[i][0], run_ranges[i][1]);
365  }
366 }
367 
368 
369 
372 
374  UInt_t run_ranges[][2])
375 {
376  //Link the records contained in the list to the set of runs (see LinkRecordToRunRanges).
377 
378  if (!list) {
379  Error("LinkListToRunRanges",
380  "NULL pointer passed for parameter TList");
381  return;
382  }
383  if (list->GetSize() == 0) {
384  Error("LinkListToRunRanges(TList*,UInt_t,UInt_t*)",
385  "The list is empty");
386  return;
387  }
388  TIter next(list);
389  KVDBRecord* rec;
390  while ((rec = (KVDBRecord*) next())) {
391  LinkRecordToRunRanges(rec, rr_number, run_ranges);
392  }
393 }
394 
395 
398 
400 {
401  //Link the records contained in the list to the set of runs (see LinkRecordToRunRanges).
402 
403  if (!list) {
404  Error("LinkListToRunRange",
405  "NULL pointer passed for parameter TList");
406  return;
407  }
408  if (list->GetSize() == 0) {
409  Error("LinkListToRunRange(TList*,KVNumberList)",
410  "The list is empty");
411  return;
412  }
413  TIter next(list);
414  KVDBRecord* rec;
415  while ((rec = (KVDBRecord*) next())) {
417  }
418 }
419 
420 
421 
427 
429 {
430  // Set up all informations on the reactions studied during the experiment,
431  // store as KVDBSystem objects in the database table `Systems`.
432  //
433  // For information on necessary input files and formats, see read_beams_targets_reactions()
434 
435  TString fp;
436  if (FindCalibFile("Reactions", fp)) {
437  Info("ReadSystemList", "Reading reaction parameters...");
439  }
440  else { // old-style 'Systems.dat' file
441  //There are 2 formats for the description of systems:
442  //
443  //+129Xe + natSn 25 MeV/A '+' indicates beginning of system description
444  //129 54 119 50 0.1 25.0 A,Z of projectile and target, target thickness (mg/cm2), beam energy (MeV/A)
445  //Run Range : 614 636 runs associated with system
446  //Run Range : 638 647 runs associated with system
447  //
448  //This is sufficient in the simple case where the experiment has a single
449  //layer target oriented perpendicular to the beam. However, for more
450  //complicated targets we can specify as follows :
451  //
452  //+155Gd + 238U 36 MeV/A
453  //155 64 238 92 0.1 36.0
454  //Target : 3 0.0 target with 3 layers, angle 0 degrees
455  //C 0.02 1st layer : carbon, 20 g/cm2
456  //238U 0.1 2nd layer : uranium-238, 100 g/cm2
457  //C 0.023 3rd layer : carbon, 23 g/cm2
458  //Run Range : 770 804
459  //
460  //Lines beginning '#' are comments.
461  std::ifstream fin;
462  if (OpenCalibFile("Systems", fin)) {
463  Info("ReadSystemList()", "Reading Systems parameters ...");
464 
465  TString line;
466 
467  char next_char = fin.peek();
468  while (next_char != '+' && fin.good()) {
469  line.ReadLine(fin, kFALSE);
470  next_char = fin.peek();
471  }
472 
473  while (fin.good() && !fin.eof() && next_char == '+') {
474  KVDBSystem* sys = new KVDBSystem("NEW SYSTEM");
475  AddSystem(sys);
476  sys->Load(fin, index_multiplier);
477  next_char = fin.peek();
478  }
479  fin.close();
480  }
481  else {
482  Error("ReadSystemList()", "Could not open file %s",
483  GetCalibFileName("Systems").Data());
484  }
485  }
486  // if any runs are not associated with any system
487  // we create an 'unknown' system and associate it to all runs
488  KVDBSystem* sys = 0;
489  TIter nextRun(GetRuns());
490  KVDBRun* run;
491  while ((run = (KVDBRun*)nextRun())) {
492  if (!run->GetSystem()) {
493  if (!sys) {
494  sys = new KVDBSystem("[unknown]");
495  AddSystem(sys);
496  }
497  sys->AddRun(run);
498  }
499  }
500 
501  // rehash the record table now that all names are set
502  fSystems->Rehash();
503 }
504 
505 
506 
513 
515 {
516  //Write the 'Systems.dat' file for this database.
517  //The actual name of the file is given by the value of the environment variable
518  //[dataset_name].INDRADB.Systems (if it exists), otherwise the value of
519  //INDRADB.Systems is used. The file is written in the
520  //$KVROOT/[dataset_directory] directory.
521 
522  ofstream sysfile;
523  KVBase::SearchAndOpenKVFile(GetDBEnv("Systems"), sysfile, fDataSet.Data());
524  TIter next(GetSystems());
525  KVDBSystem* sys;
526  TDatime now;
527  sysfile << "# " << GetDBEnv("Systems") << " file written by "
528  << ClassName() << "::WriteSystemsFile on " << now.AsString() << endl;
529  cout << GetDBEnv("Systems") << " file written by "
530  << ClassName() << "::WriteSystemsFile on " << now.AsString() << endl;
531  while ((sys = (KVDBSystem*)next())) {
532  if (strcmp(sys->GetName(), "[unknown]")) { //do not write dummy 'unknown' system
533  sys->Save(sysfile);
534  sysfile << endl;
535  }
536  }
537  sysfile.close();
538 }
539 
540 
541 
546 
547 void KVExpDB::Save(const Char_t* what)
548 {
549  //Save (in the appropriate text file) the informations on:
550  // what = "Systems" : write Systems.dat file
551  // what = "Runlist" : write Runlist.csv
552  if (!strcmp(what, "Systems")) WriteSystemsFile();
553  else if (!strcmp(what, "Runlist")) WriteRunListFile();
554 }
555 
556 
557 
558 
566 
568 {
569  //Write a file containing a line describing each run in the database.
570  //The delimiter symbol used in each line is '|' by default.
571  //The first line of the file will be a header description, given by calling
572  //KVDBRun::WriteRunListHeader() for the first run in the database.
573  //Then we call KVDBRun::WriteRunListLine() for each run.
574  //These are virtual methods redefined by child classes of KVDBRun.
575 
576  ofstream rlistf;
577  KVBase::SearchAndOpenKVFile(GetDBEnv("Runlist"), rlistf, fDataSet.Data());
578  TDatime now;
579  rlistf << "# " << GetDBEnv("Runlist") << " file written by "
580  << ClassName() << "::WriteRunListFile on " << now.AsString() << endl;
581  cout << GetDBEnv("Runlist") << " file written by "
582  << ClassName() << "::WriteRunListFile on " << now.AsString() << endl;
583  if (GetRuns() && GetRuns()->GetEntries() > 0) {
584  TIter next_run(GetRuns());
585  //write header in file
586  ((KVDBRun*) GetRuns()->At(0))->WriteRunListHeader(rlistf, GetDBEnv("Runlist.Separator")[0]);
587  KVDBRun* run;
588  while ((run = (KVDBRun*) next_run())) {
589 
590  run->WriteRunListLine(rlistf, GetDBEnv("Runlist.Separator")[0]);
591 
592  }
593  }
594  else {
595  Warning("WriteRunListFile()", "run list is empty !!!");
596  }
597  rlistf.close();
598 }
599 
600 
601 
617 
618 Bool_t KVExpDB::OpenCalibFile(const Char_t* type, ifstream& fs) const
619 {
620  //Find and open calibration parameter file of given type. Return kTRUE if all OK.
621  //types are defined in $KVROOT/KVFiles/.kvrootrc by lines such as (use INDRA as example)
622  //
623  //# Default name for file describing systems for each dataset.
624  //INDRADB.Systems: Systems.dat
625  //
626  //A file with the given name will be looked for in the dataset calibration file
627  //directory given by GetDataSetDir()
628  //
629  //Filenames specific to a given dataset may also be defined:
630  //
631  //INDRA_camp5.INDRADB.Pedestals: Pedestals5.dat
632  //
633  //where 'INDRA_camp5' is the name of the dataset in question.
634 
636 }
637 
638 
639 
671 
672 Bool_t KVExpDB::FindCalibFile(const Char_t* type, TString& fullpath, const TString& array_name) const
673 {
674  //Find calibration parameter file of given type. Return kTRUE if all OK.
675  //In this case fullpath contains the full path to the file.
676  //
677  //Types are defined in $KVROOT/KVFiles/.kvrootrc by lines such as (use INDRA as example)
678  //
679  //~~~~
680  //# Default name for file describing systems for each dataset.
681  //INDRADB.Systems: Systems.dat
682  //~~~~
683  //
684  //A file with the given name will be looked for in the dataset calibration file
685  //directory given by GetDataSetDir()
686  //
687  //Filenames specific to a given dataset may also be defined:
688  //
689  //~~~~
690  //INDRA_camp5.INDRADB.Pedestals: Pedestals5.dat
691  //~~~~
692  //
693  //where 'INDRA_camp5' is the name of the dataset in question.
694  //
695  //If 'array_name' is given and no file is found with this filename,
696  //we try looking for a file called 'array_name.filename', i.e. if a filename
697  //
698  //~~~~
699  //INDRADB.Pressures: ChIoPressures.dat
700  //~~~~
701  //
702  //is defined, but no ChIoPressures.dat file exists for the dataset, if array_name="INDRA"
703  //then we look for a file called INDRA.ChIoPressures.dat
704 
705  auto cal_file_name = GetCalibFileName(type);
706  if (cal_file_name.IsNull()) return kFALSE;
707  if (KVBase::SearchKVFile(cal_file_name, fullpath, GetDataSetDir()))
708  return kTRUE;
709  if (!array_name.IsNull()) {
710  cal_file_name.Prepend(Form("%s.", array_name.Data()));
711  return KVBase::SearchKVFile(cal_file_name, fullpath, GetDataSetDir());
712  }
713  return kFALSE;
714 }
715 
716 
717 
718 
731 
733 {
734  // Print compact listing of runs in the number list like this:
735  //
736  // root [9] gIndraDB->PrintRuns("8100-8120")
737  // RUN SYSTEM TRIGGER EVENTS COMMENTS
738  // ------------------------------------------------------------------------------------------------------------------
739  // 8100 129Xe + 58Ni 8 MeV/A M>=2 968673
740  // 8101 129Xe + 58Ni 8 MeV/A M>=2 969166
741  // 8102 129Xe + 58Ni 8 MeV/A M>=2 960772
742  // 8103 129Xe + 58Ni 8 MeV/A M>=2 970029
743  // 8104 129Xe + 58Ni 8 MeV/A M>=2 502992 disjonction ht chassis 1
744  // 8105 129Xe + 58Ni 8 MeV/A M>=2 957015 intensite augmentee a 200 pA
745 
746  printf("RUN\tSYSTEM\t\t\t\tTRIGGER\t\tEVENTS\t\tCOMMENTS\n");
747  printf("------------------------------------------------------------------------------------------------------------------\n");
748  nl.Begin();
749  while (!nl.End()) {
750  KVDBRun* run = GetDBRun(nl.Next());
751  if (!run) continue;
752  printf("%4d\t%-30s\t%s\t\t%llu\t\t%s\n",
753  run->GetNumber(), (run->GetSystem() ? run->GetSystem()->GetName() : " "), run->GetTriggerString(),
754  run->GetEvents(), run->GetComments());
755  }
756 }
757 
758 
759 
761 
763 {
764  gExpDB = this;
765 }
766 
767 
768 
769 
782 
783 KVExpDB* KVExpDB::MakeDataBase(const Char_t* name, const Char_t* datasetdir, Bool_t minimal)
784 {
785  // Static function which will create and 'Build' the database object corresponding to 'name'
786  // defined as 'Plugin' classes for KVExpDB:
787  //
788  //~~~
789  // +Plugin.KVExpDB: [name] [class] [library] "class(const char*)"
790  //~~~
791  //
792  // The 'name' corresponds to the name of the dataset, it is the argument given to the
793  // constructor and stored in member variable fDataSet.
794  //
795  // \param[in] minimal if =true, only a minimal database with runs/systems infos will be built
796 
797  TPluginHandler* ph;
798  if (!(ph = KVBase::LoadPlugin("KVExpDB", name))) {
799  return 0;
800  }
801  //execute constructor/macro for database
802  auto mda = (KVExpDB*) ph->ExecPlugin(1, name);
803  mda->SetDataSetDir(datasetdir);
804 
805  mda->Build(minimal);
806 
807  return mda;
808 }
809 
810 
811 
815 
816 ULong64_t KVExpDB::GetTotalEvents(int first_run, int last_run) const
817 {
818  // Return total number of events in range [first_run,last_run]
819  // (if last_run=-1, go to last known run)
820 
821  ULong64_t total = 0;
822  TIter next(GetRuns());
823  KVDBRun* dbr;
824  while ((dbr = (KVDBRun*)next())) {
825  if (dbr->GetNumber() >= first_run) {
826  if ((last_run > 0 && dbr->GetNumber() <= last_run)
827  || last_run == -1) total += dbr->GetEvents();
828  }
829  }
830  return total;
831 }
832 
833 
834 
837 
839 {
840  // Return total number of events for given system
841 
842  if (!GetSystem(system)) {
843  Error("GetTotalEvents", "No system with name : %s", system.Data());
844  return 0;
845  }
846  ULong64_t total = 0;
847  for (auto dbr : GetSystem(system)->GetRuns()) {
848  total += dynamic_cast<KVDBRun*>(dbr)->GetEvents();
849  }
850  return total;
851 }
852 
853 
854 
861 
863 {
864  // \param[in] glob_runfile global runfile number of a runfile (given by KVDBRunFile::GetGlobalRunFileNumber())
865  // \returns run/index information of runfile with given global runfile number
866  //
867  // \note only _good_ runfiles (with KVDBRunFile::IsBad() == kFALSE) have a global runfile number,
868  // the _bad_ runfiles are not included in the list
869 
870  if (fMapGlobRunFileNumberToRunIndex.empty()) {
871  // have to regenerate map on first call after reading database in from file.
872  // this is because no Streamer can be generated for run_index_t and so the
873  // structure cannot be written to disk
874  TIter it_run(GetRuns());
875  KVDBRun* r;
876  while ((r = (KVDBRun*)it_run())) {
877  for (auto& ri : r->GetRunIndexList()) {
878  auto& rf = GetDBRunFile(ri);
879  if (!rf.IsBad())
880  fMapGlobRunFileNumberToRunIndex[rf.GetGlobalRunFileNumber()] = ri;
881  }
882  }
883  }
884  return fMapGlobRunFileNumberToRunIndex[glob_runfile];
885 }
886 
887 
888 
917 
919 {
920  // \param[in] rlist string containing run numbers, runfile identifiers (run+index), and ranges of both
921  // \returns run_index_list containing the sequence of all _good_ runfiles corresponding to the input string
922  //
923  // \note any _bad_ runfiles (with KVDBRunFile::IsBad() == kTRUE) are excluded.
924  //
925  // The string can contain individual run numbers, runfile (runindex) identifiers,
926  // either in sequences (separated by spaces and/or commas), or as part of a range,
927  // i.e. two values separated by '-'.
928  //
929  // A number without a '.index' index suffix is interpreted as a run number,
930  // and corresponds to all runfiles of the given run. A number _with_ '.index'
931  // suffix is interpreted as meaning the given individual runfile of the corresponding
932  // run.
933  //
934  // A number with a '.0' (zero) index is interpreted as the first runfile of the
935  // given run (note that normally such a runfile is represented by the run number alone,
936  // without a suffix).
937  //
938  // Examples:
939  //
940  //~~~
941  //"40-43" => all good runfiles from runs 40, 41, 42 & 43
942  //
943  //"40-43.0" => all good runfiles from runs 40, 41 & 42, plus the first runfile of run 43
944  //
945  //"40.3-42.7" => all good runfiles from 40.3 to 42.7
946  //~~~
947 
948  run_index_list rilist;
949 
950  KVString _the_list(rlist);
951  _the_list.Begin(" ,");
952  while (!_the_list.End()) {
953  KVString item = _the_list.Next(kTRUE);
954  if (item.GetNValues("-") == 2) {
955  // this is a range
956  item.Begin("-");
957  std::vector<int> limits(2);
958  for (int i = 0; i < 2; ++i) {
959  auto titbit = item.Next(kTRUE);
960  if (titbit.Contains(".")) {
961  // this is a runindex identifier
962  limits[i] = GetDBRunFile(titbit).GetGlobalRunFileNumber();
963  }
964  else {
965  // this is a run number
966  // if at beginning of range, we start from first good file
967  // if at end of range, we include everything up to last good file
968  run_index_t ri(titbit);
969  if (i == 0)
970  limits[i] = GetDBRun(ri.run())->GetFirstGoodFile().value().get().GetGlobalRunFileNumber();
971  else limits[i] = GetDBRun(ri.run())->GetLastGoodFile().value().get().GetGlobalRunFileNumber();
972  }
973  }
974  for (int ri = limits[0]; ri <= limits[1]; ++ri)
976  }
977  else {
978  // individual run number (no index) or runfile identifier
979  if (item.Contains(".")) {
980  // this is a runindex identifier
981  rilist.Add(run_index_t{item});
982  }
983  else {
984  // run number: add all files from first to last (good) file of run
985  auto run_num = run_index_t{item}.run();
986  for (int i = GetDBRun(run_num)->GetFirstGoodFile().value().get().GetGlobalRunFileNumber();
987  i <= GetDBRun(run_num)->GetLastGoodFile().value().get().GetGlobalRunFileNumber(); ++i)
989  }
990  }
991  }
992  return rilist;
993 }
994 
995 
996 
997 
1013 
1015 {
1016  //Will look for
1017  //~~~
1018  //gEnv->GetValue("name_of_dataset.fDBType.type")
1019  //~~~
1020  //then
1021  //~~~
1022  //gEnv->GetValue("fDBType.type")
1023  //~~~
1024  //if no dataset-specific value is found,
1025  //then
1026  //~~~
1027  //gEnv->GetValue("EXPDB.type")
1028  //~~~
1029  //if no database-specific value is found
1030 
1031  if (fDataSet == "") return "";
1032  auto p = KVBase::GetDataSetEnv<TString>(fDataSet, Form("%s.%s", fDBType.Data(), type));
1033  if (!p.Length()) return KVBase::GetDataSetEnv<TString>(fDataSet, Form("EXPDB.%s", type));
1034  return p;
1035 }
1036 
1037 
1038 
1050 
1052 {
1053  // Looks for file with name given by one of the following variables:
1054  //
1055  // [DBtype].Comments
1056  // [dataset].[DBtype].Comments
1057  //
1058  // and opens it to read and add comments on runs.
1059  // Format of file is:
1060  //
1061  // run=3830-3836 | really amazing data in these runs
1062  //
1063 
1064  TString comments_file = GetCalibFileName("Comments");
1065  if (comments_file == "") return;
1066  TString fullpath;
1067  if (!FindCalibFile("Comments", fullpath)) return;
1068  Info("ReadComments", "Reading run comments in file %s...", fullpath.Data());
1069 
1070  KVFileReader fr;
1071  if (!fr.OpenFileToRead(fullpath)) {
1072  Error("ReadComments", "Problem opening file %s", fullpath.Data());
1073  return;
1074  }
1075 
1076  while (fr.IsOK()) {
1077  fr.ReadLine("|");
1078  if (fr.GetCurrentLine().BeginsWith("#")) {
1079 
1080  }
1081  else if (fr.GetCurrentLine() == "") {
1082 
1083  }
1084  else {
1085  if (fr.GetNparRead() == 2) {
1086  KVString srun(fr.GetReadPar(0));
1087  srun.Begin("=");
1088  srun.Next();
1089  KVNumberList lruns(srun.Next());
1090  KVString comments(fr.GetReadPar(1));
1091  lruns.Begin();
1092  while (!lruns.End()) {
1093  Int_t run = lruns.Next() / index_multiplier;
1094  KVDBRun* dbrun = GetDBRun(run);
1095  if (dbrun)
1096  dbrun->SetComments(comments.Data());
1097  }
1098  }
1099  }
1100  }
1101 }
1102 
1103 
1104 
int Int_t
unsigned int UInt_t
ROOT::R::TRInterface & r
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
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 Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
char * Form(const char *fmt,...)
static ValType GetDataSetEnv(const KVString &dataset, const KVString &type, const ValType &defval={})
Definition: KVBase.h:305
static Bool_t SearchKVFile(const Char_t *name, TString &fullpath, const Char_t *kvsubdir="")
Definition: KVBase.cpp:541
static Bool_t SearchAndOpenKVFile(const Char_t *name, KVSQLite::database &dbfile, const Char_t *kvsubdir="")
Definition: KVBase.cpp:652
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:796
Record folder for the database.
Definition: KVDBRecord.h:43
virtual Int_t GetNumber() const
Definition: KVDBRecord.h:73
Int_t GetGlobalRunFileNumber() const
Definition: KVDBRunFile.h:245
Description of an experimental run in database ,,.
Definition: KVDBRun.h:41
ULong64_t GetEvents() const
Definition: KVDBRun.h:197
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 SetComments(const KVString &comments)
Definition: KVDBRun.h:272
KVDBSystem * GetSystem() const
Definition: KVDBRun.cpp:240
virtual void WriteRunListLine(std::ostream &, Char_t delim='|') const
Definition: KVDBRun.cpp:94
const Char_t * GetTriggerString() const
Definition: KVDBRun.h:253
const Char_t * GetComments() const
Definition: KVDBRun.h:263
Database class used to store information on different colliding systems studied during an experiment....
Definition: KVDBSystem.h:51
void Save(std::ostream &) const
Definition: KVDBSystem.cpp:312
void SetRuns(const KVNumberList &, int=1)
Definition: KVDBSystem.cpp:458
void AddRun(KVDBRecord *)
Definition: KVDBSystem.cpp:507
void SetTarget(KVTarget *targ)
Definition: KVDBSystem.h:83
void Load(std::istream &, int=1)
Definition: KVDBSystem.cpp:360
void Rehash(void)
Definition: KVDBTable.cpp:174
virtual KVDBRecord * GetRecord(const Char_t *rec_name) const
Definition: KVDBTable.h:58
Simple cross-referenced database structure.
Definition: KVDataBase.h:137
ValueType Default(ValueType v=ValueType{}) const
Definition: KVEnv.h:58
Extension of TEnv to allow the writing of comments in the file.
Definition: KVEnv.h:18
Bool_t HasValue(const KVString &val) const
Definition: KVEnv.h:97
Value GetValueOf(Ts... args) const
Definition: KVEnv.h:69
Base class to describe database of an experiment ,,.
Definition: KVExpDB.h:61
void AddSystem(KVDBSystem *r)
Definition: KVExpDB.h:173
std::map< int, run_index_t > fMapGlobRunFileNumberToRunIndex
cannot be saved, no streamer for run_index_t
Definition: KVExpDB.h:74
run_index_list SetRunIndexListFromString(const TString &) const
Definition: KVExpDB.cpp:918
run_index_t GetRunIndexFromGlobalRunFileNumber(int glob_runfile) const
Definition: KVExpDB.cpp:862
virtual ~KVExpDB()
Destructor.
Definition: KVExpDB.cpp:276
virtual KVDBSystem * GetSystem(const Char_t *system) const
Definition: KVExpDB.h:164
virtual void ReadComments()
Definition: KVExpDB.cpp:1051
virtual void ReadSystemList()
Definition: KVExpDB.cpp:428
virtual void cd()
Definition: KVExpDB.cpp:762
KVDBTable * fRuns
table of runs
Definition: KVExpDB.h:69
virtual void LinkRecordToRun(KVDBRecord *rec, Int_t run)
Definition: KVExpDB.cpp:334
KVDBRun * GetDBRun(Int_t number) const
Definition: KVExpDB.h:144
virtual KVSeqCollection * GetRuns() const
Definition: KVExpDB.h:140
TString GetCalibFileName(const Char_t *type) const
Definition: KVExpDB.h:188
virtual void LinkListToRunRanges(TList *list, UInt_t rr_number, UInt_t run_ranges[][2])
Link the records contained in the list to the set of runs (see LinkRecordToRunRanges).
Definition: KVExpDB.cpp:373
KVDBTable * fSystems
table of systems
Definition: KVExpDB.h:70
virtual void PrintRuns(KVNumberList &) const
Definition: KVExpDB.cpp:732
ULong64_t GetTotalEvents(int first_run, int last_run=-1) const
Definition: KVExpDB.cpp:816
virtual KVSeqCollection * GetSystems() const
Definition: KVExpDB.h:168
virtual void Save(const Char_t *)
Definition: KVExpDB.cpp:547
const KVDBRunFile & GetDBRunFile(const run_index_t &r) const
Definition: KVExpDB.h:148
TString fDBType
used by GetDBEnv
Definition: KVExpDB.h:66
virtual void LinkRecordToRunRanges(KVDBRecord *rec, UInt_t rr_number, UInt_t run_ranges[][2])
Definition: KVExpDB.cpp:353
virtual void LinkListToRunRange(TList *list, const KVNumberList &nl)
Link the records contained in the list to the set of runs (see LinkRecordToRunRanges).
Definition: KVExpDB.cpp:399
void WriteSystemsFile() const
Definition: KVExpDB.cpp:514
KVExpDB()
Default constructor.
Definition: KVExpDB.cpp:238
const Char_t * GetDataSetDir() const
Definition: KVExpDB.h:215
void init()
default initialisations
Definition: KVExpDB.cpp:23
virtual void LinkRecordToRunRange(KVDBRecord *rec, UInt_t first_run, UInt_t last_run)
Definition: KVExpDB.cpp:290
int index_multiplier
Definition: KVExpDB.h:71
void WriteRunListFile() const
Definition: KVExpDB.cpp:567
virtual TString GetDBEnv(const Char_t *) const
Definition: KVExpDB.cpp:1014
Bool_t OpenCalibFile(const Char_t *type, std::ifstream &fs) const
Definition: KVExpDB.cpp:618
static KVExpDB * MakeDataBase(const Char_t *name, const Char_t *datasetdir, Bool_t minimal=false)
Definition: KVExpDB.cpp:783
void read_beams_targets_reactions()
Definition: KVExpDB.cpp:91
TString fDataSet
the name of the dataset to which this database is associated
Definition: KVExpDB.h:64
Bool_t FindCalibFile(const Char_t *type, TString &fullpath, const TString &array_name="") const
Definition: KVExpDB.cpp:672
Handle reading columns of numeric data in text files.
Definition: KVFileReader.h:121
KVString GetCurrentLine()
Definition: KVFileReader.h:320
ReadStatus ReadLine(const KVString &pattern="")
Definition: KVFileReader.h:243
Int_t GetNparRead() const
Definition: KVFileReader.h:325
Bool_t IsOK()
Definition: KVFileReader.h:231
KVString GetReadPar(Int_t pos) const
Definition: KVFileReader.h:342
Bool_t OpenFileToRead(const KVString &filename)
Definition: KVFileReader.h:210
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:123
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
TObject * At(Int_t idx) const override
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
Int_t GetNValues(TString delim) const
Definition: KVString.cpp:886
Calculation/correction of energy losses of particles through an experimental target.
Definition: KVTarget.h:128
virtual Int_t GetSize() const
const char * AsString() const
virtual const char * GetValue(const char *name, const char *dflt) const
const char * GetName() const override
virtual const char * ClassName() const
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual void Info(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Bool_t IsNull() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
List of runfiles specified by run number and file index ,.
void Add(const run_index_t &r)
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:31
int run() const
Definition: run_index.h:50
unsigned long long ULong64_t
TLine * line
double T(double x)
void Error(const char *location, const char *fmt,...)
void Info(const char *location, const char *fmt,...)
rec
constexpr Double_t R()
ClassImp(TPyArg)