10 #ifndef __KVDATAREPOSITORY_H
11 #define __KVDATAREPOSITORY_H
20 #include "KVUniqueNameList.h"
21 #include "KVDataRepositoryImpl.h"
129 TString fAccessprotocol =
"local";
130 TString fReadprotocol =
"local";
145 struct PathConcatenator {
147 PathConcatenator(
const TString& _root) : root_dir{_root} {}
152 template<
typename... Strings>
153 TString get_full_path(
const TString& path,
const Strings& ... others)
160 return get_full_path(others...);
162 template<
typename ExistCheck,
typename MakeDir>
163 void ensure_full_path_exists(ExistCheck, MakeDir)
const {}
164 template<
typename ExistCheck,
typename MakeDir,
typename... Strings>
165 void ensure_full_path_exists(ExistCheck ec, MakeDir md,
const TString& path,
const Strings& ... others)
175 ensure_full_path_exists(ec, md, others...);
178 template<
typename... Paths>
179 TString get_path_with_access_root(
const Paths& ... paths)
const
181 PathConcatenator pc{fAccessroot};
182 auto tmp = pc.get_full_path(paths...);
187 template<
typename... Paths>
188 TString get_path_with_read_root(
const Paths& ... paths)
const
190 PathConcatenator pc{fReadroot};
191 auto tmp = pc.get_full_path(paths...);
196 template<
typename... Paths>
197 TString get_path_with_arbitrary_root(
const TString& arb_root,
const Paths& ... paths)
const
199 PathConcatenator pc{arb_root};
200 auto tmp = pc.get_full_path(paths...);
207 std::unique_ptr<KVDataRepositoryImpl> _impl;
208 void set_impl_backend(
const TString& impl_type);
209 template<
typename... Paths>
210 void CreateAllNeededSubdirectories(
const TString& path1,
const Paths& ... paths)
const
212 auto check_path = [&](
TString &
p) {
215 return _impl->check_path_exists(
p);
220 _impl->make_directory(
p);
223 PathConcatenator pc{fAccessroot};
224 pc.ensure_full_path_exists(check_path, mkdir, path1, paths...);
226 void CreateAllNeededSubdirectories()
const {}
238 return _impl->GetType();
241 template<
typename... Paths>
249 return _impl->check_path_exists(get_path_with_access_root(path1, paths...));
251 template<
typename... Paths>
257 if (_impl->GetPathInfo(get_path_with_access_root(paths...,
filename),
fs))
261 template<
typename... Paths>
265 return _impl->check_path_exists(get_path_with_access_root(paths...,
filename));
268 template<
typename... Paths>
278 auto tp = get_path_with_arbitrary_root(
"/tmp", paths...);
282 template<
typename... Paths>
291 if (_impl->look_for_files_downloaded_to_temp_dir()) {
294 return get_path_with_read_root(paths...,
filename);
297 template<
typename... Paths>
304 return get_path_with_arbitrary_root(fLocalrootdir, paths...,
filename);
319 template<
typename... Paths>
330 return _impl->get_directory_listing(get_path_with_access_root(paths...));
332 template<
typename... Paths>
339 auto path = get_path_with_access_root(paths...,
filename);
340 _impl->copy_file_from(path, destination);
343 template<
typename... Paths>
353 CreateAllNeededSubdirectories(paths...);
354 auto path = get_path_with_access_root(paths...,
filename);
355 auto status = _impl->copy_file_to(source, path);
358 _impl->Chmod(path, 0664);
361 KVError::Error(
this,
"CopyFileToRepository",
"Problem copying file %s to repository (status=%d)",
362 source.
Data(), status);
366 template<
typename... Paths>
377 std::cout <<
"CreateNewFile : " <<
filename << std::endl;
383 CreateAllNeededSubdirectories(paths...);
386 template<
typename... Paths>
398 CreateAllNeededSubdirectories(paths...);
400 std::cout << std::endl <<
"Copying file " << CommitFileName <<
" to repository" << std::endl;
402 auto s = get_path_with_arbitrary_root(
gSystem->
pwd(), CommitFileName);
408 template<
typename... Paths>
417 _impl->make_directory(get_path_with_access_root(path1, paths...));
419 template<
typename... Paths>
426 auto tmp = get_path_with_access_root(paths...);
427 auto path = get_path_with_arbitrary_root(tmp,
filename);
428 std::cout <<
"Deleting file from repository: " <<
filename << std::endl;
431 "Are you sure you want to delete this file permanently ? (y/n)"
437 std::cout <<
"File not deleted" << std::endl;
441 _impl->delete_file(path);
443 template<
typename... Paths>
454 if (_impl->look_for_files_downloaded_to_temp_dir()) {
461 return open_file(path);
463 template<
typename... Paths>
468 auto open_file = [](
const TString &
f) {
478 return fTransfertype;
483 return fTransferExec;
488 return fTransferserver;
493 return fTransferuser;
498 return fLocalrootdir;
509 #ifdef __CCIN2P3_RFIO
510 #include "TRFIOFile.h"
511 class KVRFIOSystem :
public TRFIOSystem {
513 KVRFIOSystem(): TRFIOSystem() { };
514 virtual ~KVRFIOSystem() { };
516 Int_t Unlink(
const char* path);
#define ClassDef(name, id)
#define ClassDefOverride(name, id)
winID h TVirtualViewer3D TVirtualGLPainter p
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
void AssignAndDelete(TString &target, char *tobedeleted)
R__EXTERN TSystem * gSystem
Base class for KaliVeda framework.
Base class for managing repositories of data.
TString GetFullPathToTransferFile(const TString &filename, const Paths &... paths) const
void DeleteFile(const TString &filename, Bool_t confirm, const Paths &... paths) const
const Char_t * GetType() const override
Bool_t CheckSubdirExists(const TString &path1, const Paths &... paths) const
TString GetRepositoryPath(const Paths &... paths) const
void CopyFileFromRepository(const TString &filename, const TString &destination, const Paths &... paths) const
KVUniqueNameList GetDirectoryListing(const Paths &... paths) const
TString GetFileTransferUser() const
returns user name used for remote file transfer
void MakeSubdirectory(const TString &path1, const Paths &... paths) const
TString GetFileTransferServer() const
returns server url used for remote file transfer
std::optional< FileStat_t > GetFileInfo(const TString &filename, const Paths &... paths) const
TString GetFileTransferType() const
returns protocol used for remote file transfer
TFile * OpenROOTFile(const TString &filename, const Paths &... paths)
Bool_t CheckFileStatus(const TString &filename, const Paths &... paths) const
TString GetFullPathToOpenFile(const TString &filename, const Paths &... paths) const
void SetCanWrite(Bool_t yes=kTRUE)
void ReadWithXrootd(const TString &server, const TString &rootdir)
TString GetFileTransferExec() const
returns full path to executable used for remote file transfer
KVDataRepository()
Default constructor.
TObject * OpenFile(const TString &filename, const std::function< TObject *(const TString &)> &open_file, const Paths &... paths)
void Print(Option_t *opt="") const override
Print info on repository.
void CommitFile(TFile *file, const Paths &... paths)
TString GetRootDirectory() const
returns root directory of data repository (fLocalrootdir)
TFile * CreateNewFile(const TString &filename, const Paths &... paths) const
int CopyFileToRepository(const TString &filename, const TString &source, const Paths &... paths) const
Optimised list in which named objects can only be placed once.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
virtual char * ConcatFileName(const char *dir, const char *name)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
virtual char * ExpandPathName(const char *path)
virtual int Unlink(const char *name)
virtual const char * TempDirectory() const
void Error(UserClass p, const char *location, const char *va_(fmt),...)