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