KaliVeda  1.13/01
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 "KVDataSetManager.h"
14 #include "TError.h"
15 #include "TPluginManager.h"
16 #include "KVBase.h"
17 #include "KVError.h"
18 
20 
21 
22 
28 {
29  //Default constructor.
30  //Use KVDataTransfer::NewTransfer to create a new data transfer object with the correct
31  //properties to transfer files between two repositories.
32  fOK = kTRUE;
33  fSourceRep = fTargetRep = 0;
34 }
35 
36 
37 
38 
41 
42 KVDataTransfer::~KVDataTransfer()
43 {
44  //Destructor
45 }
46 
47 
48 
49 
71 
73  const Char_t* target_rep)
74 {
75  //Creates a new data transfer object to transfer files between the two named data repositories.
76  //
77  //The type of the created object depends on the values of the environment variables
78  //(defined in .kvrootrc file):
79  //~~~~
80  //source_rep.DataRepository.FileTransfer.type
81  //target_rep.DataRepository.FileTransfer.type
82  //~~~~
83  //If either of these = bbftp, we create a KVDataTransferBBFTP object.
84  //
85  //If source_rep.DataRepository.FileTransfer.type = xrd, we create a KVDataTransferXRD object.
86  //
87  //By default (no type given), we use a KVDataTransferSFTP object.
88  //In fact, the type of object created is defined in .kvrootrc by the following plugins:
89  //
90  // # Plugins for data transfer between repositories
91  // # Used by KVDataTransfer::NewTransfer
92  // Plugin.KVDataTransfer: sftp KVDataTransferSFTP KVMultiDet "KVDataTransferSFTP()"
93  // +Plugin.KVDataTransfer: bbftp KVDataTransferBBFTP KVMultiDet "KVDataTransferBBFTP()"
94  // +Plugin.KVDataTransfer: xrd KVDataTransferXRD KVMultiDet "KVDataTransferXRD()"
95 
97  auto drm = new KVDataRepositoryManager;
98  drm->Init();
99  }
100  KVDataRepository* SR =
102  if (!SR) {
103  ::Error("KVDataTransfer::NewTransfer",
104  "Unknown source data repository: %s", source_rep);
105  return 0;
106  }
107  KVDataRepository* TR =
109  if (!TR) {
110  ::Error("KVDataTransfer::NewTransfer",
111  "Unknown target data repository: %s", target_rep);
112  return 0;
113  }
114  TString uri = "sftp"; //default plugin
115  //if either one has type 'dms'...
116  if (SR->IsType("dms") || TR->IsType("dms"))
117  uri = "dms";
118  //if either one has transfer type 'bbftp'...
119  else if (!strcmp(SR->GetFileTransferType(), "bbftp")
120  || !strcmp(TR->GetFileTransferType(), "bbftp"))
121  uri = "bbftp";
122  //if source repository has transfer type 'xrd'...
123  else if (!strcmp(SR->GetFileTransferType(), "xrd"))
124  uri = "xrd";
125  TString transfer_exec = SR->GetFileTransferExec();
126  if (!strcmp(TR->GetFileTransferType(), "bbftp")) transfer_exec = TR->GetFileTransferExec();
127  //if transfer_exec=="" then we cannot perform the transfer
128  if (transfer_exec == "") {
129  ::Error("KVDataTransfer::NewTransfer",
130  "No file transfer executable to perform transfer");
131  return 0;
132  }
133 
134  //check and load plugin library
135  TPluginHandler* ph;
136  if (!(ph = KVBase::LoadPlugin("KVDataTransfer", uri)))
137  return 0;
138 
139  KVDataTransfer* tran = (KVDataTransfer*) ph->ExecPlugin(0);
140  //set target and source repositories
141  tran->fSourceRep = SR;
142  tran->fTargetRep = TR;
143  //set transfer client executable path
144  tran->SetTransferExec(transfer_exec);
145  //initialise transfer
146  tran->init();
147  return tran;
148 }
149 
150 
151 
152 
160 
162 {
163  //Perform file transfer
164  //The user selects runs which are available in the source repository in the same way as
165  //when performing data analysis
166  //Note that this will make the 'source' repository the current active repository
167  //(i.e. gDataRepository and gDataSetManager will correspond to source repository
168  //after execution of this command).
169 
170  if (!fOK) {
171  Error("KVDataTransfer::Run",
172  "Status not OK. Data transfer aborted.");
173  return;
174  }
175  //make 'source' repository the 'active' repository
176  fSourceRep->cd();
177 
178  SetMenus();
179  SetQuit(kFALSE);
184  SetSubmit(kFALSE);
185 
186  set_dataset_pointer(nullptr);
187  SetDataType("");
188  ClearRunList();
189  SetSystem(nullptr);
190 
191  //choose dataset, data type, system, runs
192  while (!IsQuit()) {
193 
194  if (IsChooseDataSet())
195  ChooseDataSet();
196  else if (IsChooseTask())
197  ChooseDataType();
198  else if (IsChooseSystem())
199  ChooseSystem();
200  else if (IsChooseRuns())
201  ChooseRuns();
202  else if (IsSubmit())
203  TransferRuns();
204 
205  }
206 }
207 
208 
209 
210 
216 
218 {
219  //Based on information gathered from user (see Run()),
220  //perform the transfer of files.
221  //Any missing directories in the target repository are created beforehand.
222  //After transfer, the available runlist for the target repository is updated
223 
224  SetSubmit(kFALSE);
225 
226  if (!GetDataSet()) {
227  Error("KVDataTransfer::Transfer",
228  "No dataset defined for transfer. Choose dataset first.");
230  return;
231  }
232  if (GetDataType() == "") {
233  Error("KVDataTransfer::Transfer",
234  "No data type defined for transfer. Choose type of data to transfer first.");
235  SetChooseTask();
236  return;
237  }
238  if (GetRunList().IsEmpty()) {
239  Error("KVDataTransfer::Transfer",
240  "No runlist defined for transfer. Choose runs to transfer first.");
241  SetChooseRuns();
242  return;
243  }
244 
246 
248 
249  ExecuteCommand();
250 
251  //delete temporary command file if present
252  if (fCmdFile != "") gSystem->Unlink(fCmdFile.Data());
253 
254  //update available run list for target repository
256 
257  //force user to choose new system
258  SetChooseSystem();
259 }
260 
261 
262 
263 
268 
270 {
271  //Make sure that the target repository has the necessary
272  //dataset/subdirectory to receive the transferred files.
273  //If not, we create the new dataset/subdir.
274 
275  Bool_t update = kFALSE;
276  if (!fTargetRep->GetDataSetManager()->GetDataSet(GetDataSet()->GetName())->IsAvailable()) {
277  //add dataset directory to target repository
279  update = kTRUE;
280  }
281  if (!fTargetRep->GetDataSetManager()->GetDataSet(GetDataSet()->GetName())->HasDataType(GetDataType())) {
282  //add subdirectory for new data type to dataset directory
284  update = kTRUE;
285  }
286  if (update) {
287  //update dataset manager of target repository with new state of available datasets/datatypes
289  }
290 }
291 
292 
293 
294 
297 
299 {
300  //Initialisation of data transfer.
301 }
302 
303 
304 
305 
310 
312 {
313  //Set dataset to be analysed.
314  //If 'name' is not the name of a valid and available dataset
315  //in the 'source' data repository an error message is printed.
316 
317  _set_dataset_pointer(nullptr);
319  if (!ds) {
320  Error("SetDataSet", "Unknown dataset %s", name);
321  }
322  else {
323  SetDataSet(ds);
324  }
325 }
326 
327 
328 
329 
338 
340 {
341  //Set dataset to be used for transfer.
342  //If the chosen dataset is not available, an error message is printed
343  //Only datasets which are available in the source repository can be transferred
344  //If the pointer actually corresponds to a dataset in the target repository,
345  //we replace it with a pointer to the dataset with the same name in the source
346  //repository.
347 
348  //allow user to reset dataset pointer to 0
350  if (!ds)
351  return;
352 
353  //check repository
354  if (ds->GetRepository() != fSourceRep) {
356  }
357  //check availablility
358  if (!ds->IsAvailable()) {
359  Error("SetDataSet",
360  "Dataset %s is not available for analysis", ds->GetName());
361  _set_dataset_pointer(nullptr);
362  }
363 
364 }
365 
366 
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
virtual Bool_t IsType(const Char_t *typ) const
Definition: KVBase.h:184
static TPluginHandler * LoadPlugin(const Char_t *base, const Char_t *uri="0")
Definition: KVBase.cpp:793
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
Manages access to one or more data repositories.
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:1399
void UpdateAvailableRuns(const Char_t *type)
Definition: KVDataSet.cpp:1036
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:287
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)