Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TTree.h
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Rene Brun 12/01/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 #ifndef ROOT_TTree
13 #define ROOT_TTree
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TTree //
18 // //
19 // A TTree object is a list of TBranch. //
20 // To Create a TTree object one must: //
21 // - Create the TTree header via the TTree constructor //
22 // - Call the TBranch constructor for every branch. //
23 // //
24 // To Fill this object, use member function Fill with no parameters. //
25 // The Fill function loops on all defined TBranch. //
26 // //
27 //////////////////////////////////////////////////////////////////////////
28 
29 #include "Compression.h"
30 #include "ROOT/TIOFeatures.hxx"
31 #include "TArrayD.h"
32 #include "TArrayI.h"
33 #include "TAttFill.h"
34 #include "TAttLine.h"
35 #include "TAttMarker.h"
36 #include "TBranch.h"
37 #include "TBuffer.h"
38 #include "TClass.h"
39 #include "TDataType.h"
40 #include "TDirectory.h"
41 #include "TObjArray.h"
42 #include "TVirtualTreePlayer.h"
43 
44 #include <array>
45 #include <atomic>
46 
47 
48 class TBranch;
49 class TBrowser;
50 class TFile;
51 class TLeaf;
52 class TH1;
53 class TTreeFormula;
54 class TPolyMarker;
55 class TEventList;
56 class TEntryList;
57 class TList;
58 class TSQLResult;
59 class TSelector;
60 class TPrincipal;
61 class TFriendElement;
62 class TCut;
63 class TVirtualIndex;
64 class TBranchRef;
65 class TBasket;
66 class TStreamerInfo;
67 class TTreeCache;
68 class TTreeCloner;
69 class TFileMergeInfo;
70 class TVirtualPerfStats;
71 
72 class TTree : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
73 
74  using TIOFeatures = ROOT::TIOFeatures;
75 
76 protected:
77  Long64_t fEntries; ///< Number of entries
78 // NOTE: cannot use std::atomic for these counters as it cannot be serialized.
79  Long64_t fTotBytes; ///< Total number of bytes in all branches before compression
80  Long64_t fZipBytes; ///< Total number of bytes in all branches after compression
81  Long64_t fSavedBytes; ///< Number of autosaved bytes
82  Long64_t fFlushedBytes; ///< Number of auto-flushed bytes
83  Double_t fWeight; ///< Tree weight (see TTree::SetWeight)
84  Int_t fTimerInterval; ///< Timer interval in milliseconds
85  Int_t fScanField; ///< Number of runs before prompting in Scan
86  Int_t fUpdate; ///< Update frequency for EntryLoop
87  Int_t fDefaultEntryOffsetLen; ///< Initial Length of fEntryOffset table in the basket buffers
88  Int_t fNClusterRange; ///< Number of Cluster range in addition to the one defined by 'AutoFlush'
89  Int_t fMaxClusterRange; ///<! Memory allocated for the cluster range.
90  Long64_t fMaxEntries; ///< Maximum number of entries in case of circular buffers
91  Long64_t fMaxEntryLoop; ///< Maximum number of entries to process
92  Long64_t fMaxVirtualSize; ///< Maximum total size of buffers kept in memory
93  Long64_t fAutoSave; ///< Autosave tree when fAutoSave entries written or -fAutoSave (compressed) bytes produced
94  Long64_t fAutoFlush; ///< Auto-flush tree when fAutoFlush entries written or -fAutoFlush (compressed) bytes produced
95  Long64_t fEstimate; ///< Number of entries to estimate histogram limits
96  Long64_t *fClusterRangeEnd; ///<[fNClusterRange] Last entry of a cluster range.
97  Long64_t *fClusterSize; ///<[fNClusterRange] Number of entries in each cluster for a given range.
98  Long64_t fCacheSize; ///<! Maximum size of file buffers
99  Long64_t fChainOffset; ///<! Offset of 1st entry of this Tree in a TChain
100  Long64_t fReadEntry; ///<! Number of the entry being processed
101  std::atomic<Long64_t> fTotalBuffers; ///<! Total number of bytes in branch buffers
102  Int_t fPacketSize; ///<! Number of entries in one packet for parallel root
103  Int_t fNfill; ///<! Local for EntryLoop
104  Int_t fDebug; ///<! Debug level
105  Long64_t fDebugMin; ///<! First entry number to debug
106  Long64_t fDebugMax; ///<! Last entry number to debug
107  TIOFeatures fIOFeatures{0}; ///< IO features to define for newly-written baskets and branches.
108  Int_t fMakeClass; ///<! not zero when processing code generated by MakeClass
109  Int_t fFileNumber; ///<! current file number (if file extensions)
110  TObject *fNotify; ///<! Object to be notified when loading a Tree
111  TDirectory *fDirectory; ///<! Pointer to directory holding this tree
112  TObjArray fBranches; ///< List of Branches
113  TObjArray fLeaves; ///< Direct pointers to individual branch leaves
114  TList *fAliases; ///< List of aliases for expressions based on the tree branches.
115  TEventList *fEventList; ///<! Pointer to event selection list (if one)
116  TEntryList *fEntryList; ///<! Pointer to event selection list (if one)
117  TArrayD fIndexValues; ///< Sorted index values
118  TArrayI fIndex; ///< Index of sorted values
119  TVirtualIndex *fTreeIndex; ///< Pointer to the tree Index (if any)
120  TList *fFriends; ///< pointer to list of friend elements
121  TVirtualPerfStats *fPerfStats; ///<! pointer to the current perf stats object
122  TList *fUserInfo; ///< pointer to a list of user objects associated to this Tree
123  TVirtualTreePlayer *fPlayer; ///<! Pointer to current Tree player
124  TList *fClones; ///<! List of cloned trees which share our addresses
125  TBranchRef *fBranchRef; ///< Branch supporting the TRefTable (if any)
126  UInt_t fFriendLockStatus; ///<! Record which method is locking the friend recursion
127  TBuffer *fTransientBuffer; ///<! Pointer to the current transient buffer.
128  Bool_t fCacheDoAutoInit; ///<! true if cache auto creation or resize check is needed
129  Bool_t fCacheDoClusterPrefetch;///<! true if cache is prefetching whole clusters
130  Bool_t fCacheUserSet; ///<! true if the cache setting was explicitly given by user
131  Bool_t fIMTEnabled; ///<! true if implicit multi-threading is enabled for this tree
132  UInt_t fNEntriesSinceSorting; ///<! Number of entries processed since the last re-sorting of branches
133  std::vector<std::pair<Long64_t,TBranch*>> fSortedBranches; ///<! Branches to be processed in parallel when IMT is on, sorted by average task time
134  std::vector<TBranch*> fSeqBranches; ///<! Branches to be processed sequentially when IMT is on
135  Float_t fTargetMemoryRatio{1.1f}; ///<! Ratio for memory usage in uncompressed buffers versus actual occupancy. 1.0
136  /// indicates basket should be resized to exact memory usage, but causes significant
137 /// memory churn.
138 #ifdef R__TRACK_BASKET_ALLOC_TIME
139  mutable std::atomic<ULong64_t> fAllocationTime{0}; ///<! Time spent reallocating basket memory buffers, in microseconds.
140 #endif
141  mutable std::atomic<UInt_t> fAllocationCount{0}; ///<! Number of reallocations basket memory buffers.
142 
143  static Int_t fgBranchStyle; ///< Old/New branch style
144  static Long64_t fgMaxTreeSize; ///< Maximum size of a file containing a Tree
145 
146 private:
147  // For simplicity, although fIMTFlush is always disabled in non-IMT builds, we don't #ifdef it out.
148  mutable Bool_t fIMTFlush{false}; ///<! True if we are doing a multithreaded flush.
149  mutable std::atomic<Long64_t> fIMTTotBytes; ///<! Total bytes for the IMT flush baskets
150  mutable std::atomic<Long64_t> fIMTZipBytes; ///<! Zip bytes for the IMT flush baskets.
151 
152  void InitializeBranchLists(bool checkLeafCount);
153  void SortBranchesByTime();
154  Int_t FlushBasketsImpl() const;
155  void MarkEventCluster();
156 
157 protected:
158  virtual void KeepCircular();
159  virtual TBranch *BranchImp(const char* branchname, const char* classname, TClass* ptrClass, void* addobj, Int_t bufsize, Int_t splitlevel);
160  virtual TBranch *BranchImp(const char* branchname, TClass* ptrClass, void* addobj, Int_t bufsize, Int_t splitlevel);
161  virtual TBranch *BranchImpRef(const char* branchname, const char* classname, TClass* ptrClass, void* addobj, Int_t bufsize, Int_t splitlevel);
162  virtual TBranch *BranchImpRef(const char* branchname, TClass* ptrClass, EDataType datatype, void* addobj, Int_t bufsize, Int_t splitlevel);
163  virtual TBranch *BranchImpArr(const char* branchname, EDataType datatype, std::size_t N, void* addobj, Int_t bufsize, Int_t splitlevel);
164  virtual Int_t CheckBranchAddressType(TBranch* branch, TClass* ptrClass, EDataType datatype, Bool_t ptr);
165  virtual TBranch *BronchExec(const char* name, const char* classname, void* addobj, Bool_t isptrptr, Int_t bufsize, Int_t splitlevel);
166  friend TBranch *TTreeBranchImpRef(TTree *tree, const char* branchname, TClass* ptrClass, EDataType datatype, void* addobj, Int_t bufsize, Int_t splitlevel);
167  Int_t SetBranchAddressImp(TBranch *branch, void* addr, TBranch** ptr);
168  virtual TLeaf *GetLeafImpl(const char* branchname, const char* leafname);
169 
170  Long64_t GetCacheAutoSize(Bool_t withDefault = kFALSE) const;
171  char GetNewlineValue(std::istream &inputStream);
172  void ImportClusterRanges(TTree *fromtree);
173  void MoveReadCache(TFile *src, TDirectory *dir);
174  Int_t SetCacheSizeAux(Bool_t autocache = kTRUE, Long64_t cacheSize = 0);
175 
176  class TFriendLock {
177  // Helper class to prevent infinite recursion in the
178  // usage of TTree Friends. Implemented in TTree.cxx.
179  TTree *fTree; // Pointer to the locked tree
180  UInt_t fMethodBit; // BIT for the locked method
181  Bool_t fPrevious; // Previous value of the BIT.
182 
183  protected:
184  TFriendLock(const TFriendLock&);
185  TFriendLock& operator=(const TFriendLock&);
186 
187  public:
188  TFriendLock(TTree* tree, UInt_t methodbit);
189  ~TFriendLock();
190  };
191  friend class TFriendLock;
192  // So that the index class can use TFriendLock:
193  friend class TTreeIndex;
194  friend class TChainIndex;
195  // So that the TTreeCloner can access the protected interfaces
196  friend class TTreeCloner;
197 
198  // use to update fFriendLockStatus
199  enum ELockStatusBits {
200  kFindBranch = BIT(0),
201  kFindLeaf = BIT(1),
202  kGetAlias = BIT(2),
203  kGetBranch = BIT(3),
204  kGetEntry = BIT(4),
205  kGetEntryWithIndex = BIT(5),
206  kGetFriend = BIT(6),
207  kGetFriendAlias = BIT(7),
208  kGetLeaf = BIT(8),
209  kLoadTree = BIT(9),
210  kPrint = BIT(10),
211  kRemoveFriend = BIT(11),
212  kSetBranchStatus = BIT(12)
213  };
214 
215 public:
216  // Used as the max value for any TTree range operation.
217  static constexpr Long64_t kMaxEntries = TVirtualTreePlayer::kMaxEntries;
218 
219  // SetBranchAddress return values
220  enum ESetBranchAddressStatus {
221  kMissingBranch = -5,
222  kInternalError = -4,
223  kMissingCompiledCollectionProxy = -3,
224  kMismatch = -2,
225  kClassMismatch = -1,
226  kMatch = 0,
227  kMatchConversion = 1,
228  kMatchConversionCollection = 2,
229  kMakeClass = 3,
230  kVoidPtr = 4,
231  kNoCheck = 5
232  };
233 
234  // TTree status bits
235  enum EStatusBits {
236  kForceRead = BIT(11),
237  kCircular = BIT(12),
238  /// If set, the branch's buffers will grow until an event cluster boundary is hit,
239  /// guaranteeing a basket per cluster. This mode does not provide any guarantee on the
240  /// memory bounds in the case of extremely large events.
241  kOnlyFlushAtCluster = BIT(14),
242  /// If set, signals that this TTree is the output of the processing of another TTree, and
243  /// the entries are reshuffled w.r.t. to the original TTree. As a safety measure, a TTree
244  /// with this bit set cannot add friends nor can be added as a friend. If you know what
245  /// you are doing, you can manually unset this bit with `ResetBit(EStatusBits::kEntriesReshuffled)`.
246  kEntriesReshuffled = BIT(19) // bits 15-18 are used by TChain
247  };
248 
249  // Split level modifier
250  enum {
251  kSplitCollectionOfPointers = 100
252  };
253 
254  class TClusterIterator
255  {
256  private:
257  TTree *fTree; // TTree upon which we are iterating.
258  Int_t fClusterRange; // Which cluster range are we looking at.
259  Long64_t fStartEntry; // Where does the cluster start.
260  Long64_t fNextEntry; // Where does the cluster end (exclusive).
261  Long64_t fEstimatedSize; // If positive, the calculated estimated tree size.
262 
263  Long64_t GetEstimatedClusterSize();
264 
265  protected:
266  friend class TTree;
267  TClusterIterator(TTree *tree, Long64_t firstEntry);
268 
269  public:
270  // Intentionally used the default copy constructor and default destructor
271  // as the TClusterIterator does not own the TTree.
272  // TClusterIterator(const TClusterIterator&);
273  // ~TClusterIterator();
274 
275  // No public constructors, the iterator must be
276  // created via TTree::GetClusterIterator
277 
278  // Move on to the next cluster and return the starting entry
279  // of this next cluster
280  Long64_t Next();
281 
282  // Move on to the previous cluster and return the starting entry
283  // of this previous cluster
284  Long64_t Previous();
285 
286  // Return the start entry of the current cluster.
287  Long64_t GetStartEntry() {
288  return fStartEntry;
289  }
290 
291  // Return the first entry of the next cluster.
292  Long64_t GetNextEntry() {
293  return fNextEntry;
294  }
295 
296  Long64_t operator()() { return Next(); }
297  };
298 
299  TTree();
300  TTree(const char* name, const char* title, Int_t splitlevel = 99, TDirectory* dir = gDirectory);
301  virtual ~TTree();
302 
303  TTree(const TTree& tt) = delete;
304  TTree& operator=(const TTree& tt) = delete;
305 
306  virtual Int_t AddBranchToCache(const char *bname, Bool_t subbranches = kFALSE);
307  virtual Int_t AddBranchToCache(TBranch *branch, Bool_t subbranches = kFALSE);
308  virtual Int_t DropBranchFromCache(const char *bname, Bool_t subbranches = kFALSE);
309  virtual Int_t DropBranchFromCache(TBranch *branch, Bool_t subbranches = kFALSE);
310  void AddClone(TTree*);
311  virtual TFriendElement *AddFriend(const char* treename, const char* filename = "");
312  virtual TFriendElement *AddFriend(const char* treename, TFile* file);
313  virtual TFriendElement *AddFriend(TTree* tree, const char* alias = "", Bool_t warn = kFALSE);
314  // As the TBasket invokes Add{Tot,Zip}Bytes on its parent tree, we must do these updates in a thread-safe
315  // manner only when we are flushing multiple baskets in parallel.
316  virtual void AddTotBytes(Int_t tot) { if (fIMTFlush) { fIMTTotBytes += tot; } else { fTotBytes += tot; } }
317  virtual void AddZipBytes(Int_t zip) { if (fIMTFlush) { fIMTZipBytes += zip; } else { fZipBytes += zip; } }
318 // NOTE: these counters aren't thread safe like the ones above.
319 #ifdef R__TRACK_BASKET_ALLOC_TIME
320  void AddAllocationTime(ULong64_t time) { fAllocationTime += time; }
321 #endif
322  void AddAllocationCount(UInt_t count) { fAllocationCount += count; }
323  virtual Long64_t AutoSave(Option_t* option = "");
324 
325  /// Add a new branch, and infer the data type from the type of `obj` being passed.
326  ///
327  /// \note This and the next overload should cover most cases for creating a branch. Try to use these two whenever
328  /// possible, unless e.g. type conversions are needed.
329  ///
330  /// \param[in] name Name of the branch to be created.
331  /// \param[in] obj Address of the object to be added. Make sure to pass a pointer to the actual type/class that
332  /// should be stored in the tree (no pointers to base classes). When calling Fill(), the current value of the type/object will be saved.
333  /// \param[in] bufsize The buffer size in bytes for this branch. When the buffer is full, it is compressed and written to disc.
334  /// The default value of 32000 bytes and should be ok for most simple types. Larger buffers (e.g. 256000) if your Tree is not split and each entry is large (Megabytes).
335  /// A small value for bufsize is beneficial if entries in the Tree are accessed randomly and the Tree is in split mode.
336  /// \param[in] splitlevel If T is a class or struct and splitlevel > 0, the members of the object are serialised as separate branches.
337  /// \return Pointer to the TBranch that was created. The branch is owned by the tree.
338  template <class T> TBranch *Branch(const char* name, T* obj, Int_t bufsize = 32000, Int_t splitlevel = 99)
339  {
340  return BranchImpRef(name, TClass::GetClass<T>(), TDataType::GetType(typeid(T)), obj, bufsize, splitlevel);
341  }
342 
343  /// Add a new branch, and infer the data type from the array `addobj` being passed.
344  ///
345  /// \note This and the previous overload should cover most cases for creating a branch. Try to use these two whenever
346  /// possible, unless e.g. type conversions are needed.
347  ///
348  /// \param[in] name Name of the branch to be created.
349  /// \param[in] obj Array of the objects to be added. When calling Fill(), the current value of the type/object will be saved.
350  /// \param[in] bufsize he buffer size in bytes for this branch. When the buffer is full, it is compressed and written to disc.
351  /// The default value of 32000 bytes and should be ok for most simple types. Larger buffers (e.g. 256000) if your Tree is not split and each entry is large (Megabytes).
352  /// A small value for bufsize is beneficial if entries in the Tree are accessed randomly and the Tree is in split mode.
353  /// \param[in] splitlevel If T is a class or struct and splitlevel > 0, the members of the object are serialised as separate branches.
354  /// \return Pointer to the TBranch that was created. The branch is owned by the tree.
355  template <class T> TBranch *Branch(const char* name, T** addobj, Int_t bufsize = 32000, Int_t splitlevel = 99)
356  {
357  return BranchImp(name, TClass::GetClass<T>(), addobj, bufsize, splitlevel);
358  }
359 
360  virtual Int_t Branch(TCollection* list, Int_t bufsize = 32000, Int_t splitlevel = 99, const char* name = "");
361  virtual Int_t Branch(TList* list, Int_t bufsize = 32000, Int_t splitlevel = 99);
362  virtual Int_t Branch(const char* folder, Int_t bufsize = 32000, Int_t splitlevel = 99);
363  virtual TBranch *Branch(const char* name, void* address, const char* leaflist, Int_t bufsize = 32000);
364  TBranch *Branch(const char* name, char* address, const char* leaflist, Int_t bufsize = 32000)
365  {
366  // Overload to avoid confusion between this signature and the template instance.
367  return Branch(name,(void*)address,leaflist,bufsize);
368  }
369  TBranch *Branch(const char* name, Long_t address, const char* leaflist, Int_t bufsize = 32000)
370  {
371  // Overload to avoid confusion between this signature and the template instance.
372  return Branch(name,(void*)address,leaflist,bufsize);
373  }
374  TBranch *Branch(const char* name, int address, const char* leaflist, Int_t bufsize = 32000)
375  {
376  // Overload to avoid confusion between this signature and the template instance.
377  return Branch(name,(void*)(Long_t)address,leaflist,bufsize);
378  }
379  virtual TBranch *Branch(const char* name, const char* classname, void* addobj, Int_t bufsize = 32000, Int_t splitlevel = 99);
380  template <class T> TBranch *Branch(const char* name, const char* classname, T* obj, Int_t bufsize = 32000, Int_t splitlevel = 99)
381  {
382  // See BranchImpRed for details. Here we __ignore
383  return BranchImpRef(name, classname, TClass::GetClass<T>(), obj, bufsize, splitlevel);
384  }
385  template <class T> TBranch *Branch(const char* name, const char* classname, T** addobj, Int_t bufsize = 32000, Int_t splitlevel = 99)
386  {
387  // See BranchImp for details
388  return BranchImp(name, classname, TClass::GetClass<T>(), addobj, bufsize, splitlevel);
389  }
390  template <typename T, std::size_t N> TBranch *Branch(const char* name, std::array<T, N> *obj, Int_t bufsize = 32000, Int_t splitlevel = 99)
391  {
392  TClass *cl = TClass::GetClass<T>();
393  if (cl) {
394  TClass *arrCl = TClass::GetClass<std::array<T, N>>();
395  Error("Branch","std::array of objects not yet supported as top level branch object (the class is %s)",
396  arrCl ? arrCl->GetName() : cl->GetName());
397  return nullptr;
398  }
399  return BranchImpArr(name, TDataType::GetType(typeid(T)), N, obj, bufsize, splitlevel);
400  }
401  virtual TBranch *Bronch(const char* name, const char* classname, void* addobj, Int_t bufsize = 32000, Int_t splitlevel = 99);
402  virtual TBranch *BranchOld(const char* name, const char* classname, void* addobj, Int_t bufsize = 32000, Int_t splitlevel = 1);
403  virtual TBranch *BranchRef();
404  virtual void Browse(TBrowser*);
405  virtual Int_t BuildIndex(const char* majorname, const char* minorname = "0");
406  TStreamerInfo *BuildStreamerInfo(TClass* cl, void* pointer = 0, Bool_t canOptimize = kTRUE);
407  virtual TFile *ChangeFile(TFile* file);
408  virtual TTree *CloneTree(Long64_t nentries = -1, Option_t* option = "");
409  virtual void CopyAddresses(TTree*,Bool_t undo = kFALSE);
410  virtual Long64_t CopyEntries(TTree* tree, Long64_t nentries = -1, Option_t *option = "");
411  virtual TTree *CopyTree(const char* selection, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0);
412  virtual TBasket *CreateBasket(TBranch*);
413  virtual void DirectoryAutoAdd(TDirectory *);
414  Int_t Debug() const { return fDebug; }
415  virtual void Delete(Option_t* option = ""); // *MENU*
416  virtual void Draw(Option_t* opt) { Draw(opt, "", "", kMaxEntries, 0); }
417  virtual Long64_t Draw(const char* varexp, const TCut& selection, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0);
418  virtual Long64_t Draw(const char* varexp, const char* selection, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0); // *MENU*
419  virtual void DropBaskets();
420  virtual void DropBuffers(Int_t nbytes);
421  virtual Int_t Fill();
422  virtual TBranch *FindBranch(const char* name);
423  virtual TLeaf *FindLeaf(const char* name);
424  virtual Int_t Fit(const char* funcname, const char* varexp, const char* selection = "", Option_t* option = "", Option_t* goption = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0); // *MENU*
425  virtual Int_t FlushBaskets(Bool_t create_cluster = true) const;
426  virtual const char *GetAlias(const char* aliasName) const;
427  UInt_t GetAllocationCount() const { return fAllocationCount; }
428 #ifdef R__TRACK_BASKET_ALLOC_TIME
429  ULong64_t GetAllocationTime() const { return fAllocationTime; }
430 #endif
431  virtual Long64_t GetAutoFlush() const {return fAutoFlush;}
432  virtual Long64_t GetAutoSave() const {return fAutoSave;}
433  virtual TBranch *GetBranch(const char* name);
434  virtual TBranchRef *GetBranchRef() const { return fBranchRef; };
435  virtual Bool_t GetBranchStatus(const char* branchname) const;
436  static Int_t GetBranchStyle();
437  virtual Long64_t GetCacheSize() const { return fCacheSize; }
438  virtual TClusterIterator GetClusterIterator(Long64_t firstentry);
439  virtual Long64_t GetChainEntryNumber(Long64_t entry) const { return entry; }
440  virtual Long64_t GetChainOffset() const { return fChainOffset; }
441  virtual Bool_t GetClusterPrefetch() const { return fCacheDoClusterPrefetch; }
442  TFile *GetCurrentFile() const;
443  Int_t GetDefaultEntryOffsetLen() const {return fDefaultEntryOffsetLen;}
444  Long64_t GetDebugMax() const { return fDebugMax; }
445  Long64_t GetDebugMin() const { return fDebugMin; }
446  TDirectory *GetDirectory() const { return fDirectory; }
447  virtual Long64_t GetEntries() const { return fEntries; }
448  virtual Long64_t GetEntries(const char *selection);
449  virtual Long64_t GetEntriesFast() const { return fEntries; }
450  virtual Long64_t GetEntriesFriend() const;
451  virtual Long64_t GetEstimate() const { return fEstimate; }
452  virtual Int_t GetEntry(Long64_t entry = 0, Int_t getall = 0);
453  Int_t GetEvent(Long64_t entry = 0, Int_t getall = 0) { return GetEntry(entry, getall); }
454  virtual Int_t GetEntryWithIndex(Int_t major, Int_t minor = 0);
455  virtual Long64_t GetEntryNumberWithBestIndex(Long64_t major, Long64_t minor = 0) const;
456  virtual Long64_t GetEntryNumberWithIndex(Long64_t major, Long64_t minor = 0) const;
457  TEventList *GetEventList() const { return fEventList; }
458  virtual TEntryList *GetEntryList();
459  virtual Long64_t GetEntryNumber(Long64_t entry) const;
460  virtual Int_t GetFileNumber() const { return fFileNumber; }
461  virtual TTree *GetFriend(const char*) const;
462  virtual const char *GetFriendAlias(TTree*) const;
463  TH1 *GetHistogram() { return GetPlayer()->GetHistogram(); }
464  virtual Bool_t GetImplicitMT() { return fIMTEnabled; }
465  virtual Int_t *GetIndex() { return &fIndex.fArray[0]; }
466  virtual Double_t *GetIndexValues() { return &fIndexValues.fArray[0]; }
467  ROOT::TIOFeatures GetIOFeatures() const;
468  virtual TIterator *GetIteratorOnAllLeaves(Bool_t dir = kIterForward);
469  virtual TLeaf *GetLeaf(const char* branchname, const char* leafname);
470  virtual TLeaf *GetLeaf(const char* name);
471  virtual TList *GetListOfClones() { return fClones; }
472  virtual TObjArray *GetListOfBranches() { return &fBranches; }
473  virtual TObjArray *GetListOfLeaves() { return &fLeaves; }
474  virtual TList *GetListOfFriends() const { return fFriends; }
475  virtual TList *GetListOfAliases() const { return fAliases; }
476 
477  // GetMakeClass is left non-virtual for efficiency reason.
478  // Making it virtual affects the performance of the I/O
479  Int_t GetMakeClass() const { return fMakeClass; }
480 
481  virtual Long64_t GetMaxEntryLoop() const { return fMaxEntryLoop; }
482  virtual Double_t GetMaximum(const char* columname);
483  static Long64_t GetMaxTreeSize();
484  virtual Long64_t GetMaxVirtualSize() const { return fMaxVirtualSize; }
485  virtual Double_t GetMinimum(const char* columname);
486  virtual Int_t GetNbranches() { return fBranches.GetEntriesFast(); }
487  TObject *GetNotify() const { return fNotify; }
488  TVirtualTreePlayer *GetPlayer();
489  virtual Int_t GetPacketSize() const { return fPacketSize; }
490  virtual TVirtualPerfStats *GetPerfStats() const { return fPerfStats; }
491  TTreeCache *GetReadCache(TFile *file) const;
492  TTreeCache *GetReadCache(TFile *file, Bool_t create);
493  virtual Long64_t GetReadEntry() const { return fReadEntry; }
494  virtual Long64_t GetReadEvent() const { return fReadEntry; }
495  virtual Int_t GetScanField() const { return fScanField; }
496  TTreeFormula *GetSelect() { return GetPlayer()->GetSelect(); }
497  virtual Long64_t GetSelectedRows() { return GetPlayer()->GetSelectedRows(); }
498  virtual Int_t GetTimerInterval() const { return fTimerInterval; }
499  TBuffer* GetTransientBuffer(Int_t size);
500  virtual Long64_t GetTotBytes() const { return fTotBytes; }
501  virtual TTree *GetTree() const { return const_cast<TTree*>(this); }
502  virtual TVirtualIndex *GetTreeIndex() const { return fTreeIndex; }
503  virtual Int_t GetTreeNumber() const { return 0; }
504  Float_t GetTargetMemoryRatio() const { return fTargetMemoryRatio; }
505  virtual Int_t GetUpdate() const { return fUpdate; }
506  virtual TList *GetUserInfo();
507  // See TSelectorDraw::GetVar
508  TTreeFormula *GetVar(Int_t i) { return GetPlayer()->GetVar(i); }
509  // See TSelectorDraw::GetVar
510  TTreeFormula *GetVar1() { return GetPlayer()->GetVar1(); }
511  // See TSelectorDraw::GetVar
512  TTreeFormula *GetVar2() { return GetPlayer()->GetVar2(); }
513  // See TSelectorDraw::GetVar
514  TTreeFormula *GetVar3() { return GetPlayer()->GetVar3(); }
515  // See TSelectorDraw::GetVar
516  TTreeFormula *GetVar4() { return GetPlayer()->GetVar4(); }
517  // See TSelectorDraw::GetVal
518  virtual Double_t *GetVal(Int_t i) { return GetPlayer()->GetVal(i); }
519  // See TSelectorDraw::GetVal
520  virtual Double_t *GetV1() { return GetPlayer()->GetV1(); }
521  // See TSelectorDraw::GetVal
522  virtual Double_t *GetV2() { return GetPlayer()->GetV2(); }
523  // See TSelectorDraw::GetVal
524  virtual Double_t *GetV3() { return GetPlayer()->GetV3(); }
525  // See TSelectorDraw::GetVal
526  virtual Double_t *GetV4() { return GetPlayer()->GetV4(); }
527  virtual Double_t *GetW() { return GetPlayer()->GetW(); }
528  virtual Double_t GetWeight() const { return fWeight; }
529  virtual Long64_t GetZipBytes() const { return fZipBytes; }
530  virtual void IncrementTotalBuffers(Int_t nbytes) { fTotalBuffers += nbytes; }
531  Bool_t IsFolder() const { return kTRUE; }
532  virtual Int_t LoadBaskets(Long64_t maxmemory = 2000000000);
533  virtual Long64_t LoadTree(Long64_t entry);
534  virtual Long64_t LoadTreeFriend(Long64_t entry, TTree* T);
535  virtual Int_t MakeClass(const char* classname = 0, Option_t* option = "");
536  virtual Int_t MakeCode(const char* filename = 0);
537  virtual Int_t MakeProxy(const char* classname, const char* macrofilename = 0, const char* cutfilename = 0, const char* option = 0, Int_t maxUnrolling = 3);
538  virtual Int_t MakeSelector(const char* selector = 0, Option_t* option = "");
539  Bool_t MemoryFull(Int_t nbytes);
540  virtual Long64_t Merge(TCollection* list, Option_t* option = "");
541  virtual Long64_t Merge(TCollection* list, TFileMergeInfo *info);
542  static TTree *MergeTrees(TList* list, Option_t* option = "");
543  virtual Bool_t Notify();
544  virtual void OptimizeBaskets(ULong64_t maxMemory=10000000, Float_t minComp=1.1, Option_t *option="");
545  TPrincipal *Principal(const char* varexp = "", const char* selection = "", Option_t* option = "np", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0);
546  virtual void Print(Option_t* option = "") const; // *MENU*
547  virtual void PrintCacheStats(Option_t* option = "") const;
548  virtual Long64_t Process(const char* filename, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0); // *MENU*
549  virtual Long64_t Process(TSelector* selector, Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0);
550  virtual Long64_t Project(const char* hname, const char* varexp, const char* selection = "", Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0);
551  virtual TSQLResult *Query(const char* varexp = "", const char* selection = "", Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0);
552  virtual Long64_t ReadFile(const char* filename, const char* branchDescriptor = "", char delimiter = ' ');
553  virtual Long64_t ReadStream(std::istream& inputStream, const char* branchDescriptor = "", char delimiter = ' ');
554  virtual void Refresh();
555  virtual void RecursiveRemove(TObject *obj);
556  virtual void RemoveFriend(TTree*);
557  virtual void Reset(Option_t* option = "");
558  virtual void ResetAfterMerge(TFileMergeInfo *);
559  virtual void ResetBranchAddress(TBranch *);
560  virtual void ResetBranchAddresses();
561  virtual Long64_t Scan(const char* varexp = "", const char* selection = "", Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0); // *MENU*
562  virtual Bool_t SetAlias(const char* aliasName, const char* aliasFormula);
563  virtual void SetAutoSave(Long64_t autos = -300000000);
564  virtual void SetAutoFlush(Long64_t autof = -30000000);
565  virtual void SetBasketSize(const char* bname, Int_t buffsize = 16000);
566  virtual Int_t SetBranchAddress(const char *bname,void *add, TBranch **ptr = 0);
567  virtual Int_t SetBranchAddress(const char *bname,void *add, TClass *realClass, EDataType datatype, Bool_t isptr);
568  virtual Int_t SetBranchAddress(const char *bname,void *add, TBranch **ptr, TClass *realClass, EDataType datatype, Bool_t isptr);
569  template <class T> Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr = 0) {
570  TClass *cl = TClass::GetClass<T>();
571  EDataType type = kOther_t;
572  if (cl==0) type = TDataType::GetType(typeid(T));
573  return SetBranchAddress(bname,add,ptr,cl,type,true);
574  }
575 #ifndef R__NO_CLASS_TEMPLATE_SPECIALIZATION
576  // This can only be used when the template overload resolution can distinguish between
577  // T* and T**
578  template <class T> Int_t SetBranchAddress(const char *bname, T *add, TBranch **ptr = 0) {
579  TClass *cl = TClass::GetClass<T>();
580  EDataType type = kOther_t;
581  if (cl==0) type = TDataType::GetType(typeid(T));
582  return SetBranchAddress(bname,add,ptr,cl,type,false);
583  }
584 #endif
585  virtual void SetBranchStatus(const char* bname, Bool_t status = 1, UInt_t* found = 0);
586  static void SetBranchStyle(Int_t style = 1); //style=0 for old branch, =1 for new branch style
587  virtual Int_t SetCacheSize(Long64_t cachesize = -1);
588  virtual Int_t SetCacheEntryRange(Long64_t first, Long64_t last);
589  virtual void SetCacheLearnEntries(Int_t n=10);
590  virtual void SetChainOffset(Long64_t offset = 0) { fChainOffset=offset; }
591  virtual void SetCircular(Long64_t maxEntries);
592  virtual void SetClusterPrefetch(Bool_t enabled) { fCacheDoClusterPrefetch = enabled; }
593  virtual void SetDebug(Int_t level = 1, Long64_t min = 0, Long64_t max = 9999999); // *MENU*
594  virtual void SetDefaultEntryOffsetLen(Int_t newdefault, Bool_t updateExisting = kFALSE);
595  virtual void SetDirectory(TDirectory* dir);
596  virtual Long64_t SetEntries(Long64_t n = -1);
597  virtual void SetEstimate(Long64_t nentries = 1000000);
598  ROOT::TIOFeatures SetIOFeatures(const ROOT::TIOFeatures &);
599  virtual void SetFileNumber(Int_t number = 0);
600  virtual void SetEventList(TEventList* list);
601  virtual void SetEntryList(TEntryList* list, Option_t *opt="");
602  virtual void SetImplicitMT(Bool_t enabled) { fIMTEnabled = enabled; }
603  virtual void SetMakeClass(Int_t make);
604  virtual void SetMaxEntryLoop(Long64_t maxev = kMaxEntries) { fMaxEntryLoop = maxev; } // *MENU*
605  static void SetMaxTreeSize(Long64_t maxsize = 100000000000LL);
606  virtual void SetMaxVirtualSize(Long64_t size = 0) { fMaxVirtualSize = size; } // *MENU*
607  virtual void SetName(const char* name); // *MENU*
608 
609  /**
610  * @brief Sets the address of the object to be notified when the tree is loaded.
611  *
612  * The method TObject::Notify is called for the given object when the tree
613  * is loaded. Specifically this occurs in the TTree::LoadTree method. To
614  * remove the notification call this method with nullptr:
615  * @code tree->SetNotify(nullptr); @endcode
616  *
617  * @param[in] obj Pointer to a TObject to be notified.
618  */
619  virtual void SetNotify(TObject* obj) { fNotify = obj; }
620 
621  virtual void SetObject(const char* name, const char* title);
622  virtual void SetParallelUnzip(Bool_t opt=kTRUE, Float_t RelSize=-1);
623  virtual void SetPerfStats(TVirtualPerfStats* perf);
624  virtual void SetScanField(Int_t n = 50) { fScanField = n; } // *MENU*
625  void SetTargetMemoryRatio(Float_t ratio) { fTargetMemoryRatio = ratio; }
626  virtual void SetTimerInterval(Int_t msec = 333) { fTimerInterval=msec; }
627  virtual void SetTreeIndex(TVirtualIndex* index);
628  virtual void SetWeight(Double_t w = 1, Option_t* option = "");
629  virtual void SetUpdate(Int_t freq = 0) { fUpdate = freq; }
630  virtual void Show(Long64_t entry = -1, Int_t lenmax = 20);
631  virtual void StartViewer(); // *MENU*
632  virtual Int_t StopCacheLearningPhase();
633  virtual Int_t UnbinnedFit(const char* funcname, const char* varexp, const char* selection = "", Option_t* option = "", Long64_t nentries = kMaxEntries, Long64_t firstentry = 0);
634  void UseCurrentStyle();
635  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
636  virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
637 
638  ClassDef(TTree, 20) // Tree descriptor (the main ROOT I/O class)
639 };
640 
641 //////////////////////////////////////////////////////////////////////////
642 // //
643 // TTreeFriendLeafIter //
644 // //
645 // Iterator on all the leaves in a TTree and its friend //
646 // //
647 //////////////////////////////////////////////////////////////////////////
648 
649 class TTreeFriendLeafIter : public TIterator {
650 
651 protected:
652  TTree *fTree; ///< tree being iterated
653  TIterator *fLeafIter; ///< current leaf sub-iterator.
654  TIterator *fTreeIter; ///< current tree sub-iterator.
655  Bool_t fDirection; ///< iteration direction
656 
657  TTreeFriendLeafIter() : fTree(0), fLeafIter(0), fTreeIter(0),
658  fDirection(0) { }
659 
660 public:
661  TTreeFriendLeafIter(const TTree* t, Bool_t dir = kIterForward);
662  TTreeFriendLeafIter(const TTreeFriendLeafIter &iter);
663  ~TTreeFriendLeafIter() { SafeDelete(fLeafIter); SafeDelete(fTreeIter); }
664  TIterator &operator=(const TIterator &rhs);
665  TTreeFriendLeafIter &operator=(const TTreeFriendLeafIter &rhs);
666 
667  const TCollection *GetCollection() const { return 0; }
668  Option_t *GetOption() const;
669  TObject *Next();
670  void Reset() { SafeDelete(fLeafIter); SafeDelete(fTreeIter); }
671  Bool_t operator !=(const TIterator&) const {
672  // TODO: Implement me
673  return false;
674  }
675  Bool_t operator !=(const TTreeFriendLeafIter&) const {
676  // TODO: Implement me
677  return false;
678  }
679  TObject *operator*() const {
680  // TODO: Implement me
681  return nullptr;
682  }
683  ClassDef(TTreeFriendLeafIter,0) //Linked list iterator
684  };
685 
686 
687 #endif