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