ROOT  6.06/09
Reference Guide
TDSet.cxx
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author: Fons Rademakers 11/01/02
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2001, 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 // TDSet //
15 // //
16 // This class implements a data set to be used for PROOF processing. //
17 // The TDSet defines the class of which objects will be processed, //
18 // the directory in the file where the objects of that type can be //
19 // found and the list of files to be processed. The files can be //
20 // specified as logical file names (LFN's) or as physical file names //
21 // (PFN's). In case of LFN's the resolution to PFN's will be done //
22 // according to the currently active GRID interface. //
23 // Examples: //
24 // TDSet treeset("TTree", "AOD"); //
25 // treeset.Add("lfn:/alien.cern.ch/alice/prod2002/file1"); //
26 // ... //
27 // treeset.AddFriend(friendset); //
28 // //
29 // or //
30 // //
31 // TDSet objset("MyEvent", "*", "/events"); //
32 // objset.Add("root://cms.cern.ch/user/prod2002/hprod_1.root"); //
33 // ... //
34 // objset.Add(set2003); //
35 // //
36 // Validity of file names will only be checked at processing time //
37 // (typically on the PROOF master server), not at creation time. //
38 // //
39 //////////////////////////////////////////////////////////////////////////
40 
41 #include "TDSet.h"
42 
43 #include "Riostream.h"
44 #include "TChain.h"
45 #include "TClass.h"
46 #include "TClassTable.h"
47 #include "TCut.h"
48 #include "TDataSetManager.h"
49 #include "TError.h"
50 #include "TEntryList.h"
51 #include "TEnv.h"
52 #include "TEventList.h"
53 #include "TFile.h"
54 #include "TFileInfo.h"
55 #include "TFileStager.h"
56 #include "TFriendElement.h"
57 #include "TKey.h"
58 #include "THashList.h"
59 #include "TMap.h"
60 #include "TROOT.h"
61 #include "TTimeStamp.h"
62 #include "TTree.h"
63 #include "TUrl.h"
64 #include "TRegexp.h"
65 #include "TVirtualPerfStats.h"
66 #include "TProof.h"
67 #include "TProofChain.h"
68 #include "TProofServ.h"
69 #include "TPluginManager.h"
70 #include "TChain.h"
71 #include "TChainElement.h"
72 #include "TSystem.h"
73 #include "THashList.h"
74 #include "TSelector.h"
75 
76 #include "TVirtualStreamerInfo.h"
77 #include "TClassRef.h"
78 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Default constructor
84 
85 TDSetElement::TDSetElement() : TNamed("",""),
86  fDirectory(), fFirst(0), fNum(0), fMsd(),
87  fTDSetOffset(0), fEntryList(0), fValid(kFALSE),
88  fEntries(0), fFriends(0), fDataSet(), fAssocObjList(0),
89  fMaxProcTime(-1)
90 {
91  ResetBit(kWriteV3);
92  ResetBit(kHasBeenLookedUp);
93  ResetBit(kEmpty);
94  ResetBit(kCorrupted);
95  ResetBit(kNewRun);
96  ResetBit(kNewPacket);
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Create a TDSet element.
101 
102 TDSetElement::TDSetElement(const char *file, const char *objname, const char *dir,
103  Long64_t first, Long64_t num,
104  const char *msd, const char *dataset)
105  : TNamed(file, objname)
106 {
107  if (first < 0) {
108  Warning("TDSetElement", "first must be >= 0, %lld is not allowed - setting to 0", first);
109  fFirst = 0;
110  } else {
111  fFirst = first;
112  }
113  if (num < -1) {
114  Warning("TDSetElement", "num must be >= -1, %lld is not allowed - setting to -1", num);
115  fNum = -1;
116  } else {
117  fNum = num;
118  }
119  fMsd = msd;
120  fTDSetOffset = 0;
121  fEntryList = 0;
122  fFriends = 0;
123  fValid = kFALSE;
124  fEntries = -1;
125  fDataSet = dataset;
126  fAssocObjList = 0;
127  if (dir)
128  fDirectory = dir;
129  fMaxProcTime = -1.;
130 
133  ResetBit(kEmpty);
135  ResetBit(kNewRun);
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// copy constructor
141 
143  : TNamed(elem.GetFileName(), elem.GetObjName())
144 {
145  fDirectory = elem.GetDirectory();
146  fFirst = elem.fFirst;
147  fNum = elem.fNum;
148  fMsd = elem.fMsd;
149  fTDSetOffset = elem.fTDSetOffset;
150  fEntryList = 0;
151  fValid = elem.fValid;
152  fEntries = elem.fEntries;
153  fFriends = 0;
154  fDataSet = elem.fDataSet;
155  fAssocObjList = 0;
156  fMaxProcTime = elem.fMaxProcTime;
159  ResetBit(kEmpty);
161  ResetBit(kNewRun);
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Clean up the element.
167 
169 {
170  DeleteFriends();
171  if (fAssocObjList) {
174  }
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Check if 'elem' is overlapping or subsequent and, if the case, return
179 /// a merged element.
180 /// Returns:
181 /// 1 if the elements are overlapping
182 /// 0 if the elements are subsequent
183 /// -1 if the elements are neither overlapping nor subsequent
184 
186 {
187  // The element must be defined
188  if (!elem) return -1;
189 
190  // The file names and object names must be the same
191  if (strcmp(GetName(), elem->GetName()) || strcmp(GetTitle(), elem->GetTitle()))
192  return -1;
193 
194  Int_t rc = -1;
195  // Check the overlap or subsequency
196  if (fFirst == 0 && fNum == -1) {
197  // Overlap, since we cover already the full range
198  rc = 1;
199  } else if (elem->GetFirst() == 0 && elem->GetNum() == -1) {
200  // Overlap, since 'elem' cover already the full range
201  fFirst = 0;
202  fNum = -1;
203  fEntries = elem->GetEntries();
204  rc = 1;
205  } else if (fFirst >= 0 && fNum > 0 && elem->GetFirst() >= 0 && elem->GetNum() > 0) {
206  Long64_t last = fFirst + fNum - 1, lastref = 0;
207  Long64_t lastelem = elem->GetFirst() + elem->GetNum() - 1;
208  if (elem->GetFirst() == last + 1) {
209  lastref = lastelem;
210  rc = 0;
211  } else if (fFirst == lastelem + 1) {
212  fFirst += elem->GetFirst();
213  lastref = last;
214  rc = 0;
215  } else if (elem->GetFirst() < last + 1 && elem->GetFirst() >= fFirst) {
216  lastref = (lastelem > last) ? lastelem : last;
217  rc = 1;
218  } else if (fFirst < lastelem + 1 && fFirst >= elem->GetFirst()) {
219  fFirst += elem->GetFirst();
220  lastref = (lastelem > last) ? lastelem : last;
221  rc = 1;
222  }
223  fNum = lastref - fFirst + 1;
224  }
225  if (rc >= 0 && fEntries < 0 && elem->GetEntries() > 0) fEntries = elem->GetEntries();
226 
227  // Done
228  return rc;
229 }
230 
231 ////////////////////////////////////////////////////////////////////////////////
232 /// Return the content of this element in the form of a TFileInfo
233 
235 {
236  // Create the TFileInfoMeta object
237  TFileInfoMeta *meta = 0;
238  Long64_t entries = (fEntries < 0 && fNum > 0) ? fNum : fEntries;
239  Printf("entries: %lld (%lld)", entries, fNum);
240  if (!strcmp(type, "TTree")) {
241  meta = new TFileInfoMeta(GetTitle(), "TTree", entries, fFirst,
242  fFirst + entries - 1);
243  } else {
244  meta = new TFileInfoMeta(GetTitle(), fDirectory, type, entries, fFirst,
245  fFirst + entries - 1);
246  }
247  TFileInfo *fi = new TFileInfo(GetName(), 0, 0, 0, meta);
248  if (!fDataSet.IsNull()) fi->SetTitle(fDataSet.Data());
250  return fi;
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// Return directory where to look for object.
255 
256 const char *TDSetElement::GetDirectory() const
257 {
258  return fDirectory;
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Print a TDSetElement. When option="a" print full data.
263 
265 {
266  if (opt && opt[0] == 'a') {
267  Printf("%s file=\"%s\" dir=\"%s\" obj=\"%s\" first=%lld num=%lld msd=\"%s\"",
268  IsA()->GetName(), GetName(), fDirectory.Data(), GetTitle(),
269  fFirst, fNum, fMsd.Data());
270  } else {
271  Printf("\tLFN: %s", GetName());
272  }
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 /// Validate by opening the file.
277 
279 {
280  Long64_t entries = GetEntries(isTree);
281  if (entries < 0) return; // Error should be reported by GetEntries()
282  if (fFirst < entries) {
283  if (fNum == -1) {
284  fNum = entries - fFirst;
285  fValid = kTRUE;
286  } else {
287  if (fNum <= entries - fFirst) {
288  fValid = kTRUE;
289  } else {
290  Error("Validate", "TDSetElement has only %lld entries starting"
291  " with entry %lld, while %lld were requested",
292  entries - fFirst, fFirst, fNum);
293  }
294  }
295  } else {
296  Error("Validate", "TDSetElement has only %lld entries with"
297  " first entry requested as %lld", entries, fFirst);
298  }
299 }
300 
301 ////////////////////////////////////////////////////////////////////////////////
302 /// Validate by checking against another element.
303 
305 {
306  // NOTE: Since this function validates against another TDSetElement,
307  // if the other TDSetElement (elem) did not use -1 to request all
308  // entries, this TDSetElement may get less than all entries if it
309  // requests all (with -1). For the application it was developed for
310  // (TProofSuperMaster::ValidateDSet) it works, since the design was
311  // to send the elements to their mass storage domain and let them
312  // look at the file and send the info back to the supermaster. The
313  // ability to set fValid was also required to be only exist in
314  // TDSetElement through certain function and not be set externally.
315  // TDSetElement may need to be extended for more general applications.
316 
317  if (!elem || !elem->GetValid()) {
318  Error("Validate", "TDSetElement to validate against is not valid");
319  return;
320  }
321 
323  TString elemname = TUrl(elem->GetFileName()).GetFileAndOptions();
324  if ((name == elemname) &&
325  !strcmp(GetDirectory(), elem->GetDirectory()) &&
326  !strcmp(GetObjName(), elem->GetObjName())) {
327  Long64_t entries = elem->fFirst + elem->fNum;
328  if (fFirst < entries) {
329  if (fNum == -1) {
330  fNum = entries - fFirst;
331  fValid = kTRUE;
332  } else {
333  if (fNum <= entries - fFirst) {
334  fValid = kTRUE;
335  } else {
336  Error("Validate", "TDSetElement requests %lld entries starting"
337  " with entry %lld, while TDSetElement to validate against"
338  " has only %lld entries", fNum, fFirst, entries);
339  }
340  }
341  } else {
342  Error("Validate", "TDSetElement to validate against has only %lld"
343  " entries, but this TDSetElement requested %lld as its first"
344  " entry", entries, fFirst);
345  }
346  } else {
347  Error("Validate", "TDSetElements do not refer to same objects");
348  }
349 }
350 
351 ////////////////////////////////////////////////////////////////////////////////
352 ///Compare elements by filename (and the fFirst).
353 
355 {
356  if (this == obj) return 0;
357 
358  const TDSetElement *elem = dynamic_cast<const TDSetElement*>(obj);
359  if (!elem) {
360  if (obj)
361  return (strncmp(GetName(),obj->GetName(),strlen(GetName()))) ? 1 : 0;
362  return -1;
363  }
364 
365  Int_t order = strncmp(GetName(),elem->GetFileName(),strlen(GetName()));
366  if (order == 0) {
367  if (GetFirst() < elem->GetFirst())
368  return -1;
369  else if (GetFirst() > elem->GetFirst())
370  return 1;
371  return 0;
372  }
373  return order;
374 }
375 
376 ////////////////////////////////////////////////////////////////////////////////
377 /// Add friend TDSetElement to this set. The friend element will be copied to this object.
378 
379 void TDSetElement::AddFriend(TDSetElement *friendElement, const char *alias)
380 {
381  if (!friendElement) {
382  Error("AddFriend", "The friend TDSetElement is null!");
383  return;
384  }
385  if (!fFriends) {
386  fFriends = new TList();
387  fFriends->SetOwner();
388  }
389  // Add alias (if any) as option 'friend_alias=<alias>|'
390  if (alias && strlen(alias) > 0) {
391  TUrl uf(friendElement->GetName());
392  TString uo(uf.GetOptions());
393  uo += TString::Format("friend_alias=%s|", alias);
394  uf.SetOptions(uo);
395  friendElement->SetName(uf.GetUrl());
396  }
397  fFriends->Add(new TDSetElement(*friendElement));
398 }
399 
400 ////////////////////////////////////////////////////////////////////////////////
401 /// Deletes the list of friends and all the friends on the list.
402 
404 {
405  if (!fFriends)
406  return;
407 
409  delete fFriends;
410  fFriends = 0;
411 }
412 
413 ////////////////////////////////////////////////////////////////////////////////
414 /// Returns next TDSetElement.
415 
417 {
418  if (!fIterator) {
419  fIterator = new TIter(fElements);
420  }
421 
423  return fCurrent;
424 }
425 
426 ////////////////////////////////////////////////////////////////////////////////
427 /// Returns number of entries in tree or objects in file.
428 /// If not yet defined and 'openfile' is TRUE, get the number from the file
429 /// (may considerably slow down the application).
430 /// Returns -1 in case of error.
431 
433 {
434  if (fEntries > -1 || !openfile)
435  return fEntries;
436 
437  Double_t start = 0;
438  if (gPerfStats) start = TTimeStamp();
439 
440  // Take into account possible prefixes
442  TString fname = gEnv->GetValue("Path.Localroot",""), pfx(fname);
443  // Get the locality (disable warnings or errors in connection attempts)
444  Int_t oldLevel = gErrorIgnoreLevel;
446  if ((typ = TFile::GetType(GetName(), "", &fname)) != TFile::kLocal) fname = GetName();
447  gErrorIgnoreLevel = oldLevel;
448  // Open the file
449  TFile *file = TFile::Open(fname);
450 
451  if (gPerfStats)
452  gPerfStats->FileOpenEvent(file, GetName(), start);
453 
454  if (file == 0) {
455  ::SysError("TDSetElement::GetEntries",
456  "cannot open file %s (type: %d, pfx: %s)", GetName(), typ, pfx.Data());
457  return -1;
458  }
459 
460  // Record end-point Url and mark as looked-up; be careful to change
461  // nothing in the file name, otherwise some cross-checks may fail.
462  // The lookup is only performed if not yet done
463  if (Lookup(kFALSE) != 0) Warning("GetEntries", "lookup problems for %s", GetName());
464 
465  TDirectory *dirsave = gDirectory;
466  if (!file->cd(fDirectory)) {
467  Error("GetEntries", "cannot cd to %s", fDirectory.Data());
468  delete file;
469  return -1;
470  }
471 
472  TDirectory *dir = gDirectory;
473  dirsave->cd();
474 
475  if (isTree) {
476 
477  TString on(GetTitle());
478  TString sreg(GetTitle());
479  // If a wild card we will use the first object of the type
480  // requested compatible with the reg expression we got
481  if (sreg.Length() <= 0 || sreg == "" || sreg.Contains("*")) {
482  if (sreg.Contains("*"))
483  sreg.ReplaceAll("*", ".*");
484  else
485  sreg = ".*";
486  TRegexp re(sreg);
487  if (dir->GetListOfKeys()) {
488  TIter nxk(dir->GetListOfKeys());
489  TKey *k = 0;
490  Bool_t notfound = kTRUE;
491  while ((k = (TKey *) nxk())) {
492  if (!strcmp(k->GetClassName(), "TTree")) {
493  TString kn(k->GetName());
494  if (kn.Index(re) != kNPOS) {
495  if (notfound) {
496  on = kn;
497  notfound = kFALSE;
498  } else if (kn != on) {
499  Warning("GetEntries",
500  "additional tree found in the file: %s", kn.Data());
501  }
502  }
503  }
504  }
505  }
506  }
507 
508  TKey *key = dir->GetKey(on);
509  if (key == 0) {
510  Error("GetEntries", "cannot find tree \"%s\" in %s",
511  GetTitle(), GetName());
512  delete file;
513  return -1;
514  }
515  TTree *tree = (TTree *) key->ReadObj();
516  if (tree == 0) {
517  // Error always reported?
518  delete file;
519  return -1;
520  }
521  fEntries = tree->GetEntries();
522  delete tree;
523 
524  } else {
525  TList *keys = dir->GetListOfKeys();
526  fEntries = keys->GetSize();
527  }
528 
529  delete file;
530  return fEntries;
531 }
532 
533 ////////////////////////////////////////////////////////////////////////////////
534 /// Resolve end-point URL for this element
535 /// Return 0 on success and -1 otherwise
536 
538 {
539  static Int_t xNetPluginOK = -1;
540  static TFileStager *xStager = 0;
541  Int_t retVal = 0;
542 
543  // Check if required
544  if (!force && HasBeenLookedUp())
545  return retVal;
546 
547  TUrl url(GetName());
548  // Save current options and anchor to be set ofthe final end URL
549  TString anch = url.GetAnchor();
550  TString opts = url.GetOptions();
551  // The full path
552  TString name(url.GetUrl());
553 
554  // Depending on the type of backend, it might not make any sense to lookup
555  Bool_t doit = kFALSE;
557  if (type == TFile::kNet) {
558  TPluginHandler *h = 0;
559  // Network files via XROOTD
560  if (xNetPluginOK == -1) {
561  // Check the plugin the first time
562  xNetPluginOK = 0;
563  if ((h = gROOT->GetPluginManager()->FindHandler("TFile", name)) &&
564  !strcmp(h->GetClass(),"TXNetFile") && h->LoadPlugin() == 0)
565  xNetPluginOK = 1;
566  }
567  doit = (xNetPluginOK == 1) ? kTRUE : kFALSE;
568  }
569 
570  // Locate the file
571  if (doit) {
572  if (!xStager || !xStager->Matches(name)) {
573  SafeDelete(xStager);
574  if (!(xStager = TFileStager::Open(name))) {
575  Error("Lookup", "TFileStager instance cannot be instantiated");
576  retVal = -1;
577  }
578  }
579  if (xStager && xStager->Locate(name.Data(), name) == 0) {
580  // Get the effective end-point Url
581  url.SetUrl(name);
582  // Restore original options and anchor, if any
583  url.SetOptions(opts);
584  url.SetAnchor(anch);
585  // Save it into the element
586  fName = url.GetUrl();
587  } else {
588  // Failure
589  Error("Lookup", "couldn't lookup %s", name.Data());
590  retVal = -1;
591  }
592  }
593 
594  // Mark has looked-up
596  return retVal;
597 }
598 
599 ////////////////////////////////////////////////////////////////////////////////
600 /// Set entry (or event) list for this element
601 
603 {
604  if (!aList)
605  return;
606 
607  // Link the proper object
608  TEventList *evl = 0;
609  TEntryList *enl = dynamic_cast<TEntryList*>(aList);
610  if (!enl)
611  evl = dynamic_cast<TEventList*>(aList);
612  if (!enl && !evl) {
613  Error("SetEntryList", "type of input object must be either TEntryList "
614  "or TEventList (found: '%s' - do nothing", aList->ClassName());
615  return;
616  }
617 
618  // Action depends on the type
619  if (enl) {
620  enl->SetEntriesToProcess(num);
621  } else {
622  for (; num > 0; num--, first++)
623  evl->Enter(evl->GetEntry((Int_t)first));
624  }
625  fEntryList = aList;
626 
627  // Done
628  return;
629 }
630 
631 ////////////////////////////////////////////////////////////////////////////////
632 /// Add an associated object to the list
633 
635 {
636  if (assocobj) {
637  if (!fAssocObjList) fAssocObjList = new TList;
638  if (fAssocObjList) fAssocObjList->Add(assocobj);
639  }
640 }
641 
642 ////////////////////////////////////////////////////////////////////////////////
643 /// Get i-th associated object.
644 /// If 'isentry' fFirst is subtracted, so that i == fFirst returns the first
645 /// object in the list.
646 /// If there are not enough elements in the list, the element i%list_size is
647 /// returned (if the list has only one element this only one element is always
648 /// returned.
649 /// This method is used when packet processing consist in processing the objects
650 /// in the associated object list.
651 
653 {
654  TObject *o = 0;
655  if (!fAssocObjList || fAssocObjList->GetSize() <= 0) return o;
656 
657  TString s;
658  Int_t pos = -1;
659  if (isentry) {
660  if (i < fFirst) return o;
661  s.Form("%lld", i - fFirst);
662  } else {
663  if (i < 0) return o;
664  s.Form("%lld", i);
665  }
666  if (!(s.IsDigit())) return o;
667  pos = s.Atoi();
668  if (pos > fAssocObjList->GetSize() - 1) pos %= fAssocObjList->GetSize();
669  return fAssocObjList->At(pos);
670 }
671 
672 ////////////////////////////////////////////////////////////////////////////////
673 /// Default ctor.
674 
676 {
677  fElements = new THashList;
678  fElements->SetOwner();
679  fIsTree = kFALSE;
680  fIterator = 0;
681  fCurrent = 0;
682  fEntryList = 0;
683  fProofChain = 0;
684  fSrvMaps = 0;
685  fSrvMapsIter = 0;
687  ResetBit(kEmpty);
691 
692  // Add to the global list
693  gROOT->GetListOfDataSets()->Add(this);
694 }
695 
696 ////////////////////////////////////////////////////////////////////////////////
697 /// Create a named TDSet object. The "type" defines the class of which objects
698 /// will be processed (default 'TTree'). The optional "objname" argument
699 /// specifies the name of the objects of the specified class.
700 /// If the "objname" is not given the behaviour depends on the 'type':
701 /// for 'TTree' the first TTree is analyzed; for other types, all objects of
702 /// the class found in the specified directory are processed.
703 /// The "dir" argument specifies in which directory the objects are
704 /// to be found, the top level directory ("/") is the default.
705 /// Directories can be specified using wildcards, e.g. "*" or "/*"
706 /// means to look in all top level directories, "/dir/*" in all
707 /// directories under "/dir", and "/*/*" to look in all directories
708 /// two levels deep.
709 /// For backward compatibility the type can also be passed via 'name',
710 /// in which case 'type' is ignored.
711 
712 TDSet::TDSet(const char *name,
713  const char *objname, const char *dir, const char *type)
714 {
715  fElements = new THashList;
716  fElements->SetOwner();
717  fIterator = 0;
718  fCurrent = 0;
719  fEntryList = 0;
720  fProofChain = 0;
721  fSrvMaps = 0;
722  fSrvMapsIter = 0;
724  ResetBit(kEmpty);
728 
729  fType = "TTree";
730  TClass *c = 0;
731  // Check name
732  if (name && strlen(name) > 0) {
733  // In the old constructor signature it was the 'type'
734  if (!type) {
735  TString cn(name);
736  if (cn.Contains(':')) cn.Remove(0, cn.Index(":")+1);
737  if (TClass::GetClass(cn))
738  fType = cn;
739  else
740  // Default type is 'TTree'
741  fName = name;
742  } else {
743  // Set name
744  fName = name;
745  // Check type
746  if (strlen(type) > 0)
747  if (TClass::GetClass(type))
748  fType = type;
749  }
750  } else if (type && strlen(type) > 0) {
751  // Check the type
752  if (TClass::GetClass(type))
753  fType = type;
754  }
755  // The correct class type
756  c = TClass::GetClass(fType);
757 
759 
760  if (objname)
761  fObjName = objname;
762 
763  if (dir)
764  fDir = dir;
765 
766  // Default name is the object name
767  if (fName.Length() <= 0)
768  fName = TString::Format("TDSet:%s", fObjName.Data());
769  // We set the default title to the 'type'
770  fTitle = fType;
771 
772  // Add to the global list
773  gROOT->GetListOfDataSets()->Add(this);
774 }
775 
776 ////////////////////////////////////////////////////////////////////////////////
777 /// Create a named TDSet object from existing TChain 'chain'.
778 /// If 'withfriends' is kTRUE add also friends.
779 /// This constructor substituted the static methods TChain::MakeTDSet
780 /// removing any residual dependence of 'tree' on 'proof'.
781 
782 TDSet::TDSet(const TChain &chain, Bool_t withfriends)
783 {
784  fElements = new THashList;
785  fElements->SetOwner();
786  fIterator = 0;
787  fCurrent = 0;
788  fEntryList = 0;
789  fProofChain = 0;
790  fSrvMaps = 0;
791  fSrvMapsIter = 0;
793  ResetBit(kEmpty);
797 
798  fType = "TTree";
799  fIsTree = kTRUE;
800  fObjName = chain.GetName();
801  fName = TString::Format("TChain:%s", chain.GetName());
802 
803  // First fill elements without friends()
804  TIter next(chain.GetListOfFiles());
805  TChainElement *elem = 0;
806  TString key;
807  while ((elem = (TChainElement *)next())) {
808  TString file(elem->GetTitle());
809  TString tree(elem->GetName());
810  Int_t isl = tree.Last('/');
811  TString dir = "/";
812  if (isl >= 0) {
813  // Copy the tree name specification
814  TString behindSlash = tree(isl + 1, tree.Length() - isl - 1);
815  // and remove it from basename
816  tree.Remove(isl);
817  dir = tree;
818  tree = behindSlash;
819  }
820  // Find MSD if any
821  TString msd(TUrl(file).GetOptions());
822  Int_t imsd = kNPOS;
823  if ((imsd = msd.Index("msd=")) != kNPOS) {
824  msd.Remove(0, imsd+4);
825  } else {
826  // Not an MSD option
827  msd = "";
828  }
829  Long64_t nent = (elem->GetEntries() > 0 &&
830  elem->GetEntries() != TTree::kMaxEntries) ? elem->GetEntries() : -1;
831  if (Add(file, tree, dir, 0, nent, ((msd.IsNull()) ? 0 : msd.Data()))) {
832  if (elem->HasBeenLookedUp()) {
833  // Save lookup information, if any
834  TDSetElement *dse = (TDSetElement *) fElements->Last();
835  if (dse) dse->SetLookedUp();
836  }
837  }
838  }
839  SetDirectory(0);
840 
841  // Add friends now, if requested
842  if (withfriends) {
843  TList processed;
844  TList chainsQueue;
845  chainsQueue.Add((TObject *)&chain);
846  processed.Add((TObject *)&chain);
847  while (chainsQueue.GetSize() > 0) {
848  TChain *c = (TChain *) chainsQueue.First();
849  chainsQueue.Remove(c);
850  TIter friendsIter(c->GetListOfFriends());
851  while(TFriendElement *fe = dynamic_cast<TFriendElement*> (friendsIter()) ) {
852  if (TChain *fc = dynamic_cast<TChain*>(fe->GetTree())) {
853  if (!processed.FindObject(fc)) { // if not yet processed
854  processed.AddFirst(fc);
855  AddFriend(new TDSet((const TChain &)(*fc), kFALSE), fe->GetName());
856  chainsQueue.Add(fc); // for further processing
857  }
858  } else {
859  Reset();
860  Error("TDSet", "Only TChains supported. Found illegal tree %s",
861  fe->GetTree()->GetName());
862  return;
863  }
864  }
865  }
866  }
867 }
868 
869 ////////////////////////////////////////////////////////////////////////////////
870 /// Cleanup.
871 
873 {
877  fSrvMaps = 0;
878  fSrvMapsIter = 0;
879 
880  gROOT->GetListOfDataSets()->Remove(this);
881 }
882 
883 ////////////////////////////////////////////////////////////////////////////////
884 /// Process TDSet on currently active PROOF session.
885 /// The last argument 'enl' specifies an entry- or event-list to be used as
886 /// event selection.
887 /// The return value is -1 in case of error and TSelector::GetStatus() in
888 /// in case of success.
889 
891  Long64_t first, TObject *enl)
892 {
893  if (!IsValid() || !fElements->GetSize()) {
894  Error("Process", "not a correctly initialized TDSet");
895  return -1;
896  }
897 
898  // Set entry list
899  SetEntryList(enl);
900 
901  if (gProof)
902  return gProof->Process(this, selector, option, nentries, first);
903 
904  Error("Process", "no active PROOF session");
905  return -1;
906 }
907 
908 ////////////////////////////////////////////////////////////////////////////////
909 /// Process TDSet on currently active PROOF session.
910 /// The last argument 'enl' specifies an entry- or event-list to be used as
911 /// event selection.
912 /// The return value is -1 in case of error and TSelector::GetStatus() in
913 /// in case of success.
914 
915 Long64_t TDSet::Process(const char *selector, Option_t *option, Long64_t nentries,
916  Long64_t first, TObject *enl)
917 {
918  if (!IsValid() || !fElements->GetSize()) {
919  Error("Process", "not a correctly initialized TDSet");
920  return -1;
921  }
922 
923  // Set entry list
924  SetEntryList(enl);
925 
926  if (gProof)
927  return gProof->Process(this, selector, option, nentries, first);
928 
929  Error("Process", "no active PROOF session");
930  return -1;
931 }
932 
933 ////////////////////////////////////////////////////////////////////////////////
934 /// Add objects that might be needed during the processing of
935 /// the selector (see Process()).
936 
938 {
939  if (gProof) {
940  gProof->AddInput(obj);
941  } else {
942  Error("AddInput","No PROOF session active");
943  }
944 }
945 
946 ////////////////////////////////////////////////////////////////////////////////
947 /// Clear input object list.
948 
950 {
951  if (gProof)
952  gProof->ClearInput();
953 }
954 
955 ////////////////////////////////////////////////////////////////////////////////
956 /// Get specified object that has been produced during the processing
957 /// (see Process()).
958 
960 {
961  if (gProof)
962  return gProof->GetOutput(name);
963  return 0;
964 }
965 
966 ////////////////////////////////////////////////////////////////////////////////
967 /// Get list with all object created during processing (see Process()).
968 
970 {
971  if (gProof)
972  return gProof->GetOutputList();
973  return 0;
974 }
975 
976 ////////////////////////////////////////////////////////////////////////////////
977 /// Print TDSet basic or full data. When option="a" print full data.
978 
979 void TDSet::Print(const Option_t *opt) const
980 {
981  const char *clnm = (IsA()) ? IsA()->GetName() : "TDSet";
982  Printf("OBJ: %s\ttype %s\t%s\tin %s\telements %d", clnm, GetName(),
983  fObjName.Data(), GetTitle(), GetListOfElements()->GetSize());
984 
985  if (opt && opt[0] == 'a') {
987  TObject *obj;
988  while ((obj = next())) {
989  obj->Print(opt);
990  }
991  }
992 }
993 
994 ////////////////////////////////////////////////////////////////////////////////
995 /// Set/change object name.
996 
997 void TDSet::SetObjName(const char *objname)
998 {
999  if (objname) {
1000  fObjName = objname;
1002  TDSetElement *e;
1003  while ((e = (TDSetElement *) next())) {
1004  e->SetTitle(objname);
1005  }
1006  }
1007 }
1008 
1009 ////////////////////////////////////////////////////////////////////////////////
1010 /// Set/change directory.
1011 
1012 void TDSet::SetDirectory(const char *dir)
1013 {
1014  if (dir)
1015  fDir = dir;
1016 }
1017 
1018 ////////////////////////////////////////////////////////////////////////////////
1019 /// Add file to list of files to be analyzed. Optionally with the
1020 /// objname and dir arguments the default, TDSet wide, objname and
1021 /// dir can be overridden.
1022 
1023 Bool_t TDSet::Add(const char *file, const char *objname, const char *dir,
1024  Long64_t first, Long64_t num, const char *msd)
1025 {
1026  if (!file || !*file) {
1027  Error("Add", "file name must be specified");
1028  return kFALSE;
1029  }
1030 
1031  TString fn = file;
1032  if (gProof && gProof->IsLite()) {
1033  TUrl u(file, kTRUE);
1034  if (!strcmp(u.GetProtocol(), "file")) {
1035  fn = u.GetFileAndOptions();
1036  gSystem->ExpandPathName(fn);
1037  if (!gSystem->IsAbsoluteFileName(fn))
1039  }
1040  }
1041 
1042  // check, if it already exists in the TDSet
1044  if (!el) {
1045  if (!objname)
1046  objname = GetObjName();
1047  if (!dir)
1048  dir = GetDirectory();
1049  fElements->Add(new TDSetElement(fn, objname, dir, first, num, msd));
1050  } else {
1051  TString msg;
1052  msg.Form("duplication detected: %40s is already in dataset - ignored", fn.Data());
1053  Warning("Add", "%s", msg.Data());
1054  if (gProofServ) {
1055  msg.Insert(0, "WARNING: ");
1057  }
1058  }
1059 
1060  return kTRUE;
1061 }
1062 
1063 ////////////////////////////////////////////////////////////////////////////////
1064 /// Add specified data set to the this set.
1065 
1067 {
1068  if (!dset)
1069  return kFALSE;
1070 
1071  if (TestBit(TDSet::kMultiDSet)) {
1072  fElements->Add(dset);
1073  return kTRUE;
1074  }
1075 
1076  if (fType != dset->GetType()) {
1077  Error("Add", "cannot add a set with a different type");
1078  return kFALSE;
1079  }
1080 
1081  TDSetElement *el;
1082  TIter next(dset->fElements);
1083  TObject *last = (dset == this) ? fElements->Last() : 0;
1084  while ((el = (TDSetElement*) next())) {
1085  Add(el->GetFileName(), el->GetObjName(), el->GetDirectory(),
1086  el->GetFirst(), el->GetNum(), el->GetMsd());
1087  if (el == last) break;
1088  }
1089 
1090  return kTRUE;
1091 }
1092 
1093 ////////////////////////////////////////////////////////////////////////////////
1094 /// Add files passed as list of TFileInfo, TUrl or TObjString objects .
1095 /// If TFileInfo, the first entry and the number of entries are also filled.
1096 /// The argument 'meta' can be used to specify one of the subsets in the
1097 /// file as described in the metadata of TFileInfo. By default the first one
1098 /// is taken.
1099 /// If 'availableOnly' is true only files available ('staged' and non corrupted)
1100 /// are taken: those not satisfying this requirement are added to 'badlist', if
1101 /// the latter is defined. By default availableOnly is false.
1102 
1103 Bool_t TDSet::Add(TCollection *filelist, const char *meta, Bool_t availableOnly,
1104  TCollection *badlist)
1105 {
1106  if (!filelist)
1107  return kFALSE;
1108 
1109  TObject *o = 0;
1110  TIter next(filelist);
1111  while ((o = next())) {
1112  TString cn(o->ClassName());
1113  if (cn == "TFileInfo") {
1114  TFileInfo *fi = (TFileInfo *)o;
1115  if (!availableOnly ||
1116  (fi->TestBit(TFileInfo::kStaged) &&
1117  !fi->TestBit(TFileInfo::kCorrupted))) {
1118  Int_t nf = fElements->GetSize();
1119  if (!Add(fi, meta)) return kFALSE;
1120  // Duplications count as bad files
1121  if (fElements->GetSize() <= nf && badlist) badlist->Add(fi);
1122  } else if (badlist) {
1123  // Return list of non-usable files
1124  badlist->Add(fi);
1125  }
1126  } else if (cn == "TUrl") {
1127  Add(((TUrl *)o)->GetUrl());
1128  } else if (cn == "TObjString") {
1129  Add(((TObjString *)o)->GetName());
1130  } else {
1131  Warning("Add","found object fo unexpected type %s - ignoring", cn.Data());
1132  }
1133  }
1134 
1135  return kTRUE;
1136 }
1137 
1138 ////////////////////////////////////////////////////////////////////////////////
1139 /// Set (or unset) the list for mapping servers coordinate for files.
1140 /// Reinitialize the related iterator if needed.
1141 /// Used by TProof.
1142 
1143 void TDSet::SetSrvMaps(TList *srvmaps)
1144 {
1145  fSrvMaps = srvmaps;
1147  if (fSrvMaps) fSrvMapsIter = new TIter(fSrvMaps);
1148 }
1149 
1150 ////////////////////////////////////////////////////////////////////////////////
1151 /// Add file described by 'fi' to list of files to be analyzed.
1152 /// The argument 'meta' can be used to specify a subsets in the
1153 /// file as described in the metadata of TFileInfo. By default the first one
1154 /// is taken.
1155 
1156 Bool_t TDSet::Add(TFileInfo *fi, const char *meta)
1157 {
1158  if (!fi) {
1159  Error("Add", "TFileInfo object name must be specified");
1160  return kFALSE;
1161  }
1162  TString msg;
1163 
1164  // Check if a remap of the server coordinates is requested
1165  const char *file = fi->GetFirstUrl()->GetUrl();
1166  Bool_t setLookedUp = kTRUE;
1167  TString file1;
1169  !(file1.IsNull())) {
1170  file = file1.Data();
1171  setLookedUp = kFALSE;
1172  }
1173  // Check if it already exists in the TDSet
1174  if (fElements->FindObject(file)) {
1175  msg.Form("duplication detected: %40s is already in dataset - ignored", file);
1176  Warning("Add", "%s", msg.Data());
1177  if (gProofServ) {
1178  msg.Insert(0, "WARNING: ");
1180  }
1181  return kTRUE;
1182  }
1183 
1184  // If more than one metadata info require the specification of the objpath;
1185  // the order in which they appear is not guaranteed and the error may be
1186  // very difficult to find.
1187  TFileInfoMeta *m = 0;
1188  if (!meta || strlen(meta) <= 0 || !strcmp(meta, "/")) {
1189  TList *fil = 0;
1190  if ((fil = fi->GetMetaDataList()) && fil->GetSize() > 1) {
1191  msg.Form("\n Object name unspecified and several objects available.\n");
1192  msg += " Please choose one from the list below:\n";
1193  TIter nx(fil);
1194  while ((m = (TFileInfoMeta *) nx())) {
1195  TString nm(m->GetName());
1196  if (nm.BeginsWith("/")) nm.Remove(0,1);
1197  msg += Form(" %s -> TProof::Process(\"%s#%s\",...)\n",
1198  nm.Data(), GetName(), nm.Data());
1199  }
1200  if (gProofServ)
1202  else
1203  Warning("Add", "%s", msg.Data());
1204  return kFALSE;
1205  }
1206  }
1207 
1208  // Get the metadata, if any
1209  m = fi->GetMetaData(meta);
1210 
1211  // Create the element
1212  const char *objname = 0;
1213  const char *dir = 0;
1214  Long64_t first = 0;
1215  Long64_t num = -1;
1216  if (!m) {
1217  objname = GetObjName();
1218  dir = GetDirectory();
1219  } else {
1220  objname = (m->GetObject() && strlen(m->GetObject())) ? m->GetObject() : GetObjName();
1221  dir = (m->GetDirectory() && strlen(m->GetDirectory())) ? m->GetDirectory() : GetDirectory();
1222  first = m->GetFirst();
1223  num = m->GetEntries();
1224  }
1225  const char *dataset = 0;
1226  if (strcmp(fi->GetTitle(), "TFileInfo")) dataset = fi->GetTitle();
1227  TDSetElement *el = new TDSetElement(file, objname, dir, first, -1, 0, dataset);
1228  el->SetEntries(num);
1229 
1230  // Set looked-up bit
1231  if (fi->TestBit(TFileInfo::kStaged) && setLookedUp)
1233  if (fi->TestBit(TFileInfo::kCorrupted))
1235 
1236  // Add the element
1237  fElements->Add(el);
1238 
1239  return kTRUE;
1240 }
1241 
1242 ////////////////////////////////////////////////////////////////////////////////
1243 /// Export TDSetElements files as list of TFileInfo objects in file
1244 /// 'fpath'. If the file exists already the action fails, unless
1245 /// 'opt == "F"'.
1246 /// Return 0 on success, -1 otherwise
1247 
1248 Int_t TDSet::ExportFileList(const char *fpath, Option_t *opt)
1249 {
1250  if (!fElements)
1251  return -1;
1252  if (fElements->GetSize() <= 0)
1253  return 0;
1254 
1255  Bool_t force = (opt[0] == 'F' || opt[0] == 'f');
1256 
1257  if (gSystem->AccessPathName(fpath, kFileExists) == kFALSE) {
1258  if (force) {
1259  // Try removing the file
1260  if (gSystem->Unlink(fpath)) {
1261  Info("ExportFileList","error removing dataset file: %s", fpath);
1262  return -1;
1263  }
1264  }
1265  }
1266 
1267  // Create the file list
1268  TList *fileinfo = new TList;
1269  fileinfo->SetOwner();
1270 
1271  TDSetElement *dse = 0;
1272  TIter next(fElements);
1273  while ((dse = (TDSetElement *) next())) {
1274  TFileInfoMeta *m = new TFileInfoMeta(dse->GetTitle(), dse->GetDirectory(), GetType(),
1275  dse->GetNum(), dse->GetFirst());
1276  TFileInfo *fi = new TFileInfo(dse->GetFileName());
1277  fi->AddMetaData(m);
1278  fileinfo->Add(fi);
1279  }
1280 
1281  // Write to file
1282  TFile *f = TFile::Open(fpath, "RECREATE");
1283  if (f) {
1284  f->cd();
1285  fileinfo->Write("fileList", TObject::kSingleKey);
1286  f->Close();
1287  } else {
1288  Info("ExportFileList","error creating dataset file: %s", fpath);
1289  SafeDelete(fileinfo);
1290  return -1;
1291  }
1292 
1293  // Cleanup
1294  SafeDelete(f);
1295  SafeDelete(fileinfo);
1296 
1297  // We are done
1298  return 0;
1299 }
1300 
1301 ////////////////////////////////////////////////////////////////////////////////
1302 /// Add friend dataset to this set. Only possible if the TDSet type is
1303 /// a TTree or derived class. The friendset will be owned by this class
1304 /// and deleted in its destructor.
1305 
1306 void TDSet::AddFriend(TDSet *friendset, const char* alias)
1307 {
1308  if (!friendset) {
1309  Error("AddFriend", "The friend TDSet is null!");
1310  return;
1311  }
1312 
1313  if (!fIsTree) {
1314  Error("AddFriend", "a friend set can only be added to a TTree TDSet");
1315  return;
1316  }
1317  TList *thisList = GetListOfElements();
1318  TList *friendsList = friendset->GetListOfElements();
1319  if (thisList->GetSize() != friendsList->GetSize() && friendsList->GetSize() != 1) {
1320  Error("AddFriend", "the friend dataset has %d elements while the main one has %d",
1321  thisList->GetSize(), friendsList->GetSize());
1322  return;
1323  }
1324  TIter next(thisList);
1325  TIter next2(friendsList);
1326  TDSetElement *friendElem = 0;
1327  if (friendsList->GetSize() == 1)
1328  friendElem = dynamic_cast<TDSetElement*> (friendsList->First());
1329  while(TDSetElement* e = dynamic_cast<TDSetElement*> (next())) {
1330  if (friendElem) // just one elem in the friend TDSet
1331  e->AddFriend(friendElem, alias);
1332  else
1333  e->AddFriend(dynamic_cast<TDSetElement*> (next2()), alias);
1334  }
1335 }
1336 
1337 ////////////////////////////////////////////////////////////////////////////////
1338 /// Reset or initialize access to the elements.
1339 
1341 {
1342  if (!fIterator) {
1343  fIterator = new TIter(fElements);
1344  } else {
1345  fIterator->Reset();
1346  }
1347 }
1348 
1349 ////////////////////////////////////////////////////////////////////////////////
1350 /// Returns number of entries in tree or objects in file. Returns -1 in
1351 /// case of error.
1352 
1353 Long64_t TDSet::GetEntries(Bool_t isTree, const char *filename, const char *path,
1354  TString &objname)
1355 {
1356  Double_t start = 0;
1357  if (gPerfStats) start = TTimeStamp();
1358 
1359  // Take into acoount possible prefixes
1361  TString fname = gEnv->GetValue("Path.Localroot",""), pfx(fname);
1362  // Get the locality (disable warnings or errors in connection attempts)
1363  Int_t oldLevel = gErrorIgnoreLevel;
1365  if ((typ = TFile::GetType(filename, "", &fname)) != TFile::kLocal) fname = filename;
1366  gErrorIgnoreLevel = oldLevel;
1367  // Open the file
1368  TFile *file = TFile::Open(fname);
1369 
1370  if (gPerfStats)
1371  gPerfStats->FileOpenEvent(file, filename, start);
1372 
1373  if (file == 0) {
1374  ::SysError("TDSet::GetEntries",
1375  "cannot open file %s (type: %d, pfx: %s)", filename, typ, pfx.Data());
1376  return -1;
1377  }
1378 
1379  TDirectory *dirsave = gDirectory;
1380  if (!file->cd(path)) {
1381  ::Error("TDSet::GetEntries", "cannot cd to %s", path);
1382  delete file;
1383  return -1;
1384  }
1385 
1386  TDirectory *dir = gDirectory;
1387  dirsave->cd();
1388 
1389  Long64_t entries;
1390  Bool_t fillname = kFALSE;
1391  if (isTree) {
1392 
1393  TString on(objname);
1394  TString sreg(objname);
1395  // If a wild card we will use the first object of the type
1396  // requested compatible with the reg expression we got
1397  if (sreg.Length() <= 0 || sreg == "" || sreg.Contains("*")) {
1398  fillname = kTRUE;
1399  if (sreg.Contains("*"))
1400  sreg.ReplaceAll("*", ".*");
1401  else
1402  sreg = ".*";
1403  TRegexp re(sreg);
1404  if (dir->GetListOfKeys()) {
1405  TIter nxk(dir->GetListOfKeys());
1406  TKey *k = 0;
1407  Bool_t notfound = kTRUE;
1408  while ((k = (TKey *) nxk())) {
1409  if (!strcmp(k->GetClassName(), "TTree")) {
1410  TString kn(k->GetName());
1411  if (kn.Index(re) != kNPOS) {
1412  if (notfound) {
1413  on = kn;
1414  notfound = kFALSE;
1415  } else if (kn != on) {
1416  ::Warning("TDSet::GetEntries",
1417  "additional tree found in the file: %s", kn.Data());
1418  }
1419  }
1420  }
1421  }
1422  }
1423  }
1424 
1425  TKey *key = dir->GetKey(on);
1426  if (key == 0) {
1427  ::Error("TDSet::GetEntries", "cannot find tree \"%s\" in %s",
1428  objname.Data(), filename);
1429  delete file;
1430  return -1;
1431  }
1432  TTree *tree = (TTree *) key->ReadObj();
1433  if (tree == 0) {
1434  // Error always reported?
1435  delete file;
1436  return -1;
1437  }
1438  entries = tree->GetEntries();
1439  delete tree;
1440 
1441  // Return full name in case of wildcards
1442  objname = (fillname) ? on : objname;
1443 
1444  } else {
1445  TList *keys = dir->GetListOfKeys();
1446  entries = keys->GetSize();
1447  }
1448 
1449  delete file;
1450  return entries;
1451 }
1452 
1453 ////////////////////////////////////////////////////////////////////////////////
1454 /// Draw expression varexp for specified entries.
1455 /// Returns -1 in case of error or number of selected events in case of success.
1456 /// This function accepts a TCut objects as argument.
1457 /// Use the operator+ to concatenate cuts.
1458 /// Example:
1459 /// dset.Draw("x",cut1+cut2+cut3);
1460 
1461 Long64_t TDSet::Draw(const char *varexp, const TCut &selection, Option_t *option,
1462  Long64_t nentries, Long64_t firstentry)
1463 {
1464  return Draw(varexp, selection.GetTitle(), option, nentries, firstentry);
1465 }
1466 
1467 ////////////////////////////////////////////////////////////////////////////////
1468 /// Draw expression varexp for specified entries.
1469 /// Returns -1 in case of error or number of selected events in case of success.
1470 /// For more see TTree::Draw().
1471 
1472 Long64_t TDSet::Draw(const char *varexp, const char *selection, Option_t *option,
1473  Long64_t nentries, Long64_t firstentry)
1474 {
1475  if (!IsValid() || !fElements->GetSize()) {
1476  Error("Draw", "not a correctly initialized TDSet");
1477  return -1;
1478  }
1479 
1480  if (gProof)
1481  return gProof->DrawSelect(this, varexp, selection, option, nentries,
1482  firstentry);
1483 
1484  Error("Draw", "no active PROOF session");
1485  return -1;
1486 }
1487 
1488 ////////////////////////////////////////////////////////////////////////////////
1489 /// Start the TTreeViewer on this TTree.
1490 
1492 {
1493  if (gROOT->IsBatch()) {
1494  Warning("StartViewer", "viewer cannot run in batch mode");
1495  return;
1496  }
1497 
1498  if (!gProof) {
1499  Error("StartViewer", "no PROOF found");
1500  return;
1501  }
1502  if (!IsTree()) {
1503  Error("StartViewer", "TDSet contents should be of type TTree (or subtype)");
1504  return;
1505  }
1506  fProofChain = new TProofChain(this, kTRUE);
1507 
1508  TPluginHandler *h;
1509  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualTreeViewer"))) {
1510  if (h->LoadPlugin() == -1)
1511  return;
1512  h->ExecPlugin(1,fProofChain);
1513  }
1514 }
1515 
1516 ////////////////////////////////////////////////////////////////////////////////
1517 /// Returns a tree header containing the branches' structure of the dataset.
1518 
1520 {
1521  return proof->GetTreeHeader(this);
1522 }
1523 
1524 ////////////////////////////////////////////////////////////////////////////////
1525 /// Check if all elements are valid.
1526 
1528 {
1530  return (TestBit(TDSet::kSomeInvalid) ? kFALSE : kTRUE);
1531 
1534  TIter nextElem(GetListOfElements());
1535  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1536  if (!elem->GetValid()) {
1538  return kFALSE;
1539  }
1540  }
1541  return kTRUE;
1542 }
1543 
1544 ////////////////////////////////////////////////////////////////////////////////
1545 /// Remove TDSetElement 'elem' from the list.
1546 /// Return 0 on success, -1 if the element is not in the list
1547 
1549 {
1550  if (!elem || !(((THashList *)(GetListOfElements()))->Remove(elem)))
1551  return -1;
1552 
1553  if (deleteElem)
1554  SafeDelete(elem);
1555  return 0;
1556 }
1557 
1558 ////////////////////////////////////////////////////////////////////////////////
1559 /// Validate the TDSet by opening files.
1560 
1562 {
1563  TIter nextElem(GetListOfElements());
1564  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1565  if (!elem->GetValid())
1566  elem->Validate(IsTree());
1567  }
1568 }
1569 
1570 ////////////////////////////////////////////////////////////////////////////////
1571 /// Resolve the end-point URL for the current elements of this data set
1572 /// If the removeMissing option is set to kTRUE, remove the TDSetElements
1573 /// that can not be located.
1574 /// The method returns the list of removed TDSetElements in *listOfMissingFiles
1575 /// if the latter is defined (the list must be created outside).
1576 
1577 void TDSet::Lookup(Bool_t removeMissing, TList **listOfMissingFiles)
1578 {
1579  // If an entry- or event- list has been given, assign the relevant portions
1580  // to each element; this allows to look-up only for the elements which have
1581  // something to be processed, so it is better to do it before the real look-up
1582  // operations.
1583  SplitEntryList();
1584 
1585  TString msg("Looking up for exact location of files");
1586  UInt_t n = 0;
1587  UInt_t ng = 0;
1588  UInt_t tot = GetListOfElements()->GetSize();
1589  UInt_t n2 = (tot > 50) ? (UInt_t) tot / 50 : 1;
1590  Bool_t st = kTRUE;
1591  TIter nextElem(GetListOfElements());
1592  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1593  if (elem->GetNum() != 0) { // -1 means "all entries"
1594  ng++;
1595  if (!elem->GetValid())
1596  if (elem->Lookup(kFALSE))
1597  if (removeMissing) {
1598  if (Remove(elem, kFALSE))
1599  Error("Lookup", "Error removing a missing file");
1600  if (listOfMissingFiles)
1601  (*listOfMissingFiles)->Add(elem->GetFileInfo(fType));
1602  }
1603  }
1604  n++;
1605  // Notify the client
1606  if (gProof && (n > 0 && !(n % n2)))
1607  gProof->SendDataSetStatus(msg, n, tot, st);
1608  // Break if we have been asked to stop
1610  break;
1611  }
1612  // Notify the client if not all the files have entries to be processed
1613  // (which may happen if an entry-list is used)
1614  if (ng < tot && gProofServ) {
1615  msg = Form("Files with entries to be processed: %d (out of %d)\n", ng, tot);
1617  } else {
1618  // Final notification to the client
1619  if (gProof) gProof->SendDataSetStatus(msg, n, tot, st);
1620  }
1621  // Done
1622  return;
1623 }
1624 
1625 ////////////////////////////////////////////////////////////////////////////////
1626 /// Flag all the elements as looked-up, so to avoid opening the files
1627 /// if the functionality is not supported
1628 
1630 {
1631  TIter nextElem(GetListOfElements());
1632  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem()))
1633  elem->SetLookedUp();
1634 }
1635 
1636 ////////////////////////////////////////////////////////////////////////////////
1637 /// Validate the TDSet against another TDSet.
1638 /// Only validates elements in common from input TDSet.
1639 
1641 {
1642  THashList bestElements;
1643  bestElements.SetOwner();
1644  TList namedHolder;
1645  namedHolder.SetOwner();
1646  TIter nextOtherElem(dset->GetListOfElements());
1647  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextOtherElem())) {
1648  if (!elem->GetValid()) continue;
1649  TString dir_file_obj = elem->GetDirectory();
1650  dir_file_obj += "_";
1651  dir_file_obj += TUrl(elem->GetFileName()).GetFileAndOptions();
1652  dir_file_obj += "_";
1653  dir_file_obj += elem->GetObjName();
1654  TPair *p = dynamic_cast<TPair*>(bestElements.FindObject(dir_file_obj));
1655  if (p) {
1656  TDSetElement *prevelem = dynamic_cast<TDSetElement*>(p->Value());
1657  if (prevelem) {
1658  Long64_t entries = prevelem->GetFirst()+prevelem->GetNum();
1659  if (entries<elem->GetFirst()+elem->GetNum()) {
1660  bestElements.Remove(p);
1661  bestElements.Add(new TPair(p->Key(), elem));
1662  delete p;
1663  }
1664  }
1665  } else {
1666  TNamed* named = new TNamed(dir_file_obj, dir_file_obj);
1667  namedHolder.Add(named);
1668  bestElements.Add(new TPair(named, elem));
1669  }
1670  }
1671 
1672  TIter nextElem(GetListOfElements());
1673  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1674  if (!elem->GetValid()) {
1675  TString dir_file_obj = elem->GetDirectory();
1676  dir_file_obj += "_";
1677  dir_file_obj += TUrl(elem->GetFileName()).GetFileAndOptions();
1678  dir_file_obj += "_";
1679  dir_file_obj += elem->GetObjName();
1680  if (TPair *p = dynamic_cast<TPair*>(bestElements.FindObject(dir_file_obj))) {
1681  TDSetElement* validelem = dynamic_cast<TDSetElement*>(p->Value());
1682  elem->Validate(validelem);
1683  }
1684  }
1685  }
1686 }
1687 
1688 //
1689 // To handle requests coming from version 3 client / masters we need
1690 // a special streamer
1691 ////////////////////////////////////////////////////////////////////////////////
1692 /// Stream an object of class TDSetElement.
1693 
1694 void TDSetElement::Streamer(TBuffer &R__b)
1695 {
1696  if (R__b.IsReading()) {
1697  UInt_t R__s, R__c;
1698  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1699  ResetBit(kWriteV3);
1700  if (R__v > 4) {
1701  R__b.ReadClassBuffer(TDSetElement::Class(), this, R__v, R__s, R__c);
1702  } else {
1703  // For version 3 client / masters we need a special streamer
1704  SetBit(kWriteV3);
1705  if (R__v > 3) {
1706  TNamed::Streamer(R__b);
1707  } else {
1708  // Old versions were not deriving from TNamed and had the
1709  // file name and the object type name in the first two members
1710  TObject::Streamer(R__b);
1711  TString name, title;
1712  R__b >> name >> title;
1713  SetNameTitle(name, title);
1714  }
1715  // Now we read the standard part
1716  R__b >> fDirectory;
1717  R__b >> fFirst;
1718  R__b >> fNum;
1719  R__b >> fMsd;
1720  R__b >> fTDSetOffset;
1721  TEventList *evl;
1722  R__b >> evl;
1723  R__b >> fValid;
1724  R__b >> fEntries;
1725 
1726  // Special treatment waiting for proper retrieving of stl containers
1727  FriendsList_t *friends = new FriendsList_t;
1728  static TClassRef classFriendsList = TClass::GetClass(typeid(FriendsList_t));
1729  R__b.ReadClassBuffer( classFriendsList, friends, classFriendsList->GetClassVersion(), 0, 0);
1730  if (friends) {
1731  // Convert friends to a TList (to be written)
1732  fFriends = new TList();
1733  fFriends->SetOwner();
1734  for (FriendsList_t::iterator i = friends->begin();
1735  i != friends->end(); ++i) {
1736  TDSetElement *dse = (TDSetElement *) i->first->Clone();
1737  fFriends->Add(new TPair(dse, new TObjString(i->second.Data())));
1738  }
1739  }
1740  // the value for fIsTree (only older versions are sending it)
1741  Bool_t tmpIsTree;
1742  R__b >> tmpIsTree;
1743  R__b.CheckByteCount(R__s, R__c, TDSetElement::IsA());
1744  }
1745  } else {
1746  if (TestBit(kWriteV3)) {
1747  // For version 3 client / masters we need a special streamer
1748  R__b << Version_t(3);
1749  TObject::Streamer(R__b);
1750  R__b << TString(GetName());
1751  R__b << TString(GetTitle());
1752  R__b << fDirectory;
1753  R__b << fFirst;
1754  R__b << fNum;
1755  R__b << fMsd;
1756  R__b << fTDSetOffset;
1757  R__b << (TEventList *)0;
1758  R__b << fValid;
1759  R__b << fEntries;
1760 
1761  // Special treatment waiting for proper retrieving of stl containers
1762  FriendsList_t *friends = new FriendsList_t;
1763  if (fFriends) {
1764  TIter nxf(fFriends);
1765  TPair *p = 0;
1766  while ((p = (TPair *)nxf()))
1767  friends->push_back(std::make_pair((TDSetElement *)p->Key(),
1768  TString(((TObjString *)p->Value())->GetName())));
1769  }
1770  static TClassRef classFriendsList = TClass::GetClass(typeid(FriendsList_t));
1771  R__b.WriteClassBuffer( classFriendsList, &friends );
1772 
1773  // Older versions had an unused boolean called fIsTree: we fill it
1774  // with its default value
1775  R__b << kFALSE;
1776  } else {
1778  }
1779  }
1780 }
1781 
1782 ////////////////////////////////////////////////////////////////////////////////
1783 /// Stream an object of class TDSet.
1784 
1785 void TDSet::Streamer(TBuffer &R__b)
1786 {
1787  if (R__b.IsReading()) {
1788  UInt_t R__s, R__c;
1789  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1790  ResetBit(kWriteV3);
1791  if (R__v > 3) {
1792  R__b.ReadClassBuffer(TDSet::Class(), this, R__v, R__s, R__c);
1793  } else {
1794  // For version 3 client / masters we need a special streamer
1795  SetBit(kWriteV3);
1796  TNamed::Streamer(R__b);
1797  R__b >> fDir;
1798  R__b >> fType;
1799  R__b >> fObjName;
1800  TList elems;
1801  elems.Streamer(R__b);
1802  elems.SetOwner(kFALSE);
1803  if (elems.GetSize() > 0) {
1804  fElements = new THashList;
1805  fElements->SetOwner();
1806  TDSetElement *e = 0;
1807  TIter nxe(&elems);
1808  while ((e = (TDSetElement *)nxe())) {
1809  fElements->Add(e);
1810  }
1811  } else {
1812  fElements = 0;
1813  }
1814  R__b >> fIsTree;
1815  }
1816  } else {
1817  if (TestBit(kWriteV3)) {
1818  // For version 3 client / masters we need a special streamer
1819  R__b << Version_t(3);
1820  TNamed::Streamer(R__b);
1821  R__b << fDir;
1822  R__b << fType;
1823  R__b << fObjName;
1824  TList elems;
1825  if (fElements) {
1826  elems.SetOwner(kFALSE);
1827  if (fElements->GetSize() > 0) {
1828  TDSetElement *e = 0;
1829  TIter nxe(fElements);
1830  while ((e = (TDSetElement *)nxe()))
1831  elems.Add(e);
1832  }
1833  }
1834  elems.Streamer(R__b);
1835  R__b << fIsTree;
1836  } else {
1837  R__b.WriteClassBuffer(TDSet::Class(),this);
1838  }
1839  }
1840 }
1841 
1842 ////////////////////////////////////////////////////////////////////////////////
1843 /// Set/Reset the 'OldStreamer' bit in this instance and its elements.
1844 /// Needed for backward compatibility in talking to old client / masters.
1845 
1847 {
1848  if (on)
1850  else
1852  // Loop over dataset elements
1853  TIter nxe(GetListOfElements());
1854  TObject *o = 0;
1855  while ((o = nxe()))
1856  if (on)
1858  else
1860 }
1861 
1862 ////////////////////////////////////////////////////////////////////////////////
1863 /// Set entry (or event) list for this data set
1864 
1866 {
1867  if (!aList)
1868  return;
1869 
1870  if (TestBit(TDSet::kMultiDSet)) {
1871 
1872  // Global entry list for all the datasets
1873  TIter nxds(fElements);
1874  TDSet *ds = 0;
1875  while ((ds = (TDSet *) nxds()))
1876  ds->SetEntryList(aList);
1877 
1878  } else {
1879 
1880  // Link the proper object
1881  TEventList *evl = 0;
1882  TEntryList *enl = dynamic_cast<TEntryList*>(aList);
1883  if (!enl)
1884  evl = dynamic_cast<TEventList*>(aList);
1885  if (!enl && !evl) {
1886  Error("SetEntryList", "type of input object must be either TEntryList "
1887  "or TEventList (found: '%s' - do nothing", aList->ClassName());
1888  return;
1889  }
1890 
1891  // Action depends on the type
1892  fEntryList = (enl) ? enl : (TEntryList *)evl;
1893  }
1894  // Done
1895  return;
1896 }
1897 
1898 ////////////////////////////////////////////////////////////////////////////////
1899 /// Splits the main entry (or event) list into sub-lists for the elements of
1900 /// thet data set
1901 
1903 {
1904  if (TestBit(TDSet::kMultiDSet)) {
1905  // Global entry list for all the datasets
1906  TIter nxds(fElements);
1907  TDSet *ds = 0;
1908  while ((ds = (TDSet *) nxds()))
1909  ds->SplitEntryList();
1910  // Done
1911  return;
1912  }
1913 
1914  if (!fEntryList) {
1915  if (gDebug > 0)
1916  Info("SplitEntryList", "no entry- (or event-) list to split - do nothing");
1917  return;
1918  }
1919 
1920  // Action depend on type of list
1921  TEntryList *enl = dynamic_cast<TEntryList *>(fEntryList);
1922  if (enl) {
1923  // TEntryList
1924  TIter next(fElements);
1925  TDSetElement *el=0;
1926  TEntryList *sublist = 0;
1927  while ((el=(TDSetElement*)next())){
1928  sublist = enl->GetEntryList(el->GetObjName(), el->GetFileName());
1929  if (sublist){
1930  el->SetEntryList(sublist);
1931  el->SetNum(sublist->GetN());
1932  } else {
1933  sublist = new TEntryList("", "");
1934  el->SetEntryList(sublist);
1935  el->SetNum(0);
1936  }
1937  }
1938  } else {
1939  TEventList *evl = dynamic_cast<TEventList *>(fEntryList);
1940  if (evl) {
1941  // TEventList
1942  TIter next(fElements);
1943  TDSetElement *el, *prev;
1944 
1945  prev = dynamic_cast<TDSetElement*> (next());
1946  if (!prev)
1947  return;
1948  Long64_t low = prev->GetTDSetOffset();
1949  Long64_t high = low;
1950  Long64_t currPos = 0;
1951  do {
1952  el = dynamic_cast<TDSetElement*> (next());
1953  // kMaxLong64 means infinity
1954  high = (el == 0) ? kMaxLong64 : el->GetTDSetOffset();
1955 #ifdef DEBUG
1956  while (currPos < evl->GetN() && evl->GetEntry(currPos) < low) {
1957  Error("SplitEntryList",
1958  "TEventList: event outside of the range of any of the TDSetElements");
1959  currPos++; // unnecessary check
1960  }
1961 #endif
1962  TEventList* nevl = new TEventList();
1963  while (currPos < evl->GetN() && evl->GetEntry((Int_t)currPos) < high) {
1964  nevl->Enter(evl->GetEntry((Int_t)currPos) - low);
1965  currPos++;
1966  }
1967  prev->SetEntryList(nevl);
1968  prev->SetNum(nevl->GetN());
1969  low = high;
1970  prev = el;
1971  } while (el);
1972  }
1973  }
1974 }
1975 
1976 ////////////////////////////////////////////////////////////////////////////////
1977 /// Return the number of files in the dataset
1978 
1980 {
1981  Int_t nf = -1;
1982  if (fElements) {
1983  nf = 0;
1984  if (TestBit(TDSet::kMultiDSet)) {
1985  TIter nxds(fElements);
1986  TDSet *ds = 0;
1987  while ((ds = (TDSet *) nxds()))
1988  if (ds->GetListOfElements()) nf += ds->GetListOfElements()->GetSize();
1989  } else {
1990  nf = fElements->GetSize();
1991  }
1992  }
1993  // Done
1994  return nf;
1995 }
const int nx
Definition: kalman.C:16
TString fTitle
Definition: TNamed.h:37
virtual void SetEntriesToProcess(Long64_t nen)
Definition: TEntryList.h:93
virtual ~TDSet()
Cleanup.
Definition: TDSet.cxx:872
static Bool_t CheckDataSetSrvMaps(TUrl *furl, TString &fn, TList *srvmaplist=0)
Check if the dataset server mappings apply to the url defined by 'furl'.
void AddInput(TObject *obj)
Add objects that might be needed during the processing of the selector (see Process()).
Definition: TDSet.cxx:937
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
virtual void Enter(Long64_t entry)
Enter element entry into the list.
Definition: TEventList.cxx:189
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1265
TString fType
Definition: TDSet.h:178
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition: TString.cxx:864
virtual Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
Definition: TSystem.cxx:945
TFileInfo * GetFileInfo(const char *type="TTree")
Return the content of this element in the form of a TFileInfo.
Definition: TDSet.cxx:234
std::list< std::pair< TDSetElement *, TString > > FriendsList_t
Definition: TDSet.h:70
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
static Long64_t GetEntries(Bool_t isTree, const char *filename, const char *path, TString &objname)
Returns number of entries in tree or objects in file.
Definition: TDSet.cxx:1353
Long64_t GetEntries(Bool_t istree=kTRUE, Bool_t openfile=kTRUE)
Returns number of entries in tree or objects in file.
Definition: TDSet.cxx:432
long long Long64_t
Definition: RtypesCore.h:69
THashList * fElements
Definition: TDSet.h:180
virtual TDSetElement * Next(Long64_t totalEntries=-1)
Returns next TDSetElement.
Definition: TDSet.cxx:416
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:107
virtual const char * WorkingDirectory()
Return working directory.
Definition: TSystem.cxx:865
llvm::StringRef GetFileName(const clang::Decl &decl, const cling::Interpreter &interp)
Return the header file to be included to declare the Decl.
Bool_t IsReading() const
Definition: TBuffer.h:81
virtual Long64_t DrawSelect(TDSet *dset, const char *varexp, const char *selection="", Option_t *option="", Long64_t nentries=-1, Long64_t firstentry=0)
Execute the specified drawing action on a data set (TDSet).
Definition: TProof.cxx:6133
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:155
TDSet()
iterator on fSrvMaps
Definition: TDSet.cxx:675
short Version_t
Definition: RtypesCore.h:61
void SetLookedUp()
Flag all the elements as looked-up, so to avoid opening the files if the functionality is not support...
Definition: TDSet.cxx:1629
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Ssiz_t Length() const
Definition: TString.h:390
const char Int_t const char TProof Int_t const char const char * msd
Definition: TXSlave.cxx:46
Collectable string class.
Definition: TObjString.h:32
const char Option_t
Definition: RtypesCore.h:62
const char * GetObjName() const
Definition: TDSet.h:229
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:212
virtual Long64_t Process(TSelector *selector, Option_t *option="", Long64_t nentries=-1, Long64_t firstentry=0, TObject *enl=0)
Process TDSet on currently active PROOF session.
Definition: TDSet.cxx:890
This class represents a WWW compatible URL.
Definition: TUrl.h:41
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
void SetWriteV3(Bool_t on=kTRUE)
Set/Reset the 'OldStreamer' bit in this instance and its elements.
Definition: TDSet.cxx:1846
#define gDirectory
Definition: TDirectory.h:218
Definition: TDSet.h:153
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
const char * GetProtocol() const
Definition: TUrl.h:73
TH1 * h
Definition: legend2.C:5
Int_t GetNumOfFiles()
Return the number of files in the dataset.
Definition: TDSet.cxx:1979
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
Definition: TUrl.cxx:108
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
Bool_t fIsTree
Definition: TDSet.h:167
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
ERunStatus GetRunStatus() const
Definition: TProof.h:976
TList * GetOutputList()
Get list with all object created during processing (see Process()).
Definition: TProof.cxx:10375
TString fDirectory
Definition: TDSet.h:82
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: TList.cxx:92
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
Regular expression class.
Definition: TRegexp.h:35
static const char * filename()
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
#define gROOT
Definition: TROOT.h:340
void AddAssocObj(TObject *assocobj)
Add an associated object to the list.
Definition: TDSet.cxx:634
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
ClassImp(TDSetElement) ClassImp(TDSet) TDSetElement
Default constructor.
Definition: TDSet.cxx:79
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 Print(Option_t *options="") const
Print a TDSetElement. When option="a" print full data.
Definition: TDSet.cxx:264
Int_t Compare(const TObject *obj) const
Compare elements by filename (and the fFirst).
Definition: TDSet.cxx:354
A TChainElement describes a component of a TChain.
Definition: TChainElement.h:30
const char * GetOptions() const
Definition: TUrl.h:80
Long_t ExecPlugin(int nargs, const T &...params)
virtual void SetNameTitle(const char *name, const char *title)
Change (i.e. set) all the TNamed parameters (name and title).
Definition: TNamed.cxx:142
TObject * fEntryList
Definition: TDSet.h:88
TString & Insert(Ssiz_t pos, const char *s)
Definition: TString.h:592
Bool_t GetValid() const
Definition: TDSet.h:121
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:310
Int_t ExportFileList(const char *filepath, Option_t *opt="")
Export TDSetElements files as list of TFileInfo objects in file 'fpath'.
Definition: TDSet.cxx:1248
TUrl * GetFirstUrl() const
Definition: TFileInfo.h:83
void Reset()
Definition: TCollection.h:161
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:732
Int_t Lookup(Bool_t force=kFALSE)
Resolve end-point URL for this element Return 0 on success and -1 otherwise.
Definition: TDSet.cxx:537
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3851
Float_t fMaxProcTime
Definition: TDSet.h:96
const char * GetObjName() const
Definition: TDSet.h:122
virtual Int_t GetN() const
Definition: TEventList.h:58
Long64_t GetNum() const
Definition: TDSet.h:116
virtual TList * GetListOfFriends() const
Definition: TTree.h:407
TList * GetOutputList()
Get list with all object created during processing (see Process()).
Definition: TDSet.cxx:969
const char * Data() const
Definition: TString.h:349
virtual TKey * GetKey(const char *, Short_t=9999) const
Definition: TDirectory.h:153
Bool_t HasBeenLookedUp() const
Definition: TDSet.h:98
const char * GetDirectory() const
Definition: TDSet.h:230
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:839
#define SafeDelete(p)
Definition: RConfig.h:436
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Definition: TSystem.cxx:1346
Long64_t GetTDSetOffset() const
Definition: TDSet.h:130
Bool_t IsTree() const
Definition: TDSet.h:225
void SetEntries(Long64_t ent)
Definition: TDSet.h:118
void Validate(Bool_t isTree)
Validate by opening the file.
Definition: TDSet.cxx:278
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
TIter * fIterator
Definition: TDSet.h:181
Bool_t AddMetaData(TObject *meta)
Add's a meta data object to the file info object.
Definition: TFileInfo.cxx:382
void Class()
Definition: Class.C:29
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
const char * GetMsd() const
Definition: TDSet.h:119
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
static EFileType GetType(const char *name, Option_t *option="", TString *prefix=0)
Resolve the file type as a function of the protocol field in 'name'.
Definition: TFile.cxx:4566
virtual ~TDSetElement()
Clean up the element.
Definition: TDSet.cxx:168
TList * GetListOfElements() const
Definition: TDSet.h:231
virtual const char * PrependPathName(const char *dir, TString &name)
Concatenate a directory and a file name.
Definition: TSystem.cxx:1054
void SetLookedUp()
Definition: TDSet.h:141
void Validate()
Validate the TDSet by opening files.
Definition: TDSet.cxx:1561
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1964
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:63
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
void SetDirectory(const char *dir)
Set/change directory.
Definition: TDSet.cxx:1012
Long64_t fTDSetOffset
Definition: TDSet.h:86
void SetSrvMaps(TList *srvmaps=0)
Set (or unset) the list for mapping servers coordinate for files.
Definition: TDSet.cxx:1143
virtual void DeleteFriends()
Deletes the list of friends and all the friends on the list.
Definition: TDSet.cxx:403
virtual Int_t SendAsynMessage(const char *msg, Bool_t lf=kTRUE)
Send an asychronous message to the master / client .
Bool_t IsLite() const
Definition: TProof.h:966
Long64_t GetFirst() const
Definition: TDSet.h:114
virtual void Print(Option_t *option="") const
This method must be overridden when a class wants to print itself.
Definition: TObject.cxx:594
A specialized string object used for TTree selections.
Definition: TCut.h:27
A doubly linked list.
Definition: TList.h:47
TList * GetMetaDataList() const
Definition: TFileInfo.h:94
const Long64_t kMaxLong64
Definition: Rtypes.h:111
Bool_t ElementsValid()
Check if all elements are valid.
Definition: TDSet.cxx:1527
virtual Long64_t GetEntry(Int_t index) const
Return value of entry at index in the list.
Definition: TEventList.cxx:220
EFileType
File type.
Definition: TFile.h:163
TDSetElement * fCurrent
iterator on fElements
Definition: TDSet.h:182
TString fDir
Definition: TDSet.h:177
TString fMsd
Definition: TDSet.h:85
TProofChain * fProofChain
entry (or event) list for processing
Definition: TDSet.h:169
void SendDataSetStatus(const char *msg, UInt_t n, UInt_t tot, Bool_t st)
Send or notify data set status.
Definition: TProof.cxx:9903
const char * GetFileName() const
Definition: TDSet.h:113
TFileInfoMeta * GetMetaData(const char *meta=0) const
Get meta data object with specified name.
Definition: TFileInfo.cxx:422
TList * fSrvMaps
current element
Definition: TDSet.h:183
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:494
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition: TObject.cxx:187
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:674
TObject * Next()
Definition: TCollection.h:158
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:284
Collection abstract base class.
Definition: TCollection.h:48
TClass * IsA() const
TObject * Value() const
Definition: TMap.h:125
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2321
unsigned int UInt_t
Definition: RtypesCore.h:42
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
TMarker * m
Definition: textangle.C:8
char * Form(const char *fmt,...)
Long64_t GetEntries() const
Definition: TFileInfo.h:151
TObject * GetOutput(const char *name)
Get specified object that has been produced during the processing (see Process()).
Definition: TProof.cxx:10329
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:499
A TEventList object is a list of selected events (entries) in a TTree.
Definition: TEventList.h:33
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
virtual Long64_t Draw(const char *varexp, const char *selection, Option_t *option="", Long64_t nentries=-1, Long64_t firstentry=0)
Draw expression varexp for specified entries.
Definition: TDSet.cxx:1472
virtual Long64_t Process(TDSet *dset, const char *selector, Option_t *option="", Long64_t nentries=-1, Long64_t firstentry=0)
Process a data set (TDSet) using the specified selector (.C) file or Tselector object Entry- or event...
Definition: TProof.cxx:5293
const char * GetAnchor() const
Definition: TUrl.h:79
Version_t GetClassVersion() const
Definition: TClass.h:382
Bool_t IsNull() const
Definition: TString.h:387
TObjArray * GetListOfFiles() const
Definition: TChain.h:109
Int_t MergeElement(TDSetElement *elem)
Check if 'elem' is overlapping or subsequent and, if the case, return a merged element.
Definition: TDSet.cxx:185
TString fName
Definition: TNamed.h:36
TString fObjName
Definition: TDSet.h:179
void AddInput(TObject *obj)
Add objects that might be needed during the processing of the selector (see Process()).
Definition: TProof.cxx:10301
#define Printf
Definition: TGeoToOCC.h:18
#define gPerfStats
void Print(Option_t *option="") const
Print TDSet basic or full data. When option="a" print full data.
Definition: TDSet.cxx:979
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
virtual TTree * GetTreeHeader(TProof *proof)
Returns a tree header containing the branches' structure of the dataset.
Definition: TDSet.cxx:1519
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:580
void ClearInput()
Clear input object list.
Definition: TDSet.cxx:949
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
R__EXTERN TProof * gProof
Definition: TProof.h:1110
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition: TObject.cxx:932
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:106
void SetAnchor(const char *anchor)
Definition: TUrl.h:95
virtual Int_t GetSize() const
Definition: TCollection.h:95
double f(double x)
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
void SetObjName(const char *objname)
Set/change object name.
Definition: TDSet.cxx:997
double Double_t
Definition: RtypesCore.h:55
TObject * Key() const
Definition: TMap.h:124
void ClearInput()
Clear input object list.
Definition: TProof.cxx:10309
Describe directory structure in memory.
Definition: TDirectory.h:41
virtual void SetEntryList(TObject *aList)
Set entry (or event) list for this data set.
Definition: TDSet.cxx:1865
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
TNamed()
Definition: TNamed.h:40
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:76
Definition: TProof.h:339
int nentries
Definition: THbookFile.cxx:89
TObject * GetOutput(const char *name)
Get specified object that has been produced during the processing (see Process()).
Definition: TDSet.cxx:959
void SetNum(Long64_t num)
Definition: TDSet.h:120
static TFileStager * Open(const char *stager)
Open a stager, after having loaded the relevant plug-in.
virtual void Reset()
Reset or initialize access to the elements.
Definition: TDSet.cxx:1340
virtual void Add(TObject *obj)=0
virtual TTree * GetTreeHeader(TDSet *tdset)
Creates a tree header (a tree with nonexisting files) object for the DataSet.
Definition: TProof.cxx:10609
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2881
virtual void AddFriend(TDSetElement *friendElement, const char *alias)
Add friend TDSetElement to this set. The friend element will be copied to this object.
Definition: TDSet.cxx:379
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual Long64_t GetN() const
Definition: TEntryList.h:77
Long64_t GetFirst() const
Definition: TFileInfo.h:152
void SetEntryList(TObject *aList, Long64_t first=-1, Long64_t num=-1)
Set entry (or event) list for this element.
Definition: TDSet.cxx:602
Mother of all ROOT objects.
Definition: TObject.h:58
void Lookup(Bool_t removeMissing=kFALSE, TList **missingFiles=0)
Resolve the end-point URL for the current elements of this data set If the removeMissing option is se...
Definition: TDSet.cxx:1577
const char Int_t const char TProof * proof
Definition: TXSlave.cxx:46
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:556
const char * GetDirectory() const
Get the object's directory in the ROOT file.
Definition: TFileInfo.cxx:578
Bool_t IsDigit() const
Returns true if all characters in string are digits (0-9) or white spaces, i.e.
Definition: TString.cxx:1806
void SplitEntryList()
for browsing purposes
Definition: TDSet.cxx:1902
TClassRef is used to implement a permanent reference to a TClass object.
Definition: TClassRef.h:33
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:727
TObject * GetAssocObj(Long64_t i, Bool_t isentry=kFALSE)
Get i-th associated object.
Definition: TDSet.cxx:652
virtual Bool_t Add(const char *file, const char *objname=0, const char *dir=0, Long64_t first=0, Long64_t num=-1, const char *msd=0)
Add file to list of files to be analyzed.
Definition: TDSet.cxx:1023
Long64_t fNum
Definition: TDSet.h:84
TList * fFriends
Definition: TDSet.h:91
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:433
R__EXTERN TProofServ * gProofServ
Definition: TProofServ.h:359
Long64_t fEntries
Definition: TDSet.h:90
virtual void Add(TObject *obj)
Definition: TList.h:81
const Ssiz_t kNPOS
Definition: Rtypes.h:115
A TFriendElement TF describes a TTree object TF in a file.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
A chain is a collection of files containg TTree objects.
Definition: TChain.h:35
void SetOptions(const char *opt)
Definition: TUrl.h:96
virtual TEntryList * GetEntryList(const char *treename, const char *filename, Option_t *opt="")
Return the entry list, correspoding to treename and filename By default, the filename is first tried ...
Definition: TEntryList.cxx:777
const Int_t kError
Definition: TError.h:41
TString fDataSet
Definition: TDSet.h:93
TObject * fEntryList
Definition: TDSet.h:168
R__EXTERN Int_t gDebug
Definition: Rtypes.h:128
virtual Bool_t Matches(const char *s)
Definition: TFileStager.h:50
const char * GetType() const
Definition: TDSet.h:228
virtual Long64_t GetEntries() const
Definition: TTree.h:382
A TTree object has a header with a name and a title.
Definition: TTree.h:94
Class describing a generic file including meta information.
Definition: TFileInfo.h:50
void ResetBit(UInt_t f)
Definition: TObject.h:172
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4579
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1243
TIter * fSrvMapsIter
list for mapping server coordinates for files
Definition: TDSet.h:184
virtual Int_t Locate(const char *u, TString &f)
Just check if the file exists locally.
const char * GetClass() const
Bool_t IsValid() const
Definition: TDSet.h:226
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
A TSelector object is used by the TTree::Draw, TTree::Scan, TTree::Process to navigate in a TTree and...
Definition: TSelector.h:39
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void AddFriend(TDSet *friendset, const char *alias)
Add friend dataset to this set.
Definition: TDSet.cxx:1306
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
TObject * obj
TList * fAssocObjList
Definition: TDSet.h:94
A List of entry numbers in a TTree or TChain.
Definition: TEntryList.h:27
const Int_t n
Definition: legend1.C:16
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write all objects in this collection.
static constexpr Long64_t kMaxEntries
Definition: TTree.h:217
Bool_t fValid
Definition: TDSet.h:89
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
const char * GetDirectory() const
Return directory where to look for object.
Definition: TDSet.cxx:256
virtual void StartViewer()
Start the TTreeViewer on this TTree.
Definition: TDSet.cxx:1491
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:898
Int_t Remove(TDSetElement *elem, Bool_t deleteElem=kTRUE)
Remove TDSetElement 'elem' from the list.
Definition: TDSet.cxx:1548
const char * GetObject() const
Get the object name, with path stripped off.
Definition: TFileInfo.cxx:587
Long64_t fFirst
Definition: TDSet.h:83
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:904