KaliVeda
Toolkit for HIC analysis
KVDMSDataRepository.cpp
1 //Created by KVClassFactory on Thu Oct 18 10:38:52 2012
2 //Author: John Frankland
3 
4 #include "KVDMSDataRepository.h"
5 #include "KVDMS.h"
6 #include "KVDataSet.h"
7 
8 using namespace std;
9 
11 
12 
13 
17 {
18  // Default constructor
19  fDMS = NULL;
20  SetType("dms");
21 }
22 
23 
24 
27 
29 {
30  // Destructor
31  SafeDelete(fDMS);
32 }
33 
34 
35 
44 
45 std::unique_ptr<KVUniqueNameList> KVDMSDataRepository::GetDirectoryListing(const KVDataSet* ds,
46  const Char_t* datatype, const Char_t* subdir)
47 {
48  //Use the DMS catalogue in order to examine the directory
49  //
50  // /root_of_data_repository/[datasetdir]/[datatype]/[subdir]
51  // /root_of_data_repository/[datasetdir]/[datatype] (if subdir="", default value)
52  // /root_of_data_repository/[datasetdir] (if datatype="", default value)
53  //
54  //and fill a TList with one KVDMSFile_t object for each entry in the directory,
55 
56  TString path, tmp;
57  AssignAndDelete(path,
58  gSystem->ConcatFileName(fAccessroot.Data(),
59  ds->GetDataPathSubdir()));
60  if (strcmp(datatype, "")) {
61  AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
62  path = tmp;
63  if (strcmp(subdir, "")) {
64  AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), subdir));
65  path = tmp;
66  }
67  }
68 
69  return fDMS->GetFullListing(path.Data());
70 }
71 
72 
73 
74 
78 
80  const Char_t* subdir)
81 {
82  //Returns kTRUE if the following path is valid
83  // /root_of_data_repository/dir/[subdir]
84 
85  TString dirname, path;
86  if (subdir) {
87  AssignAndDelete(path, gSystem->ConcatFileName(fAccessroot.Data(), dir));
88  dirname = subdir;
89  }
90  else {
91  path = fAccessroot.Data();
92  dirname = dir;
93  // check that 'dir' is not a path containing several directories
94  // in this case all but the last have to be put in 'path'
95  if (dirname.Contains("/")) {
96  AssignAndDelete(path, gSystem->ConcatFileName(fAccessroot.Data(), gSystem->DirName(dir)));
97  dirname = gSystem->BaseName(dir);
98  }
99  }
100  return fDMS->DirectoryContains(dirname.Data(), path.Data());
101 }
102 
103 
104 
105 
109 
111  const Char_t* datatype,
112  const Char_t* filename,
113  const Char_t* destination)
114 {
115  //Copy file [datasetdir]/[datatypedir]/[filename] from the repository to [destination]
116  //We check if the file to copy exists.
117 
118  if (CheckFileStatus(ds, datatype, filename)) {
119  TString path, tmp;
120  AssignAndDelete(path,
121  gSystem->ConcatFileName(fAccessroot.Data(), ds->GetDataPathSubdir()));
122  AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
124  //copy file
125  fDMS->get(path.Data(), destination);
126  }
127 }
128 
129 
130 
131 
135 
137  const KVDataSet* ds,
138  const Char_t* datatype,
139  const Char_t* filename)
140 {
141  // Copy file [source] to [datasetdir]/[datatypedir]/[filename] in the repository
142  // Returns status of file transfer command
143 
144  TString path, tmp;
145  AssignAndDelete(path,
146  gSystem->ConcatFileName(fAccessroot.Data(), ds->GetDataPathSubdir()));
147  AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
149 
150  //copy file
151  return fDMS->put(source, path.Data());
152 }
153 
154 
155 
156 
164 
166  const Char_t* datatype,
167  const Char_t* runfile)
168 {
169  //Checks if the run file of given type is physically present in dataset subdirectory,
170  //i.e. (schematically), if
171  //
172  // /root_of_data_repository/[datasetdir]/[datatypedir]/[runfile]
173  //
174  //exists. If it does, the returned value is kTRUE (=1).
175 
176  TString path, tmp;
177  AssignAndDelete(tmp,
178  gSystem->ConcatFileName(fAccessroot.Data(), ds->GetDataPathSubdir()));
179  AssignAndDelete(path, gSystem->ConcatFileName(tmp.Data(), ds->GetDataTypeSubdir(datatype)));
180  return fDMS->DirectoryContains(runfile, path.Data());
181 }
182 
183 
184 
185 
188 
190  const Char_t* datatype)
191 {
192  // Overrides KVDataRepository method.
193  TString path, tmp;
194  AssignAndDelete(tmp,
195  gSystem->ConcatFileName(fAccessroot.Data(), ds->GetDataPathSubdir()));
196  AssignAndDelete(path, gSystem->ConcatFileName(tmp.Data(), ds->GetDataTypeSubdir(datatype)));
197  fDMS->mkdir(path.Data());
198 }
199 
200 
201 
202 
208 
210  const Char_t* datatype,
211  const Char_t* filename, Bool_t confirm)
212 {
213  //Delete repository file [datasetdir]/[datatypedir]/[filename]
214  //
215  //By default (confirm=kTRUE) we ask for confirmation before deleting.
216  //Set confirm=kFALSE to delete without confirmation (DANGER!!!)
217 
218  TString path, tmp;
219  AssignAndDelete(path,
220  gSystem->ConcatFileName(fAccessroot.Data(), ds->GetDataPathSubdir()));
221  AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
223  TString cmd;
224  cout << "Deleting file from repository: " << filename << endl;
225  if (confirm) {
226  cout <<
227  "Are you sure you want to delete this file permanently ? (y/n)"
228  << endl;
229  TString answer;
230  cin >> answer;
231  answer.ToUpper();
232  if (!answer.BeginsWith("Y")) {
233  cout << "File not deleted" << endl;
234  return;
235  }
236  }
237  fDMS->forcedelete(path.Data());
238 }
239 
240 
241 
242 
245 
246 int KVDMSDataRepository::Chmod(const char* file, UInt_t mode)
247 {
248  // Overrides KVDataRepository method.
249  return fDMS->chmod(file, mode);
250 }
251 
252 
253 
268 
270  const Char_t* datatype,
271  const Char_t* runfile,
272  FileStat_t& fs) const
273 {
274  //Checks if the run file of given type is physically present in dataset subdirectory,
275  //i.e. (schematically), if
276  //
277  // /root_of_data_repository/[datasetdir]/[datatypedir]/[runfile]
278  //
279  //exists. If it does, the returned value is kTRUE (=1), in which case the FileStat_t object
280  //contains information about the file:
281  // WARNING:
282  // only fs.fSize and fs.fMtime are used
283  // in addition, the modification time corresponds to the last time that
284  // the DMS declaration of the file was changed, not the last physical
285  // modification of the file, i.e. it will be the date at which the file
286  // was imported into the DMS catalogue, the file may be much older.
287 
288  TString path, tmp;
289  AssignAndDelete(path,
290  gSystem->ConcatFileName(fAccessroot.Data(), ds->GetDataPathSubdir()));
291  AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
292  AssignAndDelete(path, gSystem->ConcatFileName(tmp.Data(), runfile));
293 
294  DMSFile_t DMSfile;
295  if (fDMS->GetPathInfo(path.Data(), DMSfile)) {
296  fs.fSize = DMSfile.GetSize();
297  fs.fMtime = DMSfile.GetModTime().Convert();
298  return kTRUE;
299  }
300  return kFALSE;
301 }
302 
303 
304 
312 
313 const Char_t* KVDMSDataRepository::GetFullPathToOpenFile(const KVDataSet* dataset, const Char_t* datatype, const Char_t* runfile)
314 {
315  // Redefinition of KVDataRepository::GetFullPathToOpenFile
316  //
317  // If ReadProtocol != "root" then we use the DMS to download copies of data repository
318  // files to the user's temporary directory for analysis - see OpenDataSetRunFile.
319  // In this case, the full path to open the given file is that of the temporary directory copy
320 
321  // get read protocol for dataset and datatype
322  TString RP = GetReadProtocol(dataset->GetName(), datatype);
323  if (RP == "root") return KVDataRepository::GetFullPathToOpenFile(dataset, datatype, runfile);
324 
325  // look for file in temp dir
326  static TString tmpdir_filepath;
327  AssignAndDelete(tmpdir_filepath, gSystem->ConcatFileName(gSystem->TempDirectory(), runfile));
328  return tmpdir_filepath.Data();
329 }
330 
331 
332 
344 
346 {
347  // Overrides KVDataRepository method
348  //
349  // If ReadProtocol == "root" we use KVDataRepository method to open file via xrootd server
350  //
351  // If ReadProtocol != "root" (default if user does not specify [name].DataRepository.ReadProtocol:root):
352  //
353  // 1) we look for a copy of the file in the user's temporary directory (gSystem->TempDirectory());
354  // 2) if no copy exists, we download the file to the user's temporary directory
355  // 3) we open the file in the user's temporary directory
356 
357  // get read protocol for dataset and datatype
358  TString RP = GetReadProtocol(ds->GetName(), type);
359  if (RP == "root") return KVDataRepository::OpenDataSetRunFile(ds, type, run, opt);
360 
361  // get name of file
362  TString filename = ds->GetRunfileName(type, run);
363  if (filename == "") {
364  Error("OpenDataSetRunFile", "No file found for run %s of data-type %s",
365  run.as_string().Data(), type.Data());
366  return nullptr;
367  }
368 
369  // look for file in temp dir
370  TString tmpdir_filepath;
371  AssignAndDelete(tmpdir_filepath, gSystem->ConcatFileName(gSystem->TempDirectory(), filename.Data()));
372 
373  if (gSystem->AccessPathName(tmpdir_filepath)) {
374  // copy file to temp dir
375  CopyFileFromRepository(ds, type, filename, tmpdir_filepath);
376  }
377 
378  return OpenDataSetFile(ds, type, tmpdir_filepath, opt);
379 }
380 
381 
382 
unsigned int UInt_t
#define SafeDelete(p)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
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 mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
void AssignAndDelete(TString &target, char *tobedeleted)
R__EXTERN TSystem * gSystem
UInt_t GetSize() const
Definition: KVDMS.h:39
KVDatime GetModTime() const
Definition: KVDMS.h:31
Manage remote data repository using a Data Management System.
Bool_t CheckSubdirExists(const Char_t *dir, const Char_t *subdir=0) override
std::unique_ptr< KVUniqueNameList > GetDirectoryListing(const KVDataSet *, const Char_t *datatype="", const Char_t *subdir="") override
virtual ~KVDMSDataRepository()
Destructor.
TObject * OpenDataSetRunFile(const KVDataSet *ds, const KVString &type, const run_index_t &run, Option_t *opt="") override
int Chmod(const char *file, UInt_t mode) override
Overrides KVDataRepository method.
Bool_t GetFileInfo(const KVDataSet *, const Char_t *datatype, const Char_t *runfile, FileStat_t &fs) const override
void CopyFileFromRepository(const KVDataSet *, const Char_t *datatype, const Char_t *filename, const Char_t *destination) override
void DeleteFile(const KVDataSet *, const Char_t *datatype, const Char_t *filename, Bool_t confirm=kTRUE) override
void MakeSubdirectory(const KVDataSet *, const Char_t *datatype="") override
Overrides KVDataRepository method.
Bool_t CheckFileStatus(const KVDataSet *, const Char_t *datatype, const Char_t *runfile) override
int CopyFileToRepository(const Char_t *source, const KVDataSet *, const Char_t *datatype, const Char_t *filename) override
const Char_t * GetFullPathToOpenFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile) override
virtual TObject * OpenDataSetRunFile(const KVDataSet *ds, const KVString &type, const run_index_t &run, Option_t *opt="")
virtual const Char_t * GetFullPathToOpenFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition: KVDataSet.h:36
virtual const Char_t * GetDataPathSubdir() const
Returns name of top-level directory in data repository used to store data files for this dataset.
Definition: KVDataSet.h:91
KVString GetRunfileName(const KVString &type, const run_index_t &run) const
Definition: KVDataSet.cpp:957
const Char_t * GetDataTypeSubdir(const Char_t *type) const
Definition: KVDataSet.h:95
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
UInt_t Convert(Bool_t toGMT=kFALSE) const
const char * GetName() const override
const char * Data() const
void ToUpper()
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual const char * DirName(const char *pathname)
virtual char * ConcatFileName(const char *dir, const char *name)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
virtual const char * BaseName(const char *pathname)
virtual const char * TempDirectory() const
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:33
TString as_string() const
Definition: run_index.h:94
void Error(const char *location, const char *fmt,...)
ClassImp(TPyArg)