ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
63 TDSetElement::TDSetElement() : TNamed("",""),
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 {
69  ResetBit(kWriteV3);
70  ResetBit(kHasBeenLookedUp);
71  ResetBit(kEmpty);
72  ResetBit(kCorrupted);
73  ResetBit(kNewRun);
74  ResetBit(kNewPacket);
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 
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 
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  return;
584 
585  // Link the proper object
586  TEventList *evl = 0;
587  TEntryList *enl = dynamic_cast<TEntryList*>(aList);
588  if (!enl)
589  evl = dynamic_cast<TEventList*>(aList);
590  if (!enl && !evl) {
591  Error("SetEntryList", "type of input object must be either TEntryList "
592  "or TEventList (found: '%s' - do nothing", aList->ClassName());
593  return;
594  }
595 
596  // Action depends on the type
597  if (enl) {
598  enl->SetEntriesToProcess(num);
599  } else {
600  for (; num > 0; num--, first++)
601  evl->Enter(evl->GetEntry((Int_t)first));
602  }
603  fEntryList = aList;
604 
605  // Done
606  return;
607 }
608 
609 ////////////////////////////////////////////////////////////////////////////////
610 /// Add an associated object to the list
611 
613 {
614  if (assocobj) {
615  if (!fAssocObjList) fAssocObjList = new TList;
616  if (fAssocObjList) fAssocObjList->Add(assocobj);
617  }
618 }
619 
620 ////////////////////////////////////////////////////////////////////////////////
621 /// Get i-th associated object.
622 /// If 'isentry' fFirst is subtracted, so that i == fFirst returns the first
623 /// object in the list.
624 /// If there are not enough elements in the list, the element i%list_size is
625 /// returned (if the list has only one element this only one element is always
626 /// returned.
627 /// This method is used when packet processing consist in processing the objects
628 /// in the associated object list.
629 
631 {
632  TObject *o = 0;
633  if (!fAssocObjList || fAssocObjList->GetSize() <= 0) return o;
634 
635  TString s;
636  Int_t pos = -1;
637  if (isentry) {
638  if (i < fFirst) return o;
639  s.Form("%lld", i - fFirst);
640  } else {
641  if (i < 0) return o;
642  s.Form("%lld", i);
643  }
644  if (!(s.IsDigit())) return o;
645  pos = s.Atoi();
646  if (pos > fAssocObjList->GetSize() - 1) pos %= fAssocObjList->GetSize();
647  return fAssocObjList->At(pos);
648 }
649 
650 
651 /** \class TDSet
652 \ingroup proofkernel
653 
654 This class implements a data set to be used for PROOF processing.
655 The TDSet defines the class of which objects will be processed,
656 the directory in the file where the objects of that type can be
657 found and the list of files to be processed. The files can be
658 specified as logical file names (LFN's) or as physical file names
659 (PFN's). In case of LFN's the resolution to PFN's will be done
660 according to the currently active GRID interface.
661 Examples:
662  TDSet treeset("TTree", "AOD");
663  treeset.Add("lfn:/alien.cern.ch/alice/prod2002/file1");
664  ...
665  treeset.AddFriend(friendset);
666 
667 or
668 
669  TDSet objset("MyEvent", "*", "/events");
670  objset.Add("root://cms.cern.ch/user/prod2002/hprod_1.root");
671  ...
672  objset.Add(set2003);
673 
674 Validity of file names will only be checked at processing time
675 (typically on the PROOF master server), not at creation time.
676 
677 */
678 
679 ////////////////////////////////////////////////////////////////////////////////
680 /// Default ctor.
681 
683 {
684  fElements = new THashList;
685  fElements->SetOwner();
686  fIsTree = kFALSE;
687  fIterator = 0;
688  fCurrent = 0;
689  fEntryList = 0;
690  fProofChain = 0;
691  fSrvMaps = 0;
692  fSrvMapsIter = 0;
694  ResetBit(kEmpty);
698 
699  // Add to the global list
700  gROOT->GetListOfDataSets()->Add(this);
701 }
702 
703 ////////////////////////////////////////////////////////////////////////////////
704 /// Create a named TDSet object. The "type" defines the class of which objects
705 /// will be processed (default 'TTree'). The optional "objname" argument
706 /// specifies the name of the objects of the specified class.
707 /// If the "objname" is not given the behaviour depends on the 'type':
708 /// for 'TTree' the first TTree is analyzed; for other types, all objects of
709 /// the class found in the specified directory are processed.
710 /// The "dir" argument specifies in which directory the objects are
711 /// to be found, the top level directory ("/") is the default.
712 /// Directories can be specified using wildcards, e.g. "*" or "/*"
713 /// means to look in all top level directories, "/dir/*" in all
714 /// directories under "/dir", and "/*/*" to look in all directories
715 /// two levels deep.
716 /// For backward compatibility the type can also be passed via 'name',
717 /// in which case 'type' is ignored.
718 
719 TDSet::TDSet(const char *name,
720  const char *objname, const char *dir, const char *type)
721 {
722  fElements = new THashList;
723  fElements->SetOwner();
724  fIterator = 0;
725  fCurrent = 0;
726  fEntryList = 0;
727  fProofChain = 0;
728  fSrvMaps = 0;
729  fSrvMapsIter = 0;
731  ResetBit(kEmpty);
735 
736  fType = "TTree";
737  TClass *c = 0;
738  // Check name
739  if (name && strlen(name) > 0) {
740  // In the old constructor signature it was the 'type'
741  if (!type) {
742  TString cn(name);
743  if (cn.Contains(':')) cn.Remove(0, cn.Index(":")+1);
744  if (TClass::GetClass(cn))
745  fType = cn;
746  else
747  // Default type is 'TTree'
748  fName = name;
749  } else {
750  // Set name
751  fName = name;
752  // Check type
753  if (strlen(type) > 0)
754  if (TClass::GetClass(type))
755  fType = type;
756  }
757  } else if (type && strlen(type) > 0) {
758  // Check the type
759  if (TClass::GetClass(type))
760  fType = type;
761  }
762  // The correct class type
763  c = TClass::GetClass(fType);
764 
766 
767  if (objname)
768  fObjName = objname;
769 
770  if (dir)
771  fDir = dir;
772 
773  // Default name is the object name
774  if (fName.Length() <= 0)
775  fName = TString::Format("TDSet:%s", fObjName.Data());
776  // We set the default title to the 'type'
777  fTitle = fType;
778 
779  // Add to the global list
780  gROOT->GetListOfDataSets()->Add(this);
781 }
782 
783 ////////////////////////////////////////////////////////////////////////////////
784 /// Create a named TDSet object from existing TChain 'chain'.
785 /// If 'withfriends' is kTRUE add also friends.
786 /// This constructor substituted the static methods TChain::MakeTDSet
787 /// removing any residual dependence of 'tree' on 'proof'.
788 
789 TDSet::TDSet(const TChain &chain, Bool_t withfriends)
790 {
791  fElements = new THashList;
792  fElements->SetOwner();
793  fIterator = 0;
794  fCurrent = 0;
795  fEntryList = 0;
796  fProofChain = 0;
797  fSrvMaps = 0;
798  fSrvMapsIter = 0;
800  ResetBit(kEmpty);
804 
805  fType = "TTree";
806  fIsTree = kTRUE;
807  fObjName = chain.GetName();
808  fName = TString::Format("TChain:%s", chain.GetName());
809 
810  // First fill elements without friends()
811  TIter next(chain.GetListOfFiles());
812  TChainElement *elem = 0;
813  TString key;
814  while ((elem = (TChainElement *)next())) {
815  TString file(elem->GetTitle());
816  TString tree(elem->GetName());
817  Int_t isl = tree.Last('/');
818  TString dir = "/";
819  if (isl >= 0) {
820  // Copy the tree name specification
821  TString behindSlash = tree(isl + 1, tree.Length() - isl - 1);
822  // and remove it from basename
823  tree.Remove(isl);
824  dir = tree;
825  tree = behindSlash;
826  }
827  // Find MSD if any
828  TString msd(TUrl(file).GetOptions());
829  Int_t imsd = kNPOS;
830  if ((imsd = msd.Index("msd=")) != kNPOS) {
831  msd.Remove(0, imsd+4);
832  } else {
833  // Not an MSD option
834  msd = "";
835  }
836  Long64_t nent = (elem->GetEntries() > 0 &&
837  elem->GetEntries() != TTree::kMaxEntries) ? elem->GetEntries() : -1;
838  if (Add(file, tree, dir, 0, nent, ((msd.IsNull()) ? 0 : msd.Data()))) {
839  if (elem->HasBeenLookedUp()) {
840  // Save lookup information, if any
841  TDSetElement *dse = (TDSetElement *) fElements->Last();
842  if (dse) dse->SetLookedUp();
843  }
844  }
845  }
846  SetDirectory(0);
847 
848  // Add friends now, if requested
849  if (withfriends) {
850  TList processed;
851  TList chainsQueue;
852  chainsQueue.Add((TObject *)&chain);
853  processed.Add((TObject *)&chain);
854  while (chainsQueue.GetSize() > 0) {
855  TChain *c = (TChain *) chainsQueue.First();
856  chainsQueue.Remove(c);
857  TIter friendsIter(c->GetListOfFriends());
858  while(TFriendElement *fe = dynamic_cast<TFriendElement*> (friendsIter()) ) {
859  if (TChain *fc = dynamic_cast<TChain*>(fe->GetTree())) {
860  if (!processed.FindObject(fc)) { // if not yet processed
861  processed.AddFirst(fc);
862  AddFriend(new TDSet((const TChain &)(*fc), kFALSE), fe->GetName());
863  chainsQueue.Add(fc); // for further processing
864  }
865  } else {
866  Reset();
867  Error("TDSet", "Only TChains supported. Found illegal tree %s",
868  fe->GetTree()->GetName());
869  return;
870  }
871  }
872  }
873  }
874 }
875 
876 ////////////////////////////////////////////////////////////////////////////////
877 /// Cleanup.
878 
880 {
884  fSrvMaps = 0;
885  fSrvMapsIter = 0;
886 
887  gROOT->GetListOfDataSets()->Remove(this);
888 }
889 
890 ////////////////////////////////////////////////////////////////////////////////
891 /// Process TDSet on currently active PROOF session.
892 /// The last argument 'enl' specifies an entry- or event-list to be used as
893 /// event selection.
894 /// The return value is -1 in case of error and TSelector::GetStatus() in
895 /// in case of success.
896 
898  Long64_t first, TObject *enl)
899 {
900  if (!IsValid() || !fElements->GetSize()) {
901  Error("Process", "not a correctly initialized TDSet");
902  return -1;
903  }
904 
905  // Set entry list
906  SetEntryList(enl);
907 
908  if (gProof)
909  return gProof->Process(this, selector, option, nentries, first);
910 
911  Error("Process", "no active PROOF session");
912  return -1;
913 }
914 
915 ////////////////////////////////////////////////////////////////////////////////
916 /// Process TDSet on currently active PROOF session.
917 /// The last argument 'enl' specifies an entry- or event-list to be used as
918 /// event selection.
919 /// The return value is -1 in case of error and TSelector::GetStatus() in
920 /// in case of success.
921 
922 Long64_t TDSet::Process(const char *selector, Option_t *option, Long64_t nentries,
923  Long64_t first, TObject *enl)
924 {
925  if (!IsValid() || !fElements->GetSize()) {
926  Error("Process", "not a correctly initialized TDSet");
927  return -1;
928  }
929 
930  // Set entry list
931  SetEntryList(enl);
932 
933  if (gProof)
934  return gProof->Process(this, selector, option, nentries, first);
935 
936  Error("Process", "no active PROOF session");
937  return -1;
938 }
939 
940 ////////////////////////////////////////////////////////////////////////////////
941 /// Add objects that might be needed during the processing of
942 /// the selector (see Process()).
943 
945 {
946  if (gProof) {
947  gProof->AddInput(obj);
948  } else {
949  Error("AddInput","No PROOF session active");
950  }
951 }
952 
953 ////////////////////////////////////////////////////////////////////////////////
954 /// Clear input object list.
955 
957 {
958  if (gProof)
959  gProof->ClearInput();
960 }
961 
962 ////////////////////////////////////////////////////////////////////////////////
963 /// Get specified object that has been produced during the processing
964 /// (see Process()).
965 
967 {
968  if (gProof)
969  return gProof->GetOutput(name);
970  return 0;
971 }
972 
973 ////////////////////////////////////////////////////////////////////////////////
974 /// Get list with all object created during processing (see Process()).
975 
977 {
978  if (gProof)
979  return gProof->GetOutputList();
980  return 0;
981 }
982 
983 ////////////////////////////////////////////////////////////////////////////////
984 /// Print TDSet basic or full data. When option="a" print full data.
985 
986 void TDSet::Print(const Option_t *opt) const
987 {
988  const char *clnm = (IsA()) ? IsA()->GetName() : "TDSet";
989  Printf("OBJ: %s\ttype %s\t%s\tin %s\telements %d", clnm, GetName(),
990  fObjName.Data(), GetTitle(), GetListOfElements()->GetSize());
991 
992  if (opt && opt[0] == 'a') {
994  TObject *obj;
995  while ((obj = next())) {
996  obj->Print(opt);
997  }
998  }
999 }
1000 
1001 ////////////////////////////////////////////////////////////////////////////////
1002 /// Set/change object name.
1003 
1004 void TDSet::SetObjName(const char *objname)
1005 {
1006  if (objname) {
1007  fObjName = objname;
1009  TDSetElement *e;
1010  while ((e = (TDSetElement *) next())) {
1011  e->SetTitle(objname);
1012  }
1013  }
1014 }
1015 
1016 ////////////////////////////////////////////////////////////////////////////////
1017 /// Set/change directory.
1018 
1019 void TDSet::SetDirectory(const char *dir)
1020 {
1021  if (dir)
1022  fDir = dir;
1023 }
1024 
1025 ////////////////////////////////////////////////////////////////////////////////
1026 /// Add file to list of files to be analyzed. Optionally with the
1027 /// objname and dir arguments the default, TDSet wide, objname and
1028 /// dir can be overridden.
1029 
1030 Bool_t TDSet::Add(const char *file, const char *objname, const char *dir,
1031  Long64_t first, Long64_t num, const char *msd)
1032 {
1033  if (!file || !*file) {
1034  Error("Add", "file name must be specified");
1035  return kFALSE;
1036  }
1037 
1038  TString fn = file;
1039  if (gProof && gProof->IsLite()) {
1040  TUrl u(file, kTRUE);
1041  if (!strcmp(u.GetProtocol(), "file")) {
1042  fn = u.GetFileAndOptions();
1043  gSystem->ExpandPathName(fn);
1044  if (!gSystem->IsAbsoluteFileName(fn))
1046  }
1047  }
1048 
1049  // check, if it already exists in the TDSet
1051  if (!el) {
1052  if (!objname)
1053  objname = GetObjName();
1054  if (!dir)
1055  dir = GetDirectory();
1056  fElements->Add(new TDSetElement(fn, objname, dir, first, num, msd));
1057  } else {
1058  TString msg;
1059  msg.Form("duplication detected: %40s is already in dataset - ignored", fn.Data());
1060  Warning("Add", "%s", msg.Data());
1061  if (gProofServ) {
1062  msg.Insert(0, "WARNING: ");
1064  }
1065  }
1066 
1067  return kTRUE;
1068 }
1069 
1070 ////////////////////////////////////////////////////////////////////////////////
1071 /// Add specified data set to the this set.
1072 
1074 {
1075  if (!dset)
1076  return kFALSE;
1077 
1078  if (TestBit(TDSet::kMultiDSet)) {
1079  fElements->Add(dset);
1080  return kTRUE;
1081  }
1082 
1083  if (fType != dset->GetType()) {
1084  Error("Add", "cannot add a set with a different type");
1085  return kFALSE;
1086  }
1087 
1088  TDSetElement *el;
1089  TIter next(dset->fElements);
1090  TObject *last = (dset == this) ? fElements->Last() : 0;
1091  while ((el = (TDSetElement*) next())) {
1092  Add(el->GetFileName(), el->GetObjName(), el->GetDirectory(),
1093  el->GetFirst(), el->GetNum(), el->GetMsd());
1094  if (el == last) break;
1095  }
1096 
1097  return kTRUE;
1098 }
1099 
1100 ////////////////////////////////////////////////////////////////////////////////
1101 /// Add files passed as list of TFileInfo, TUrl or TObjString objects .
1102 /// If TFileInfo, the first entry and the number of entries are also filled.
1103 /// The argument 'meta' can be used to specify one of the subsets in the
1104 /// file as described in the metadata of TFileInfo. By default the first one
1105 /// is taken.
1106 /// If 'availableOnly' is true only files available ('staged' and non corrupted)
1107 /// are taken: those not satisfying this requirement are added to 'badlist', if
1108 /// the latter is defined. By default availableOnly is false.
1109 
1110 Bool_t TDSet::Add(TCollection *filelist, const char *meta, Bool_t availableOnly,
1111  TCollection *badlist)
1112 {
1113  if (!filelist)
1114  return kFALSE;
1115 
1116  TObject *o = 0;
1117  TIter next(filelist);
1118  while ((o = next())) {
1119  TString cn(o->ClassName());
1120  if (cn == "TFileInfo") {
1121  TFileInfo *fi = (TFileInfo *)o;
1122  if (!availableOnly ||
1123  (fi->TestBit(TFileInfo::kStaged) &&
1124  !fi->TestBit(TFileInfo::kCorrupted))) {
1125  Int_t nf = fElements->GetSize();
1126  if (!Add(fi, meta)) return kFALSE;
1127  // Duplications count as bad files
1128  if (fElements->GetSize() <= nf && badlist) badlist->Add(fi);
1129  } else if (badlist) {
1130  // Return list of non-usable files
1131  badlist->Add(fi);
1132  }
1133  } else if (cn == "TUrl") {
1134  Add(((TUrl *)o)->GetUrl());
1135  } else if (cn == "TObjString") {
1136  Add(((TObjString *)o)->GetName());
1137  } else {
1138  Warning("Add","found object fo unexpected type %s - ignoring", cn.Data());
1139  }
1140  }
1141 
1142  return kTRUE;
1143 }
1144 
1145 ////////////////////////////////////////////////////////////////////////////////
1146 /// Set (or unset) the list for mapping servers coordinate for files.
1147 /// Reinitialize the related iterator if needed.
1148 /// Used by TProof.
1149 
1150 void TDSet::SetSrvMaps(TList *srvmaps)
1151 {
1152  fSrvMaps = srvmaps;
1154  if (fSrvMaps) fSrvMapsIter = new TIter(fSrvMaps);
1155 }
1156 
1157 ////////////////////////////////////////////////////////////////////////////////
1158 /// Add file described by 'fi' to list of files to be analyzed.
1159 /// The argument 'meta' can be used to specify a subsets in the
1160 /// file as described in the metadata of TFileInfo. By default the first one
1161 /// is taken.
1162 
1163 Bool_t TDSet::Add(TFileInfo *fi, const char *meta)
1164 {
1165  if (!fi) {
1166  Error("Add", "TFileInfo object name must be specified");
1167  return kFALSE;
1168  }
1169  TString msg;
1170 
1171  // Check if a remap of the server coordinates is requested
1172  const char *file = fi->GetFirstUrl()->GetUrl();
1173  Bool_t setLookedUp = kTRUE;
1174  TString file1;
1176  !(file1.IsNull())) {
1177  file = file1.Data();
1178  setLookedUp = kFALSE;
1179  }
1180  // Check if it already exists in the TDSet
1181  if (fElements->FindObject(file)) {
1182  msg.Form("duplication detected: %40s is already in dataset - ignored", file);
1183  Warning("Add", "%s", msg.Data());
1184  if (gProofServ) {
1185  msg.Insert(0, "WARNING: ");
1187  }
1188  return kTRUE;
1189  }
1190 
1191  // If more than one metadata info require the specification of the objpath;
1192  // the order in which they appear is not guaranteed and the error may be
1193  // very difficult to find.
1194  TFileInfoMeta *m = 0;
1195  if (!meta || strlen(meta) <= 0 || !strcmp(meta, "/")) {
1196  TList *fil = 0;
1197  if ((fil = fi->GetMetaDataList()) && fil->GetSize() > 1) {
1198  msg.Form("\n Object name unspecified and several objects available.\n");
1199  msg += " Please choose one from the list below:\n";
1200  TIter nx(fil);
1201  while ((m = (TFileInfoMeta *) nx())) {
1202  TString nm(m->GetName());
1203  if (nm.BeginsWith("/")) nm.Remove(0,1);
1204  msg += Form(" %s -> TProof::Process(\"%s#%s\",...)\n",
1205  nm.Data(), GetName(), nm.Data());
1206  }
1207  if (gProofServ)
1209  else
1210  Warning("Add", "%s", msg.Data());
1211  return kFALSE;
1212  }
1213  }
1214 
1215  // Get the metadata, if any
1216  m = fi->GetMetaData(meta);
1217 
1218  // Create the element
1219  const char *objname = 0;
1220  const char *dir = 0;
1221  Long64_t first = 0;
1222  Long64_t num = -1;
1223  if (!m) {
1224  objname = GetObjName();
1225  dir = GetDirectory();
1226  } else {
1227  objname = (m->GetObject() && strlen(m->GetObject())) ? m->GetObject() : GetObjName();
1228  dir = (m->GetDirectory() && strlen(m->GetDirectory())) ? m->GetDirectory() : GetDirectory();
1229  first = m->GetFirst();
1230  num = m->GetEntries();
1231  }
1232  const char *dataset = 0;
1233  if (strcmp(fi->GetTitle(), "TFileInfo")) dataset = fi->GetTitle();
1234  TDSetElement *el = new TDSetElement(file, objname, dir, first, -1, 0, dataset);
1235  el->SetEntries(num);
1236 
1237  // Set looked-up bit
1238  if (fi->TestBit(TFileInfo::kStaged) && setLookedUp)
1240  if (fi->TestBit(TFileInfo::kCorrupted))
1242 
1243  // Add the element
1244  fElements->Add(el);
1245 
1246  return kTRUE;
1247 }
1248 
1249 ////////////////////////////////////////////////////////////////////////////////
1250 /// Export TDSetElements files as list of TFileInfo objects in file
1251 /// 'fpath'. If the file exists already the action fails, unless
1252 /// 'opt == "F"'.
1253 /// Return 0 on success, -1 otherwise
1254 
1255 Int_t TDSet::ExportFileList(const char *fpath, Option_t *opt)
1256 {
1257  if (!fElements)
1258  return -1;
1259  if (fElements->GetSize() <= 0)
1260  return 0;
1261 
1262  Bool_t force = (opt[0] == 'F' || opt[0] == 'f');
1263 
1264  if (gSystem->AccessPathName(fpath, kFileExists) == kFALSE) {
1265  if (force) {
1266  // Try removing the file
1267  if (gSystem->Unlink(fpath)) {
1268  Info("ExportFileList","error removing dataset file: %s", fpath);
1269  return -1;
1270  }
1271  }
1272  }
1273 
1274  // Create the file list
1275  TList *fileinfo = new TList;
1276  fileinfo->SetOwner();
1277 
1278  TDSetElement *dse = 0;
1279  TIter next(fElements);
1280  while ((dse = (TDSetElement *) next())) {
1281  TFileInfoMeta *m = new TFileInfoMeta(dse->GetTitle(), dse->GetDirectory(), GetType(),
1282  dse->GetNum(), dse->GetFirst());
1283  TFileInfo *fi = new TFileInfo(dse->GetFileName());
1284  fi->AddMetaData(m);
1285  fileinfo->Add(fi);
1286  }
1287 
1288  // Write to file
1289  TFile *f = TFile::Open(fpath, "RECREATE");
1290  if (f) {
1291  f->cd();
1292  fileinfo->Write("fileList", TObject::kSingleKey);
1293  f->Close();
1294  } else {
1295  Info("ExportFileList","error creating dataset file: %s", fpath);
1296  SafeDelete(fileinfo);
1297  return -1;
1298  }
1299 
1300  // Cleanup
1301  SafeDelete(f);
1302  SafeDelete(fileinfo);
1303 
1304  // We are done
1305  return 0;
1306 }
1307 
1308 ////////////////////////////////////////////////////////////////////////////////
1309 /// Add friend dataset to this set. Only possible if the TDSet type is
1310 /// a TTree or derived class. The friendset will be owned by this class
1311 /// and deleted in its destructor.
1312 
1313 void TDSet::AddFriend(TDSet *friendset, const char* alias)
1314 {
1315  if (!friendset) {
1316  Error("AddFriend", "The friend TDSet is null!");
1317  return;
1318  }
1319 
1320  if (!fIsTree) {
1321  Error("AddFriend", "a friend set can only be added to a TTree TDSet");
1322  return;
1323  }
1324  TList *thisList = GetListOfElements();
1325  TList *friendsList = friendset->GetListOfElements();
1326  if (thisList->GetSize() != friendsList->GetSize() && friendsList->GetSize() != 1) {
1327  Error("AddFriend", "the friend dataset has %d elements while the main one has %d",
1328  thisList->GetSize(), friendsList->GetSize());
1329  return;
1330  }
1331  TIter next(thisList);
1332  TIter next2(friendsList);
1333  TDSetElement *friendElem = 0;
1334  if (friendsList->GetSize() == 1)
1335  friendElem = dynamic_cast<TDSetElement*> (friendsList->First());
1336  while(TDSetElement* e = dynamic_cast<TDSetElement*> (next())) {
1337  if (friendElem) // just one elem in the friend TDSet
1338  e->AddFriend(friendElem, alias);
1339  else
1340  e->AddFriend(dynamic_cast<TDSetElement*> (next2()), alias);
1341  }
1342 }
1343 
1344 ////////////////////////////////////////////////////////////////////////////////
1345 /// Reset or initialize access to the elements.
1346 
1348 {
1349  if (!fIterator) {
1350  fIterator = new TIter(fElements);
1351  } else {
1352  fIterator->Reset();
1353  }
1354 }
1355 
1356 ////////////////////////////////////////////////////////////////////////////////
1357 /// Returns number of entries in tree or objects in file. Returns -1 in
1358 /// case of error.
1359 
1360 Long64_t TDSet::GetEntries(Bool_t isTree, const char *filename, const char *path,
1361  TString &objname)
1362 {
1363  Double_t start = 0;
1364  if (gPerfStats) start = TTimeStamp();
1365 
1366  // Take into acoount possible prefixes
1368  TString fname = gEnv->GetValue("Path.Localroot",""), pfx(fname);
1369  // Get the locality (disable warnings or errors in connection attempts)
1370  Int_t oldLevel = gErrorIgnoreLevel;
1372  if ((typ = TFile::GetType(filename, "", &fname)) != TFile::kLocal) fname = filename;
1373  gErrorIgnoreLevel = oldLevel;
1374  // Open the file
1375  TFile *file = TFile::Open(fname);
1376 
1377  if (gPerfStats)
1378  gPerfStats->FileOpenEvent(file, filename, start);
1379 
1380  if (file == 0) {
1381  ::SysError("TDSet::GetEntries",
1382  "cannot open file %s (type: %d, pfx: %s)", filename, typ, pfx.Data());
1383  return -1;
1384  }
1385 
1386  TDirectory *dirsave = gDirectory;
1387  if (!file->cd(path)) {
1388  ::Error("TDSet::GetEntries", "cannot cd to %s", path);
1389  delete file;
1390  return -1;
1391  }
1392 
1394  dirsave->cd();
1395 
1396  Long64_t entries;
1397  Bool_t fillname = kFALSE;
1398  if (isTree) {
1399 
1400  TString on(objname);
1401  TString sreg(objname);
1402  // If a wild card we will use the first object of the type
1403  // requested compatible with the reg expression we got
1404  if (sreg.Length() <= 0 || sreg == "" || sreg.Contains("*")) {
1405  fillname = kTRUE;
1406  if (sreg.Contains("*"))
1407  sreg.ReplaceAll("*", ".*");
1408  else
1409  sreg = ".*";
1410  TRegexp re(sreg);
1411  if (dir->GetListOfKeys()) {
1412  TIter nxk(dir->GetListOfKeys());
1413  TKey *k = 0;
1414  Bool_t notfound = kTRUE;
1415  while ((k = (TKey *) nxk())) {
1416  if (!strcmp(k->GetClassName(), "TTree")) {
1417  TString kn(k->GetName());
1418  if (kn.Index(re) != kNPOS) {
1419  if (notfound) {
1420  on = kn;
1421  notfound = kFALSE;
1422  } else if (kn != on) {
1423  ::Warning("TDSet::GetEntries",
1424  "additional tree found in the file: %s", kn.Data());
1425  }
1426  }
1427  }
1428  }
1429  }
1430  }
1431 
1432  TKey *key = dir->GetKey(on);
1433  if (key == 0) {
1434  ::Error("TDSet::GetEntries", "cannot find tree \"%s\" in %s",
1435  objname.Data(), filename);
1436  delete file;
1437  return -1;
1438  }
1439  TTree *tree = (TTree *) key->ReadObj();
1440  if (tree == 0) {
1441  // Error always reported?
1442  delete file;
1443  return -1;
1444  }
1445  entries = tree->GetEntries();
1446  delete tree;
1447 
1448  // Return full name in case of wildcards
1449  objname = (fillname) ? on : objname;
1450 
1451  } else {
1452  TList *keys = dir->GetListOfKeys();
1453  entries = keys->GetSize();
1454  }
1455 
1456  delete file;
1457  return entries;
1458 }
1459 
1460 ////////////////////////////////////////////////////////////////////////////////
1461 /// Draw expression varexp for specified entries.
1462 /// Returns -1 in case of error or number of selected events in case of success.
1463 /// This function accepts a TCut objects as argument.
1464 /// Use the operator+ to concatenate cuts.
1465 /// Example:
1466 /// dset.Draw("x",cut1+cut2+cut3);
1467 
1468 Long64_t TDSet::Draw(const char *varexp, const TCut &selection, Option_t *option,
1469  Long64_t nentries, Long64_t firstentry)
1470 {
1471  return Draw(varexp, selection.GetTitle(), option, nentries, firstentry);
1472 }
1473 
1474 ////////////////////////////////////////////////////////////////////////////////
1475 /// Draw expression varexp for specified entries.
1476 /// Returns -1 in case of error or number of selected events in case of success.
1477 /// For more see TTree::Draw().
1478 
1479 Long64_t TDSet::Draw(const char *varexp, const char *selection, Option_t *option,
1480  Long64_t nentries, Long64_t firstentry)
1481 {
1482  if (!IsValid() || !fElements->GetSize()) {
1483  Error("Draw", "not a correctly initialized TDSet");
1484  return -1;
1485  }
1486 
1487  if (gProof)
1488  return gProof->DrawSelect(this, varexp, selection, option, nentries,
1489  firstentry);
1490 
1491  Error("Draw", "no active PROOF session");
1492  return -1;
1493 }
1494 
1495 ////////////////////////////////////////////////////////////////////////////////
1496 /// Start the TTreeViewer on this TTree.
1497 
1499 {
1500  if (gROOT->IsBatch()) {
1501  Warning("StartViewer", "viewer cannot run in batch mode");
1502  return;
1503  }
1504 
1505  if (!gProof) {
1506  Error("StartViewer", "no PROOF found");
1507  return;
1508  }
1509  if (!IsTree()) {
1510  Error("StartViewer", "TDSet contents should be of type TTree (or subtype)");
1511  return;
1512  }
1513  fProofChain = new TProofChain(this, kTRUE);
1514 
1515  TPluginHandler *h;
1516  if ((h = gROOT->GetPluginManager()->FindHandler("TVirtualTreeViewer"))) {
1517  if (h->LoadPlugin() == -1)
1518  return;
1519  h->ExecPlugin(1,fProofChain);
1520  }
1521 }
1522 
1523 ////////////////////////////////////////////////////////////////////////////////
1524 /// Returns a tree header containing the branches' structure of the dataset.
1525 
1527 {
1528  return proof->GetTreeHeader(this);
1529 }
1530 
1531 ////////////////////////////////////////////////////////////////////////////////
1532 /// Check if all elements are valid.
1533 
1535 {
1537  return (TestBit(TDSet::kSomeInvalid) ? kFALSE : kTRUE);
1538 
1541  TIter nextElem(GetListOfElements());
1542  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1543  if (!elem->GetValid()) {
1545  return kFALSE;
1546  }
1547  }
1548  return kTRUE;
1549 }
1550 
1551 ////////////////////////////////////////////////////////////////////////////////
1552 /// Remove TDSetElement 'elem' from the list.
1553 /// Return 0 on success, -1 if the element is not in the list
1554 
1556 {
1557  if (!elem || !(((THashList *)(GetListOfElements()))->Remove(elem)))
1558  return -1;
1559 
1560  if (deleteElem)
1561  SafeDelete(elem);
1562  return 0;
1563 }
1564 
1565 ////////////////////////////////////////////////////////////////////////////////
1566 /// Validate the TDSet by opening files.
1567 
1569 {
1570  TIter nextElem(GetListOfElements());
1571  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1572  if (!elem->GetValid())
1573  elem->Validate(IsTree());
1574  }
1575 }
1576 
1577 ////////////////////////////////////////////////////////////////////////////////
1578 /// Resolve the end-point URL for the current elements of this data set
1579 /// If the removeMissing option is set to kTRUE, remove the TDSetElements
1580 /// that can not be located.
1581 /// The method returns the list of removed TDSetElements in *listOfMissingFiles
1582 /// if the latter is defined (the list must be created outside).
1583 
1584 void TDSet::Lookup(Bool_t removeMissing, TList **listOfMissingFiles)
1585 {
1586  // If an entry- or event- list has been given, assign the relevant portions
1587  // to each element; this allows to look-up only for the elements which have
1588  // something to be processed, so it is better to do it before the real look-up
1589  // operations.
1590  SplitEntryList();
1591 
1592  TString msg("Looking up for exact location of files");
1593  UInt_t n = 0;
1594  UInt_t ng = 0;
1595  UInt_t tot = GetListOfElements()->GetSize();
1596  UInt_t n2 = (tot > 50) ? (UInt_t) tot / 50 : 1;
1597  Bool_t st = kTRUE;
1598  TIter nextElem(GetListOfElements());
1599  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1600  if (elem->GetNum() != 0) { // -1 means "all entries"
1601  ng++;
1602  if (!elem->GetValid())
1603  if (elem->Lookup(kFALSE))
1604  if (removeMissing) {
1605  if (Remove(elem, kFALSE))
1606  Error("Lookup", "Error removing a missing file");
1607  if (listOfMissingFiles)
1608  (*listOfMissingFiles)->Add(elem->GetFileInfo(fType));
1609  }
1610  }
1611  n++;
1612  // Notify the client
1613  if (gProof && (n > 0 && !(n % n2)))
1614  gProof->SendDataSetStatus(msg, n, tot, st);
1615  // Break if we have been asked to stop
1617  break;
1618  }
1619  // Notify the client if not all the files have entries to be processed
1620  // (which may happen if an entry-list is used)
1621  if (ng < tot && gProofServ) {
1622  msg = Form("Files with entries to be processed: %d (out of %d)\n", ng, tot);
1624  } else {
1625  // Final notification to the client
1626  if (gProof) gProof->SendDataSetStatus(msg, n, tot, st);
1627  }
1628  // Done
1629  return;
1630 }
1631 
1632 ////////////////////////////////////////////////////////////////////////////////
1633 /// Flag all the elements as looked-up, so to avoid opening the files
1634 /// if the functionality is not supported
1635 
1637 {
1638  TIter nextElem(GetListOfElements());
1639  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem()))
1640  elem->SetLookedUp();
1641 }
1642 
1643 ////////////////////////////////////////////////////////////////////////////////
1644 /// Validate the TDSet against another TDSet.
1645 /// Only validates elements in common from input TDSet.
1646 
1648 {
1649  THashList bestElements;
1650  bestElements.SetOwner();
1651  TList namedHolder;
1652  namedHolder.SetOwner();
1653  TIter nextOtherElem(dset->GetListOfElements());
1654  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextOtherElem())) {
1655  if (!elem->GetValid()) continue;
1656  TString dir_file_obj = elem->GetDirectory();
1657  dir_file_obj += "_";
1658  dir_file_obj += TUrl(elem->GetFileName()).GetFileAndOptions();
1659  dir_file_obj += "_";
1660  dir_file_obj += elem->GetObjName();
1661  TPair *p = dynamic_cast<TPair*>(bestElements.FindObject(dir_file_obj));
1662  if (p) {
1663  TDSetElement *prevelem = dynamic_cast<TDSetElement*>(p->Value());
1664  if (prevelem) {
1665  Long64_t entries = prevelem->GetFirst()+prevelem->GetNum();
1666  if (entries<elem->GetFirst()+elem->GetNum()) {
1667  bestElements.Remove(p);
1668  bestElements.Add(new TPair(p->Key(), elem));
1669  delete p;
1670  }
1671  }
1672  } else {
1673  TNamed* named = new TNamed(dir_file_obj, dir_file_obj);
1674  namedHolder.Add(named);
1675  bestElements.Add(new TPair(named, elem));
1676  }
1677  }
1678 
1679  TIter nextElem(GetListOfElements());
1680  while (TDSetElement *elem = dynamic_cast<TDSetElement*>(nextElem())) {
1681  if (!elem->GetValid()) {
1682  TString dir_file_obj = elem->GetDirectory();
1683  dir_file_obj += "_";
1684  dir_file_obj += TUrl(elem->GetFileName()).GetFileAndOptions();
1685  dir_file_obj += "_";
1686  dir_file_obj += elem->GetObjName();
1687  if (TPair *p = dynamic_cast<TPair*>(bestElements.FindObject(dir_file_obj))) {
1688  TDSetElement* validelem = dynamic_cast<TDSetElement*>(p->Value());
1689  elem->Validate(validelem);
1690  }
1691  }
1692  }
1693 }
1694 
1695 //
1696 // To handle requests coming from version 3 client / masters we need
1697 // a special streamer
1698 ////////////////////////////////////////////////////////////////////////////////
1699 /// Stream an object of class TDSetElement.
1700 
1701 void TDSetElement::Streamer(TBuffer &R__b)
1702 {
1703  if (R__b.IsReading()) {
1704  UInt_t R__s, R__c;
1705  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1706  ResetBit(kWriteV3);
1707  if (R__v > 4) {
1708  R__b.ReadClassBuffer(TDSetElement::Class(), this, R__v, R__s, R__c);
1709  } else {
1710  // For version 3 client / masters we need a special streamer
1711  SetBit(kWriteV3);
1712  if (R__v > 3) {
1713  TNamed::Streamer(R__b);
1714  } else {
1715  // Old versions were not deriving from TNamed and had the
1716  // file name and the object type name in the first two members
1717  TObject::Streamer(R__b);
1718  TString name, title;
1719  R__b >> name >> title;
1720  SetNameTitle(name, title);
1721  }
1722  // Now we read the standard part
1723  R__b >> fDirectory;
1724  R__b >> fFirst;
1725  R__b >> fNum;
1726  R__b >> fMsd;
1727  R__b >> fTDSetOffset;
1728  TEventList *evl;
1729  R__b >> evl;
1730  R__b >> fValid;
1731  R__b >> fEntries;
1732 
1733  // Special treatment waiting for proper retrieving of stl containers
1734  FriendsList_t *friends = new FriendsList_t;
1735  static TClassRef classFriendsList = TClass::GetClass(typeid(FriendsList_t));
1736  R__b.ReadClassBuffer( classFriendsList, friends, classFriendsList->GetClassVersion(), 0, 0);
1737  if (friends) {
1738  // Convert friends to a TList (to be written)
1739  fFriends = new TList();
1740  fFriends->SetOwner();
1741  for (FriendsList_t::iterator i = friends->begin();
1742  i != friends->end(); ++i) {
1743  TDSetElement *dse = (TDSetElement *) i->first->Clone();
1744  fFriends->Add(new TPair(dse, new TObjString(i->second.Data())));
1745  }
1746  }
1747  // the value for fIsTree (only older versions are sending it)
1748  Bool_t tmpIsTree;
1749  R__b >> tmpIsTree;
1750  R__b.CheckByteCount(R__s, R__c, TDSetElement::IsA());
1751  }
1752  } else {
1753  if (TestBit(kWriteV3)) {
1754  // For version 3 client / masters we need a special streamer
1755  R__b << Version_t(3);
1756  TObject::Streamer(R__b);
1757  R__b << TString(GetName());
1758  R__b << TString(GetTitle());
1759  R__b << fDirectory;
1760  R__b << fFirst;
1761  R__b << fNum;
1762  R__b << fMsd;
1763  R__b << fTDSetOffset;
1764  R__b << (TEventList *)0;
1765  R__b << fValid;
1766  R__b << fEntries;
1767 
1768  // Special treatment waiting for proper retrieving of stl containers
1769  FriendsList_t *friends = new FriendsList_t;
1770  if (fFriends) {
1771  TIter nxf(fFriends);
1772  TPair *p = 0;
1773  while ((p = (TPair *)nxf()))
1774  friends->push_back(std::make_pair((TDSetElement *)p->Key(),
1775  TString(((TObjString *)p->Value())->GetName())));
1776  }
1777  static TClassRef classFriendsList = TClass::GetClass(typeid(FriendsList_t));
1778  R__b.WriteClassBuffer( classFriendsList, &friends );
1779 
1780  // Older versions had an unused boolean called fIsTree: we fill it
1781  // with its default value
1782  R__b << kFALSE;
1783  } else {
1785  }
1786  }
1787 }
1788 
1789 ////////////////////////////////////////////////////////////////////////////////
1790 /// Stream an object of class TDSet.
1791 
1792 void TDSet::Streamer(TBuffer &R__b)
1793 {
1794  if (R__b.IsReading()) {
1795  UInt_t R__s, R__c;
1796  Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1797  ResetBit(kWriteV3);
1798  if (R__v > 3) {
1799  R__b.ReadClassBuffer(TDSet::Class(), this, R__v, R__s, R__c);
1800  } else {
1801  // For version 3 client / masters we need a special streamer
1802  SetBit(kWriteV3);
1803  TNamed::Streamer(R__b);
1804  R__b >> fDir;
1805  R__b >> fType;
1806  R__b >> fObjName;
1807  TList elems;
1808  elems.Streamer(R__b);
1809  elems.SetOwner(kFALSE);
1810  if (elems.GetSize() > 0) {
1811  fElements = new THashList;
1812  fElements->SetOwner();
1813  TDSetElement *e = 0;
1814  TIter nxe(&elems);
1815  while ((e = (TDSetElement *)nxe())) {
1816  fElements->Add(e);
1817  }
1818  } else {
1819  fElements = 0;
1820  }
1821  R__b >> fIsTree;
1822  }
1823  } else {
1824  if (TestBit(kWriteV3)) {
1825  // For version 3 client / masters we need a special streamer
1826  R__b << Version_t(3);
1827  TNamed::Streamer(R__b);
1828  R__b << fDir;
1829  R__b << fType;
1830  R__b << fObjName;
1831  TList elems;
1832  if (fElements) {
1833  elems.SetOwner(kFALSE);
1834  if (fElements->GetSize() > 0) {
1835  TDSetElement *e = 0;
1836  TIter nxe(fElements);
1837  while ((e = (TDSetElement *)nxe()))
1838  elems.Add(e);
1839  }
1840  }
1841  elems.Streamer(R__b);
1842  R__b << fIsTree;
1843  } else {
1844  R__b.WriteClassBuffer(TDSet::Class(),this);
1845  }
1846  }
1847 }
1848 
1849 ////////////////////////////////////////////////////////////////////////////////
1850 /// Set/Reset the 'OldStreamer' bit in this instance and its elements.
1851 /// Needed for backward compatibility in talking to old client / masters.
1852 
1854 {
1855  if (on)
1857  else
1859  // Loop over dataset elements
1860  TIter nxe(GetListOfElements());
1861  TObject *o = 0;
1862  while ((o = nxe()))
1863  if (on)
1865  else
1867 }
1868 
1869 ////////////////////////////////////////////////////////////////////////////////
1870 /// Set entry (or event) list for this data set
1871 
1873 {
1874  if (!aList)
1875  return;
1876 
1877  if (TestBit(TDSet::kMultiDSet)) {
1878 
1879  // Global entry list for all the datasets
1880  TIter nxds(fElements);
1881  TDSet *ds = 0;
1882  while ((ds = (TDSet *) nxds()))
1883  ds->SetEntryList(aList);
1884 
1885  } else {
1886 
1887  // Link the proper object
1888  TEventList *evl = 0;
1889  TEntryList *enl = dynamic_cast<TEntryList*>(aList);
1890  if (!enl)
1891  evl = dynamic_cast<TEventList*>(aList);
1892  if (!enl && !evl) {
1893  Error("SetEntryList", "type of input object must be either TEntryList "
1894  "or TEventList (found: '%s' - do nothing", aList->ClassName());
1895  return;
1896  }
1897 
1898  // Action depends on the type
1899  fEntryList = (enl) ? enl : (TEntryList *)evl;
1900  }
1901  // Done
1902  return;
1903 }
1904 
1905 ////////////////////////////////////////////////////////////////////////////////
1906 /// Splits the main entry (or event) list into sub-lists for the elements of
1907 /// thet data set
1908 
1910 {
1911  if (TestBit(TDSet::kMultiDSet)) {
1912  // Global entry list for all the datasets
1913  TIter nxds(fElements);
1914  TDSet *ds = 0;
1915  while ((ds = (TDSet *) nxds()))
1916  ds->SplitEntryList();
1917  // Done
1918  return;
1919  }
1920 
1921  if (!fEntryList) {
1922  if (gDebug > 0)
1923  Info("SplitEntryList", "no entry- (or event-) list to split - do nothing");
1924  return;
1925  }
1926 
1927  // Action depend on type of list
1928  TEntryList *enl = dynamic_cast<TEntryList *>(fEntryList);
1929  if (enl) {
1930  // TEntryList
1931  TIter next(fElements);
1932  TDSetElement *el=0;
1933  TEntryList *sublist = 0;
1934  while ((el=(TDSetElement*)next())){
1935  sublist = enl->GetEntryList(el->GetObjName(), el->GetFileName());
1936  if (sublist){
1937  el->SetEntryList(sublist);
1938  el->SetNum(sublist->GetN());
1939  } else {
1940  sublist = new TEntryList("", "");
1941  el->SetEntryList(sublist);
1942  el->SetNum(0);
1943  }
1944  }
1945  } else {
1946  TEventList *evl = dynamic_cast<TEventList *>(fEntryList);
1947  if (evl) {
1948  // TEventList
1949  TIter next(fElements);
1950  TDSetElement *el, *prev;
1951 
1952  prev = dynamic_cast<TDSetElement*> (next());
1953  if (!prev)
1954  return;
1955  Long64_t low = prev->GetTDSetOffset();
1956  Long64_t high = low;
1957  Long64_t currPos = 0;
1958  do {
1959  el = dynamic_cast<TDSetElement*> (next());
1960  // kMaxLong64 means infinity
1961  high = (el == 0) ? kMaxLong64 : el->GetTDSetOffset();
1962 #ifdef DEBUG
1963  while (currPos < evl->GetN() && evl->GetEntry(currPos) < low) {
1964  Error("SplitEntryList",
1965  "TEventList: event outside of the range of any of the TDSetElements");
1966  currPos++; // unnecessary check
1967  }
1968 #endif
1969  TEventList* nevl = new TEventList();
1970  while (currPos < evl->GetN() && evl->GetEntry((Int_t)currPos) < high) {
1971  nevl->Enter(evl->GetEntry((Int_t)currPos) - low);
1972  currPos++;
1973  }
1974  prev->SetEntryList(nevl);
1975  prev->SetNum(nevl->GetN());
1976  low = high;
1977  prev = el;
1978  } while (el);
1979  }
1980  }
1981 }
1982 
1983 ////////////////////////////////////////////////////////////////////////////////
1984 /// Return the number of files in the dataset
1985 
1987 {
1988  Int_t nf = -1;
1989  if (fElements) {
1990  nf = 0;
1991  if (TestBit(TDSet::kMultiDSet)) {
1992  TIter nxds(fElements);
1993  TDSet *ds = 0;
1994  while ((ds = (TDSet *) nxds()))
1995  if (ds->GetListOfElements()) nf += ds->GetListOfElements()->GetSize();
1996  } else {
1997  nf = fElements->GetSize();
1998  }
1999  }
2000  // Done
2001  return nf;
2002 }
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:879
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:944
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:1213
TString fType
Definition: TDSet.h:178
virtual Bool_t IsAbsoluteFileName(const char *dir)
Return true if dir is an absolute pathname.
Definition: TSystem.cxx:929
TFileInfo * GetFileInfo(const char *type="TTree")
Return the content of this element in the form of a TFileInfo.
Definition: TDSet.cxx:212
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:1360
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:180
virtual TDSetElement * Next(Long64_t totalEntries=-1)
Returns next TDSetElement.
Definition: TDSet.cxx:394
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:83
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:6144
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:158
TDSet()
iterator on fSrvMaps
Definition: TDSet.cxx:682
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:1636
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
return c
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:213
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:897
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:1853
This class implements a data set to be used for PROOF processing.
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:1986
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:979
TList * GetOutputList()
Get list with all object created during processing (see Process()).
Definition: TProof.cxx:10386
TString fDirectory
Definition: TDSet.h:82
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: TList.cxx:93
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
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:344
void AddAssocObj(TObject *assocobj)
Add an associated object to the list.
Definition: TDSet.cxx:612
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:57
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:497
void Print(Option_t *options="") const
Print a TDSetElement. When option="a" print full data.
Definition: TDSet.cxx:242
Int_t Compare(const TObject *obj) const
Compare elements by filename (and the fFirst).
Definition: TDSet.cxx:332
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:311
Int_t ExportFileList(const char *filepath, Option_t *opt="")
Export TDSetElements files as list of TFileInfo objects in file 'fpath'.
Definition: TDSet.cxx:1255
TUrl * GetFirstUrl() const
Definition: TFileInfo.h:83
void Reset()
Definition: TCollection.h:161
TFile * f
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: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: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:411
TChain chain("h42")
TList * GetOutputList()
Get list with all object created during processing (see Process()).
Definition: TDSet.cxx:976
const char * Data() const
Definition: TString.h:349
virtual TKey * GetKey(const char *, Short_t=9999) const
Definition: TDirectory.h:156
Manages an element of a TDSet.
Definition: TDSet.h:68
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:1294
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:256
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:2321
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
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
void Class()
Definition: Class.C:29
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:146
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:1038
void SetLookedUp()
Definition: TDSet.h:141
void Validate()
Validate the TDSet by opening files.
Definition: TDSet.cxx:1568
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1951
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:1019
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:1150
virtual void DeleteFriends()
Deletes the list of friends and all the friends on the list.
Definition: TDSet.cxx:381
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:969
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:1534
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:9914
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:545
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
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:675
TObject * Next()
Definition: TCollection.h:158
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:285
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:2308
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:10340
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:499
bool first
Definition: line3Dfit.C:48
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:1479
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:5304
const char * GetAnchor() const
Definition: TUrl.h:79
Version_t GetClassVersion() const
Definition: TClass.h:381
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:163
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:10312
#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:986
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:1526
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:581
void ClearInput()
Clear input object list.
Definition: TDSet.cxx:956
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:1113
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
tuple tree
Definition: tree.py:24
virtual Int_t GetSize() const
Definition: TCollection.h:95
tuple file
Definition: fildir.py:20
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:1004
double Double_t
Definition: RtypesCore.h:55
TObject * Key() const
Definition: TMap.h:124
void ClearInput()
Clear input object list.
Definition: TProof.cxx:10320
Describe directory structure in memory.
Definition: TDirectory.h:44
virtual void SetEntryList(TObject *aList)
Set entry (or event) list for this data set.
Definition: TDSet.cxx:1872
int type
Definition: TGX11.cxx:120
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
void dir(char *path=0)
Definition: rootalias.C:30
TNamed()
Definition: TNamed.h:40
The TTimeStamp encapsulates seconds and ns since EPOCH.
Definition: TTimeStamp.h:76
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition: TProof.h:342
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:966
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:1347
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:10620
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:2801
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
#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:580
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:1584
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:557
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:1793
void SplitEntryList()
for browsing purposes
Definition: TDSet.cxx:1909
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:630
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:1030
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:360
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:386
A TTree object has a header with a name and a title.
Definition: TTree.h:98
#define gDirectory
Definition: TDirectory.h:221
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:4498
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition: TSystem.cxx:1191
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:1313
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:221
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:234
virtual void StartViewer()
Start the TTreeViewer on this TTree.
Definition: TDSet.cxx:1498
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:1555
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