9 #include "KVDataSetManager.h"
10 #include "KVDataRepositoryManager.h"
12 #include "TObjString.h"
13 #include "TObjArray.h"
14 #include "Riostream.h"
17 #include "TPluginManager.h"
22 #define CHMODE(u,g,o) ((u << 6) + (g << 3) + o)
37 fCacheAvailable = kFALSE;
48 KVDataSetManager::~KVDataSetManager()
81 if (!ReadDataSetList())
86 fCacheAvailable = gEnv->GetValue(Form(
"%s.DataRepository.CacheAvailable", dr->GetName()),
88 fMaxCacheTime = (UInt_t)gEnv->GetValue(Form(
"%s.DataRepository.MaxCacheTime", dr->GetName()),
92 if (dr) fCacheFileName.Form(
"%s.available.datasets", dr->GetName());
96 if (!GetNavailable() && dr && dr->
IsRemote())
return kFALSE;
102 if (GetNavailable()) {
103 for (Int_t i = 1; i <= GetNavailable(); i++)
104 GetAvailableDataSet(i)->SetAnalysisTasks(&fTasks);
108 if (!dr) gDataSetManager =
this;
126 TString groups = gEnv->GetValue(
"UserGroup",
"");
132 TObjArray* toks = groups.Tokenize(
' ');
133 TObjString* group_name;
134 TIter next_name(toks);
136 while ((group_name = (TObjString*) next_name())) {
141 GetValue(Form(
"%s.Users", group_name->String().Data()),
"");
142 fUserGroups.SetValue(group_name->String().Data(), users);
158 KVString manip_list = gEnv->GetValue(
"DataSet",
"");
162 TObjArray* manips = manip_list.Tokenize(
" ");
165 while ((manip = (TObjString*)next())) {
168 ds->
SetName(manip->GetString().Data());
169 ds->SetTitle(gEnv->GetValue(Form(
"%s.DataSet.Title", manip->GetString().Data()),
"Experimental dataset"));
170 ds->
SetDataPathSubdir(gEnv->GetValue(Form(
"%s.DataSet.RepositoryDir", manip->GetString().Data()), manip->GetString().Data()));
171 ds->
SetUserGroups(gEnv->GetValue(Form(
"%s.DataSet.UserGroup", manip->GetString().Data()),
""));
193 KVString task_list = gEnv->GetValue(
"DataAnalysisTask",
"");
197 task_list.
Begin(
" ");
198 while (!task_list.
End()) {
201 TString name = task_list.
Next();
202 dat->SetName(name.Data());
203 dat->SetTitle(gEnv->GetValue(Form(
"%s.DataAnalysisTask.Title", name.Data()),
""));
204 dat->
SetPrereq(gEnv->GetValue(Form(
"%s.DataAnalysisTask.Prereq", name.Data()),
""));
205 dat->
SetDataAnalyser(gEnv->GetValue(Form(
"%s.DataAnalysisTask.Analyser", name.Data()),
"KVDataAnalyser"));
206 dat->
SetWithUserClass(gEnv->GetValue(Form(
"%s.DataAnalysisTask.UserClass", name.Data()), kFALSE));
207 dat->
SetUserBaseClass(gEnv->GetValue(Form(
"%s.DataAnalysisTask.UserClass.Base", name.Data()),
""));
208 dat->
SetStatusUpdateInterval(gEnv->GetValue(Form(
"%s.DataAnalysisTask.StatusUpdateInterval", name.Data()), 1000));
233 if (Sopt.BeginsWith(
"AVAIL")) {
235 cout <<
" *** No available datasets ***" <<
240 for (
int i = 1; i <= fNavailable; i++) {
242 cout <<
"\t" << i <<
". " << ds->GetTitle() << endl;
247 if (fDataSets.GetSize()) {
248 TIter next(&fDataSets);
302 if (fCacheAvailable) {
304 if (CheckCacheStatus()) {
306 if (ReadAvailableDatasetsFile())
return;
311 if (fRepository) fRepository->PrintAvailableDatasetsUpdateWarning();
315 TString tmp_file_path = fCacheFileName;
319 if (fDataSets.GetSize()) {
320 TIter next(&fDataSets);
329 tmp_file << ds->GetName() <<
" : ";
342 if (fNavailable && fRepository) {
344 gSystem->CopyFile(tmp_file_path, runlist, kTRUE);
346 gSystem->Chmod(runlist.Data(), CHMODE(6, 6, 4));
350 gSystem->Unlink(tmp_file_path);
355 ReadAvailableDatasetsFile();
381 if (fDataSets.GetSize() && index < fDataSets.GetSize())
394 return (
KVDataSet*) fDataSets.FindObjectByName(name);
409 if (fNavailable && index && index <= fNavailable)
410 return GetDataSet(fIndex[index - 1]);
432 const Char_t* username)
437 TString Username = strcmp(username,
438 "") ? username : gSystem->GetUserInfo()->
441 if (fUserGroups.HasParameter(groupname)) {
442 if (fUserGroups.GetTStringValue(groupname).Contains(Username.Data()))
477 if (GetNavailable()) {
478 for (Int_t i = 1; i <= GetNavailable(); i++)
479 GetAvailableDataSet(i)->SetAnalysisTasks(&fTasks);
517 if (OpenAvailableDatasetsFile()) {
518 Info(
"ReadAvailableDataSetsFile",
519 "Reading cached information in file %s", fCacheFileName.Data());
522 line.ReadLine(fDatasets);
523 while (fDatasets.good()) {
525 TObjArray* toks = line.Tokenize(
": ,");
528 TString datasetname = ((TObjString*) toks->At(0))->String();
529 KVDataSet* dataset = GetDataSet(datasetname.Data());
537 for (
int i = 1; i < toks->GetEntries(); i++) {
550 line.ReadLine(fDatasets);
558 TIter next(&fDataSets);
592 Info(
"KVDataSetManager::CheckCacheStatus",
"Checking for available datasets cache file...");
596 FileStat_t file_info;
597 gSystem->GetPathInfo(fullpath.Data(), file_info);
598 TDatime file_date(file_info.fMtime);
600 UInt_t file_age = now.Convert() - file_date.Convert();
601 Info(
"KVDataSetManager::CheckCacheStatus",
"...file found. It is %u seconds old", file_age);
602 if (file_age < fMaxCacheTime) {
603 Info(
"KVDataSetManager::CheckCacheStatus",
"Using cached file");
607 Info(
"KVDataSetManager::CheckCacheStatus",
"File is too old (max time=%u). Update will be performed.", fMaxCacheTime);
610 Info(
"KVDataSetManager::CheckCacheStatus",
"...no file found");
629 return (
KVDataAnalysisTask*)GetAnalysisTaskList()->FindObjectAny(
"title", keywords, kTRUE, kFALSE);
static void OpenTempFile(TString &base, std::ofstream &fp)
static const Char_t * GetWORKDIRFilePath(const Char_t *namefile="")
static Bool_t SearchKVFile(const Char_t *name, TString &fullpath, const Char_t *kvsubdir="")
static Bool_t SearchAndOpenKVFile(const Char_t *name, KVSQLite::database &dbfile, const Char_t *kvsubdir="")
Define and manage data analysis tasks.
virtual void SetDataAnalyser(const Char_t *d)
virtual void SetPrereq(const Char_t *p)
virtual void SetStatusUpdateInterval(Long64_t n)
virtual void SetUserBaseClass(const Char_t *d)
virtual void SetWithUserClass(Bool_t w=kTRUE)
Base class for managing repositories of experimental data.
virtual Bool_t IsRemote() const
Returns kTRUE for remote repositories, kFALSE for local repositories.
Manage all datasets contained in a given data repository.
virtual void Print(Option_t *opt="") const
virtual void ReadUserGroups()
virtual Bool_t ReadDataSetList()
virtual Bool_t Init(KVDataRepository *=0)
KVDataAnalysisTask * GetAnalysisTaskAny(const Char_t *keywords) const
virtual Bool_t OpenAvailableDatasetsFile()
virtual Bool_t CheckCacheStatus()
virtual Bool_t ReadAvailableDatasetsFile()
virtual Bool_t CheckUser(const Char_t *groupname, const Char_t *username="")
virtual KVDataAnalysisTask * GetTask(const Char_t *name)
Return pointer to named data analysis task.
KVDataSet * GetDataSet(Int_t) const
Return pointer to DataSet using index in list of all datasets, index>=0.
virtual KVDataSet * NewDataSet()
Creates and returns pointer to new data set object.
virtual Bool_t ReadTaskList()
virtual void CheckAvailability()
virtual KVDataSet * GetAvailableDataSet(Int_t) const
Manage an experimental dataset corresponding to a given experiment or campaign.
virtual void SetUserGroups(const Char_t *groups)
virtual void SetDataPathSubdir(const Char_t *s)
virtual const Char_t * GetAvailableDataTypes() const
virtual void ls(Option_t *opt="") const
Print dataset information.
virtual void AddAvailableDataType(const Char_t *)
void SetName(const char *name)
virtual void CheckAvailable()
virtual Bool_t IsAvailable() const
Returns kTRUE if this dataset is available for analysis, i.e. if any associated data files are stored...
virtual void SetAvailable(Bool_t yes=kTRUE)
virtual Bool_t CheckUserCanAccess()
void SetRepository(KVDataRepository *)
Set pointer to data repository in which dataset is stored.
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