KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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
8using namespace std;
9
11
12
13
15
17{
18 // Default constructor
19 fDMS = NULL;
20 SetType("dms");
21}
22
23
24
27
33
34
35
45
47 const Char_t* datatype, const Char_t* subdir)
48{
49 //Use the DMS catalogue in order to examine the directory
50 //
51 // /root_of_data_repository/[datasetdir]/[datatype]/[subdir]
52 // /root_of_data_repository/[datasetdir]/[datatype] (if subdir="", default value)
53 // /root_of_data_repository/[datasetdir] (if datatype="", default value)
54 //
55 //and fill a TList with one KVDMSFile_t object for each entry in the directory,
56 //User must delete the TList after use (list will delete its members)
57
58 TString path, tmp;
59 AssignAndDelete(path,
61 ds->GetDataPathSubdir()));
62 if (strcmp(datatype, "")) {
63 AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
64 path = tmp;
65 if (strcmp(subdir, "")) {
66 AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), subdir));
67 path = tmp;
68 }
69 }
70
71 return fDMS->GetFullListing(path.Data());
72}
73
74
75
76
80
82 const Char_t* subdir)
83{
84 //Returns kTRUE if the following path is valid
85 // /root_of_data_repository/dir/[subdir]
86
87 TString dirname, path;
88 if (subdir) {
90 dirname = subdir;
91 }
92 else {
93 path = fAccessroot.Data();
94 dirname = dir;
95 // check that 'dir' is not a path containing several directories
96 // in this case all but the last have to be put in 'path'
97 if (dirname.Contains("/")) {
99 dirname = gSystem->BaseName(dir);
100 }
101 }
102 return fDMS->DirectoryContains(dirname.Data(), path.Data());
103}
104
105
106
107
111
113 const Char_t* datatype,
114 const Char_t* filename,
115 const Char_t* destination)
116{
117 //Copy file [datasetdir]/[datatypedir]/[filename] from the repository to [destination]
118 //We check if the file to copy exists.
119
120 if (CheckFileStatus(ds, datatype, filename)) {
121 TString path, tmp;
122 AssignAndDelete(path,
124 AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
126 //copy file
127 fDMS->get(path.Data(), destination);
128 }
129}
130
131
132
133
137
139 const KVDataSet* ds,
140 const Char_t* datatype,
141 const Char_t* filename)
142{
143 // Copy file [source] to [datasetdir]/[datatypedir]/[filename] in the repository
144 // Returns status of file transfer command
145
146 TString path, tmp;
147 AssignAndDelete(path,
149 AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
151
152 //copy file
153 return fDMS->put(source, path.Data());
154}
155
156
157
158
166
168 const Char_t* datatype,
169 const Char_t* runfile)
170{
171 //Checks if the run file of given type is physically present in dataset subdirectory,
172 //i.e. (schematically), if
173 //
174 // /root_of_data_repository/[datasetdir]/[datatypedir]/[runfile]
175 //
176 //exists. If it does, the returned value is kTRUE (=1).
177
178 TString path, tmp;
179 AssignAndDelete(tmp,
181 AssignAndDelete(path, gSystem->ConcatFileName(tmp.Data(), ds->GetDataTypeSubdir(datatype)));
182 return fDMS->DirectoryContains(runfile, path.Data());
183}
184
185
186
187
190
192 const Char_t* datatype)
193{
194 // Overrides KVDataRepository method.
195 TString path, tmp;
196 AssignAndDelete(tmp,
198 AssignAndDelete(path, gSystem->ConcatFileName(tmp.Data(), ds->GetDataTypeSubdir(datatype)));
199 fDMS->mkdir(path.Data());
200}
201
202
203
204
210
212 const Char_t* datatype,
213 const Char_t* filename, Bool_t confirm)
214{
215 //Delete repository file [datasetdir]/[datatypedir]/[filename]
216 //
217 //By default (confirm=kTRUE) we ask for confirmation before deleting.
218 //Set confirm=kFALSE to delete without confirmation (DANGER!!!)
219
220 TString path, tmp;
221 AssignAndDelete(path,
223 AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
225 TString cmd;
226 cout << "Deleting file from repository: " << filename << endl;
227 if (confirm) {
228 cout <<
229 "Are you sure you want to delete this file permanently ? (y/n)"
230 << endl;
231 TString answer;
232 cin >> answer;
233 answer.ToUpper();
234 if (!answer.BeginsWith("Y")) {
235 cout << "File not deleted" << endl;
236 return;
237 }
238 }
239 fDMS->forcedelete(path.Data());
240}
241
242
243
244
247
249{
250 // Overrides KVDataRepository method.
251 return fDMS->chmod(file, mode);
252}
253
254
255
270
272 const Char_t* datatype,
273 const Char_t* runfile,
274 FileStat_t& fs)
275{
276 //Checks if the run file of given type is physically present in dataset subdirectory,
277 //i.e. (schematically), if
278 //
279 // /root_of_data_repository/[datasetdir]/[datatypedir]/[runfile]
280 //
281 //exists. If it does, the returned value is kTRUE (=1), in which case the FileStat_t object
282 //contains information about the file:
283 // WARNING:
284 // only fs.fSize and fs.fMtime are used
285 // in addition, the modification time corresponds to the last time that
286 // the DMS declaration of the file was changed, not the last physical
287 // modification of the file, i.e. it will be the date at which the file
288 // was imported into the DMS catalogue, the file may be much older.
289
290 TString path, tmp;
291 AssignAndDelete(path,
293 AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype)));
294 AssignAndDelete(path, gSystem->ConcatFileName(tmp.Data(), runfile));
295
296 DMSFile_t DMSfile;
297 if (fDMS->GetPathInfo(path.Data(), DMSfile)) {
298 fs.fSize = DMSfile.GetSize();
299 fs.fMtime = DMSfile.GetModTime().Convert();
300 return kTRUE;
301 }
302 return kFALSE;
303}
304
305
306
314
315const Char_t* KVDMSDataRepository::GetFullPathToOpenFile(const KVDataSet* dataset, const Char_t* datatype, const Char_t* runfile)
316{
317 // Redefinition of KVDataRepository::GetFullPathToOpenFile
318 //
319 // If ReadProtocol != "root" then we use the DMS to download copies of data repository
320 // files to the user's temporary directory for analysis - see OpenDataSetRunFile.
321 // In this case, the full path to open the given file is that of the temporary directory copy
322
323 // get read protocol for dataset and datatype
324 TString RP = GetReadProtocol(dataset->GetName(), datatype);
325 if (RP == "root") return KVDataRepository::GetFullPathToOpenFile(dataset, datatype, runfile);
326
327 // look for file in temp dir
328 static TString tmpdir_filepath;
329 AssignAndDelete(tmpdir_filepath, gSystem->ConcatFileName(gSystem->TempDirectory(), runfile));
330 return tmpdir_filepath.Data();
331}
332
333
334
346
348{
349 // Overrides KVDataRepository method
350 //
351 // If ReadProtocol == "root" we use KVDataRepository method to open file via xrootd server
352 //
353 // If ReadProtocol != "root" (default if user does not specify [name].DataRepository.ReadProtocol:root):
354 //
355 // 1) we look for a copy of the file in the user's temporary directory (gSystem->TempDirectory());
356 // 2) if no copy exists, we download the file to the user's temporary directory
357 // 3) we open the file in the user's temporary directory
358
359 // get read protocol for dataset and datatype
360 TString RP = GetReadProtocol(ds->GetName(), type);
361 if (RP == "root") return KVDataRepository::OpenDataSetRunFile(ds, type, run, opt);
362
363 // get name of file
365 if (filename == "") {
366 Error("OpenDataSetRunFile", "No file found for run %d of data-type %s", run, type);
367 return nullptr;
368 }
369
370 // look for file in temp dir
371 TString tmpdir_filepath;
373
374 if (gSystem->AccessPathName(tmpdir_filepath)) {
375 // copy file to temp dir
376 CopyFileFromRepository(ds, type, filename, tmpdir_filepath);
377 }
378
379 return OpenDataSetFile(ds, type, tmpdir_filepath, opt);
380}
381
382
383
int Int_t
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.
virtual ~KVDMSDataRepository()
Destructor.
virtual Bool_t GetFileInfo(const KVDataSet *, const Char_t *datatype, const Char_t *runfile, FileStat_t &fs)
virtual Bool_t CheckSubdirExists(const Char_t *dir, const Char_t *subdir=0)
virtual int Chmod(const char *file, UInt_t mode)
Overrides KVDataRepository method.
virtual void DeleteFile(const KVDataSet *, const Char_t *datatype, const Char_t *filename, Bool_t confirm=kTRUE)
virtual int CopyFileToRepository(const Char_t *source, const KVDataSet *, const Char_t *datatype, const Char_t *filename)
virtual KVUniqueNameList * GetDirectoryListing(const KVDataSet *, const Char_t *datatype="", const Char_t *subdir="")
virtual const Char_t * GetFullPathToOpenFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
virtual void CopyFileFromRepository(const KVDataSet *, const Char_t *datatype, const Char_t *filename, const Char_t *destination)
virtual Bool_t CheckFileStatus(const KVDataSet *, const Char_t *datatype, const Char_t *runfile)
virtual void MakeSubdirectory(const KVDataSet *, const Char_t *datatype="")
Overrides KVDataRepository method.
KVDMS * fDMS
connection to Data Management System
TObject * OpenDataSetRunFile(const KVDataSet *ds, const Char_t *type, Int_t run, Option_t *opt="")
virtual Int_t forcedelete(const Char_t *path)=0
virtual Bool_t GetPathInfo(const Char_t *path, DMSFile_t &fs)
Definition KVDMS.cpp:166
virtual Int_t chmod(const Char_t *path, UInt_t mode)=0
virtual Int_t get(const Char_t *source, const Char_t *target=".")=0
virtual Bool_t DirectoryContains(const Char_t *name, const Char_t *directory="")
Definition KVDMS.cpp:233
virtual Int_t mkdir(const Char_t *path, Option_t *opt="")=0
virtual Int_t put(const Char_t *source, const Char_t *target=".")=0
virtual KVUniqueNameList * GetFullListing(const Char_t *directory="")
Definition KVDMS.cpp:127
virtual TObject * OpenDataSetRunFile(const KVDataSet *ds, const Char_t *type, Int_t run, Option_t *opt="")
virtual const Char_t * GetReadProtocol(const Char_t *dataset, const Char_t *datatype)
virtual const Char_t * GetFullPathToOpenFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
TObject * OpenDataSetFile(const KVDataSet *ds, const Char_t *type, const TString &fname, Option_t *opt="")
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition KVDataSet.h:35
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:95
const Char_t * GetRunfileName(const Char_t *type, Int_t run) const
const Char_t * GetDataTypeSubdir(const Char_t *type) const
Definition KVDataSet.h:99
Optimised list in which named objects can only be placed once.
UInt_t Convert(Bool_t toGMT=kFALSE) const
const char * GetName() const override
virtual void Error(const char *method, const char *msgfmt,...) const
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
ClassImp(TPyArg)