KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVDataTransfer.cpp
Go to the documentation of this file.
1 /*
2 $Id: KVDataTransfer.cpp,v 1.6 2007/05/31 09:59:22 franklan Exp $
3 $Revision: 1.6 $
4 $Date: 2007/05/31 09:59:22 $
5 */
6 
7 //Created by KVClassFactory on Mon Sep 18 14:27:21 2006
8 //Author: franklan
9 
10 #include "KVDataTransfer.h"
11 #include "KVDataSet.h"
13 #include "KVDataRepository.h"
14 #include "KVDataSetManager.h"
15 #include "TError.h"
16 #include "TPluginManager.h"
17 #include "KVBase.h"
18 #include "KVError.h"
19 
21 
22 
23 
29 {
30  //Default constructor.
31  //Use KVDataTransfer::NewTransfer to create a new data transfer object with the correct
32  //properties to transfer files between two repositories.
33  fOK = kTRUE;
34  fSourceRep = fTargetRep = 0;
35 }
36 
37 
38 
39 
42 
43 KVDataTransfer::~KVDataTransfer()
44 {
45  //Destructor
46 }
47 
48 
49 
50 
69 
71  const Char_t* target_rep)
72 {
73  //Creates a new data transfer object to transfer files between the two named data repositories.
74  //The type of the created object depends on the values of the environment variables
75  //(defined in .kvrootrc file):
76  //
77  //source_rep.DataRepository.FileTransfer.type
78  //target_rep.DataRepository.FileTransfer.type
79  //
80  //If either of these = bbftp, we create a KVDataTransferBBFTP object.
81  //If source_rep.DataRepository.FileTransfer.type = xrd, we create a KVDataTransferXRD object.
82  //By default (no type given), we use a KVDataTransferSFTP object.
83  //In fact, the type of object created is defined in .kvrootrc by the following plugins:
84  //
85  // # Plugins for data transfer between repositories
86  // # Used by KVDataTransfer::NewTransfer
87  // Plugin.KVDataTransfer: sftp KVDataTransferSFTP KVMultiDet "KVDataTransferSFTP()"
88  // +Plugin.KVDataTransfer: bbftp KVDataTransferBBFTP KVMultiDet "KVDataTransferBBFTP()"
89  // +Plugin.KVDataTransfer: xrd KVDataTransferXRD KVMultiDet "KVDataTransferXRD()"
90 
91  KVDataRepository* SR =
93  if (!SR) {
94  ::Error("KVDataTransfer::NewTransfer",
95  "Unknown source data repository: %s", source_rep);
96  return 0;
97  }
98  KVDataRepository* TR =
100  if (!TR) {
101  ::Error("KVDataTransfer::NewTransfer",
102  "Unknown target data repository: %s", target_rep);
103  return 0;
104  }
105  TString uri = "sftp"; //default plugin
106  //if either one has transfer type 'bbftp'...
107  if (!strcmp(SR->GetFileTransferType(), "bbftp")
108  || !strcmp(TR->GetFileTransferType(), "bbftp"))
109  uri = "bbftp";
110  //if source repository has transfer type 'xrd'...
111  else if (!strcmp(SR->GetFileTransferType(), "xrd"))
112  uri = "xrd";
113  TString transfer_exec = SR->GetFileTransferExec();
114  if (!strcmp(TR->GetFileTransferType(), "bbftp")) transfer_exec = TR->GetFileTransferExec();
115  //if transfer_exec=="" then we cannot perform the transfer
116  if (transfer_exec == "") {
117  ::Error("KVDataTransfer::NewTransfer",
118  "No file transfer executable to perform transfer");
119  return 0;
120  }
121 
122  //check and load plugin library
123  TPluginHandler* ph;
124  if (!(ph = KVBase::LoadPlugin("KVDataTransfer", uri)))
125  return 0;
126 
127  KVDataTransfer* tran = (KVDataTransfer*) ph->ExecPlugin(0);
128  //set target and source repositories
129  tran->fSourceRep = SR;
130  tran->fTargetRep = TR;
131  //set transfer client executable path
132  tran->SetTransferExec(transfer_exec);
133  //initialise transfer
134  tran->init();
135  return tran;
136 }
137 
138 
139 
140 
148 
150 {
151  //Perform file transfer
152  //The user selects runs which are available in the source repository in the same way as
153  //when performing data analysis
154  //Note that this will make the 'source' repository the current active repository
155  //(i.e. gDataRepository and gDataSetManager will correspond to source repository
156  //after execution of this command).
157 
158  if (!fOK) {
159  Error("KVDataTransfer::Run",
160  "Status not OK. Data transfer aborted.");
161  return;
162  }
163  //make 'source' repository the 'active' repository
164  fSourceRep->cd();
165 
166  SetMenus();
167  SetQuit(kFALSE);
172  SetSubmit(kFALSE);
173 
174  set_dataset_pointer(nullptr);
175  SetDataType("");
176  ClearRunList();
177  SetSystem(nullptr);
178 
179  //choose dataset, data type, system, runs
180  while (!IsQuit()) {
181 
182  if (IsChooseDataSet())
183  ChooseDataSet();
184  else if (IsChooseTask())
185  ChooseDataType();
186  else if (IsChooseSystem())
187  ChooseSystem();
188  else if (IsChooseRuns())
189  ChooseRuns();
190  else if (IsSubmit())
191  TransferRuns();
192 
193  }
194 }
195 
196 
197 
198 
204 
206 {
207  //Based on information gathered from user (see Run()),
208  //perform the transfer of files.
209  //Any missing directories in the target repository are created beforehand.
210  //After transfer, the available runlist for the target repository is updated
211 
212  SetSubmit(kFALSE);
213 
214  if (!GetDataSet()) {
215  Error("KVDataTransfer::Transfer",
216  "No dataset defined for transfer. Choose dataset first.");
218  return;
219  }
220  if (GetDataType() == "") {
221  Error("KVDataTransfer::Transfer",
222  "No data type defined for transfer. Choose type of data to transfer first.");
223  SetChooseTask();
224  return;
225  }
226  if (GetRunList().IsEmpty()) {
227  Error("KVDataTransfer::Transfer",
228  "No runlist defined for transfer. Choose runs to transfer first.");
229  SetChooseRuns();
230  return;
231  }
232 
234 
236 
237  ExecuteCommand();
238 
239  //delete temporary command file if present
240  if (fCmdFile != "") gSystem->Unlink(fCmdFile.Data());
241 
242  //update available run list for target repository
244 
245  //force user to choose new system
246  SetChooseSystem();
247 }
248 
249 
250 
251 
256 
258 {
259  //Make sure that the target repository has the necessary
260  //dataset/subdirectory to receive the transferred files.
261  //If not, we create the new dataset/subdir.
262 
263  Bool_t update = kFALSE;
264  if (!fTargetRep->GetDataSetManager()->GetDataSet(GetDataSet()->GetName())->IsAvailable()) {
265  //add dataset directory to target repository
267  update = kTRUE;
268  }
269  if (!fTargetRep->GetDataSetManager()->GetDataSet(GetDataSet()->GetName())->HasDataType(GetDataType())) {
270  //add subdirectory for new data type to dataset directory
272  update = kTRUE;
273  }
274  if (update) {
275  //update dataset manager of target repository with new state of available datasets/datatypes
277  }
278 }
279 
280 
281 
282 
285 
287 {
288  //Initialisation of data transfer.
289 }
290 
291 
292 
293 
298 
300 {
301  //Set dataset to be analysed.
302  //If 'name' is not the name of a valid and available dataset
303  //in the 'source' data repository an error message is printed.
304 
305  _set_dataset_pointer(nullptr);
307  if (!ds) {
308  Error("SetDataSet", "Unknown dataset %s", name);
309  }
310  else {
311  SetDataSet(ds);
312  }
313 }
314 
315 
316 
317 
326 
328 {
329  //Set dataset to be used for transfer.
330  //If the chosen dataset is not available, an error message is printed
331  //Only datasets which are available in the source repository can be transferred
332  //If the pointer actually corresponds to a dataset in the target repository,
333  //we replace it with a pointer to the dataset with the same name in the source
334  //repository.
335 
336  //allow user to reset dataset pointer to 0
338  if (!ds)
339  return;
340 
341  //check repository
342  if (ds->GetRepository() != fSourceRep) {
344  }
345  //check availablility
346  if (!ds->IsAvailable()) {
347  Error("SetDataSet",
348  "Dataset %s is not available for analysis", ds->GetName());
349  _set_dataset_pointer(nullptr);
350  }
351 
352 }
353 
354 
KVDataRepositoryManager * gDataRepositoryManager
Defines macros for standard error messages.
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
R__EXTERN TSystem * gSystem
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:756
const KVString & GetDataType() const
void SetSubmit(Bool_t yes=kTRUE)
void SetQuit(Bool_t yes=kTRUE)
void SetDataType(const Char_t *name)
void SetMenus(Bool_t on=kTRUE)
Bool_t IsSubmit() const
Bool_t IsQuit() const
KVDataRepository * GetRepository(const Char_t *name) const
Base class for managing repositories of experimental data.
virtual KVDataSetManager * GetDataSetManager() const
Return pointer to data set manager for this repository.
virtual const Char_t * GetFileTransferExec() const
returns full path to executable used for remote file transfer
virtual const Char_t * GetFileTransferType() const
returns protocol used for remote file transfer
virtual void MakeSubdirectory(const KVDataSet *dataset, const Char_t *datatype="")
Bool_t IsChooseTask() const
Bool_t IsChooseRuns() const
void SetDataSet(KVDataSet *ds)
void ChooseRuns(KVDBSystem *system=nullptr, const Char_t *data_type="")
void ChooseSystem(const Char_t *data_type="")
void SetChooseSystem(Bool_t yes=kTRUE)
const KVDataSet * GetDataSet() const
void SetChooseRuns(Bool_t yes=kTRUE)
void SetSystem(KVDBSystem *syst)
Set the System used in the analysis.
Bool_t IsChooseDataSet() const
const KVNumberList & GetRunList() const
Bool_t IsChooseSystem() const
void SetChooseDataSet(Bool_t yes=kTRUE)
void SetChooseTask(Bool_t yes=kTRUE)
void _set_dataset_pointer(KVDataSet *ds)
virtual void Update()
KVDataSet * GetDataSet(Int_t) const
Return pointer to DataSet using index in list of all datasets, index>=0.
Manage an experimental dataset corresponding to a given experiment or campaign.
Definition: KVDataSet.h:207
KVDataRepository * GetRepository() const
Get pointer to data repository in which dataset is stored.
Definition: KVDataSet.cpp:1398
void UpdateAvailableRuns(const Char_t *type)
Definition: KVDataSet.cpp:1035
virtual Bool_t IsAvailable() const
Returns kTRUE if this dataset is available for analysis, i.e. if any associated data files are stored...
Definition: KVDataSet.h:282
Base class for transferring data between data repositories.
virtual void Run()
virtual void init()
Initialisation of data transfer.
virtual void set_dataset_name(const Char_t *name)
virtual void CheckTargetRepository()
virtual void set_dataset_pointer(KVDataSet *ds)
virtual void TransferRuns()
virtual void ExecuteCommand()=0
Bool_t fOK
may be set to kFALSE by init(), in which case Run() will abort
KVDataRepository * fTargetRep
repository where files will be copied
virtual void SetTransferExec(const Char_t *path)
static KVDataTransfer * NewTransfer(const Char_t *source_rep, const Char_t *target_rep)
virtual void WriteTransferScript()=0
TString fCmdFile
name of command file given to transfer agent
KVDataRepository * fSourceRep
repository containing source files
virtual const char * GetName() const
virtual const char * GetName() const
virtual void Error(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs, const T &... params)
const char * Data() const
virtual int Unlink(const char *name)
void update(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData, double factorWeightDecay, EnumRegularization regularization)