ROOT  6.06/09
Reference Guide
TSelVerifyDataSet.cxx
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author: Sangsu Ryu 28/06/2011
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TSelVerifyDataSet //
15 // //
16 // Selector to verify dataset in parallel on workers //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 
20 #define TSelVerifyDataSet_cxx
21 
22 #include "TSelVerifyDataSet.h"
23 #include "TDataSetManager.h"
24 #include "TDSet.h"
25 #include "TParameter.h"
26 #include "TTree.h"
27 #include "TFile.h"
28 #include "TNamed.h"
29 #include "TSystem.h"
30 #include "TROOT.h"
31 #include "TEnv.h"
32 #include "TFileStager.h"
33 #include "TProofDebug.h"
34 #include "TProofServ.h"
35 #include "TFileCollection.h"
36 #include "TFileInfo.h"
37 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Constructor
42 
44 {
45  InitMembers();
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Constructor
50 
52 {
53  InitMembers();
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Initialize members
58 
60 {
61  fFopt = -1;
62  fSopt = 0;
63  fRopt = 0;
64 
65  fAllf = 0;
66  fCheckstg = 0;
67  fNonStgf = 0;
68  fReopen = 0;
69  fTouch = 0;
70  fStgf = 0;
71  fNoaction = 0;
72  fFullproc = 0;
73  fLocateonly = 0;
74  fStageonly = 0;
75  fDoall = 0;
76  fGetlistonly = 0;
77  fScanlist = 0;
78  fDbg = 0;
79 
81  fTouched = 0;
82  fOpened = 0;
83  fDisappeared = 0;
84  fSubDataSet = 0;
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Worker Begin
89 
91 {
92  TString dsname, opts;
93 
94  TNamed* par = dynamic_cast<TNamed*>(fInput->FindObject("PROOF_VerifyDataSet"));
95  if (par) {
96  dsname = par->GetTitle();
97  } else {
98  Abort("cannot find dataset name: cannot continue", kAbortProcess);
99  return;
100  }
101 
102  par = dynamic_cast<TNamed*>(fInput->FindObject("PROOF_VerifyDataSetOption"));
103  if (par) {
104  opts = par->GetTitle();
105  } else {
106  Abort("cannot find verify options: cannot continue", kAbortProcess);
107  return;
108  }
109 
110  par = dynamic_cast<TNamed*>(fInput->FindObject("PROOF_MSS"));
111  if (par) {
112  fMss = par->GetTitle();
113  PDB(kSelector, 2) Info("SlaveBegin", "dataset MSS: '%s'", fMss.Data());
114  }
115 
116  par = dynamic_cast<TNamed*>(fInput->FindObject("PROOF_StageOption"));
117  if (par) {
118  fStageopts = par->GetTitle();
119  PDB(kSelector, 2) Info("SlaveBegin", "dataset stage options: '%s'", fStageopts.Data());
120  }
121 
122  // Extract the directives
123  UInt_t o = 0;
124  if (!opts.IsNull()) {
125  // Selection options
126  if (strstr(opts, "allfiles:") || strchr(opts, 'A'))
128  else if (strstr(opts, "staged:") || strchr(opts, 'D'))
130  // Pre-action options
131  if (strstr(opts, "open:") || strchr(opts, 'O'))
133  if (strstr(opts, "touch:") || strchr(opts, 'T'))
135  if (strstr(opts, "nostagedcheck:") || strchr(opts, 'I'))
137  // Process options
138  if (strstr(opts, "noaction:") || strchr(opts, 'N'))
140  if (strstr(opts, "locateonly:") || strchr(opts, 'L'))
142  if (strstr(opts, "stageonly:") || strchr(opts, 'S'))
144  // Auxilliary options
145  if (strstr(opts, "verbose:") || strchr(opts, 'V'))
147  } else {
148  // Default
150  }
151 
152  PDB(kSelector, 1) Info("SlaveBegin", "o=%d", o);
153  // File selection
154  fFopt = ((o & TDataSetManager::kAllFiles)) ? -1 : 0;
155  if (fFopt >= 0) {
156  if ((o & TDataSetManager::kStagedFiles)) {
157  fFopt = 10;
158  } else {
159  if ((o & TDataSetManager::kReopen)) fFopt++;
160  if ((o & TDataSetManager::kTouch)) fFopt++;
161  }
162  if ((o & TDataSetManager::kNoStagedCheck)) fFopt += 100;
163  } else {
165  Warning("SlaveBegin", "kAllFiles mode: ignoring kStagedFiles or kReopen"
166  " or kTouch requests");
167  }
168  if ((o & TDataSetManager::kNoStagedCheck)) fFopt -= 100;
169  }
170  PDB(kSelector, 1) Info("SlaveBegin", "fFopt=%d", fFopt);
171 
172  // Type of action
173  fSopt = ((o & TDataSetManager::kNoAction)) ? -1 : 0;
174  if (fSopt >= 0) {
176  Error("SlaveBegin", "kLocateOnly and kStageOnly cannot be processed concurrently");
177  return;
178  }
179  if ((o & TDataSetManager::kLocateOnly)) fSopt = 1;
180  if ((o & TDataSetManager::kStageOnly)) fSopt = 2;
181  } else if ((o & TDataSetManager::kLocateOnly) || (o & TDataSetManager::kStageOnly)) {
182  Warning("SlaveBegin", "kNoAction mode: ignoring kLocateOnly or kStageOnly requests");
183  }
184  PDB(kSelector, 1) Info("SlaveBegin", "fSopt=%d", fSopt);
185 
187 
188  // File selection, Reopen and Touch options
189  fAllf = (fFopt == -1) ? kTRUE : kFALSE;
190  fCheckstg = (fFopt >= 100 || fFopt < -1) ? kFALSE : kTRUE;
191  if (fFopt >= 0) fFopt %= 100;
192  fNonStgf = (fFopt >= 0 && fFopt < 10) ? kTRUE : kFALSE;
193  fReopen = (fFopt >= 1 && fFopt < 10) ? kTRUE : kFALSE;
194  fTouch = (fFopt >= 2 && fFopt < 10) ? kTRUE : kFALSE;
195  fStgf = (fFopt == 10) ? kTRUE : kFALSE;
196 
197  PDB(kSelector, 1) Info("SlaveBegin",
198  "fAllf=%d fCheckstg=%d fNonStgf=%d fReopen=%d fTouch=%d fStgf=%d",
200 
201  // File processing options
202  fNoaction = (fSopt == -1) ? kTRUE : kFALSE;
203  fFullproc = (fSopt == 0) ? kTRUE : kFALSE;
204  fLocateonly = (fSopt == 1) ? kTRUE : kFALSE;
205  fStageonly = (fSopt == 2) ? kTRUE : kFALSE;
206 
207  PDB(kSelector, 1) Info("SlaveBegin",
208  "fNoaction=%d fFullproc=%d fLocateonly=%d fStageonly=%d",
210 
211  // Run options
212  fDoall = (fRopt == 0) ? kTRUE : kFALSE;
213  fGetlistonly = (fRopt == 1) ? kTRUE : kFALSE;
214  fScanlist = (fRopt == 2) ? kTRUE : kFALSE;
215 
216  PDB(kSelector, 1) Info("SlaveBegin",
217  "fDoall=%d fGetlistonly=%d fScanlist=%d",
219 
220  TString hostname(TUrl(gSystem->HostName()).GetHostFQDN());
221  TString thisordinal = gProofServ ? gProofServ->GetOrdinal() : "n.d";
222  TString title =
223  TString::Format("TSelVerifyDataSet_%s_%s", hostname.Data(), thisordinal.Data());
224  fSubDataSet= new TFileCollection(dsname, title);
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Process a single entry
229 
231 {
232  TDSetElement *fCurrent = 0;
233  TPair *elemPair = 0;
234  if (fInput && (elemPair = dynamic_cast<TPair *>
235  (fInput->FindObject("PROOF_CurrentElement")))) {
236  if ((fCurrent = dynamic_cast<TDSetElement *>(elemPair->Value())))
237  Info("Process", "entry %lld: file: '%s'", entry, fCurrent->GetName());
238  }
239  if (!fCurrent) {
240  Error("Process", "entry %lld: current element not found!", entry);
241  return kFALSE;
242  }
243 
244  TFileInfo *fileInfo = dynamic_cast<TFileInfo*>(fCurrent->GetAssocObj(0));
245  if (!fileInfo) {
246  Error("Process", "can not get TFileInfo; returning");
247  return kFALSE;
248  }
249 
250  PDB(kSelector, 1) {
251  Info("Process", "input fileinfo: ");
252  fileInfo->Print("L");
253  }
254 
255  TFileStager *stager = 0;
256  Bool_t createStager = kFALSE;
257 
258  TFileInfo* newfileinfo = new TFileInfo(*fileInfo);
259  newfileinfo->SetIndex(fileInfo->GetIndex());
260 
261  if (fDoall || fGetlistonly) {
262 
263  stager = (fMss && strlen(fMss) > 0) ? TFileStager::Open(fMss) : 0;
264  createStager = (stager) ? kFALSE : kTRUE;
265 
266  // Check which files have been staged, this can be replaced by a bulk command,
267  // once it exists in the xrdclient
268 
269  // For real time monitoring
271 
272  Bool_t changed = kFALSE;
273  Bool_t touched = kFALSE;
274  Bool_t disappeared = kFALSE;
275 
276  TDataSetManager::CheckStagedStatus(newfileinfo, fFopt, -1, 0, stager, createStager,
277  fDbg, changed, touched, disappeared);
278 
279  if (changed) fChangedDs = kTRUE;
280  if (touched) fTouched++;
281  if (disappeared) fDisappeared++;
282 
283  SafeDelete(stager);
284 
285  PDB(kSelector, 1) Info("Process",
286  "fChangedDs = %d, fTouched = %d disappeared = %d",
288 
289  // If required to only get the list we are done
290  if (fGetlistonly) {
291  Info("Process", "updated fileinfo: ");
292  newfileinfo->Print("F");
293  fSubDataSet->Add(newfileinfo);
294  return kTRUE;
295  }
296  }
297 
298  if (!fNoaction && (fDoall || fScanlist)) {
299 
300  // Point to the fileinfo
301  //newStagedFiles = (!fDoall && fScanlist && flist) ? flist : newStagedFiles;
302  if (!fDoall && fScanlist) {
303  SafeDelete(newfileinfo);
304  newfileinfo = new TFileInfo(*fileInfo);
305  newfileinfo->SetIndex(fileInfo->GetIndex());
306  }
307 
308  // Loop over now staged files
309  PDB(kSelector, 1) Info("Process",
310  "file appear to be newly staged; %s",
311  newfileinfo->GetFirstUrl()->GetUrl());
312 
313  // If staging files, prepare the stager
314  if (fLocateonly || fStageonly) {
315  stager = (fMss && strlen(fMss) > 0) ? TFileStager::Open(fMss) : 0;
316  createStager = (stager) ? kFALSE : kTRUE;
317  }
318 
319  // Process the file
320  Bool_t changed = kFALSE;
321  Bool_t opened = kFALSE;
322  TDataSetManager::ProcessFile(newfileinfo, fSopt, fCheckstg, fDoall, stager, createStager, fStageopts,
323  fDbg, changed, opened);
324 
325  if (changed) fChangedDs = kTRUE;
326  if (opened) fOpened++;
327  }
328 
329  PDB(kSelector, 1) {
330  Info("Process", "updated fileinfo: ");
331  newfileinfo->Print("L");
332  }
333  fSubDataSet->Add(newfileinfo);
334 
335  return kTRUE;
336 }
337 
338 ////////////////////////////////////////////////////////////////////////////////
339 /// Worker Terminate
340 
342 {
343  if (fSubDataSet) {
344  fSubDataSet->Update();
345  if (fSubDataSet->GetNFiles() > 0) {
347  Info("SlaveTerminate",
348  "sub-dataset '%s' added to the output list (%lld files)",
350  }
351  // Add information for registration
352  fOutput->Add(new TNamed(TString::Format("DATASET_%s", fSubDataSet->GetName()).Data(),"OT:sortidx:"));
353  fOutput->Add(new TNamed("PROOFSERV_RegisterDataSet", ""));
354  }
355 
356  // Send the number of files disppeared, opened and mark 'changed'if any fileinfo in the dataset has changed
357  TString hostname(TUrl(gSystem->HostName()).GetHostFQDN());
358  TString thisordinal = gProofServ ? gProofServ->GetOrdinal() : "n.d";
359  TString sfdisppeared= TString::Format("PROOF_NoFilesDisppeared_%s_%s", hostname.Data(), thisordinal.Data());
360  fOutput->Add(new TParameter<Int_t>(sfdisppeared.Data(), fDisappeared));
361  TString sfOpened= TString::Format("PROOF_NoFilesOpened_%s_%s", hostname.Data(), thisordinal.Data());
362  fOutput->Add(new TParameter<Int_t>(sfOpened.Data(), fOpened));
363  TString sfTouched = TString::Format("PROOF_NoFilesTouched_%s_%s", hostname.Data(), thisordinal.Data());
364  fOutput->Add(new TParameter<Int_t>(sfTouched.Data(), fTouched));
365  TString schanged= TString::Format("PROOF_DataSetChanged_%s_%s", hostname.Data(), thisordinal.Data());
366  fOutput->Add(new TParameter<Bool_t>(schanged.Data(), fChangedDs));
367 }
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
double par[1]
Definition: unuranDistr.cxx:38
Long64_t GetNFiles() const
TSelectorList * fOutput
Definition: TSelector.h:50
long long Long64_t
Definition: RtypesCore.h:69
void Print(Option_t *options="") const
Print information about this object.
Definition: TFileInfo.cxx:475
This class represents a WWW compatible URL.
Definition: TUrl.h:41
virtual void SlaveTerminate()
Worker Terminate.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
TFileCollection * fSubDataSet
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:496
void SetIndex(Int_t idx)
Definition: TFileInfo.h:111
static void ProcessFile(TFileInfo *fileInfo, Int_t sopt, Bool_t checkstg, Bool_t doall, TFileStager *stager, Bool_t createStager, const char *stageopts, Bool_t dbg, Bool_t &changed, Bool_t &opened)
Locate, stage, or fully validate file "fileInfo".
TUrl * GetFirstUrl() const
Definition: TFileInfo.h:83
const char * Data() const
Definition: TString.h:349
Int_t Update(Long64_t avgsize=-1)
Update accumulated information about the elements of the collection (e.g.
#define SafeDelete(p)
Definition: RConfig.h:436
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
#define PDB(mask, level)
Definition: TProofDebug.h:58
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
TSelVerifyDataSet()
Constructor.
std::vector< std::vector< double > > Data
ClassImp(TSelVerifyDataSet) TSelVerifyDataSet
Constructor.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
static Bool_t CheckStagedStatus(TFileInfo *fileInfo, Int_t fopt, Int_t maxfiles, Int_t newstagedfiles, TFileStager *stager, Bool_t createStager, Bool_t dbg, Bool_t &changed, Bool_t &touched, Bool_t &disappeared)
Check stage status of the file described by "fileInfo".
virtual void SlaveBegin(TTree *tree)
Worker Begin.
Named parameter, streamable and storable.
Definition: TParameter.h:49
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual void Abort(const char *why, EAbort what=kAbortProcess)
Abort processing.
Definition: TSelector.cxx:114
Int_t Add(TFileInfo *info)
Add TFileInfo to the collection.
TObject * Value() const
Definition: TMap.h:125
unsigned int UInt_t
Definition: RtypesCore.h:42
void InitMembers()
Initialize members.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Bool_t IsNull() const
Definition: TString.h:387
Long64_t entry
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
virtual const char * HostName()
Return the system's host name.
Definition: TSystem.cxx:307
const char * GetOrdinal() const
Definition: TProofServ.h:265
static TFileStager * Open(const char *stager)
Open a stager, after having loaded the relevant plug-in.
virtual void DispatchOneEvent(Bool_t pendingOnly=kFALSE)
Dispatch a single event.
Definition: TSystem.cxx:433
virtual Bool_t Process(Long64_t entry)
Process a single entry.
TObject * GetAssocObj(Long64_t i, Bool_t isentry=kFALSE)
Get i-th associated object.
Definition: TDSet.cxx:652
TList * fInput
Current object if processing object (vs. TTree)
Definition: TSelector.h:49
R__EXTERN TProofServ * gProofServ
Definition: TProofServ.h:359
virtual void Add(TObject *obj)
Definition: TList.h:81
Class that contains a list of TFileInfo's and accumulated meta data information about its entries...
A TTree object has a header with a name and a title.
Definition: TTree.h:94
Int_t GetIndex() const
Definition: TFileInfo.h:110
Class describing a generic file including meta information.
Definition: TFileInfo.h:50
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904