KaliVeda
Toolkit for HIC analysis
KVRemoteDataRepository.cpp
1 /*
2 $Id: KVRemoteDataRepository.cpp,v 1.6 2007/11/21 11:34:41 franklan Exp $
3 $Revision: 1.6 $
4 $Date: 2007/11/21 11:34:41 $
5 */
6 
7 //Created by KVClassFactory on Thu Jul 13 23:44:40 2006
8 //Author: John Frankland
9 
10 #include "KVRemoteDataRepository.h"
11 #include "KVRemoteDataSetManager.h"
12 #include "TSocket.h"
13 
14 using namespace std;
15 
17 
18 
19 
23 {
24  //Default constructor
25 
26  SetType("remote");
27 }
28 
29 
30 
33 
34 KVRemoteDataRepository::~KVRemoteDataRepository()
35 {
36  //Destructor
37 }
38 
39 
40 
41 
47 
49  const Char_t*)
50 {
51  //Returns kTRUE if the following path is valid
52  // /root_of_data_repository/dir/[subdir]
53  //For a remote data repository, this is not possible.
54  //Always returns kFALSE.
55  Warning("CheckSubdirExists",
56  "Always returns false for remote data repository");
57  return kFALSE;
58 }
59 
60 
61 
62 
73 
75  const Char_t*,
76  const Char_t*,
77  FileStat_t&)
78 {
79  //Checks if the run file of given type is physically present in dataset subdirectory,
80  //i.e. (schematically), if
81  //
82  // /root_of_data_repository/[datasetdir]/[datatype]/[runfile]
83  //
84  //exists. If it does, the returned value is kTRUE (=1), in which case the FileStat_t object
85  //contains information about the file.
86  //For a remote data repository, this is not possible.
87  //Always returns kFALSE.
88  Warning("GetFileInfo",
89  "Always returns false for remote data repository");
90  return kFALSE;
91 }
92 
93 
94 
95 
105 
107  const Char_t*,
108  const Char_t*)
109 {
110  //Checks if the run file of given type is physically present in dataset subdirectory,
111  //i.e. (schematically), if
112  //
113  // /root_of_data_repository/[datasetdir]/[datatype]/[runfile]
114  //
115  //exists. If it does, the returned value is kTRUE (=1).
116  //For a remote data repository, this is not possible.
117  //Always returns kFALSE.
118  Warning("CheckFileStatus",
119  "Always returns false for remote data repository");
120  return kFALSE;
121 }
122 
123 
124 
125 
131 
133  const Char_t*,
134  const Char_t*,
135  const Char_t*)
136 {
137  //Copy file [datasetdir]/[datatype]/[filename] from the repository to [destination]
138  //We check if the file to copy exists.
139  //For remote repositories, this uses the bbftp protocol (if available).
140  //NEEDS IMPLEMENTATION.
141  Info("CopyFileFromRepository", "Not implemented yet");
142 }
143 
144 
145 
146 
151 
153  const KVDataSet*,
154  const Char_t*,
155  const Char_t*)
156 {
157  //Copy file [source] to [datasetdir]/[datatype]/[filename] in the repository
158  //For remote repositories, this uses the bbftp protocol (if available).
159  //NEEDS IMPLEMENTATION.
160  Info("CopyFileToRepository", "Not implemented yet");
161  return -1;
162 }
163 
164 
165 
166 
170 
172  const Char_t*)
173 {
174  //Create a new subdirectory in the repository
175  //Impossible on distant data repositories.
176  Info("MakeSubdirectory", "Impossible on remote data repositories");
177 }
178 
179 
180 
181 
185 
187  const Char_t*, const Char_t*)
188 {
189  //Impossible on distant data repositories.
190  //Will return 0 (null pointer).
191  Info("GetDirectoryListing", "Impossible on remote data repositories");
192  return 0;
193 }
194 
195 
196 
197 
201 
203  const Char_t*,
204  const Char_t*,
205  Bool_t)
206 {
207  //Delete repository file [datasetdir]/[datatype]/[filename]
208  //Impossible on distant data repositories.
209  Info("DeleteFile", "Impossible on remote data repositories");
210 }
211 
212 
213 
214 
217 
219 {
220  //Create and return pointer to new data set manager
221  return (new KVRemoteDataSetManager);
222 }
223 
224 
225 
226 
241 
243  const
244  Char_t*
245  datatype,
246  const
247  Char_t*
248  runfile)
249 {
250  //Used by KVDataTransfer.
251  //Returns the full path needed to transfer a runfile belonging to the given dataset
252  //either from or to the repository, using sftp or bbftp etc.
253  //This is a concatenation of the repository root directory with the dataset
254  //subdirectories and filename.
255  //However, for a remote data repository, the type of operating system may be different
256  //to gSystem, i.e. the system on the local machine. In this case, gSystem->ConcatFileName
257  //may not necessarily give the right paths for the remote machine: e.g. local machine
258  //is Windows, remote repository is Linux, paths for Linux machine will have a mix of
259  //"/" and "\" in them.
260  //We try to remedy this by looking at fLocalrootdir: if it contains "/" we take the result
261  //of the concatenation performed by KVDataRepository::GetFullPathToTransferFile
262  //and replace any "\" by "/", and vice versa.
263 
264  static TString path;
265  path =
267  runfile);
268  if (fLocalrootdir.Contains("/"))
269 // path.ReplaceAll("\\", "/");
270  path = gSystem->UnixPathName(path.Data());
271  else if (fLocalrootdir.Contains("\\"))
272  path.ReplaceAll("/", "\\");
273  return path.Data();
274 }
275 
276 
277 
278 
286 
288  const Char_t*
289  datatype,
290  const Char_t*
291  runfile)
292 {
293  //When accessing remote data repositories, the operating system corresponding
294  //to the remote file system may not be the same as the local operating system
295  //(corresponding to gSystem). Therefore use of gSystem->ConcatFileName may lead
296  //to paths which mix '/' and '\'.
297  //We check for this here by converting the result of KVDataRepository::GetFullPath
298  //depending on whether the root directory of this repository contains '/' or '\'
299  static TString path;
300  path =
301  KVDataRepository::GetFullPathToOpenFile(dataset, datatype,
302  runfile);
303  if (fLocalrootdir.Contains("/"))
304  path = gSystem->UnixPathName(path.Data());
305  else if (fLocalrootdir.Contains("\\"))
306  path.ReplaceAll("/", "\\");
307  return path.Data();
308 }
309 
310 
311 
312 
331 
333 {
334  //Before reading data in a remote data repository, it may be necessary to 'connect' to the repository
335  //in some way: e.g. we may need to open an SSH tunnel to an xrootd server.
336  //Call this method to make sure any required connection has been made, and if successful
337  //the method returns kTRUE; otherwise return kFALSE.
338  //
339  //XROOTD via SSH tunnel
340  //===================
341  //Configure using the following environment variables:
342  //
343  // ccali.DataRepository.XRDTunnel.host: ccali.in2p3.fr
344  // ccali.DataRepository.XRDTunnel.port: 10000
345  //
346  //The host and port to use are obligatory. Optionally you may also change the following:
347  //
348  // ccali.DataRepository.XRDTunnel.retry: #max number of tries before giving up on connection, default = 30
349  //
350  // ccali.DataRepository.XRDTunnel.user: #username for login to tunnel host. default is local username.
351 
352  if (fXRDtunnel) {
353  //check existence of SSH tunnel to xrootd server
354  TSocket* sock = new TSocket("localhost", fXRDtunPort);
355  Int_t iRetry = 0;
356  if (!sock->IsValid()) {
357  //open tunnel
358  TString command = "xterm -e \"ssh -X -L";
359  command += fXRDtunSpec;
360  command += " ";
361  command += Form("%s@%s\" &", fXRDtunUser.Data(), fXRDtunHost.Data());
362  gSystem->Exec(command.Data());
363  cout << "Waiting for connection to xrootd server via SSH tunnel ";
364  while (!sock->IsValid() && iRetry < fXRDtunRetry) {
365  cout << ".";
366  cout.flush();
367  gSystem->Sleep(2000);
368  sock->Close();
369  delete sock;
370  sock = new TSocket("localhost", fXRDtunPort);
371  iRetry++;
372  }
373  cout << endl;
374  }
375  sock->Close();
376  delete sock;
377  if (iRetry == fXRDtunRetry) {
378  cout << "Connection timeout " << endl;
379  return kFALSE;
380  }
381  }
382  return kTRUE;
383 }
384 
385 
int Int_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
virtual const Char_t * GetFullPathToTransferFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
virtual const Char_t * GetFullPathToOpenFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
Manage all datasets contained in a given data repository.
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition: KVDataSet.h:35
Manage a collection of data files on a remote machine.
virtual void CopyFileFromRepository(const KVDataSet *ds, const Char_t *datatype, const Char_t *filename, const Char_t *destination)
virtual const Char_t * GetFullPathToOpenFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
virtual Bool_t CheckSubdirExists(const Char_t *dir, const Char_t *subdir=0)
virtual void MakeSubdirectory(const KVDataSet *ds, const Char_t *datatype="")
virtual KVDataSetManager * NewDataSetManager()
Create and return pointer to new data set manager.
virtual const Char_t * GetFullPathToTransferFile(const KVDataSet *dataset, const Char_t *datatype, const Char_t *runfile)
virtual KVUniqueNameList * GetDirectoryListing(const KVDataSet *ds, const Char_t *datatype="", const Char_t *subdir="")
virtual int CopyFileToRepository(const Char_t *source, const KVDataSet *ds, const Char_t *datatype, const Char_t *filename)
virtual void DeleteFile(const KVDataSet *ds, const Char_t *datatype, const Char_t *filename, Bool_t confirm=kTRUE)
virtual Bool_t GetFileInfo(const KVDataSet *ds, const Char_t *datatype, const Char_t *runfile, FileStat_t &fs)
virtual Bool_t CheckFileStatus(const KVDataSet *ds, const Char_t *datatype, const Char_t *runfile)
Manage datasets stored in a remote data repository.
Optimised list in which named objects can only be placed once.
virtual void Close(Option_t *opt="")
virtual Bool_t IsValid() const
const char * Data() const
TString & ReplaceAll(const char *s1, const char *s2)
virtual Int_t Exec(const char *shellcmd)
virtual const char * UnixPathName(const char *unixpathname)
virtual void Sleep(UInt_t milliSec)
void Info(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
ClassImp(TPyArg)