KaliVeda
Toolkit for HIC analysis
KVDataSet.cpp
1 /*
2 $Id: KVDataSet.cpp,v 1.41 2009/03/11 14:22:41 franklan Exp $
3 $Revision: 1.41 $
4 $Date: 2009/03/11 14:22:41 $
5 $Author: franklan $
6 */
7 
8 #include "TMethodCall.h"
9 #include "KVDataSet.h"
10 #include "KVDataSetRepository.h"
11 #include "KVDataRepositoryManager.h"
12 #include "KVDataSetManager.h"
13 #include "TSystem.h"
14 #include "TObjArray.h"
15 #include "TObjString.h"
16 #include "KVDBSystem.h"
17 #include "KVDBRun.h"
18 #include "TEnv.h"
19 #include "KVAvailableRunsFile.h"
20 #include "KVNumberList.h"
21 #include "TPluginManager.h"
22 #include "TClass.h"
23 #include "KVRunFile.h"
24 
25 using namespace std;
26 
28 
29 KVDataSet* gDataSet;
30 
31 
34 
36 {
37  //Default constructor
38  fAllTasks.SetOwner(kTRUE);
39  fTasks.SetOwner(kFALSE);
40 }
41 
42 
43 
48 
50 {
51  // \param type name of data type ('raw', 'recon', ...)
52  // \returns pointer to available runs file object for given data type
53  // \note if no data repository is associated with dataset, returns nullptr
54  if (!fRepository) return nullptr;
55  KVAvailableRunsFile* avrf =
56  (KVAvailableRunsFile*) fAvailableRuns.FindObjectByName(type);
57  if (!avrf) {
58  avrf = fRepository->NewAvailableRunsFile(type, this);
59  fAvailableRuns.Add(avrf);
60  }
61  return avrf;
62 }
63 
64 
65 
81 
83 {
84  //Returns name of file containing database for dataset.
85  //
86  //This is fixed as `DataBase.root.M.m.p` where
87  // - `M` is the current major version number
88  // - `m` is the current minor version number
89  // - `p` is the current patch number
90  //
91  //(fixed to be consistent with CMake function INSTALL_KALIVEDA_DATASETS which sets up
92  //the Makefile for each dataset which automatically triggers rebuilding of the ROOT file
93  //when source files change: thus we must have the right file name!)
94  //
95  //This in order to avoid problems if several different versions of KaliVeda
96  //use the same working directory (in user's `$HOME/.kaliveda`) to write the
97  //database files, which are often incompatible between versions
98 
99  TString n = "DataBase.root";
100  n.Append(Form(".%d.%d.%d", GetKVMajorVersion(),
101  GetKVMinorVersion(), GetKVPatchVersion()));
102  return n;
103 }
104 
105 
106 
111 
113 {
114  //\returns name of database object in database file.
115  //
116  //If this is not set explicitly with SetDBName(), we use the name of the dataset by default
117 
118  return (fDBName != "" ? fDBName.Data() : GetName());
119 }
120 
121 
122 
123 
126 
127 void KVDataSet::OpenDBFile(const Char_t* full_path_to_dbfile) const
128 {
129  //Open the database from a file on disk.
130 
131  TDirectory* work_dir = gDirectory; //keep pointer to current directory
132  fDBase.reset(new TFile(full_path_to_dbfile, "READ"));
133 
134  if (fDBase->IsOpen()) {
135  fDataBase = dynamic_cast<KVExpDB*>(fDBase->Get(GetDBName()));
136  if (!fDataBase) {
137  Error("OpenDBFile", "%s not found in file %s", GetDBName().Data(),
138  GetDBFileName().Data());
139  }
140  else {
141  fDataBase->ReadObjects(fDBase.get()); // read any associated objects
142  }
143  work_dir->cd(); //back to initial working directory
144  }
145 }
146 
147 
148 
149 
152 
154 {
155  // \returns full path to file where database is written on disk
156 
157  TString dbfile = GetDBFileName();
158  TString dbfile_fullpath;
159  TString tmp;
160 
161  // If this dataset is just an alias for another dataset i.e. if DataSet.Directory
162  // is set with just the name of another dataset (not a full path to dataset files)
163  // then the database file should be written/found under the name of the alias.
164  TString dataset_alias = GetDataSetEnv("DataSet.Directory", GetName());
165  TString db_alias = GetName();
166  if (!gSystem->IsAbsoluteFileName(dataset_alias)) db_alias = dataset_alias;
167 
168  AssignAndDelete(tmp, gSystem->ConcatFileName(GetDATABASEFilePath(), db_alias.Data()));
169  AssignAndDelete(dbfile_fullpath, gSystem->ConcatFileName(tmp.Data(), dbfile.Data()));
170  return dbfile_fullpath;
171 }
172 
173 
174 
177 
179 {
180  //Check configuration variables to see if the task parameters have been "tweaked" for the dataset.
181 
182  KVString envar = GetDataSetEnv(Form("%s.DataAnalysisTask.Title", t->GetName()));
183  if (envar != "") t->SetTitle(envar);
184  envar = GetDataSetEnv(Form("%s.DataAnalysisTask.Analyser", t->GetName()));
185  if (envar != "") t->SetDataAnalyser(envar);
186  envar = GetDataSetEnv(Form("%s.DataAnalysisTask.UserClass.Base", t->GetName()));
187  if (envar != "") t->SetUserBaseClass(envar);
188  envar = GetDataSetEnv(Form("%s.DataAnalysisTask.Prereq", t->GetName()));
189  if (envar != "") t->SetPrereq(envar);
190  envar = GetDataSetEnv(Form("%s.DataAnalysisTask.UserClass.ExtraACliCIncludes", t->GetName()));
191  if (envar != "") t->SetExtraAClicIncludes(envar);
192  Int_t nev = (Int_t)GetDataSetEnv(Form("%s.DataAnalysisTask.StatusUpdateInterval", t->GetName()), 0.0);
193  if (nev > 0) t->SetStatusUpdateInterval(nev);
194 }
195 
196 
197 
198 
202 
204 {
205  // Write the experiment database for this dataset to disk (ROOT file), creating and setting
206  // permissions for any required directories
207 
208  TString dbfile_fullpath = GetFullPathToDB();
209  TString tmp = gSystem->DirName(dbfile_fullpath.Data()); //full path to directory $KVROOT/db/[dataset name]
210 
211  if (gSystem->AccessPathName(tmp.Data())) { // directory $KVROOT/db/[dataset name] does not exist
212 
213  if (gSystem->mkdir(tmp.Data()) == -1) { // problem creating $KVROOT/db/[dataset name]
214 
215  TString tmp2 = gSystem->DirName(tmp.Data());// full path to directory $KVROOT/db
216 
217  if (gSystem->AccessPathName(tmp2.Data())) { // directory $KVROOT/db does not exist
218 
219  if (gSystem->mkdir(tmp2.Data()) == -1) { // problem creating $KVROOT/db
220  Error("SaveDataBase", "Cannot create directory %s required to save database",
221  tmp2.Data());
222  return;
223  }
224  gSystem->Chmod(tmp2.Data(), 0775);
225  }
226  else {
227  Error("SaveDataBase", "Cannot create directory %s required to save database, even though %s exists: check disk space ?",
228  tmp.Data(), tmp2.Data());
229  return;
230  }
231  //try again
232  if (gSystem->mkdir(tmp.Data()) == -1) {
233  Error("SaveDataBase", "Cannot create directory %s required to save database",
234  tmp.Data());
235  return;
236  }
237  else {
238  gSystem->Chmod(tmp.Data(), 0775);
239  }
240  }
241  else {
242  gSystem->Chmod(tmp.Data(), 0775);
243  }
244  }
245 
246  WriteDBFile(dbfile_fullpath.Data());
247 }
248 
249 
250 
251 
254 
255 void KVDataSet::WriteDBFile(const Char_t* full_path_to_dbfile) const
256 {
257  //Write the database to disk.
258 
259  TDirectory* work_dir = gDirectory; //keep pointer to current directory
260  if (!fDataBase) {
261  Error("WriteDBFile", "Database has not been built");
262  return;
263  }
264  fDBase.reset(new TFile(full_path_to_dbfile, "recreate"));
265  fDBase->cd(); //set as current directory (maybe not necessary)
266  fDataBase->Write(GetDBName()); //write database to file with given name
267  fDataBase->WriteObjects(fDBase.get()); //write any associated objects
268  fDBase->Write(); // write file header etc.
269  fDBase->Close(); // close file
270  gSystem->Chmod(full_path_to_dbfile, 0664); // set permissions to rw-rw-r--
271  work_dir->cd(); //back to initial working directory
272 }
273 
274 
275 
287 
289 {
290  //\returns pointer to database associated with this dataset.
291  //
292  //Opens, updates or creates database file if necessary
293  //(the database is automatically rebuilt if the source files are
294  //more recent than the last database file).
295  //
296  //\param[in] opt optional option string:
297  // - if opt="update": force regeneration of the database from source files in dataset directory
298  // - if opt="minimal": if database not built/out of date, only build runs/systems database
299  // - note that both options can be given to force update of minimal database
300 
301  OpenDataBase(opt);
302  return fDataBase;
303 }
304 
305 
306 
318 
319 void KVDataSet::OpenDataBase(const TString& opt) const
320 {
321  //Open the database for this dataset.
322  //
323  //If the database does not exist or is older than the source files
324  //the database is automatically rebuilt (see DataBaseNeedUpdate()).
325  //
326  //\param[in] opt build option
327  //
328  // - if opt="update" we force rebuilding of the database
329  // - if opt="minimal" only a minimal database of runs & systems for the dataset is built
330  // - note that both options can be given to force update of minimal database
331 
332  TString _opt(opt);
333  _opt.ToUpper();
334  auto update = (_opt.Contains("UPDATE"));
335  auto minimal = (_opt.Contains("MINIMAL"));
336 
337  auto rebuild_database = [&](bool start_from_minimal = false) {
338  if (start_from_minimal)
339  Info("OpenDataBase", "Updating existing minimal database...");
340  else {
341  if (minimal)
342  Info("OpenDataBase", "Creating a new minimal database...");
343  else
344  Info("OpenDataBase", "Creating a new full database...");
345  }
346 
347  fDataBaseUpdateInProgress = true;
348  //check if it is the currently active database (gDataBase),
349  //in which case we must 'cd()' to it after rebuilding
350  auto is_glob_db = (fDataBase == gExpDB);
351  if (!start_from_minimal) {
352  if (fDataBase) {
353  delete fDataBase;
354  fDataBase = 0;
355  }
356  fDataBase = KVExpDB::MakeDataBase(GetDBName(), GetDataSetDir(), minimal);
357  if (!fDataBase) {
358  // no database defined for dataset
359  Info("OpenDataBase", "No database defined for dataset");
360  fDataBaseUpdateInProgress = false;
361  return;
362  }
363  }
364  else
365  fDataBase->CompleteDataBase();
366  SaveDataBase();
367  if (fDataBase && is_glob_db) fDataBase->cd();
368  fDataBaseUpdateInProgress = false;
369  };
370 
371  if (update || DataBaseNeedsUpdate()) {
372  //if option="update" or database out of date or does not exist, (re)build the database
373  rebuild_database();
374  }
375  else if (!fDataBase) {
376  // if database is not in memory at this point, we need to
377  // open the database file and read in the database
378 
379  //load plugin for database
380  if (!LoadPlugin("KVExpDB", GetDBName())) {
381  Error("GetDataBase", "Cannot load required plugin library");
382  return;
383  }
384  //look for database file in dataset subdirectory
385  TString dbfile_fullpath = GetFullPathToDB();
386  //open database file
387  OpenDBFile(dbfile_fullpath.Data());
388 
389  // if the previously built database was minimal but nobody asked for
390  // a minimal database (=> they want the full monty), we rebuild a full database
391  if (fDataBase && fDataBase->IsMinimal() && !minimal)
392  rebuild_database(true);
393  }
394  else if (fDataBase && fDataBase->IsMinimal() && !minimal) {
395  // database is already open, but was only a minimal build
396  // now we want the full monty!
397  rebuild_database(true);
398  }
399 }
400 
401 
402 
403 
406 
408 {
409  //Print dataset information
410  cout << "Dataset name=" << GetName() << " (" << GetTitle() << ")";
411  if (IsAvailable()) {
412  cout << " [ AVAILABLE: ";
413  cout << fDatatypes.Data();
414  cout << "]";
415  }
416  else
417  cout << " [UNAVAILABLE]";
418  cout << endl;
419 }
420 
421 
422 
429 
430 void KVDataSet::Print(Option_t* opt) const
431 {
432  //Print dataset information
433  //
434  //param[in] opt select optional output formats:
435  // - if string contains "tasks", print numbered list of tasks that can be performed
436  // - if string contains "data", print list of available data types
437 
438  TString Sopt(opt);
439  Sopt.ToUpper();
440  if (Sopt.Contains("TASK")) {
441  if (!GetNtasks()) {
442  cout << " *** No available analysis tasks ***"
443  << endl;
444  return;
445  }
446  else {
447  for (int i = 1; i <= GetNtasks(); i++) {
448  KVDataAnalysisTask* dat = GetAnalysisTask(i);
449  cout << "\t" << i << ". " << dat->GetTitle() << endl;
450  }
451  }
452  cout << endl;
453  }
454  else if (Sopt.Contains("DATA")) {
455  cout << "Available data types: " << fDatatypes.Data() << endl;
456  }
457  else {
458  ls(opt);
459  }
460 }
461 
462 
463 
472 
474 {
475  //Check if this data set is physically present and available for analysis.
476  //
477  //In other words we check if the value of GetDataPathSubdir() is a subdirectory
478  //of the current data repository.
479  //If so, we proceed to check for the existence of sudirectories corresponding
480  // to any of the datatypes associated with the dataset.
481  //
482 
483  if (!fRepository) // for a stand-alone KVDataSetManager not linked to a KVDataRepository,
484  SetAvailable(); // all known datasets are 'available'
485  else
486  SetAvailable(fRepository->CheckSubdirExists(GetDataPathSubdir()));
487  if (!IsAvailable())
488  return;
489  //check subdirectories
490  KVString data_types = GetDataSetEnv("KVDataSet.DataTypes", "");
491  if (data_types == "") {
492  Warning("CheckAvailable", "No datatypes defined for this dataset: %s\nCheck value of KVDataSet.DataTypes or %s.KVDataSet.DataTypes",
493  GetName(), GetName());
494  SetAvailable(kFALSE);
495  }
496  fDatatypes = "";
497  // loop over data types
498  data_types.Begin(" ");
499  while (!data_types.End()) {
500  KVString type = data_types.Next(kTRUE);
501  if (!fRepository ||
502  (fRepository && fRepository->CheckSubdirExists(GetDataPathSubdir(), GetDataTypeSubdir(type.Data())))
503  ) {
504  AddAvailableDataType(type.Data());
505  }
506  }
507  //check at least one datatype exists
508  SetAvailable(fDatatypes != "");
509 }
510 
511 
512 
514 
516 {
517  if (fDatatypes != "") fDatatypes += " ";
518  KVString _type = type;
519  _type.Remove(TString::kBoth, ' '); //strip whitespace
520  fDatatypes += _type;
521 }
522 
523 
524 
531 
533 {
534  // Add to fAllTasks list any data analysis task in list 'task_list'
535  //
536  // Add to fTasks list any data analysis task in list 'task_list' whose pre-requisite datatype is present for this dataset.
537  //
538  // Any dataset-specific "tweaking" of the task (including the prerequisite datatype) is done here.
539 
540  TString availables = gEnv->GetValue(Form("%s.DataAnalysisTask", GetName()), "");
541  fAllTasks.Clear();
542  fTasks.Clear();
543  TIter nxt(task_list);
544  KVDataAnalysisTask* dat;
545  while ((dat = (KVDataAnalysisTask*) nxt())) {
546  //make new copy of default analysis task
547  if (availables == "" || availables.Contains(dat->GetName())) {
548  KVDataAnalysisTask* new_task = new KVDataAnalysisTask(*dat);
549  //check if any dataset-specific parameters need to be changed
550  SetDataSetSpecificTaskParameters(new_task);
551  fAllTasks.Add(new_task);
552  // add tasks with available prerequisite data to fTasks
553  if (HasDataType(new_task->GetPrereq())) {
554  fTasks.Add(new_task);
555  }
556  }
557  }
558 }
559 
560 
561 
565 
567 {
568  //Returns the number of tasks associated to dataset which are compatible
569  //with the available data
570 
571  return fTasks.GetSize();
572 }
573 
574 
575 
580 
582 {
583  //Return kth analysis task in list of available tasks.
584  //
585  //\param[in] k task number in range [1, GetNtasks()]. Corresponds to the number shown next to the title of the task when Print("tasks") is called
586  return (KVDataAnalysisTask*) fTasks.At(k - 1);
587 }
588 
589 
590 
595 
597 {
598  //\returns list of available systems for this dataset and the given datatype
599  //
600  //\param[in] datatype type of data
601 
602  if (!GetAvailableRunsFile(datatype)) {
603  Error("GetListOfAvailableSystems(const Char_t*)",
604  "No available runs file for type %s", datatype.Data());
605  return {};
606  }
607  return GetAvailableRunsFile(datatype)->GetListOfAvailableSystems();
608 }
609 
610 
611 
616 
618 {
619  //\returns list of available systems for this dataset and the prerequisite datatype for the given analysis task
620  //
621  //\param[in] datan data analysis task
622 
623  return GetListOfAvailableSystems(datan->GetPrereq());
624 }
625 
626 
627 
635 
637 {
638  //\returns list of available runfiles for this dataset and the given datatype and system.
639  //
640  //\param[in] datatype type of data
641  //\param[in] systol pointer to system
642  //
643  //If no systems are defined for the dataset then we return a list of available runfiles for the given datatype
644 
645  if (!GetAvailableRunsFile(datatype)) {
646  Error("GetListOfAvailableSystems(const Char_t*)",
647  "No available runs file for type %s", datatype.Data());
648  return {};
649  }
650  return GetAvailableRunsFile(datatype)->GetListOfAvailableRunFilesForSystem(systol);
651 }
652 
653 
654 
662 
664 {
665  //\returns list of available runfiles for this dataset, given system, and the prerequisite datatype for the given analysis task
666  //
667  //\param[in] datan data analysis task
668  //\param[in] pointer to system
669  //
670  //If no systems are defined for the dataset then we return a list of available runfiles for the given datatype
671 
672  return GetListOfAvailableRunFilesForSystem(datan->GetPrereq(), systol);
673 }
674 
675 
676 
679 
681 {
682  // \returns the list of systems corresponding to the given list of runfiles & datatype
683 
684  if (!GetAvailableRunsFile(datatype)) {
685  Error("GetSystemsForRunFiles",
686  "No available runs file for type %s", datatype.Data());
687  return {};
688  }
689  return GetAvailableRunsFile(datatype)->GetSystemsForRunFiles(rl);
690 }
691 
692 
693 
714 
715 void KVDataSet::SetName(const char* name)
716 {
717  // Set name of dataset
718  //
719  // Also sets path to directory containing database informations
720  // for this dataset, i.e. list of runs, systems, calibration files etc.
721  //
722  // By default, just the name of the dataset is used, i.e.
723  // `[DATADIR]/name`
724  // (where `DATADIR` = path given by KVBase::GetDATADIRFilePath())
725  //
726  // However, if the variable
727  //~~~
728  // [name].DataSet.Directory: [path]
729  //~~~
730  // has been set, the value of `[path]` will be used:
731  // - if [path] is an absolute path name, it will be used as such
732  // - if [path] is an incomplete or relative path, it will be prepended with `[DATADIR]/`
733  //
734  // This allows to use one dataset as an alias for another, by setting `DataSet.Directory`
735  // to the name of an existing dataset
737  TString path = GetDataSetEnv("DataSet.Directory", name);
738  if (gSystem->IsAbsoluteFileName(path)) fCalibDir = path;
739  else {
740  // in this case (not an absolute path but just the name of another dataset)
741  // this dataset is an alias for another dataset.
742  fCalibDir = GetDATADIRFilePath(path);
743  // the name of the database object is the name of the "true" dataset
744  SetDBName(path);
745  }
746 }
747 
748 
749 
752 
754 {
755  //\returns full path to directory containing database and calibration/identification parameters etc. for this dataset.
756 
757  return fCalibDir.Data();
758 }
759 
760 
761 
774 
775 void KVDataSet::cd() const
776 {
777  // Makes this dataset the "currently active" or default dataset.
778  //
779  //At the same time, the database and data repository associated with
780  //this dataset also become the "currently active" ones:
781  //
782  // | global pointer | represents | base class |
783  // |----------------|------------|------------|
784  // | `gDataSet` | active dataset | KVDataSet |
785  // | `gExpDB` | associated experimental database | KVExpDB |
786  // | `gDataRepository` | repository containing runfiles | KVDataRepository |
787  //
788 
789  gDataSet = const_cast<KVDataSet*>(this);
790  if (fRepository) fRepository->cd();
791  KVExpDB* db = GetDataBase();
792  if (db) db->cd();
793 }
794 
795 
796 
824 
826 {
827  // Open file containing data of given datatype for given run number of this dataset.
828  //
829  // \returns a pointer to the opened file; if the file is not available, we return nullptr.
830  //
831  // The user must cast the returned pointer to the correct class, which will
832  // depend on the data type and the dataset
833  //
834  // **SPECIAL CASE: MFM data with EBYEDAT frames**
835  //
836  // If the variable
837  //
838  //~~~~~~~~~~~~~~~~~~~~~~~~~
839  // [dataset].MFM.WithEbyedat: yes
840  //~~~~~~~~~~~~~~~~~~~~~~~~~
841  //
842  // is set, then we expect to find the necessary `ACTIONS_*` files in the dataset directory
843  // in subdirectory `ebyedat` (they should have the same names as the data files prefixed by
844  // `ACTIONS_[expname].CHC_PAR.`).
845  //
846  // If in addition the variable
847  //
848  //~~~~~~~~~~~~~~~~~~~~~~~~~
849  // [dataset].MFM.EbyedatActionsExpName: [expname]
850  //~~~~~~~~~~~~~~~~~~~~~~~~~
851  //
852  // is set, then we use the same `ACTIONS` file for all runs, with name `ACTIONS_[expname].CHC_PAR`
853 
854  if (!GetRepository()) return nullptr;
855 
856  auto file_open = [&](const TString & fpth) {
857  return file_opener(type, fpth, GetName());
858  };
859 
860  if (!strcmp(type, "raw") && !strcmp(GetDataSetEnv("MFM.WithEbyedat", ""), "yes")) {
861  TString ebydir = GetDataSetDir();
862  ebydir += "/ebyedat";
863  gEnv->SetValue("KVMFMDataFileReader.ActionsDirectory", ebydir);
864  if (strcmp(GetDataSetEnv("MFM.EbyedatActionsExpName", ""), ""))
865  gEnv->SetValue("KVMFMDataFileReader.ActionsExpName", GetDataSetEnv("MFM.EbyedatActionsExpName", ""));
866  TObject* f = GetRepository()->OpenFile(GetRunfileName(type, run), file_open, GetDataPathSubdir(), GetDataTypeSubdir(type));
867  // reset in case another dataset opens a raw MFM file without EBYEDAT data
868  gEnv->SetValue("KVMFMDataFileReader.ActionsDirectory", "");
869  gEnv->SetValue("KVMFMDataFileReader.ActionsExpName", "");
870  return f;
871  }
872  return GetRepository()->OpenFile(GetRunfileName(type, run), file_open, GetDataPathSubdir(), GetDataTypeSubdir(type));
873 }
874 
875 
876 
877 
881 
883  const run_index_t& run) const
884 {
885  //\return full path to file containing data of given datatype for given run/index of this dataset
886  // \note only works for available run files, if their is no file in the repository for this run, the returned path will be empty
887 
888  TString file("");
889  if (fRepository) file = GetRunfileName(type, run);
890  if (file == "")
891  return file.Data();
892  return fRepository->GetFullPathToOpenFile(file, GetDataPathSubdir(), GetDataTypeSubdir(type));
893 }
894 
895 
896 
897 
901 
903 {
904  //\return name of file containing data of given datatype for given run/index of this dataset
905  //\note only works for available run files, if there is no file in the repository for this run, the returned path will be empty
906 
907  if (!HasDataType(type)) {
908  Error("GetRunfileName",
909  "No data of type \"%s\" available for dataset %s", (const char*)type,
910  GetName());
911  return 0;
912  }
913  //get name of file from available runs file
914  return GetAvailableRunsFile(type)->GetFileName(run);
915 }
916 
917 
918 
919 
925 
926 std::optional<TDatime> KVDataSet::GetRunfileDate(const KVString& type, const run_index_t& run)
927 {
928  //\return date of file containing data of given datatype for given run/index of this dataset
929  //
930  //\note only works for available runfiles, if there is no file in the repository for this run/index,
931  //an error will be printed and std::optional will not contain a value
932 
933  if (!HasDataType(type)) {
934  Error("GetRunfileDate",
935  "No data of type \"%s\" available for dataset %s", (const char*)type,
936  GetName());
937  return std::nullopt;
938  }
939  //get date of file from available runs file
940  TDatime date;
942  if (!GetAvailableRunsFile(type)->GetRunInfo(run, date, filename)) {
943  Error("GetRunfileDate",
944  "Runfile not found for run %d index %d (data type: %s)", run.run(), run.index(), (const char*)type);
945  return std::nullopt;
946  }
947  return date;
948 }
949 
950 
951 
974 
975 std::optional<run_index_t> KVDataSet::GetRunNumberFromFileName(const TString& datatype, const TString& filename)
976 {
977  // \returns run number and eventual index by parsing the name of a runfile for given datatype. if filename does not have correct format, returns std::nullopt
978  //
979  // If the runfile in question was generated using an index multiplier, e.g. if it contains the number
980  // '17001' when the index multiplier defined for the dataset is 1000, we return '17' as the
981  // run number and '1' as the index.
982  //
983  // Usage examples (using global pointer gDataSet to currently 'active' dataset):
984  //~~~{.cpp}
985  //auto run = gDataSet->GetRunNumberFromFileName(filename);
986  //
987  //if(!run) // no value (std::nullopt) returned
988  //{
989  // std::cerr << "Filename " << filename << " is not right format\n";
990  //}
991  //else
992  //{
993  // std::cout << "Filename " << filename << " corresponds to run number " << run.value().run();
994  // if(run.has_index()) std::cout << ", file index = " << run.index();
995  // std::cout << std::endl;
996  //}
997  //~~~
998 
999  auto arf = GetAvailableRunsFile(datatype);
1000  auto v = arf->IsRunFileName(filename);
1001  if (!v) return v;
1002  // if the returned value has a non-null index, there is nothing more to do
1003  if (v.value().has_index()) return v;
1004  int r = v.value().run();
1005  // check if returned run number actually consists of run*multiplier+index
1006  auto db = GetDataBase("minimal");
1007  if (db->HasIndexMultiplier() && r > db->GetIndexMultiplier()) {
1008  r /= db->GetIndexMultiplier();
1009  int i = v.value().run() % db->GetIndexMultiplier();
1010  return run_index_t{r, i};
1011  }
1012  return v;
1013 }
1014 
1015 
1016 
1017 
1022 
1024 {
1025  //We check the availability of the run by looking in the available runs file associated
1026  //with the given datatype.
1027 
1028  //check data type is available
1029  if (!HasDataType(type)) {
1030  Error("CheckRunfileAvailable",
1031  "No data of type \"%s\" available for dataset %s", (const char*)type,
1032  GetName());
1033  return 0;
1034  }
1035  return GetAvailableRunsFile(type)->CheckAvailable(run);
1036 }
1037 
1038 
1039 
1040 
1055 
1056 const Char_t* KVDataSet::GetBaseFileName(const Char_t* type, const run_index_t& run) const
1057 {
1058  //PRIVATE METHOD: Returns base name of data file containing data for the run of given datatype.
1059  //The filename corresponds to one of the formats defined in $KVROOT/KVFiles/.kvrootrc
1060  //by variables like:
1061  //
1062  //~~~
1063  //[dataset].DataSet.RunFileName.[type]: run%R.dat
1064  //~~~
1065  //
1066  //%R will be replaced with the run number
1067  //
1068  //IF the format contains '%D' it will be replaced with the current date and time
1069  //
1070  // Any index will be appended at the end: ".index"
1071 
1072  static TString tmp;
1073  //get format string
1074  TString fmt = GetDataSetEnv(Form("DataSet.RunFileName.%s", type));
1075  TString run_num(Form("%d", run.run()));
1076  KVDatime now;
1077  TString date(now.AsSQLString());
1078  tmp = fmt;
1079  tmp.ReplaceAll("%R", run_num);
1080  if (fmt.Contains("%D")) {
1081  tmp.ReplaceAll("%D", date);
1082  }
1083  if (run.has_index()) tmp += Form(".%d", run.index());
1084  return tmp.Data();
1085 }
1086 
1087 
1088 
1089 
1099 
1101 {
1102  //Update list of available runs for given data 'type'
1103  //
1104  //As we never clear the sqlite database of any previously existing runfiles
1105  //beforehand, it is possible that newer versions of said files have been
1106  //added and that we will therefore end up with multiple copies of files in the
1107  //database. Therefore we perform an automatic 'CleanRunfileDataBase' afterwards,
1108  //but only to remove runfiles which no longer physically exist
1109 
1110  //check data type is available
1111  if (!HasDataType(type)) {
1112  Error("UpdateAvailableRuns",
1113  "No data of type \"%s\" available for dataset %s", (const char*)type,
1114  GetName());
1115  }
1116  KVAvailableRunsFile* a = GetAvailableRunsFile(type);
1117  a->Update();
1118  CleanRunfileDataBase(type);
1119 }
1120 
1121 
1122 
1123 
1128 
1130 {
1131  // Create a new runfile for the dataset of given datatype.
1132  // (only if this dataset is associated with a data repository)
1133  // Once the file has been filled, use CommitRunfile to submit it to the repository.
1134 
1135  if (!fRepository) return nullptr;
1136  TString tmp = GetBaseFileName(type, run);
1137  //turn any spaces into "_"
1138  tmp.ReplaceAll(" ", "_");
1139  return fRepository->CreateNewFile(this, type, tmp.Data());
1140 }
1141 
1142 
1143 
1144 
1153 
1154 void KVDataSet::DeleteRunfile(const KVString& type, const run_index_t& run, Bool_t confirm)
1155 {
1156  // Delete the file for the given run/index of data type "type" from the repository.
1157  // By default, confirm=kTRUE, which means that the user will be asked to confirm
1158  // that the file should be deleted. If confirm=kFALSE, no confirmation will be asked
1159  // for and the file will be deleted straight away.
1160  //
1161  // WARNING: this really does DELETE files in the repository, they cannot be
1162  // retrieved once they have been deleted.
1163 
1164  if (!fRepository) return;
1165 
1166  //get name of file to delete
1167  TString filename = GetAvailableRunsFile(type)->GetFileName(run);
1168  if (filename == "") {
1169  Error("DeleteRunfile", "Run %s of type %s does not exist.",
1170  run.as_string().Data(), (const char*)type);
1171  return;
1172  }
1173  //delete file
1174  //prevent accidental deletion of certain types of runfiles
1175  KVString doNotDelete = GetDataSetEnv("DataSet.RunFile.DoNotDelete", "all");
1176  if (doNotDelete == "all" || doNotDelete.Contains(type)) {
1177  Error("DeleteRunFile", "%s files cannot be deleted", (const char*)type);
1178  return;
1179  }
1180  fRepository->DeleteFile(this, type, filename, confirm);
1181  //was file deleted ? if so, remove entry from available runs file
1182  if (!fRepository->CheckFileStatus(this, type, filename.Data()))
1183  GetAvailableRunsFile(type)->Remove(run);
1184 }
1185 
1186 
1187 
1188 
1200 
1201 void KVDataSet::DeleteRunfiles(const Char_t* type, const run_index_list& nl, Bool_t confirm)
1202 {
1203  // Delete files corresponding to a list of runs/index of data type "type" from the repository.
1204  //
1205  // By default, confirm=kTRUE, which means that the user will be asked to confirm
1206  // that each file should be deleted.
1207  //
1208  // If confirm=kFALSE, no confirmation will be asked for and the file will be deleted straight away.
1209  //
1210  // if "nl" is empty (default value) all runs of the dataset corresponding to the given type will be deleted
1211  //
1212  // WARNING: this really does DELETE files in the repository, they cannot be retrieved once they have been deleted.
1213 
1214  auto NL = nl;
1215  if (NL.IsEmpty()) NL = GetRunList(type);
1216  if (NL.IsEmpty()) return;
1217  for (auto& r : NL)
1218  DeleteRunfile(type, r, confirm);
1219 }
1220 
1221 
1222 
1223 
1231 
1232 run_index_list KVDataSet::GetRunList_DateSelection(const TString& type, const KVUnownedList& systems, std::optional<KVDatime> min_date, std::optional<KVDatime> max_date)
1233 {
1234  // Prints out and returns list of runs after date / time selection
1235  //
1236  // Runs generated between ]min;max[ are selected
1237  // - if min=NULL runs with date <max are selected
1238  // - if max=NULL runs with date >min are selected
1239  // - if max and min are NULL returns empty list
1240 
1241  if (!min_date && !max_date) return {};
1242 
1243  if (min_date) printf("date minimum %s\n", min_date.value().AsString());
1244  if (max_date) printf("date maximum %s\n", max_date.value().AsString());
1245 
1246  run_index_list numb;
1247 
1248  for (auto _sys : systems) {
1249  auto sys = (KVDBSystem*)_sys;
1250  auto lrun = GetListOfAvailableRunFilesForSystem(type, sys);
1251 
1252  for (auto _run : lrun) {
1253  auto run = (KVRunFile*)_run;
1254 
1255  if (min_date && max_date) {
1256  if (min_date.value() < run->GetFileWrittenDatime() && run->GetFileWrittenDatime() < max_date.value()) {
1257  numb.Add(run->GetRunIndex());
1258  }
1259  }
1260  else if (min_date) {
1261  if (min_date.value() < run->GetFileWrittenDatime()) {
1262  numb.Add(run->GetRunIndex());
1263  }
1264  }
1265  else if (max_date) {
1266  if (run->GetFileWrittenDatime() < max_date.value()) {
1267  numb.Add(run->GetRunIndex());
1268  }
1269  }
1270  }
1271  }
1272  return numb;
1273 
1274 }
1275 
1276 
1277 
1278 
1285 
1287 {
1288  // Returns list of runs which are present for data type "base_type" but not for "other_type"
1289  //
1290  // If pointer to system is given, only runs for the system are considered.
1291  //
1292  // If OnlyCol=kTRUE (kFALSE default) only systems with KVDBSystem::IsCollision()=kTRUE are considered
1293 
1294  run_index_list manquant;
1295  auto ll = GetListOfAvailableSystems(ref_type);
1296  if (ll.IsEmpty()) {
1297  //numb.Clear();
1298  Info("GetRunList_StageSelection", "No data available of type \"%s\"", ref_type.Data());
1299  return manquant;
1300  }
1301  if (system && !ll.FindObject(system)) {
1302  Info("GetRunList_StageSelection", "No data available of type \"%s\" for system %s", ref_type.Data(), system->GetName());
1303  return manquant;
1304  }
1305 
1306  Info("GetRunList_StageSelection", "Liste des runs presents dans \"%s\" mais absent dans \"%s\"", ref_type.Data(), type.Data());
1307 
1308  KVDBSystem* sys = 0;
1309 
1310  for (Int_t nl = 0; nl < ll.GetEntries(); nl += 1) {
1311 
1312  sys = (KVDBSystem*)ll.At(nl);
1313  if (system && sys != system) continue;
1314  if (OnlyCol && !sys->IsCollision()) continue;
1315  auto nsys = GetRunList(type, sys);
1316  auto nsys_ref = GetRunList(ref_type, sys);
1317  Int_t nref = nsys_ref.GetNValues();
1318 
1319  nsys_ref.Remove(nsys);
1320 
1321  Info("GetRunList_StageSelection", "\nKVDBSystem : %s --> %d runs manquants sur %d : %s",
1322  sys->GetName(),
1323  nsys_ref.GetNValues(),
1324  nref,
1325  nsys_ref.AsString().Data()
1326  );
1327  manquant.Add(nsys_ref);
1328  }
1329  return manquant;
1330 }
1331 
1332 
1333 
1339 
1340 run_index_list KVDataSet::GetRunList_StageSelection(const TString& type, const TString& ref_type, const KVUnownedList& systems, Bool_t OnlyCol)
1341 {
1342  // \returns list of runfiless which are present for data type "base_type" but not for "other_type"
1343  // for the systems (KVDBSystem pointers) in the list.
1344  //
1345  // If OnlyCol=kTRUE (kFALSE default) only systems with KVDBSystem::IsCollision()=kTRUE are considered
1346 
1347  run_index_list manquant;
1348  auto ll = GetListOfAvailableSystems(ref_type);
1349  if (ll.IsEmpty()) {
1350  //numb.Clear();
1351  Info("GetRunList_StageSelection", "No data available of type \"%s\"", ref_type.Data());
1352  return manquant;
1353  }
1354 
1355  Info("GetRunList_StageSelection", "Liste des runs presents dans \"%s\" mais absent dans \"%s\"", ref_type.Data(), type.Data());
1356 
1357  KVDBSystem* sys = 0;
1358 
1359  for (Int_t nl = 0; nl < ll.GetEntries(); nl += 1) {
1360 
1361  sys = (KVDBSystem*)ll.At(nl);
1362  if (!systems.Contains(sys)) continue;
1363  if (OnlyCol && !sys->IsCollision()) continue;
1364  auto nsys = GetRunList(type, sys);
1365  auto nsys_ref = GetRunList(ref_type, sys);
1366  Int_t nref = nsys_ref.GetNValues();
1367 
1368  nsys_ref.Remove(nsys);
1369 
1370  Info("GetRunList_StageSelection", "\nKVDBSystem : %s --> %d runs manquants sur %d : %s",
1371  sys->GetName(),
1372  nsys_ref.GetNValues(),
1373  nref,
1374  nsys_ref.AsString().Data()
1375  );
1376  manquant.Add(nsys_ref);
1377  }
1378  return manquant;
1379 }
1380 
1381 
1382 
1387 
1389 {
1390  // Returns list of runs of given type that were created with the given version of KaliVeda.
1391  //
1392  // If system!="" then only runs for the given system are considered
1393 
1394  run_index_list runs;
1395  if (sys) {
1396  auto lrun = GetListOfAvailableRunFilesForSystem(type, sys);
1397  TIter next(&lrun);
1398  KVRunFile* run;
1399  while ((run = (KVRunFile*)next())) {
1400  if (!strcmp(run->GetVersion(), version)) runs.Add(run->GetRunIndex());
1401  }
1402  return runs;
1403  }
1404  auto ll = GetListOfAvailableSystems(type);
1405  if (ll.IsEmpty()) {
1406  //numb.Clear();
1407  Info("GetRunList_VersionSelection", "No data available of type \"%s\"", type.Data());
1408  return runs;
1409  }
1410  Int_t nsys = ll.GetEntries();
1411  for (Int_t nl = 0; nl < nsys; nl += 1) {
1412  sys = (KVDBSystem*)ll.At(nl);
1413  auto lrun = GetListOfAvailableRunFilesForSystem(type, sys);
1414  TIter next(&lrun);
1415  KVRunFile* run;
1416  while ((run = (KVRunFile*)next())) {
1417  if (!strcmp(run->GetVersion(), version)) runs.Add(run->GetRunIndex());
1418  }
1419  }
1420  return runs;
1421 }
1422 
1423 
1424 
1429 
1430 void KVDataSet::CommitRunfile(const KVString& type, const run_index_t& run, TFile* file)
1431 {
1432  // Commit a runfile previously created with NewRunfile() to the repository.
1433  // Any previous version of the runfile will be deleted.
1434  // The available runs list for this data 'type' is updated.
1435 
1436  if (!fRepository) return;
1437 
1438  //keep name of file for updating available runs list
1439  TString newfile = gSystem->BaseName(file->GetName());
1440 
1441  fRepository->CommitFile(file, type, this);
1442  //update list of available datatypes of dataset,
1443  //in case this addition has created a new subdirectory
1444  CheckAvailable();
1445  //check if previous version of file exists
1446  //get name of file from available runs file
1447  //note that when the file is the first of a new subdirectory, GetAvailableRunsFile->GetFileName
1448  //will cause the available runs file to be created, and it will contain one entry:
1449  //the new file!
1450  TString oldfile = GetAvailableRunsFile(type)->GetFileName(run);
1451  if (oldfile != "" && oldfile != newfile) {
1452  //delete previous version - no confirmation
1453  fRepository->DeleteFile(this, type, oldfile.Data(),
1454  kFALSE);
1455  //was file deleted ? if so, remove entry from available runs file
1456  if (!fRepository->CheckFileStatus(this, type, oldfile.Data()))
1457  GetAvailableRunsFile(type)->Remove(run);
1458  }
1459  if (oldfile != newfile) {
1460  //add entry for new run in available runs file
1461  GetAvailableRunsFile(type)->Add(run, newfile.Data());
1462  }
1463 }
1464 
1465 
1466 
1467 
1470 
1472 {
1473  //Set pointer to data repository in which dataset is stored
1474  fRepository = dr;
1475 }
1476 
1477 
1478 
1479 
1482 
1484 {
1485  //Get pointer to data repository in which dataset is stored
1486  return fRepository;
1487 }
1488 
1489 
1490 
1491 
1496 
1498 {
1499  //Check all runs for a given datatype and make sure that only one version
1500  //exists for each runfile. If not, we print a report on the runfiles which occur
1501  //multiple times, with the associated date and file name.
1502 
1503  auto doubles = GetAvailableRunsFile(data_type)->CheckMultiRunfiles();
1504  if (doubles.empty()) {
1505  cout << "OK. No runs appear more than once." << endl;
1506  }
1507  else {
1508  cout << "Runs which appear more than once: " << endl << endl;
1509  //print dates and filenames for each run
1510 
1511  for (auto& rr : doubles) {
1512  KVList filenames, dates;
1513 
1514  //get infos for current run
1515  GetAvailableRunsFile(data_type)->GetRunInfos(rr, dates, filenames);
1516 
1517  cout << "Run " << rr << " : " << dates.GetEntries() << " files >>>>>>" << endl;
1518  for (int i = 0; i < dates.GetEntries(); i++) {
1519 
1520  cout << "\t" << ((TObjString*) filenames.At(i))->String().
1521  Data() << "\t" << ((TObjString*) dates.At(i))->String().
1522  Data() << endl;
1523 
1524  }
1525  }
1526  }
1527 }
1528 
1529 
1530 
1531 
1542 
1543 void KVDataSet::CleanMultiRunfiles(const Char_t* data_type, Bool_t confirm)
1544 {
1545  // Check all runs for a given datatype and make sure that only one version
1546  // exists for each run. If not, we print a report on the runfiles which occur
1547  // multiple times, with the associated date and file name, and then we
1548  // destroy all but the most recent version of the file in the repository, and
1549  // update the runlist accordingly.
1550  //
1551  // By default, we ask for confirmation before deleting each file.
1552  //
1553  // Call with confirm=kFALSE to delete WITHOUT CONFIRMATION (DANGER!! WARNING!!!)
1554 
1555  if (!fRepository) return;
1556 
1557  KVAvailableRunsFile* ARF = GetAvailableRunsFile(data_type);
1558  auto doubles = ARF->CheckMultiRunfiles();
1559  if (doubles.empty()) {
1560  cout << "OK. No runs appear more than once." << endl;
1561  }
1562  else {
1563  cout << "Runs which appear more than once: " << endl << endl;
1564  //print dates and filenames for each run
1565 
1566  KVList filenames, dates;
1567  for (auto& rr : doubles) {
1568  //get infos for current run
1569  ARF->GetRunInfos(rr, dates, filenames);
1570  TDatime most_recent("1998-12-25 00:00:00");
1571  Int_t i_most_recent = 0;
1572  cout << "Run " << rr << " : " << dates.GetEntries() << " files >>>>>>" << endl;
1573  for (int i = 0; i < dates.GetEntries(); i++) {
1574  //check if run is most recent
1575  TDatime rundate(((TObjString*) dates.At(i))->String().Data());
1576  if (rundate > most_recent) {
1577  most_recent = rundate;
1578  i_most_recent = i;
1579  }
1580  }
1581  //Now, we loop over the list again, this time we destroy all but the most recent
1582  //version of the runfile
1583  for (int i = 0; i < dates.GetEntries(); i++) {
1584  if (i == i_most_recent) {
1585  cout << "KEEP : ";
1586  }
1587  else {
1588  cout << "DELETE : ";
1589  }
1590  cout << "\t" << ((TObjString*) filenames.At(i))->String().
1591  Data() << "\t" << ((TObjString*) dates.At(i))->String().
1592  Data() << endl;
1593  if (i != i_most_recent) {
1594  //delete file from repository forever and ever
1595  fRepository->DeleteFile(this, data_type,
1596  ((TObjString*) filenames.At(i))->
1597  String().Data(), confirm);
1598  //remove file entry from available runlist
1599  ARF->Remove(rr,
1600  ((TObjString*) filenames.At(i))->String());
1601  }
1602  }
1603  }
1604  }
1605 }
1606 
1607 
1608 
1613 
1615 {
1616  // Similar to CleanMultiRunfiles(), but here the aim is only to remove from the
1617  // sqlite database any runfiles which are no longer physically present in the
1618  // repository i.e. they have already been deleted but our database was not updated.
1619 
1620  if (!fRepository) return;
1621 
1622  Info("CleanRunfileDataBase", "Checking for spurious duplicates (non-existent files)...");
1623 
1624  KVAvailableRunsFile* ARF = GetAvailableRunsFile(data_type);
1625 
1626  auto doubles = ARF->CheckMultiRunfiles();
1627  if (!doubles.empty()) {
1628  for (auto& ri : doubles) {
1629  // for each run/index, get full list of available files
1630  KVList dates, files;
1631  ARF->GetRunInfos(ri, dates, files);
1632  // now check that each file is physically present
1633  for (auto f : files) {
1634  TString fname = dynamic_cast<TObjString*>(f)->GetString();
1635  if (!fRepository->CheckFileStatus(this, data_type, fname)) {
1636  Info("CleanRunfileDataBase", "File %s does not exist : remove from database...", fname.Data());
1637  ARF->Remove(ri, fname);
1638  }
1639  }
1640  }
1641  }
1642  else
1643  Info("CleanRunfileDataBase", "Database is apparently consistent");
1644 }
1645 
1646 
1647 
1648 
1655 
1657  KVDataSetRepository* other_repos)
1658 {
1659  //Use this method to check whether the file of type "data_type" for run number "run"
1660  //in the data repository "other_repos" is more recent than the file contained in the data
1661  //repository corresponding to this dataset.
1662  //
1663  //Returns kFALSE if file in other repository is more recent.
1664 
1665  if (!other_repos)
1666  return kTRUE;
1667  //get dataset with same name as this one from dataset manager of other repository
1668  KVDataSet* ds = other_repos->GetDataSetManager()->GetDataSet(GetName());
1669  if (!ds) {
1670  Error("CheckRunfileUpToDate",
1671  "Dataset \"%s\" not found in repository \"%s\"", GetName(),
1672  other_repos->GetName());
1673  return kFALSE;
1674  }
1675  //compare dates of the two runfiles
1676  if (GetRunfileDate(data_type, run) < ds->GetRunfileDate(data_type, run))
1677  return kFALSE;
1678  return kTRUE;
1679 }
1680 
1681 
1682 
1683 
1690 
1692  const KVString& other_repos)
1693 {
1694  //Use this method to check whether the file of type "data_type" for run number "run"
1695  //in the data repository "other_repos" is more recent than the file contained in the data
1696  //repository corresponding to this dataset.
1697  //Returns kTRUE if no repository with name "other_repos" exists.
1698  //Returns kFALSE if file in other repository is more recent.
1699 
1700  auto _or = gDataRepositoryManager->GetRepository(other_repos);
1701  if (_or)
1702  return CheckRunfileUpToDate(data_type, run, _or);
1703  Error("CheckRunfileUpToDate",
1704  "No data repository known with this name : %s", (const char*) other_repos);
1705  return kTRUE;
1706 }
1707 
1708 
1709 
1710 
1714 
1715 void KVDataSet::CheckUpToDate(const Char_t* data_type,
1716  const Char_t* other_repos)
1717 {
1718  //Check whether all files of type "data_type" for run number "run" in the data repository
1719  //are up to date (i.e. at least as recent) as compared to the files in data repository "other_repos".
1720 
1721  if (!fRepository) return;
1722 
1723  auto _or =
1724  dynamic_cast<KVDataSetRepository*>(gDataRepositoryManager->GetRepository(other_repos));
1725  if (!_or) {
1726  Error("CheckUpToDate",
1727  "No data repository known with this name : %s", other_repos);
1728  return;
1729  }
1730  auto runlist = GetAvailableRunsFile(data_type)->GetRunList();
1731  Int_t need_update = 0;
1732  for (auto& rr : runlist) {
1733  //check run
1734  if (!CheckRunfileUpToDate(data_type, rr, _or)) {
1735  cout << " *** run " << rr << " needs update ***" <<
1736  endl;
1737  cout << "\t\tREPOSITORY: " << fRepository->
1738  GetName() << "\tDATE: " << GetRunfileDate(data_type, rr).value().AsString() << endl;
1739  cout << "\t\tREPOSITORY: " << other_repos << "\tDATE: " << _or->
1740  GetDataSetManager()->GetDataSet(GetName())->
1741  GetRunfileDate(data_type, rr).value().AsString() << endl;
1742  need_update++;
1743  }
1744  }
1745  if (!need_update) {
1746  cout << " *** All runfiles are up to date for data type " <<
1747  data_type << endl;
1748  }
1749 }
1750 
1751 
1752 
1753 
1757 
1759  const Char_t* other_repos)
1760 {
1761  //Returns list of all runs of type "data_type" which may be updated
1762  //from the repository named "other_repos". See CheckUpToDate().
1763 
1764  run_index_list updates;
1765  if (!fRepository) return updates;
1766 
1767  auto _or = gDataRepositoryManager->GetRepository(other_repos);
1768  if (!_or) {
1769  Error("CheckUpToDate",
1770  "No data repository known with this name : %s", other_repos);
1771  return updates;
1772  }
1773  auto runlist = GetAvailableRunsFile(data_type)->GetRunList();
1774  for (auto& rr : runlist) {
1775  //check run
1776  if (!CheckRunfileUpToDate(data_type, rr, _or)) {
1777  //run is out of date
1778  updates.Add(rr);
1779  }
1780  }
1781  return updates;
1782 }
1783 
1784 
1785 
1786 
1791 
1793  const KVDBSystem* system) const
1794 {
1795  //Returns list of all files available for given "data_type"
1796  //
1797  //If a pointer to a reaction system is given, only files for the given system will be included in the list.
1798 
1799  if (!fRepository || !HasDataType(data_type)) {
1800  Error("GetRunList",
1801  "No data of type %s available. Runlist will be empty.",
1802  data_type);
1803  return {};
1804  }
1805 
1806  return GetAvailableRunsFile(data_type)->GetRunList(system);
1807 }
1808 
1809 
1810 
1811 
1842 
1844 {
1845  //This method returns a pointer to the available analysis task whose description (title) contains
1846  //all of the whitespace-separated keywords (which may be regular expressions)
1847  //given in the string "keywords". The comparison is case-insensitive.
1848  //
1849  //WARNING: this method can only be used to access analysis tasks that are
1850  //available for this dataset, i.e. for which the corresponding prerequisite data type
1851  //is available in the repository.
1852  //For unavailable data/tasks, use GetAnalysisTaskAny(const Char_t*).
1853  //
1854  //EXAMPLES
1855  //Let us suppose that the current dataset has the following list of tasks:
1856  //~~~
1857  // root [2] gDataSet->Print("tasks")
1858  // 1. Event reconstruction from raw data (raw->recon)
1859  // 2. Analysis of raw data
1860  // 3. Identification of reconstructed events (recon->ident)
1861  // 4. Analysis of reconstructed events (recon)
1862  // 5. Analysis of partially identified & calibrated reconstructed events (ident)
1863  // 6. Analysis of fully calibrated physical data (root)
1864  //~~~
1865  //Then the following will occur:
1866  //~~~
1867  // root [14] gDataSet->GetAnalysisTask("raw->recon")->Print()
1868  // KVDataAnalysisTask : Event reconstruction from raw data (raw->recon)
1869  //
1870  // root [10] gDataSet->GetAnalysisTask("analysis root")->Print()
1871  // KVDataAnalysisTask : Analysis of fully calibrated physical data (root)
1872  //~~~
1873 
1874  //case-insensitive search for matches in list based on 'title' attribute
1875  return (KVDataAnalysisTask*)fTasks.FindObjectAny("title", keywords, kTRUE, kFALSE);
1876 }
1877 
1878 
1879 
1880 
1882 
1884 {
1885  if (!dat->WithUserClass()) {
1886  Error("MakeAnalysisClass",
1887  "No user class required for analysis task \"%s\"", dat->GetTitle());
1888  return false;
1889  }
1890 
1891  //all analysis base classes must define a static Make(const Char_t * classname)
1892  //which generates the skeleton class files.
1893 
1894  TClass* cl = nullptr;
1895  //has the user base class for the task been compiled and loaded ?
1897  else
1898  return false;
1899 
1900  //set up call to static Make method
1901  unique_ptr<TMethodCall> methcall(new TMethodCall(cl, "Make", Form("\"%s\"", classname)));
1902 
1903  if (!methcall->IsValid()) {
1904  Error("MakeAnalysisClass", "static Make(const Char_t*) method for class %s is not valid",
1905  cl->GetName());
1906  return false;
1907  }
1908 
1909  //generate skeleton class
1910  methcall->Execute();
1911 
1912  return true;
1913 }
1914 
1915 
1916 
1952 
1953 TObject* KVDataSet::file_opener(const TString& type, const TString& fname, Option_t* opt)
1954 {
1955  // For the give datatype 'type', open file using fullpath 'fname' and whatever kind of class is defined
1956  // to be used for opening files of this datatype. Returns file handle as a TObject* pointer.
1957  //
1958  //The default base classes for each type are defined as in this example:
1959  //
1960  // # Default base classes for reading runfiles of different types
1961  // DataSet.RunFileClass.raw: KVRawDataReader
1962  // DataSet.RunFileClass.recon: TFile
1963  // DataSet.RunFileClass.ident: TFile
1964  // DataSet.RunFileClass.root: TFile
1965  //
1966  //A different base class can be defined for a specific dataset/datatype
1967  //by adding a line to your $HOME/.kvrootrc like this:
1968  //
1969  //name_of_dataset.DataSet.RunFileClass.data_type: BaseClassName
1970  //
1971  //The actual class to be used is then defined by plugins, for example
1972  //
1973  //name_of_dataset.DataSet.RunFileClass.data_type: plugin_name
1974  //
1975  //where 'plugin_name' is one of the known plugins for the default base class for the given data_type,
1976  //i.e. if data_type="raw" we could use one of either "GANIL" or "MFM" as plugin_name:
1977  //
1978  //Plugin.KVRawDataReader: GANIL KVGANILDataReader kaliveda-core "KVGANILDataReader()"
1979  //+Plugin.KVRawDataReader: MFM KVMFMDataFileReader kaliveda-core "KVMFMDataFileReader()"
1980  //
1981  //If no plugin is found for the base class defined by DataSet.RunFileClass, the base class is used.
1982  //
1983  //To actually open the file, each base class & plugin must define a method
1984  //~~~{.cpp}
1985  // static BaseClass* Open(const Char_t* path, Option_t* opt="", ...)
1986  //~~~
1987  //which takes the full path to the file as argument (any other arguments taking default options)
1988  //and returns a pointer of the BaseClass type to the created object which can be used to read the file.}
1989 
1990  KVString plugin_class = GetDataSetEnv(Form("DataSet.RunFileClass.%s", type.Data()));
1991 
1992  TPluginHandler* ph = nullptr;
1993  KVString base_class;
1994  if (IsThisAPlugin(plugin_class, base_class)) {
1995 
1996  //look for plugin specific to dataset & type
1997  ph = LoadPlugin(base_class, plugin_class);
1998 
1999  }
2000  else
2001  base_class = plugin_class;
2002  TClass* cl;
2003  if (!ph) {
2004  //no plugin - use base class
2005  cl = TClass::GetClass(base_class.Data());
2006  }
2007  else {
2008  cl = TClass::GetClass(ph->GetClass());
2009  }
2010 
2011  //set up call to static Open method
2012  std::unique_ptr<TMethodCall> methcall;
2013  if (strcmp(opt, "")) {
2014  //Open with option
2015  methcall = std::make_unique<TMethodCall>(cl, "Open", Form("\"%s\", \"%s\"", fname.Data(), opt));
2016  }
2017  else {
2018  //Open without option
2019  methcall = std::make_unique<TMethodCall>(cl, "Open", Form("\"%s\"", fname.Data()));
2020  }
2021 
2022  if (!methcall->IsValid()) {
2023  if (ph) Error("OpenDataSetFile", "Open method for class %s is not valid", ph->GetClass());
2024  else Error("OpenDataSetFile", "Open method for class %s is not valid", base_class.Data());
2025  return nullptr;
2026  }
2027 
2028  //open the file
2029  Long_t retval;
2030  methcall->Execute(retval);
2031  return ((TObject*)(retval));
2032 }
2033 
2034 
2035 
2048 
2049 bool KVDataSet::MakeAnalysisClass(const Char_t* task, const Char_t* classname)
2050 {
2051  //Create a skeleton analysis class to be used for analysis of the data belonging to this dataset.
2052  //
2053  // task = keywords contained in title of analysis task (see GetAnalysisTask(const Char_t*))
2054  // (you do not need to include 'analysis', it is added automatically)
2055  // classname = name of new analysis class
2056  //
2057  //Example:
2058  // MakeAnalysisClass("raw", "MyRawDataAnalysis")
2059  // --> make skeleton raw data analysis class in files MyRawDataAnalysis.cpp & MyRawDataAnalysis.h
2060  // MakeAnalysisClass("fully calibrated", "MyDataAnalysis")
2061  // --> make skeleton data analysis class in files MyDataAnalysis.cpp & MyDataAnalysis.h
2062 
2063  KVString _task = task;
2064  if (!_task.Contains("nalysis")) _task += " analysis";
2065  //We want to be able to write analysis classes even when we don't have any data
2066  //to analyse. Therefore we use GetAnalysisTaskAny.
2067  auto dat = GetAnalysisTaskAny(_task.Data());
2068  if (!dat) {
2069  Error("MakeAnalysisClass",
2070  "called for unknown or unavailable analysis task : %s", _task.Data());
2071  return false;
2072  }
2073  return make_analysis_class(dat, classname);
2074 }
2075 
2076 
2077 
2084 
2085 bool KVDataSet::MakeAnalysisClass(int task, const Char_t* classname)
2086 {
2087  //Create a skeleton analysis class to be used for analysis of the data belonging to this dataset.
2088  //
2089  // task = index of analysis task as shown in KVDataSet::Print("tasks")
2090  // classname = name of new analysis class
2091  //
2092 
2093  auto dat = GetAnalysisTask(task);
2094  if (!dat) {
2095  Error("MakeAnalysisClass",
2096  "called for unknown or unavailable analysis task index : %d", task);
2097  return false;
2098  }
2099  return make_analysis_class(dat, classname);
2100 }
2101 
2102 
2103 
2104 
2108 
2109 Bool_t KVDataSet::OpenDataSetFile(const Char_t* filename, ifstream& file)
2110 {
2111  // Look for (and open for reading, if found) the named file in the directory which
2112  // contains the files for this dataset (given by GetDataSetDir())
2113 
2114  return OpenDataSetFile(GetName(), filename, file);
2115 }
2116 
2117 
2118 
2122 
2123 Bool_t KVDataSet::OpenDataSetFile(const TString& dataset, const Char_t* filename, ifstream& file)
2124 {
2125  // Static method to look for (and open for reading, if found) the named file in the directory which
2126  // contains the files for the dataset
2127 
2128  TString datasetdir = KVBase::GetDataSetEnv(dataset, "DataSet.Directory", dataset);
2129  if (gSystem->IsAbsoluteFileName(datasetdir)) {
2130  // dataset directory is outside of standard KV installation directories
2131  // use absolute path to search for file
2132  TString abspath;
2133  abspath.Form("%s/%s", datasetdir.Data(), filename);
2134  return SearchAndOpenKVFile(abspath, file);
2135  }
2136  // dataset directory is a subdirectory of GetDATADIRFilePath()
2137  return SearchAndOpenKVFile(filename, file, datasetdir);
2138 }
2139 
2140 
2141 
2145 
2147 {
2148  // Find a file in the dataset directory (given by GetDataSetDir())
2149  // Returns full path to file if found, empty string if not
2150 
2151  return GetFullPathToDataSetFile(GetName(), filename);
2152 }
2153 
2154 
2155 
2159 
2161 {
2162  // Static method to find a file in the dataset directory (given by GetDataSetDir())
2163  // Returns full path to file if found, empty string if not
2164 
2165  TString fullpath;
2166  TString datasetdir = KVBase::GetDataSetEnv(dataset, "DataSet.Directory", dataset);
2167  if (!SearchKVFile(filename, fullpath, datasetdir)) {
2168  ::Warning("KVDataSet::GetFullPathToDataSetFile", "File %s not found in dataset subdirectory %s", filename, datasetdir.Data());
2169  fullpath = "";
2170  }
2171  return fullpath;
2172 }
2173 
2174 
2175 
2179 
2180 Bool_t KVDataSet::FindDataSetFile(const TString& dataset, const Char_t* filename)
2181 {
2182  // Static method to find a file in the dataset directory (given by GetDataSetDir())
2183  // Returns kTRUE if found, kFALSE if not
2184 
2185  TString fullpath;
2186  TString datasetdir = KVBase::GetDataSetEnv(dataset, "DataSet.Directory", dataset);
2187  return SearchKVFile(filename, fullpath, datasetdir);
2188 }
2189 
2190 
2191 
2195 
2197 {
2198  // Find a file in the dataset directory (given by GetDataSetDir())
2199  // Returns kTRUE if found, kFALSE if not
2200 
2201  return FindDataSetFile(GetName(), filename);
2202 }
2203 
2204 
2205 
2206 
2215 
2217 {
2218  //This method returns the analysis task whose description (title) contains
2219  //all of the whitespace-separated keywords (which may be regular expressions)
2220  //given in the string "keywords". The comparison is case-insensitive.
2221  //The analysis task does not need to be "available", i.e. the associated prerequisite
2222  //data type does not have to be present in the repository (see GetAnalysisTask).
2223  //
2224  // If no task is found, returns nullptr
2225 
2226  KVDataAnalysisTask* tsk = (KVDataAnalysisTask*)fAllTasks.FindObjectAny("title", keywords, kTRUE, kFALSE);
2227  if (!tsk) {
2228  Error("GetAnalysisTaskAny", "No task found with the following keywords in its title : %s", keywords);
2229  }
2230  return tsk;
2231 }
2232 
2233 
2234 
2235 
2242 
2244 {
2245  // Returns kTRUE if database needs to be regenerated from source files,
2246  // i.e. if source files are more recent than DataBase.root
2247  //
2248  // In case no directory exists for dataset (dataset added 'on the fly')
2249  // we create the directory and fill it with dummy files (Makefile, Runlist.csv, Systems.dat)
2250 
2251  TString pwd = gSystem->pwd();
2252 
2253  TString path = "";
2254  if (!SearchKVFile(GetDataSetDir(), path)) {
2255  // dataset directory doesn't exist - create it
2256  Info("DataBaseNeedsUpdate", "%s: Creating new dataset directory %s",
2257  GetName(), GetDataSetDir());
2258  if (gSystem->mkdir(GetDataSetDir())) {
2259  // problem creating directory
2260  Error("DataBaseNeedsUpdate",
2261  "%s: Dataset directory %s does not exist and cannot be created ?",
2262  GetName(), GetDataSetDir());
2263  return kFALSE;
2264  }
2265  // create dummy files
2266  SearchKVFile(GetDataSetDir(), path); // get full path
2267  path += "/";
2268  TString filename = path + "Makefile";
2269  ofstream of1(filename.Data());
2270  of1 << "$(KV_WORK_DIR)/db/" << GetName() << "/DataBase.root : Runlist.csv Systems.dat" << endl;
2271  of1 << "\t@echo Database needs update" << endl;
2272  of1.close();
2273  filename = path + "Runlist.csv";
2274  ofstream of2(filename.Data());
2275  of2 << "# Automatically generated dummy Runlist.csv file" << endl;
2276  of2.close();
2277  filename = path + "Systems.dat";
2278  ofstream of3(filename.Data());
2279  of3 << "# Automatically generated dummy Systems.dat file" << endl;
2280  of3.close();
2281  }
2282  gSystem->cd(GetDataSetDir());
2283  TString cmd = "make -q";
2284  Int_t ret = gSystem->Exec(cmd.Data());
2285  gSystem->cd(pwd.Data());
2286  return (ret != 0);
2287 }
2288 
2289 
2290 
2307 
2309 {
2310  // Returns name of output repository for given task.
2311  // By default it is the name of the repository associated with this dataset,
2312  // but can be changed by the following environment variables:
2313  //
2314  // [repository].DefaultOutputRepository: [other repository]
2315  // - this means that all tasks carried out on data in [repository]
2316  // will have their output files placed in [other repository]
2317  //
2318  // [taskname].DataAnalysisTask.OutputRepository: [other repository]
2319  // - this means that for [taskname], any output files will
2320  // be placed in [other repository]
2321  //
2322  // [dataset].[taskname].DataAnalysisTask.OutputRepository: [other repository]
2323  // - this means that for given [dataset] & [taskname],
2324  // any output files will be placed in [other repository]
2325 
2326  if (gEnv->Defined(Form("%s.DataRepository.DefaultOutputRepository", GetRepository()->GetName())))
2327  return TString(gEnv->GetValue(Form("%s.DataRepository.DefaultOutputRepository", GetRepository()->GetName()), ""));
2328  TString orep = GetDataSetEnv(Form("%s.DataAnalysisTask.OutputRepository", taskname), GetRepository()->GetName());
2329  return orep;
2330 }
2331 
2332 
2333 
2334 
2337 
2338 void KVDataSet::CopyRunfilesFromRepository(const Char_t* type, const run_index_list& runs, const Char_t* destdir)
2339 {
2340  // Copies the runfiles of given "type" into the local directory "destdir".
2341 
2342  auto repo = GetRepository();
2343  for (auto& run : runs) {
2344  TString filename = GetRunfileName(type, run);
2345  TString destpath;
2346  AssignAndDelete(destpath, gSystem->ConcatFileName(destdir, filename));
2347  repo->CopyFileFromRepository(this, type, filename, destpath);
2348  }
2349 }
2350 
2351 
2352 
2353 
2357 
2358 void KVDataSet::CopyRunfilesToRepository(const Char_t* type, const run_index_list& runs, const Char_t* destrepo)
2359 {
2360  // Copies the runfiles of given "type" from the data repository associated
2361  // with this dataset into the local repository "destrepo".
2362 
2363  auto repo = GetRepository();
2364  auto dest_repo = dynamic_cast<KVDataSetRepository*>(gDataRepositoryManager->GetRepository(destrepo));
2365 
2366  if (!dest_repo) {
2367  Error("CopyRunfilesToRepository", "Unknown destination repository : %s", destrepo);
2368  gDataRepositoryManager->Print();
2369  return;
2370  }
2371 
2372  KVDataSet* dest_ds = dest_repo->GetDataSetManager()->GetDataSet(GetName());
2373  dest_repo->CreateAllNeededSubdirectories(dest_ds, type);
2374  for (auto& run : runs) {
2375  TString filename = GetRunfileName(type, run);
2376  TString destpath = dest_repo->GetFullPathToTransferFile(dest_ds, type, filename);
2377  repo->CopyFileFromRepository(this, type, filename, destpath);
2378  }
2379 }
2380 
2381 
int Int_t
long Long_t
ROOT::R::TRInterface & r
#define f(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
#define gDirectory
R__EXTERN TEnv * gEnv
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 filename
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,...)
void AssignAndDelete(TString &target, char *tobedeleted)
R__EXTERN TSystem * gSystem
Handles lists of available runs for different datasets and types of data.
void GetRunInfos(const run_index_t &run, KVList &dates, KVList &names)
virtual void Remove(const run_index_t &run, const KVString &filename="")
Remove from the db ALL entries corresponding to the given run/index (and filename if given)
std::forward_list< run_index_t > CheckMultiRunfiles()
Returns a list with all run/indexes for which more than one file is in the available runs db.
virtual void Add(const run_index_t &run, const KVString &filename)
static ValType GetDataSetEnv(const KVString &dataset, const KVString &type, const ValType &defval)
Definition: KVBase.h:306
Database class used to store information on different colliding systems studied during an experiment....
Definition: KVDBSystem.h:51
Bool_t IsCollision() const
retourne kTRUE, si le systeme est une collision ie projectile+cible
Definition: KVDBSystem.cpp:128
Define and manage data analysis tasks.
virtual void SetDataAnalyser(const Char_t *d)
virtual Bool_t WithUserClass() const
virtual void SetPrereq(const Char_t *p)
virtual void SetStatusUpdateInterval(Long64_t n)
virtual const Char_t * GetUserBaseClass() const
virtual Bool_t CheckUserBaseClassIsLoaded() const
void SetExtraAClicIncludes(const KVString &list)
virtual const Char_t * GetPrereq() const
virtual void SetUserBaseClass(const Char_t *d)
void Print(Option_t *opt="") const
KVDataSetRepository * GetRepository(const TString &name) const
KVDataSet * GetDataSet(Int_t) const
Return pointer to DataSet using index in list of all datasets, index>=0.
A repository for experimental datasets.
KVDataSetManager * GetDataSetManager() const
Return pointer to data set manager for this repository.
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition: KVDataSet.h:146
std::optional< TDatime > GetRunfileDate(const KVString &type, const run_index_t &run)
Definition: KVDataSet.cpp:926
TString GetFullPathToRunfile(const KVString &type, const run_index_t &run) const
Definition: KVDataSet.cpp:882
TString GetFullPathToDB() const
Definition: KVDataSet.cpp:153
void ls(Option_t *opt="") const override
Print dataset information.
Definition: KVDataSet.cpp:407
TString GetOutputRepository(const Char_t *taskname) const
Definition: KVDataSet.cpp:2308
void OpenDBFile(const Char_t *full_path_to_dbfile) const
Open the database from a file on disk.
Definition: KVDataSet.cpp:127
void SetRepository(KVDataSetRepository *)
Set pointer to data repository in which dataset is stored.
Definition: KVDataSet.cpp:1471
TString GetDBName() const
Definition: KVDataSet.cpp:112
void CheckMultiRunfiles(const Char_t *data_type)
Definition: KVDataSet.cpp:1497
Bool_t CheckRunfileAvailable(const KVString &type, const run_index_t &run)
Definition: KVDataSet.cpp:1023
virtual const Char_t * GetBaseFileName(const Char_t *type, const run_index_t &run) const
Definition: KVDataSet.cpp:1056
void CleanRunfileDataBase(const Char_t *data_type)
Definition: KVDataSet.cpp:1614
void CheckUpToDate(const Char_t *data_type, const Char_t *other_repos)
Definition: KVDataSet.cpp:1715
run_index_list GetRunList(const Char_t *data_type, const KVDBSystem *sys=0) const
Definition: KVDataSet.cpp:1792
void OpenDataBase(const TString &="") const
Definition: KVDataSet.cpp:319
TString GetFullPathToDataSetFile(const Char_t *filename) const
Definition: KVDataSet.cpp:2146
void CopyRunfilesFromRepository(const Char_t *type, const run_index_list &runs, const Char_t *destdir)
Copies the runfiles of given "type" into the local directory "destdir".
Definition: KVDataSet.cpp:2338
run_index_list GetRunList_DateSelection(const TString &type, const KVUnownedList &systems, std::optional< KVDatime > min_date=std::nullopt, std::optional< KVDatime > max_date=std::nullopt)
Definition: KVDataSet.cpp:1232
const Char_t * GetDataSetDir() const
Definition: KVDataSet.cpp:753
void CommitRunfile(const KVString &type, const run_index_t &run, TFile *file)
Definition: KVDataSet.cpp:1430
void AddAvailableDataType(const Char_t *)
Definition: KVDataSet.cpp:515
KVUniqueNameList GetSystemsForRunFiles(const TString &datatype, const run_index_list &) const
Definition: KVDataSet.cpp:680
bool make_analysis_class(const KVDataAnalysisTask *, const Char_t *classname)
Definition: KVDataSet.cpp:1883
KVDataAnalysisTask * GetAnalysisTask(Int_t) const
Definition: KVDataSet.cpp:581
KVAvailableRunsFile * GetAvailableRunsFile(const TString &type) const
Definition: KVDataSet.cpp:49
void SaveDataBase() const
Definition: KVDataSet.cpp:203
KVDataAnalysisTask * GetAnalysisTaskAny(const Char_t *keywords) const
Definition: KVDataSet.cpp:2216
void SetAnalysisTasks(const KVSeqCollection *)
Definition: KVDataSet.cpp:532
TFile * NewRunfile(const KVString &type, const run_index_t &run)
Definition: KVDataSet.cpp:1129
KVList GetListOfAvailableRunFilesForSystem(const TString &datatype, KVDBSystem *systol)
Definition: KVDataSet.cpp:636
void CheckAvailable()
Definition: KVDataSet.cpp:473
void DeleteRunfile(const KVString &type, const run_index_t &run, Bool_t confirm=kTRUE)
Definition: KVDataSet.cpp:1154
Int_t GetNtasks() const
Definition: KVDataSet.cpp:566
TObject * file_opener(const TString &, const TString &, Option_t *="")
Definition: KVDataSet.cpp:1953
run_index_list GetRunList_VersionSelection(const TString &type, const TString &version, KVDBSystem *sys=0)
Definition: KVDataSet.cpp:1388
KVExpDB * GetDataBase(const TString &opt="") const
Definition: KVDataSet.cpp:288
void DeleteRunfiles(const Char_t *type, const run_index_list &lrun={}, Bool_t confirm=kTRUE)
Definition: KVDataSet.cpp:1201
Bool_t CheckRunfileUpToDate(const KVString &data_type, const run_index_t &run, KVDataSetRepository *other_repos)
Definition: KVDataSet.cpp:1656
TObject * open_runfile(const KVString &type, const run_index_t &run)
Definition: KVDataSet.cpp:825
void CopyRunfilesToRepository(const Char_t *type, const run_index_list &runs, const Char_t *destrepo)
Definition: KVDataSet.cpp:2358
KVDataSetRepository * GetRepository() const
Get pointer to data repository in which dataset is stored.
Definition: KVDataSet.cpp:1483
KVString GetRunfileName(const KVString &type, const run_index_t &run) const
Definition: KVDataSet.cpp:902
Bool_t DataBaseNeedsUpdate() const
Definition: KVDataSet.cpp:2243
Bool_t OpenDataSetFile(const Char_t *filename, std::ifstream &file)
void SetDataSetSpecificTaskParameters(KVDataAnalysisTask *) const
Check configuration variables to see if the task parameters have been "tweaked" for the dataset.
Definition: KVDataSet.cpp:178
run_index_list GetRunList_StageSelection(const TString &other_type, const TString &base_type, KVDBSystem *sys=0, Bool_t OnlyCol=kFALSE)
Definition: KVDataSet.cpp:1286
void cd() const
Definition: KVDataSet.cpp:775
void WriteDBFile(const Char_t *full_path_to_dbfile) const
Write the database to disk.
Definition: KVDataSet.cpp:255
void Print(Option_t *opt="") const override
Definition: KVDataSet.cpp:430
void SetName(const char *name) override
Definition: KVDataSet.cpp:715
void UpdateAvailableRuns(const KVString &type)
Definition: KVDataSet.cpp:1100
run_index_list GetUpdatableRuns(const Char_t *data_type, const Char_t *other_repos)
Definition: KVDataSet.cpp:1758
bool MakeAnalysisClass(const Char_t *task, const Char_t *classname)
Definition: KVDataSet.cpp:2049
KVDataSet()
Default constructor.
Definition: KVDataSet.cpp:35
std::optional< run_index_t > GetRunNumberFromFileName(const TString &datatype, const TString &filename)
Definition: KVDataSet.cpp:975
void CleanMultiRunfiles(const Char_t *data_type, Bool_t confirm=kTRUE)
Definition: KVDataSet.cpp:1543
static Bool_t FindDataSetFile(const TString &dataset, const Char_t *filename)
Definition: KVDataSet.cpp:2180
KVUnownedList GetListOfAvailableSystems(const TString &datatype)
Definition: KVDataSet.cpp:596
TString GetDBFileName() const
Definition: KVDataSet.cpp:82
Extension of TDatime to handle various useful date formats.
Definition: KVDatime.h:33
Base class to describe database of an experiment ,,.
Definition: KVExpDB.h:61
virtual void cd()
Definition: KVExpDB.cpp:757
static KVExpDB * MakeDataBase(const Char_t *name, const Char_t *datasetdir, Bool_t minimal=false)
Definition: KVExpDB.cpp:778
Extended TList class which owns its objects by default.
Definition: KVList.h:22
Description of an individual data file in an experimental dataset.
Definition: KVRunFile.h:19
const Char_t * GetVersion() const
Definition: KVRunFile.h:84
const run_index_t & GetRunIndex() const
Definition: KVRunFile.h:56
KaliVeda extensions to ROOT collection classes.
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
Optimised list in which named objects can only be placed once.
Extended TList class which does not own its objects by default.
Definition: KVUnownedList.h:20
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
virtual Int_t GetEntries() const
Bool_t Contains(const char *name) const
const char * AsSQLString() const
virtual Bool_t cd()
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
Bool_t Defined(const char *name) const
TObject * FindObject(const char *name) const override
virtual void SetTitle(const char *title="")
const char * GetName() const override
const char * GetTitle() const override
virtual void SetName(const char *name)
const char * GetClass() const
const char * Data() const
void ToUpper()
void Form(const char *fmt,...)
TString & Remove(EStripType s, char c)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
Bool_t cd(const char *path)
const char * pwd()
virtual int Chmod(const char *file, UInt_t mode)
virtual const char * DirName(const char *pathname)
virtual char * ConcatFileName(const char *dir, const char *name)
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
virtual Int_t Exec(const char *shellcmd)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
virtual const char * BaseName(const char *pathname)
virtual Bool_t IsAbsoluteFileName(const char *dir)
List of runfiles specified by run number and file index ,.
Int_t GetEntries() const
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
TString as_string() const
Definition: run_index.h:95
int index(int no_index=-1) const
Definition: run_index.h:55
bool has_index() const
Definition: run_index.h:59
const Int_t n
void Error(const char *location, const char *fmt,...)
void Info(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
void update(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData, double factorWeightDecay, EnumRegularization regularization)
const char * String
v
TArc a
ClassImp(TPyArg)