KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVRemoteAvailableRunsFile.cpp
Go to the documentation of this file.
1 /*
2 $Id: KVRemoteAvailableRunsFile.cpp,v 1.4 2008/02/08 08:19:59 franklan Exp $
3 $Revision: 1.4 $
4 $Date: 2008/02/08 08:19:59 $
5 */
6 
7 //Created by KVClassFactory on Mon May 22 00:14:11 2006
8 //Author: John Frankland
9 
11 #include "KVDataRepository.h"
12 #include "KVDataSet.h"
13 #include "TSystem.h"
14 #include "TEnv.h"
15 
16 using namespace std;
17 
19 
20 
21 
25 {
26  //default Constructor
27  init();
28 }
29 
30 
31 
35 
37  type,
38  KVDataSet*
40  (type, ds)
41 {
42  //Constructor with name of datatype
43  //and pointer to parent dataset
44  init();
45 }
46 
47 
48 
52 
53 KVRemoteAvailableRunsFile::~KVRemoteAvailableRunsFile()
54 {
55  //Destructor
56  //Delete the runlist file from the temp directory if it has been opened
57  if (IsFileOpen()) {
61  }
62  }
63 }
64 
65 
66 
67 
71 
73 {
74  //Find executable 'curl' or programme indicated by
75  //value of DataRepository.RemoteAvailableRuns.protocol
77  ("%s.DataRepository.RemoteAvailableRuns.protocol",
78  GetDataSet()->GetRepository()->GetName()), "curl");
80 }
81 
82 
83 
84 
99 
101 {
102  //Initialise fRunlist so that it can be used to read the available runs file from the beginning.
103  //
104  //If the file has already been opened, this means resetting the ifstream to the start of the file.
105  //
106  //If not already open, open the file containing the list of available runs for the dataset.
107  //What this actually means is:
108  // - read value of DataRepository.RemoteAvailableRuns.url for the data repository
109  // - use 'curl' or programme indicated by value of
110  // DataRepository.RemoteAvailableRuns.protocol to make local copy
111  // of file
112  // - open copy
113  //Returns kFALSE in case of problems.
114 
115  //already open ?
116  if (IsFileOpen()) {
117  fRunlist.clear(); // clear any error flags (EOF etc.)
118  fRunlist.seekg(0, ios::beg); // set file buffer pointer to beginning of file
119  //if we can get a lock on the file, all is well. if not, we need to fetch a new
120  //copy
121  if (runlist_lock.Lock()) return kTRUE;
122  }
123  TString http =
124  gEnv->GetValue(Form("%s.DataRepository.RemoteAvailableRuns.url",
125  GetDataSet()->GetRepository()->GetName()), "");
126  if (http == "") {
127  Warning("OpenAvailableRunsFile(ifstream& runlist)",
128  "%s.DataRepository.RemoteAvailableRuns.url is not defined. See $KVROOT/KVFiles/.kvrootrc",
129  GetDataSet()->GetRepository()->GetName());
130  return kFALSE;
131  }
132  TString url;
133  url.Form("%s/%s", http.Data(), GetFileName());
134  //remote file will be copied to $TEMP directory with name
135  //repository.available_runs....
138  TString cmd;
139  cmd.Form("%s -o%s %s", fCurl.Data(), fFilePath.Data(), url.Data());
140  //lock temp file - just in case
142  if (gSystem->Exec(cmd.Data())) {
144  return kFALSE; // problem with curl
145  }
146  fRunlist.open(fFilePath.Data());
147  if (!fRunlist.good() || !fRunlist.is_open()) {
148  Error("OpenAvailableRunsFile",
149  "Cannot open temp file to copy remote runlist file");
151  return kFALSE;
152  }
153  return kTRUE;
154 }
155 
156 
157 
158 
163 
165 {
166  //Redefines KVAvailableRunsFile::CloseAvailableRunsFile
167  //We do not want to transfer the file again every time we need to read it,
168  //therefore we do not close the file, simply remove the lock.
170 }
171 
172 
173 
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
R__EXTERN TEnv * gEnv
int type
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
Handles lists of available runs for different datasets and types of data.
const Char_t * GetFileName() const
const KVDataSet * GetDataSet() const
KVLockfile runlist_lock
for locking runlist file
std::ifstream fRunlist
for reading runlist file
static Bool_t FindExecutable(TString &exec, const Char_t *path="$(PATH)")
Definition: KVBase.cpp:1001
static void GetTempFileName(TString &base)
Definition: KVBase.cpp:848
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition: KVDataSet.h:207
Bool_t Release()
Definition: KVLockfile.cpp:195
Bool_t Lock(const Char_t *filename="")
Definition: KVLockfile.cpp:165
List of available runfiles in a remote data repository.
KVRemoteAvailableRunsFile()
default Constructor
TString fCurl
full path to executable used to copy files
TString fFilePath
full path to copy of remote file kept in temp dir
virtual const char * GetValue(const char *name, const char *dflt) const
virtual const char * GetName() const
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
const char * Data() const
void Form(const char *fmt,...)
virtual Int_t Exec(const char *shellcmd)
virtual int Unlink(const char *name)