KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVRemoteDataSetManager.cpp
1/*
2$Id: KVRemoteDataSetManager.cpp,v 1.5 2007/09/20 11:30:17 franklan Exp $
3$Revision: 1.5 $
4$Date: 2007/09/20 11:30:17 $
5*/
6
7//Created by KVClassFactory on Thu Sep 7 15:16:29 2006
8//Author: John Frankland
9
10#include "KVRemoteDataSetManager.h"
11#include "KVDataRepository.h"
12#include "TError.h"
13#include "TObjString.h"
14#include "TObjArray.h"
15#include "TEnv.h"
16
17using namespace std;
18
20
21
22
24
26{
27 //Default constructor
28}
29
30
31
34
39
40
41
65
67{
68 //Transfers file $KVROOT/KVFiles/[repository name].available.datasets
69 //from remote machine containing info on available datasets and
70 //associated subdirectories in remote data repository.
71 //Copies to local working directory and opens for reading, if all goes
72 //well (returns kTRUE).
73 //Returns kFALSE in case of problems.
74 //
75 //N.B. If 'curl' is used to transfer the file, we check for HTML code in the file
76 //It can happen that 'curl' itself does not give an error when the web server
77 //is down, but transfers a file which looks like this:
78// <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
79// <html><head>
80// <title>403 Forbidden</title>
81// </head><body>
82// <h1>Forbidden</h1>
83// <p>You don't have permission to access /KaliVedaDoc/ccali.available.datasets
84// on this server.</p>
85// <p>Additionally, a 403 Forbidden
86// error was encountered while trying to use an ErrorDocument to handle the request.</p>
87// <hr>
88// <address>Apache/2.0.53 (Unix) mod_ssl/2.0.53 OpenSSL/0.9.7a DAV/2 PHP/5.1.6 mod_python/3.2.8 Python/2.4.2 mod_jk/1.2.15 mod_perl/2.0.2 Perl/v5.8.7 Server at indra.in2p3.fr Port 80</address>
89// </body></html>
90
91
92 TString http =
93 gEnv->GetValue(Form("%s.DataRepository.RemoteAvailableRuns.url",
94 fRepository->GetName()), "");
95 if (http == "") {
96 Warning("OpenAvailableDatasetsFile()",
97 "%s.DataRepository.RemoteAvailableRuns.url is not defined. See $KVROOT/KVFiles/.kvrootrc",
99 return kFALSE;
100 }
101 TString url;
102 url.Form("%s/%s", http.Data(), fCacheFileName.Data());
103
104 //Find executable 'curl' or programme indicated by
105 //value of DataRepository.RemoteAvailableRuns.protocol
107 ("%s.DataRepository.RemoteAvailableRuns.protocol",
108 fRepository->GetName()), "curl");
110 Error("OpenAvailableDatasetsFile",
111 "Executable for file transfer \"%s\" not found. You cannot use remote data repository.",
112 fCurl.Data());
113 return kFALSE;
114 }
115 TString cmd;
116 cmd.Form("%s -oremote.available.datasets %s", fCurl.Data(), url.Data());
117 if (gSystem->Exec(cmd.Data()))
118 return kFALSE; // problem with curl
119 fDatasets.open("remote.available.datasets");
120 if (fCurl.Contains("curl")) {
121 //check contents of file for HTML code
123 line.ReadLine(fDatasets);
124 if (line.Contains("<")) {
125 Error("OpenAvailableDatasetsFile",
126 "Remote available datasets file transferred by curl contains HTML code :");
127 //print contents of file
128 cout << line.Data() << endl;
129 line.ReadLine(fDatasets);
130 while (fDatasets.good()) {
131 cout << line.Data() << endl;
132 line.ReadLine(fDatasets);
133 }
134 Error("OpenAvailableDatasetsFile",
135 "You cannot use this remote data repository");
136 return kFALSE;
137 }
138 else { // no HTML in file : OK
139 //reset stream to beginning of file
140 fDatasets.clear(); // clear any error flags (EOF etc.)
141 fDatasets.seekg(0, ios::beg); // set file buffer pointer to beginning of file
142 }
143 }
144 return kTRUE;
145}
146
147
148
162
164{
165 //Check availability of datasets in repository associated to this data set manager
166 //For remote data sets/repositories, this is done by transferring from the remote
167 //machine the file $KVROOT/KVFiles/[repository name].available.datasets and
168 //reading from it the datasets and subdirectories which are present on the remote
169 //machine.
170 //Example file:
171 //INDRA_camp1 : root
172 //INDRA_camp2 :
173 //INDRA_camp4 :
174 //INDRA_camp5 : raw,recon,ident,root
175 //INDRA_e416a : raw,
176 //INDRA_e475s :
177
178 fNavailable = 0;
180}
181
182
bool Bool_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
R__EXTERN TEnv * gEnv
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
static Bool_t FindExecutable(TString &exec, const Char_t *path="$(PATH)")
Definition KVBase.cpp:1001
TString fCacheFileName
name of cache file ( = [repository name].available.datasets)
KVDataRepository * fRepository
the repository for which data sets are handled
Int_t fNavailable
number of available datasets
virtual Bool_t ReadAvailableDatasetsFile()
std::ifstream fDatasets
for reading cached repository available datasets file
Manage datasets stored in a remote data repository.
virtual ~KVRemoteDataSetManager()
Destructor.
TString fCurl
full path to executable used to copy files
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
virtual const char * GetValue(const char *name, const char *dflt) const
const char * GetName() const override
const char * Data() const
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual Int_t Exec(const char *shellcmd)
TLine * line
void Error(const char *location, const char *fmt,...)
void Warning(const char *location, const char *fmt,...)
ClassImp(TPyArg)