10 #include "KVDataRepository.h"
11 #include "KVDataSetManager.h"
15 #include "KVDataSet.h"
31 #define CHMODE(u,g,o) ((u << 6) + (g << 3) + o)
52 gDataRepository =
this;
53 gDataSetManager = fDSM;
82 if (fLocalrootdir ==
"") {
83 Error(
"Init",
"Top-level directory for repository %s is not defined. Set %s.DataRepository.RootDir variable in .kvrootrc",
84 GetName(), GetName());
103 fXRDtunnel = (fXRDtunPort = (
Int_t)
gEnv->
GetValue(
Form(
"%s.DataRepository.XRDTunnel.port", GetName()), 0));
116 GetValue(
Form(
"%s.DataRepository.FileTransfer.type", GetName()),
118 if (fTransfertype.Contains(
"bbftp")) {
119 fTransferExec = fTransfertype;
120 fTransfertype =
"bbftp";
122 Error(
"Init",
"Executable for bbftp client not found. Check %s.DataRepository.FileTransfer.type",
126 else if (fTransfertype.Contains(
"sftp")) {
127 fTransferExec = fTransfertype;
128 fTransfertype =
"sftp";
133 else if (fTransfertype.Contains(
"root")) {
134 fTransferExec =
"root";
135 fTransfertype =
"xrd";
136 if (!fXRDtunnel) fTransferExec =
"";
140 GetValue(
Form(
"%s.DataRepository.FileTransfer.server", GetName()),
142 fTransferuser =
gEnv->
GetValue(
Form(
"%s.DataRepository.FileTransfer.user", GetName()),
"");
143 if (fTransferuser ==
"") {
145 fTransferuser = user->
fUser;
148 SetFullPath(fAccessroot, fAccessprotocol.Data());
149 SetFullPath(fReadroot, fReadprotocol.Data());
154 fDSM = NewDataSetManager();
157 return fDSM->Init(
this);
169 Info(
"Print",
"configuration of repository is as follows - ");
170 cout <<
"\tname = " << GetName() << endl;
171 cout <<
"\tRootDir = " << fLocalrootdir.Data() << endl;
172 cout <<
"\tAccessProtocol = " << fAccessprotocol.Data() << endl;
173 cout <<
"\tAccessRootDir = " << fAccessroot.Data() << endl;
174 cout <<
"\tReadProtocol = " << fReadprotocol.Data() << endl;
175 cout <<
"\tReadRootDir = " << fReadroot.Data() << endl;
176 cout <<
"\tCanWrite = " << fCanWrite << endl;
177 cout <<
"\tXRDServer = " << fXrootdserver.Data() << endl;
178 cout <<
"\tXRDRootDir = " << fXrootdrootdir.Data() << endl;
180 cout <<
"\tXRDTunnel.host = " << fXRDtunHost.Data() << endl;
181 cout <<
"\tXRDTunnel.port = " << fXRDtunPort << endl;
182 cout <<
"\tXRDTunnel.user = " << fXRDtunUser.Data() << endl;
183 cout <<
"\tXRDTunnel.retry = " << fXRDtunRetry << endl;
185 cout <<
"\tRFIOServer = " << fRfioserver.Data() << endl;
186 cout <<
"\tRFIORootDir = " << fRfiorootdir.Data() << endl;
187 cout <<
"\tTransferType = " << fTransfertype.Data() << endl;
188 cout <<
"\tTransferServer = " << fTransferserver.Data() << endl;
189 cout <<
"\tTransferUser = " << fTransferuser.Data() << endl;
213 KVDataRepository::~KVDataRepository()
272 path = fLocalrootdir;
273 else if (tmp ==
"root")
274 path.
Form(
"root://%s/%s", fXrootdserver.Data(),
275 fXrootdrootdir.Data());
276 else if (tmp ==
"rfio")
277 path.
Form(
"rfio:%s:%s", fRfioserver.Data(), fRfiorootdir.Data());
280 "Unknown protocol in call to SetFullPath : %s", protocol);
388 TString read_proto = GetReadProtocol(dataset->
GetName(), datatype);
389 if (read_proto ==
"none") {
390 Error(
"GetFullPathToOpenFile",
"Datatype \"%s\" can not be read from the repository \"%s\"",
391 datatype, GetName());
396 if (read_proto != fReadprotocol) {
397 SetFullPath(read_root, read_proto.
Data());
400 read_root = fReadroot;
476 (
"%s.DataRepository.ReadProtocol.%s.%s", GetName(),
477 dataset, datatype),
"");
483 (
"%s.DataRepository.ReadProtocol.%s", GetName(), dataset),
490 (
"%s.DataRepository.ReadProtocol.%s", GetName(), datatype),
494 return fReadprotocol;
507 const Char_t* destination)
512 if (CheckFileStatus(dataset, datatype,
filename)) {
519 CopyFile(path.
Data(), destination);
547 int status = CopyFile(source, path.
Data());
550 Chmod(path.
Data(), CHMODE(6, 6, 4));
553 Error(
"CopyFileToRepository",
"Problem copying file %s to repository (%d)",
582 if (strcmp(datatype,
""))
586 cout <<
"Creating new repository directory: " << path.
Data() << endl;
589 Chmod(path.
Data(), CHMODE(7, 7, 5));
625 if (strcmp(datatype,
"")) {
628 if (strcmp(subdir,
"")) {
636 Error(
"KVDataRepository::GetDirectoryListing",
"Cannot open %s",
690 cout <<
"CreateNewFile : " <<
filename << endl;
705 MakeSubdirectory(dataset, datatype);
707 return new TFile(GetFullPathToOpenFile(dataset, datatype,
filename),
747 fCommitFileName =
file->GetName();
759 fCommitDataSet = dataset;
760 fCommitDataType = datatype;
763 CreateAllNeededSubdirectories(fCommitDataSet, fCommitDataType);
765 cout << endl <<
"Copying file " << fCommitFileName <<
" to repository"
770 fCommitFileName.Data()));
771 CopyFileToRepository(s.Data(), fCommitDataSet,
772 fCommitDataType.Data(), fCommitFileName.Data());
805 cout <<
"Deleting file from repository: " <<
filename << endl;
808 "Are you sure you want to delete this file permanently ? (y/n)"
814 cout <<
"File not deleted" << endl;
865 TIter next(fHelpers);
866 while ((helper = (
TSystem*) next()))
867 if (HelperIsConsistentWith(helper, path, dirptr))
878 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TSystem", path)) &&
879 h->LoadPlugin() == 0)
882 #ifdef __WITHOUT_TNETSYSTEM_CTOR_BOOL_T
891 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TSystem", path)) &&
892 h->LoadPlugin() == 0)
893 helper = (
TSystem*)
h->ExecPlugin(0);
898 else if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TSystem", path))) {
899 if (
h->LoadPlugin() == -1)
901 helper = (
TSystem*)
h->ExecPlugin(0);
905 fHelpers->
Add(helper);
963 if (overwrite) open_option.
Prepend(
"RE");
974 int bufsize = 1024 * 1024;
976 if (filesize > 0 && filesize < 1024 * 1024) bufsize = 1024;
977 char* buf =
new char[bufsize];
980 Long64_t bytes_read, bytes_wrote, bytes_left, last_bytes_read, last_bytes_wrote;
981 bytes_read = bytes_wrote = bytes_left = last_bytes_read = last_bytes_wrote = 0;
987 while (bufsize && !ret && !from->
ReadBuffer(buf, bufsize)) {
994 if (bytes_wrote != bytes_read)
997 bytes_left = filesize - last_bytes_read;
998 if (bytes_left < bufsize) bufsize = (int)bytes_left;
1054 return (checkproto || checkdir);
1103 fXRDtunHost =
gEnv->
GetValue(
Form(
"%s.DataRepository.XRDTunnel.host", GetName()),
"");
1104 if (fXRDtunHost ==
"") {
1105 Error(
"PrepareXRDTunnel",
"Give host through which to tunnel : %s.DataRepository.XRDTunnel.host",
1110 fXRDtunUser =
gEnv->
GetValue(
Form(
"%s.DataRepository.XRDTunnel.user", GetName()),
"");
1111 if (fXRDtunUser ==
"") {
1113 fXRDtunUser = user->
fUser;
1116 fXRDtunSpec =
Form(
"%d:%s", fXRDtunPort, fXrootdserver.Data());
1120 fXrootdserver.Form(
"localhost:%d", fXRDtunPort);
1234 if (fname ==
"")
return nullptr;
1236 return OpenDataSetFile(ds,
type, fname, opt);
1311 if (!IsConnected())
return nullptr;
1318 if (IsThisAPlugin(plugin_class, base_class)) {
1321 ph = LoadPlugin(base_class, plugin_class);
1325 base_class = plugin_class;
1337 if (strcmp(opt,
"")) {
1347 if (ph)
Error(
"OpenDataSetFile",
"Open method for class %s is not valid", ph->
GetClass());
1348 else Error(
"OpenDataSetFile",
"Open method for class %s is not valid", base_class.
Data());
1375 MakeSubdirectory(DataSet);
1378 MakeSubdirectory(DataSet, DataType);
1384 #ifdef __CCIN2P3_RFIO
1399 FILE* rfio_fopen(
const char* path,
const char* mode);
1400 int rfio_fclose(FILE* s);
1401 int rfio_fread(
void* buffer,
size_t size,
size_t count, FILE* stream);
1402 int rfio_fwrite(
const void* buffer,
size_t size,
size_t count, FILE* stream);
1403 int rfio_feof(FILE* stream);
1404 int rfio_stat(
const char* path,
struct stat* statbuf);
1405 int rfio_rmdir(
const char* path);
1406 int rfio_unlink(
const char* path);
1407 int rfio_chmod(
const char* path, mode_t mode);
1417 Int_t KVRFIOSystem::Unlink(
const char* path)
1424 if (rfio_stat(url.GetFile(), &finfo) < 0)
1428 return rfio_rmdir(url.GetFile());
1430 return rfio_unlink(url.GetFile());
1439 int KVRFIOSystem::Chmod(
const char*
file,
UInt_t mode)
1444 return rfio_chmod(url.GetFile(), mode);
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
char * Form(const char *fmt,...)
void AssignAndDelete(TString &target, char *tobedeleted)
Bool_t R_ISDIR(Int_t mode)
R__EXTERN TSystem * gSystem
Handles lists of available runs for different datasets and types of data.
Base class for KaliVeda framework.
static Bool_t FindExecutable(TString &exec, const Char_t *path="$(PATH)")
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Base class for managing repositories of experimental data.
virtual KVDataSetManager * GetDataSetManager() const
Return pointer to data set manager for this repository.
virtual int CopyFileToRepository(const Char_t *source, const KVDataSet *dataset, const Char_t *datatype, const Char_t *filename)
virtual int Chmod(const char *file, UInt_t mode)
virtual TObject * OpenDataSetRunFile(const KVDataSet *ds, const Char_t *type, Int_t run, Option_t *opt="")
virtual void CopyFileFromRepository(const KVDataSet *dataset, const Char_t *datatype, const Char_t *filename, const Char_t *destination)
virtual const Char_t * GetReadProtocol(const Char_t *dataset, const Char_t *datatype)
static KVDataRepository * NewRepository(const Char_t *type)
virtual void Print(Option_t *opt="") const
Print info on repository.
virtual int CopyFile(const char *f, const char *t, Bool_t overwrite=kFALSE)
virtual KVUniqueNameList * GetDirectoryListing(const KVDataSet *dataset, const Char_t *datatype="", const Char_t *subdir="")
virtual Bool_t CheckFileStatus(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
virtual Bool_t GetFileInfo(const KVDataSet *dataset, 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 void PrepareXRDTunnel()
void SetFullPath(TString &path, const Char_t *protocol)
virtual KVAvailableRunsFile * NewAvailableRunsFile(const Char_t *, const KVDataSet *)
void CreateAllNeededSubdirectories(const KVDataSet *DataSet, const Char_t *DataType)
virtual KVDataSetManager * NewDataSetManager()
Create and return pointer to new data set manager.
Bool_t HelperIsConsistentWith(TSystem *helper, const char *path, void *dirptr=0)
TSystem * FindHelper(const char *path, void *dirptr=0)
virtual void CommitFile(TFile *file, const Char_t *datatype, const KVDataSet *dataset)
virtual void DeleteFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *filename, Bool_t confirm=kTRUE)
virtual TFile * CreateNewFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *filename)
KVDataRepository()
Default constructor.
virtual const Char_t * GetFullPathToTransferFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
virtual void MakeSubdirectory(const KVDataSet *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 all datasets contained in a given data repository.
Manage an experimental dataset corresponding to a given experiment or campaign.
const Char_t * GetDataSetEnv(const Char_t *type, const Char_t *defval="") const
virtual const Char_t * GetDataPathSubdir() const
Returns name of top-level directory in data repository used to store data files for this dataset.
TString GetFullPathToRunfile(const Char_t *type, Int_t run) const
const Char_t * GetDataTypeSubdir(const Char_t *type) const
virtual void SetOwner(Bool_t enable=kTRUE)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Optimised list in which named objects can only be placed once.
virtual void Add(TObject *obj)
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
virtual const char * GetValue(const char *name, const char *dflt) const
virtual Long64_t GetSize() const
virtual Long64_t GetBytesRead() const
virtual Bool_t WriteBuffer(const char *buf, Int_t len)
virtual Long64_t GetBytesWritten() const
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
virtual Bool_t ReadBuffer(char *buf, Int_t len)
virtual Bool_t Add(const TH1 *h, const TH1 *h2, Double_t c1=1, Double_t c2=1)
const char * GetName() const override
const TString & GetString() const
R__ALWAYS_INLINE Bool_t IsZombie() const
const char * GetClass() const
Longptr_t ExecPlugin(int nargs)
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
TString & Prepend(char c, Ssiz_t rep=1)
void Form(const char *fmt,...)
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual void * GetDirPtr() const
virtual int Chmod(const char *file, UInt_t mode)
virtual void FreeDirectory(void *dirp)
virtual void * OpenDirectory(const char *name)
virtual char * ConcatFileName(const char *dir, const char *name)
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
virtual int GetPathInfo(const char *path, FileStat_t &buf)
virtual UserGroup_t * GetUserInfo(const char *user=nullptr)
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
virtual const char * GetDirEntry(void *dirp)
virtual char * ExpandPathName(const char *path)
virtual int Unlink(const char *name)
const char * GetUrl(Bool_t withDeflt=kFALSE) const
void SetOptions(const char *opt)
const char * GetProtocol() const
Type GetType(const std::string &Name)