KaliVeda
Toolkit for HIC analysis
KVDataSetRepository.cpp
1 #include "KVDataSetRepository.h"
2 #include "KVDataSetManager.h"
3 #include "KVAvailableRunsFile.h"
4 
5 
14 
15 Bool_t KVDataSetRepository::GetFileInfo(const KVDataSet* dataset, const TString& datatype, const TString& runfile, FileStat_t& fs) const
16 {
17  //Checks if the run file of given type is physically present in dataset subdirectory,
18  //i.e. (schematically), if
19  //
20  // /root_of_data_repository/[datasetdir]/[datatypedir]/[runfile]
21  //
22  //exists. If it does, the returned value is kTRUE (=1), in which case the FileStat_t object
23  //contains information about the file.
24 
25  auto _fs = KVDataRepository::GetFileInfo(runfile, dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype));
26  if (_fs)
27  fs = _fs.value();
28  return _fs.has_value();
29 }
30 
31 
32 
40 
41 Bool_t KVDataSetRepository::CheckFileStatus(const KVDataSet* dataset, const TString& datatype, const TString& runfile)
42 {
43  //Checks if the run file of given type is physically present in dataset subdirectory,
44  //i.e. (schematically), if
45  //
46  // /root_of_data_repository/[datasetdir]/[datatypedir]/[runfile]
47  //
48  //exists. If it does, the returned value is kTRUE (=1).
49 
50  return KVDataRepository::CheckFileStatus(runfile, dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype));
51 }
52 
53 
54 
62 
63 TString KVDataSetRepository::GetFullPathToTransferFile(const KVDataSet* dataset, const TString& datatype, const TString& runfile)
64 {
65  //Used by KVDataTransfer.
66  //
67  //Returns the full path needed to transfer a runfile belonging to the given dataset
68  //either from or to the repository, using sftp or bbftp etc.
69  //This is just a concatenation of the repository root directory with the dataset
70  //subdirectories and filename.
71 
72  return KVDataRepository::GetFullPathToTransferFile(runfile, dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype));
73 }
74 
75 
76 
87 
89 {
90  //Use the access protocol defined by DataRepository.AccessProtocol (=local by default)
91  //in order to open the directory
92  //
93  // /root_of_data_repository/[datasetdir]/[datatype]/[subdir]
94  // /root_of_data_repository/[datasetdir]/[datatype] (if subdir="", default value)
95  // /root_of_data_repository/[datasetdir] (if datatype="", default value)
96  //
97  //and fill a KVUniqueNameList with one KVBase object for each entry in the directory,
98  //excluding "." and ".."
99 
100  return KVDataRepository::GetDirectoryListing(dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype), subdir);
101 }
102 
103 
104 
108 
109 void KVDataSetRepository::CopyFileFromRepository(const KVDataSet* dataset, const TString& datatype, const TString& filename, const TString& destination)
110 {
111  //Copy file [datasetdir]/[datatypedir]/[filename] from the repository to [destination]
112  //We check if the file to copy exists.
113 
114  KVDataRepository::CopyFileFromRepository(filename, destination, dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype));
115 }
116 
117 
118 
123 
124 int KVDataSetRepository::CopyFileToRepository(const TString& source, const KVDataSet* dataset, const TString& datatype, const TString& filename)
125 {
126  //Copy file [source] to [datasetdir]/[datatypedir]/[filename] in the repository
127  //The file access permissions are set to '664 (u:rw, g:rw, o:r)
128  //Returns status of file transfer command
129 
130  return KVDataRepository::CopyFileToRepository(filename, source, dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype));
131 }
132 
133 
134 
144 
145 TFile* KVDataSetRepository::CreateNewFile(const KVDataSet* dataset, const TString& datatype, const TString& filename)
146 {
147  //This will create and open a new ROOT runfile for the dataset in the repository,
148  //ready to be written.
149  //
150  //If the subdirectory for 'datatype' does not exist, it will be created.
151  //
152  //In fact, if the repository is not one in which files can be created and written
153  //directly (i.e. if CanWrite() = kFALSE), the file will be created in the local working
154  //directory, and only copied into the repository when CommitFile is called.
155 
156  return KVDataRepository::CreateNewFile(filename, dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype));
157 }
158 
159 
160 
174 
175 void KVDataSetRepository::CommitFile(TFile* file, const TString& datatype, const KVDataSet* dataset)
176 {
177  //Add this file (previously created by a call to CreateNewFile) to the repository.
178  //Any objects should be written to the file before calling this method, either by
179  //calling the Write() method of each object, or by calling file->Write().
180  //No file->Write() is done here: we only close (delete) the TFile.
181  //
182  //For repositories in which files can be created and written directly (i.e. if CanWrite() = kTRUE),
183  //we just have to close the file.
184  //For repositories where CanWrite() = kFALSE, we close the file, then copy it to the correct place in the repository,
185  //using the previously recorded values of fCommitDataSetDir, fCommitDataType,
186  //and fCommitFileName. Then we remove the local copy from disk.
187  //
188  //NB: after calling this method, the TFile pointer 'file' must not be used!!!
189 
190  KVDataRepository::CommitFile(file, dataset->GetDataPathSubdir(), dataset->GetDataTypeSubdir(datatype));
191 }
192 
193 
194 
205 
206 void KVDataSetRepository::MakeSubdirectory(const KVDataSet* dataset, const TString& datatype)
207 {
208  //Create a new subdirectory in the repository:
209  //~~~
210  // /root_of_data_repository/[datasetdir]
211  //~~~
212  //or with 'datatype' given:
213  //~~~
214  // /root_of_data_repository/[datasetdir]/[datatypedir]
215  //~~~
216  //Set access permissions to 775 (u:rwx, g:rwx, o:rx)
217 
219 }
220 
221 
222 
226 
228 {
229  // Ensure that all required subdirectories exist and any missing ones are created
230  // in order to store a runfile of given DataType for the given DataSet
231 
233 }
234 
235 
236 
241 
242 void KVDataSetRepository::DeleteFile(const KVDataSet* ds, const TString& datatype, const TString& runfile, Bool_t confirm)
243 {
244  // Delete file from repository.
245  //
246  // If confirm=kTRUE, ask for confirmation first (=kFALSE, no confirmation required)
247 
248  KVDataRepository::DeleteFile(runfile, confirm, ds->GetDataPathSubdir(), ds->GetDataTypeSubdir(datatype));
249 }
250 
251 
252 
255 
257 {
258  //Return pointer to data set manager for this repository
259  return fDSM.get();
260 }
261 
262 
263 
266 
268 {
269  // Just to allow std::unique_ptr<KVDataSetManager> member with incomplete (forward) declaration of KVDataSetManager
270 }
271 
272 
273 
275 
277 {
279  gDataSetManager = GetDataSetManager();
280 }
281 
282 
283 
285 
287 {
289  //data set manager
290  fDSM.reset(new KVDataSetManager);
291 
292  //return status of dataset manager
293  return fDSM->Init(this);
294 }
295 
296 
297 
305 
307 {
308  // Create new instance of class derived from KVAvailableRunsFile.
309  //
310  // Actual class of object depends on the type of the repository back-end
311  // which is used to select one of the
312  // Plugin.KVDataAvailableRunsFile's defined in .kvrootrc.
313 
314  //check and load plugin library
315  TPluginHandler* ph = KVBase::LoadPlugin("KVAvailableRunsFile", GetType());
316  if (!ph)
317  return new KVAvailableRunsFile(data_type, ds);
318 
319  //execute constructor/macro for plugin
320  return ((KVAvailableRunsFile*) ph->ExecPlugin(2, data_type, ds));
321 }
322 
323 
324 
325 
330 
332 {
333  // Create new instance of KVDataSetRepository
334  //
335  // local_or_irods = "local" => KVDataRepositoryImpl or "irods" => IRODSDataRepositoryImpl
336 
337  auto dr = new KVDataSetRepository;
338  dr->set_impl_backend(local_or_irods);
339 
340  return dr;
341 }
342 
343 
345 
bool Bool_t
char Char_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 GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Handles lists of available runs for different datasets and types of data.
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:796
TString GetFullPathToTransferFile(const TString &filename, const Paths &... paths) const
void DeleteFile(const TString &filename, Bool_t confirm, const Paths &... paths) const
virtual void cd()
const Char_t * GetType() const override
void CopyFileFromRepository(const TString &filename, const TString &destination, const Paths &... paths) const
KVUniqueNameList GetDirectoryListing(const Paths &... paths) const
void MakeSubdirectory(const TString &path1, const Paths &... paths) const
std::optional< FileStat_t > GetFileInfo(const TString &filename, const Paths &... paths) const
virtual Bool_t Init()
Bool_t CheckFileStatus(const TString &filename, const Paths &... paths) const
void CreateAllNeededSubdirectories() const
void CommitFile(TFile *file, const Paths &... paths)
TFile * CreateNewFile(const TString &filename, const Paths &... paths) const
int CopyFileToRepository(const TString &filename, const TString &source, const Paths &... paths) const
Manage all datasets contained in a given data repository.
A repository for experimental datasets.
Bool_t CheckFileStatus(const KVDataSet *dataset, const TString &datatype, const TString &runfile)
void MakeSubdirectory(const KVDataSet *dataset, const TString &datatype="")
TFile * CreateNewFile(const KVDataSet *dataset, const TString &datatype, const TString &filename)
std::unique_ptr< KVDataSetManager > fDSM
void CommitFile(TFile *file, const TString &datatype, const KVDataSet *dataset)
~KVDataSetRepository()
Just to allow std::unique_ptr<KVDataSetManager> member with incomplete (forward) declaration of KVDat...
int CopyFileToRepository(const TString &source, const KVDataSet *dataset, const TString &datatype, const TString &filename)
KVDataSetManager * GetDataSetManager() const
Return pointer to data set manager for this repository.
static KVDataSetRepository * NewRepository(const TString &local_or_irods)
void CopyFileFromRepository(const KVDataSet *dataset, const TString &datatype, const TString &filename, const TString &destination)
Bool_t GetFileInfo(const KVDataSet *dataset, const TString &datatype, const TString &runfile, FileStat_t &fs) const
KVDataSetRepository()=default
handles datasets in repository
virtual KVAvailableRunsFile * NewAvailableRunsFile(const Char_t *, const KVDataSet *)
void DeleteFile(const KVDataSet *ds, const TString &datatype, const TString &runfile, Bool_t confirm)
TString GetFullPathToTransferFile(const KVDataSet *dataset, const TString &datatype, const TString &runfile)
KVUniqueNameList GetDirectoryListing(const KVDataSet *dataset, const TString &datatype="", const TString &subdir="")
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition: KVDataSet.h:146
KVString GetDataPathSubdir() const
Definition: KVDataSet.h:200
KVString GetDataTypeSubdir(const TString &type) const
Definition: KVDataSet.h:205
Optimised list in which named objects can only be placed once.
Longptr_t ExecPlugin(int nargs)
ClassImp(TPyArg)