21 #define CHMODE(u,g,o) ((u << 6) + (g << 3) + o)
39 runlist_lock.SetTimeout(60);
40 runlist_lock.SetSuspend(5);
41 runlist_lock.SetSleeptime(1);
88 KVAvailableRunsFile::~KVAvailableRunsFile()
115 Error(
"GetFileName",
"Dataset has not been set for this file.");
124 return filename.
Data();
162 Error(
"GetFilePath",
"Dataset has not been set for this file.");
181 return filepath.
Data();
215 Error(
"CheckDirectoryForAvailableRunsFile",
"cannot create directory %s - check access permissions",
GetFilePath());
222 Error(
"CheckDirectoryForAvailableRunsFile",
"directory %s is not writable - check access permissions",
GetFilePath());
262 Error(
"IsRunFileName",
"No default format set for datatype: %s",
267 if (fmt.
Contains(
"%I") && (imult < 0)) {
268 Error(
"IsRunFileName",
"No index multiplier set for datatype: %s with format: %s",
356 bool with_index = fmt.
Contains(
"%I");
357 bool two_part_date =
false;
358 bool got_date =
false;
362 if (np_fmt == np_fn || (with_index && np_fn == np_fmt - 1)) {
363 _file.
Begin(separators);
364 fmt.
Begin(separators);
365 int index(0), run(0);
366 char date1[100], date2[100];
369 while (!_file.
End()) {
377 sscanf(run_part.
Data(), fmt_part.
Data(), &run, date1);
381 sscanf(run_part.
Data(), fmt_part.
Data(), &run);
385 sscanf(run_part.
Data(), fmt_part.
Data(), &index);
387 else if (fmt_part.
Contains(
"%D1")) {
389 sscanf(run_part.
Data(), fmt_part.
Data(), date1);
392 else if (fmt_part.
Contains(
"%D2")) {
394 sscanf(run_part.
Data(), fmt_part.
Data(), date2);
399 sscanf(run_part.
Data(), fmt_part.
Data(), date1);
403 if (with_index) run = index_multiplier * run + index;
516 if (!no_existing_file) {
530 cout << endl <<
"Updating runlist : " << flush;
537 TIter next(dir_list);
543 unique_ptr<KVExpDB> db_garbage;
547 db_garbage.reset(db);
549 while ((objs = (
KVBase*) next())) {
564 if (!no_existing_file) {
588 Info(
"Update",
"the current run [%s] is not in database", objs->
GetName());
596 Warning(
"Update",
"%s GetFileInfo return kFALSE", objs->
GetName());
603 cout << '>
' << flush;
606 cout << " DONE" << endl;
611 if (CheckDirectoryForAvailableRunsFile()) {
613 if (no_existing_file) {
614 //use "lockfile" to make sure nobody else tries to modify available_runs file
615 //while we are working on it
616 if (!runlist_lock.Lock(runlist.Data())) return;
619 //copy temporary file to available runs file directory, overwrite previous
620 gSystem->CopyFile(tmp_file_path, runlist, kTRUE);
621 //set access permissions to 664
622 gSystem->Chmod(runlist.Data(), CHMODE(6, 6, 4));
626 runlist_lock.Release();
629 gSystem->Unlink(tmp_file_path);
642 Bool_t KVAvailableRunsFile::GetRunInfo(Int_t run, TDatime& modtime,
645 //Look for a given run number in the file, and read the file's modification date/time and filename
654 if (filenames.GetEntries() == 1) {
659 else if (filenames.GetEntries() > 1) {
661 "Multiple versions of this runfile exist in the repository. Infos for most recent file will be returned.");
663 "You should clean the repository using KVDataSet::CleanMultiRunfiles.");
665 TDatime most_recent(
"1998-12-25 00:00:00");
666 Int_t i_most_recent = 0;
667 for (
int i = 0; i < dates.GetEntries(); i++) {
670 if (rundate > most_recent) {
671 most_recent = rundate;
706 Error(
"GetRunInfos",
"Error opening available runs file");
718 if (
line.BeginsWith(
Form(
"%d|", run))) {
721 unique_ptr<TObjArray> toks(
line.Tokenize(
'|'));
731 dates->
Add(toks->At(1)->Clone());
733 files->
Add(toks->At(2)->Clone());
757 Error(
"CheckAvailable",
"Error opening available runs file");
766 if (
line.BeginsWith(
Form(
"%d|", run))) {
885 Error(
"GetListOfAvailableSystems",
886 "Error opening available runs file");
892 Int_t good_lines = 0;
897 TString kvversion, username, filename;
899 unique_ptr<KVExpDB> garbage_db;
902 garbage_db.reset(db);
907 unique_ptr<TObjArray> toks(fLine.
Tokenize(
'|'));
908 if (toks->GetSize()) {
916 fRunNumber = kvs.
Atoi();
917 kvversion = username =
"";
922 if (toks->GetEntries() > 3) {
923 kvversion = ((
TObjString*) toks->At(3))->GetString();
924 username = ((
TObjString*) toks->At(4))->GetString();
936 sys_list =
new TList;
958 sys_list =
new TList;
972 if (sys_list && sys_list->
GetSize() > 1)
976 Error(
"GetListOfAvailableSystems",
977 "Available runs file is empty or absent");
1000 Error(
"UpdateInfos",
"Error opening available runs file");
1016 if (
line.BeginsWith(
Form(
"%d|", run))) {
1018 unique_ptr<TObjArray> toks(
line.Tokenize(
'|'));
1021 if (ReadFileName != FileName) {
1023 tmp_file <<
line.Data() << endl;
1027 tmp_file << run <<
"|" << ((
TObjString*) toks->At(1))->
String() <<
"|" << filename <<
"|" << kvversion <<
"|" << username << endl;
1033 tmp_file <<
line.Data() << endl;
1075 Error(
"Remove",
"Error opening available runs file");
1084 Bool_t withFileName = (FileName !=
"");
1090 if (!withFileName) {
1093 if (!
line.BeginsWith(
Form(
"%d|", run))) {
1095 tmp_file <<
line.Data() << endl;
1101 if (
line.BeginsWith(
Form(
"%d|", run))) {
1103 unique_ptr<TObjArray> toks(
line.Tokenize(
'|'));
1107 if (ReadFileName != FileName) {
1109 tmp_file <<
line.Data() << endl;
1115 tmp_file <<
line.Data() << endl;
1157 Error(
"Add",
"Error opening available runs file");
1169 tmp_file <<
line.Data() << endl;
1189 tmp_file << run <<
'|' << modt.
1190 AsSQLString() <<
'|' << filename <<
'|' <<
GetKVVersion() <<
'|' << userinfo->
fUser << endl;
1229 Warning(
"OpenAvailableRunsFile",
"runlist file does not exist...");
1232 Error(
"OpenAvailableRunsFile",
1233 "Something weird: I just made the available runlist file, but I still can't open it!");
1299 Error(
"GetRunList",
"Cannot open available runs file");
1308 unique_ptr<KVExpDB> garbage_db;
1311 garbage_db.reset(db);
1318 fRunNumber = kvs.
Atoi();
1326 runs.
Add(fRunNumber);
1331 runs.
Add(fRunNumber);
1376 Error(
"ReadFile",
"Cannot open available runs file");
1385 Int_t line_number = 1;
1394 unique_ptr<TObjArray> toks(fLine.
Tokenize(
'|'));
1400 Int_t nfields = toks->GetEntries();
1403 Warning(
"ReadFile",
"Strange '/' symbol in run number (line:%d)!!!", line_number);
1409 fRunNumber = kvs.
Atoi();
1411 Warning(
"ReadFile",
"Less than 2 fields in entry for run %d (line:%d)???", fRunNumber, line_number);
1429 for (
Int_t ii = 0; ii < Occurs; ii++) {
1431 if (olddate == datestring) {
1433 duplicate_lines.
Add(line_number);
1452 kvversion = ((
TObjString*) toks->At(3))->GetString();
1453 username = ((
TObjString*) toks->At(4))->GetString();
1465 Info(
"ReadFile",
"There were %d duplicate entries in available runs file, they will be removed", duplicate_lines.
GetNValues());
1491 if (!NVL)
return NULL;
1493 for (OccNum = 0; OccNum < Occurs; OccNum++) {
1517 for (
Int_t OccNum = 0; OccNum < Occurs; OccNum++) {
1518 if (NVL->
IsValue(
Form(
"Filename[%d]", OccNum), filename)) {
1539 Error(
"Remove",
"Error opening available runs file");
1550 Int_t line_number = 1;
1553 lines_to_be_removed.
Begin();
1554 Int_t next_line_to_remove = 0;
1555 if (!lines_to_be_removed.
End()) next_line_to_remove = lines_to_be_removed.
Next();
1559 if (line_number != next_line_to_remove)
1560 tmp_file <<
line.Data() << endl;
1562 if (!lines_to_be_removed.
End()) next_line_to_remove = lines_to_be_removed.
Next();
void AssignAndDelete(TString &target, char *tobedeleted)
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Handles lists of available runs for different datasets and types of data.
virtual void CloseAvailableRunsFile()
Bool_t CheckDirectoryForAvailableRunsFile()
virtual void Add(Int_t run, const Char_t *filename)
virtual Bool_t GetRunInfo(Int_t run, TDatime &modtime, TString &filename)
Bool_t ExtractDateFromFileName(const Char_t *name, KVDatime &date)
const Char_t * GetDataType() const
KVNumberList CheckMultiRunfiles()
Returns a list with all runs which occur more than once in the available runs file.
const KVDataSet * fDataSet
dataset to which this file belongs
virtual Bool_t CheckAvailable(Int_t run)
virtual void Update(Bool_t no_existing_file=kFALSE)
KVHashList * fAvailableRuns
temporary list used to store infos when updating
virtual KVNumberList GetRunList(const KVDBSystem *system=0)
const Char_t * GetFileName() const
KVLockfile runlist_lock
for locking runlist file
KVNameValueList * RunHasFileWithDateAndName(Int_t run, const Char_t *filename, TDatime modtime, Int_t &OccNum)
virtual TList * GetListOfAvailableSystems(const KVDBSystem *systol=0)
virtual Int_t Count(Int_t run)
static KVString date_read_from_filename
virtual void UpdateInfos(Int_t run, const Char_t *filename, const Char_t *kvversion, const Char_t *username)
const Char_t * GetFullPathToAvailableRunsFile() const
virtual void Remove(Int_t run, const Char_t *filename="")
KVAvailableRunsFile()
Default ctor.
virtual void GetRunInfos(Int_t run, KVList *dates, KVList *names)
virtual Bool_t InfosNeedUpdate(Int_t run, const Char_t *filename)
std::ifstream fRunlist
for reading runlist file
Int_t IsRunFileName(const Char_t *filename)
virtual Bool_t OpenAvailableRunsFile()
const Char_t * GetFilePath() const
void RemoveDuplicateLines(KVNumberList lines_to_be_removed)
Base class for KaliVeda framework.
static void OpenTempFile(TString &base, std::ofstream &fp)
static const Char_t * GetWORKDIRFilePath(const Char_t *namefile="")
static bool is_gnuinstall()
static const Char_t * GetDataSetEnv(const Char_t *dataset, const Char_t *type, const Char_t *defval)
static Bool_t SearchAndOpenKVFile(const Char_t *name, std::ifstream &file, const Char_t *kvsubdir="", KVLockfile *locks=0)
static const Char_t * GetKVVersion()
Returns KaliVeda version string.
virtual Int_t GetNumber() const
Description of an experimental run in database ,.
void SetDatime(TDatime &dat)
void SetUserName(const Char_t *U)
void SetKVVersion(const Char_t *V)
KVDBSystem * GetSystem() const
Database class used to store information on different colliding systems studied during an experiment.
void SetNumberRuns(Int_t n)
set number of runs associated to this system
Base class for managing repositories of experimental data.
virtual KVUniqueNameList * GetDirectoryListing(const KVDataSet *dataset, const Char_t *datatype="", const Char_t *subdir="")
virtual Bool_t GetFileInfo(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile, FileStat_t &fs)
Manage an experimental dataset corresponding to a given experiment or campaign.
KVDataRepository * GetRepository() const
Get pointer to data repository in which dataset is stored.
const Char_t * GetDataSetDir() const
const Char_t * GetDataSetEnv(const Char_t *type, const Char_t *defval="") const
virtual const Char_t * GetDataPathSubdir() const
Returns name of top-level directory in data repository used to store data files for this dataset.
KVExpDB * GetDataBase(Option_t *opt="") const
const Char_t * GetDataTypeSubdir(const Char_t *type) const
Extension of TDatime to handle various useful date formats.
static Bool_t IsGANACQFormat(const Char_t *date)
static Bool_t IsSQLFormat(const Char_t *date)
static Bool_t IsGANACQ2010Format(const Char_t *date)
void SetSQLDate(const Char_t *SQLDateString)
void SetGanacqNarvalDate(const Char_t *GanacqDateString)
static Bool_t IsGANACQNarvalFormat(const Char_t *date)
void SetGanacq2010Date(const Char_t *GanacqDateString)
void SetGanacqDate(const Char_t *GanacqDateString)
Base class to describe database of an experiment ,.
KVDBRun * GetDBRun(Int_t number) const
Extended version of ROOT THashList.
Extended TList class which owns its objects by default.
Bool_t Lock(const Char_t *filename="")
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Int_t GetIntValue(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
Bool_t IsValue(const Char_t *name, value_type value) const
const Char_t * GetStringValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
Strings used to represent a set of ranges of values.
void Add(Int_t)
Add value 'n' to the list.
Description of an individual run file in an experimental dataset.
virtual void SetOwner(Bool_t enable=kTRUE)
virtual Int_t GetSize() const
virtual void Add(TObject *obj)
virtual void Delete(Option_t *option="")
virtual TObject * FindObject(const char *name) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
Int_t GetNValues(TString delim) const
Optimised list in which named objects can only be placed once.
virtual void SetOwner(Bool_t enable=kTRUE)
Bool_t Contains(const char *name) const
virtual Int_t GetSize() const
const char * AsSQLString() const
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void Add(TObject *obj)
virtual void Sort(Bool_t order=kSortAscending)
virtual const char * GetName() const
TObject * At(Int_t idx) const
const char * GetName() const
virtual TObject * Clone(const char *newname="") 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
TObjArray * Tokenize(const TString &delim) const
const char * Data() const
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
std::istream & ReadLine(std::istream &str, Bool_t skipWhite=kTRUE)
virtual int Chmod(const char *file, UInt_t mode)
virtual int CopyFile(const char *from, const char *to, Bool_t overwrite=kFALSE)
virtual char * ConcatFileName(const char *dir, const char *name)
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
virtual UserGroup_t * GetUserInfo(const char *user=nullptr)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
virtual const char * BaseName(const char *pathname)
virtual char * ExpandPathName(const char *path)
virtual int Unlink(const char *name)
Double_t Max(Double_t a, Double_t b)