KaliVeda
Toolkit for HIC analysis
KVDataTransfer.cpp
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"
12 #include "KVDataRepositoryManager.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 
60 
62  const Char_t* target_rep)
63 {
64  //Creates a new data transfer object to transfer files between the two named data repositories.
65  //
66  //The type of the created object depends on the values of the environment variables
67  //(defined in .kvrootrc file):
68  //~~~~
69  //source_rep.DataRepository.FileTransfer.type
70  //target_rep.DataRepository.FileTransfer.type
71  //~~~~
72  //If either of these = bbftp, we create a KVDataTransferBBFTP object.
73  //
74  //If source_rep.DataRepository.FileTransfer.type = xrd, we create a KVDataTransferXRD object.
75  //
76  //By default (no type given), we use a KVDataTransferSFTP object.
77  //In fact, the type of object created is defined in .kvrootrc by the following plugins:
78  //
79  // # Plugins for data transfer between repositories
80  // # Used by KVDataTransfer::NewTransfer
81  // Plugin.KVDataTransfer: sftp KVDataTransferSFTP KVMultiDet "KVDataTransferSFTP()"
82  // +Plugin.KVDataTransfer: bbftp KVDataTransferBBFTP KVMultiDet "KVDataTransferBBFTP()"
83  // +Plugin.KVDataTransfer: xrd KVDataTransferXRD KVMultiDet "KVDataTransferXRD()"
84 
85  if (!gDataRepositoryManager) {
86  auto drm = new KVDataRepositoryManager;
87  drm->Init();
88  }
89  KVDataRepository* SR =
90  gDataRepositoryManager->GetRepository(source_rep);
91  if (!SR) {
92  ::Error("KVDataTransfer::NewTransfer",
93  "Unknown source data repository: %s", source_rep);
94  return 0;
95  }
96  KVDataRepository* TR =
97  gDataRepositoryManager->GetRepository(target_rep);
98  if (!TR) {
99  ::Error("KVDataTransfer::NewTransfer",
100  "Unknown target data repository: %s", target_rep);
101  return 0;
102  }
103  TString uri = "sftp"; //default plugin
104  //if either one has type 'dms'...
105  if (SR->IsType("dms") || TR->IsType("dms"))
106  uri = "dms";
107  //if either one has transfer type 'bbftp'...
108  else if (!strcmp(SR->GetFileTransferType(), "bbftp")
109  || !strcmp(TR->GetFileTransferType(), "bbftp"))
110  uri = "bbftp";
111  //if source repository has transfer type 'xrd'...
112  else if (!strcmp(SR->GetFileTransferType(), "xrd"))
113  uri = "xrd";
114  TString transfer_exec = SR->GetFileTransferExec();
115  if (!strcmp(TR->GetFileTransferType(), "bbftp")) transfer_exec = TR->GetFileTransferExec();
116  //if transfer_exec=="" then we cannot perform the transfer
117  if (transfer_exec == "") {
118  ::Error("KVDataTransfer::NewTransfer",
119  "No file transfer executable to perform transfer");
120  return 0;
121  }
122 
123  //check and load plugin library
124  TPluginHandler* ph;
125  if (!(ph = KVBase::LoadPlugin("KVDataTransfer", uri)))
126  return 0;
127 
128  KVDataTransfer* tran = (KVDataTransfer*) ph->ExecPlugin(0);
129  //set target and source repositories
130  tran->fSourceRep = SR;
131  tran->fTargetRep = TR;
132  //set transfer client executable path
133  tran->SetTransferExec(transfer_exec);
134  //initialise transfer
135  tran->init();
136  return tran;
137 }
138 
139 
140 
141 
149 
151 {
152  //Perform file transfer
153  //The user selects runs which are available in the source repository in the same way as
154  //when performing data analysis
155  //Note that this will make the 'source' repository the current active repository
156  //(i.e. gDataRepository and gDataSetManager will correspond to source repository
157  //after execution of this command).
158 
159  if (!fOK) {
160  Error("KVDataTransfer::Run",
161  "Status not OK. Data transfer aborted.");
162  return;
163  }
164  //make 'source' repository the 'active' repository
165  fSourceRep->cd();
166 
167  SetMenus();
168  SetQuit(kFALSE);
173  SetSubmit(kFALSE);
174 
175  set_dataset_pointer(nullptr);
176  SetDataType("");
177  ClearRunList();
178  SetSystem(nullptr);
179 
180  //choose dataset, data type, system, runs
181  while (!IsQuit()) {
182 
183  if (IsChooseDataSet())
184  ChooseDataSet();
185  else if (IsChooseTask())
186  ChooseDataType();
187  else if (IsChooseSystem())
188  ChooseSystem();
189  else if (IsChooseRuns())
190  ChooseRuns();
191  else if (IsSubmit())
192  TransferRuns();
193 
194  }
195 }
196 
197 
198 
199 
205 
207 {
208  //Based on information gathered from user (see Run()),
209  //perform the transfer of files.
210  //Any missing directories in the target repository are created beforehand.
211  //After transfer, the available runlist for the target repository is updated
212 
213  SetSubmit(kFALSE);
214 
215  if (!GetDataSet()) {
216  Error("KVDataTransfer::Transfer",
217  "No dataset defined for transfer. Choose dataset first.");
219  return;
220  }
221  if (GetDataType() == "") {
222  Error("KVDataTransfer::Transfer",
223  "No data type defined for transfer. Choose type of data to transfer first.");
224  SetChooseTask();
225  return;
226  }
227  if (GetRunList().IsEmpty()) {
228  Error("KVDataTransfer::Transfer",
229  "No runlist defined for transfer. Choose runs to transfer first.");
230  SetChooseRuns();
231  return;
232  }
233 
235 
237 
238  ExecuteCommand();
239 
240  //delete temporary command file if present
241  if (fCmdFile != "") gSystem->Unlink(fCmdFile.Data());
242 
243  //update available run list for target repository
245 
246  //force user to choose new system
247  SetChooseSystem();
248 }
249 
250 
251 
252 
257 
259 {
260  //Make sure that the target repository has the necessary
261  //dataset/subdirectory to receive the transferred files.
262  //If not, we create the new dataset/subdir.
263 
264  Bool_t update = kFALSE;
265  if (!fTargetRep->GetDataSetManager()->GetDataSet(GetDataSet()->GetName())->IsAvailable()) {
266  //add dataset directory to target repository
268  update = kTRUE;
269  }
270  if (!fTargetRep->GetDataSetManager()->GetDataSet(GetDataSet()->GetName())->HasDataType(GetDataType())) {
271  //add subdirectory for new data type to dataset directory
273  update = kTRUE;
274  }
275  if (update) {
276  //update dataset manager of target repository with new state of available datasets/datatypes
278  }
279 }
280 
281 
282 
283 
286 
288 {
289  //Initialisation of data transfer.
290 }
291 
292 
293 
294 
299 
301 {
302  //Set dataset to be analysed.
303  //If 'name' is not the name of a valid and available dataset
304  //in the 'source' data repository an error message is printed.
305 
306  _set_dataset_pointer(nullptr);
308  if (!ds) {
309  Error("SetDataSet", "Unknown dataset %s", name);
310  }
311  else {
312  SetDataSet(ds);
313  }
314 }
315 
316 
317 
318 
327 
329 {
330  //Set dataset to be used for transfer.
331  //If the chosen dataset is not available, an error message is printed
332  //Only datasets which are available in the source repository can be transferred
333  //If the pointer actually corresponds to a dataset in the target repository,
334  //we replace it with a pointer to the dataset with the same name in the source
335  //repository.
336 
337  //allow user to reset dataset pointer to 0
339  if (!ds)
340  return;
341 
342  //check repository
343  if (ds->GetRepository() != fSourceRep) {
345  }
346  //check availablility
347  if (!ds->IsAvailable()) {
348  Error("SetDataSet",
349  "Dataset %s is not available for analysis", ds->GetName());
350  _set_dataset_pointer(nullptr);
351  }
352 
353 }
354 
355 
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
char name[80]
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:772
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="")
const run_index_list & GetRunList() const
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
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:146
KVDataRepository * GetRepository() const
Get pointer to data repository in which dataset is stored.
Definition: KVDataSet.cpp:1374
virtual Bool_t IsAvailable() const
Definition: KVDataSet.h:223
void UpdateAvailableRuns(const KVString &type)
Definition: KVDataSet.cpp:1005
Base class for transferring data between data repositories.
virtual void init()
Initialisation of data transfer.
virtual void CheckTargetRepository()
virtual void TransferRuns()
void set_dataset_pointer(KVDataSet *ds) override
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
void Run() override
TString fCmdFile
name of command file given to transfer agent
KVDataRepository * fSourceRep
repository containing source files
void set_dataset_name(const Char_t *name) override
const char * GetName() const override
virtual const char * GetName() const
virtual void Error(const char *method, const char *msgfmt,...) const
Longptr_t ExecPlugin(int nargs)
const char * Data() const
virtual int Unlink(const char *name)
void update(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData, double factorWeightDecay, EnumRegularization regularization)
ClassImp(TPyArg)