Logo ROOT   6.10/09
Reference Guide
TBranch.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_TBranch
13 #define ROOT_TBranch
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TBranch //
19 // //
20 // A TTree object is a list of TBranchs. //
21 // A TBranch describes the branch data structure and supports : //
22 // the list of TBaskets (branch buffers) associated to this branch. //
23 // the list of TLeaves (branch description) //
24 //////////////////////////////////////////////////////////////////////////
25 
26 #include <memory>
27 
28 #include "TNamed.h"
29 
30 #include "TObjArray.h"
31 
32 #include "TAttFill.h"
33 
34 #include "TDataType.h"
35 
36 class TTree;
37 class TBasket;
38 class TLeaf;
39 class TBrowser;
40 class TDirectory;
41 class TFile;
42 class TClonesArray;
43 class TTreeCloner;
44 
45  const Int_t kDoNotProcess = BIT(10); // Active bit for branches
46  const Int_t kIsClone = BIT(11); // to indicate a TBranchClones
47  const Int_t kBranchObject = BIT(12); // branch is a TObject*
48  const Int_t kBranchAny = BIT(17); // branch is an object*
50 
51 namespace ROOT {
52  namespace Internal {
53  class TBranchIMTHelper; ///< A helper class for managing IMT work during TTree:Fill operations.
54  }
55 }
56 
57 class TBranch : public TNamed , public TAttFill {
58 
59 protected:
60  friend class TTreeCloner;
61  friend class TTree;
62 
63  // TBranch status bits
64  enum EStatusBits {
65  kAutoDelete = BIT(15),
66  kDoNotUseBufferMap = BIT(22) // If set, at least one of the entry in the branch will use the buffer's map of classname and objects.
67  };
68 
69  static Int_t fgCount; ///<! branch counter
70  Int_t fCompress; ///< Compression level and algorithm
71  Int_t fBasketSize; ///< Initial Size of Basket Buffer
72  Int_t fEntryOffsetLen; ///< Initial Length of fEntryOffset table in the basket buffers
73  Int_t fWriteBasket; ///< Last basket number written
74  Long64_t fEntryNumber; ///< Current entry number (last one filled in this branch)
75  Int_t fOffset; ///< Offset of this branch
76  Int_t fMaxBaskets; ///< Maximum number of Baskets so far
77  Int_t fNBaskets; ///<! Number of baskets in memory
78  Int_t fSplitLevel; ///< Branch split level
79  Int_t fNleaves; ///<! Number of leaves
80  Int_t fReadBasket; ///<! Current basket number when reading
81  Long64_t fReadEntry; ///<! Current entry number when reading
82  Long64_t fFirstBasketEntry; ///<! First entry in the current basket.
83  Long64_t fNextBasketEntry; ///<! Next entry that will requires us to go to the next basket
84  TBasket *fCurrentBasket; ///<! Pointer to the current basket.
85  Long64_t fEntries; ///< Number of entries
86  Long64_t fFirstEntry; ///< Number of the first entry in this branch
87  Long64_t fTotBytes; ///< Total number of bytes in all leaves before compression
88  Long64_t fZipBytes; ///< Total number of bytes in all leaves after compression
89  TObjArray fBranches; ///< -> List of Branches of this branch
90  TObjArray fLeaves; ///< -> List of leaves of this branch
91  TObjArray fBaskets; ///< -> List of baskets of this branch
92  Int_t *fBasketBytes; ///<[fMaxBaskets] Length of baskets on file
93  Long64_t *fBasketEntry; ///<[fMaxBaskets] Table of first entry in each basket
94  Long64_t *fBasketSeek; ///<[fMaxBaskets] Addresses of baskets on file
95  TTree *fTree; ///<! Pointer to Tree header
96  TBranch *fMother; ///<! Pointer to top-level parent branch in the tree.
97  TBranch *fParent; ///<! Pointer to parent branch.
98  char *fAddress; ///<! Address of 1st leaf (variable or object)
99  TDirectory *fDirectory; ///<! Pointer to directory where this branch buffers are stored
100  TString fFileName; ///< Name of file where buffers are stored ("" if in same file as Tree header)
101  TBuffer *fEntryBuffer; ///<! Buffer used to directly pass the content without streaming
102  TBuffer *fTransientBuffer; ///<! Pointer to the current transient buffer.
103  TList *fBrowsables; ///<! List of TVirtualBranchBrowsables used for Browse()
104 
105  Bool_t fSkipZip; ///<! After being read, the buffer will not be unzipped.
106 
107  typedef void (TBranch::*ReadLeaves_t)(TBuffer &b);
108  ReadLeaves_t fReadLeaves; ///<! Pointer to the ReadLeaves implementation to use.
109  typedef void (TBranch::*FillLeaves_t)(TBuffer &b);
110  FillLeaves_t fFillLeaves; ///<! Pointer to the FillLeaves implementation to use.
111  void ReadLeavesImpl(TBuffer &b);
112  void ReadLeaves0Impl(TBuffer &b);
113  void ReadLeaves1Impl(TBuffer &b);
114  void ReadLeaves2Impl(TBuffer &b);
115  void FillLeavesImpl(TBuffer &b);
116 
117  void SetSkipZip(Bool_t skip = kTRUE) { fSkipZip = skip; }
118  void Init(const char *name, const char *leaflist, Int_t compress);
119 
120  TBasket *GetFreshBasket();
121  Int_t WriteBasket(TBasket* basket, Int_t where) { return WriteBasketImpl(basket, where, nullptr); }
122 
123  TString GetRealFileName() const;
124 
125 private:
126  Int_t FillEntryBuffer(TBasket* basket,TBuffer* buf, Int_t& lnew);
127  Int_t WriteBasketImpl(TBasket* basket, Int_t where, ROOT::Internal::TBranchIMTHelper *);
128  TBranch(const TBranch&) = delete; // not implemented
129  TBranch& operator=(const TBranch&) = delete; // not implemented
130 
131 public:
132  TBranch();
133  TBranch(TTree *tree, const char *name, void *address, const char *leaflist, Int_t basketsize=32000, Int_t compress=-1);
134  TBranch(TBranch *parent, const char *name, void *address, const char *leaflist, Int_t basketsize=32000, Int_t compress=-1);
135  virtual ~TBranch();
136 
137  virtual void AddBasket(TBasket &b, Bool_t ondisk, Long64_t startEntry);
138  virtual void AddLastBasket(Long64_t startEntry);
139  Int_t BackFill();
140  virtual void Browse(TBrowser *b);
141  virtual void DeleteBaskets(Option_t* option="");
142  virtual void DropBaskets(Option_t *option = "");
143  void ExpandBasketArrays();
144  Int_t Fill() { return FillImpl(nullptr); }
145  virtual Int_t FillImpl(ROOT::Internal::TBranchIMTHelper *);
146  virtual TBranch *FindBranch(const char *name);
147  virtual TLeaf *FindLeaf(const char *name);
149  Int_t FlushOneBasket(UInt_t which);
150 
151  virtual char *GetAddress() const {return fAddress;}
152  TBasket *GetBasket(Int_t basket);
153  Int_t *GetBasketBytes() const {return fBasketBytes;}
154  Long64_t *GetBasketEntry() const {return fBasketEntry;}
155  virtual Long64_t GetBasketSeek(Int_t basket) const;
156  virtual Int_t GetBasketSize() const {return fBasketSize;}
157  virtual TList *GetBrowsables();
158  virtual const char* GetClassName() const;
159  Int_t GetCompressionAlgorithm() const;
160  Int_t GetCompressionLevel() const;
161  Int_t GetCompressionSettings() const;
162  TDirectory *GetDirectory() const {return fDirectory;}
163  virtual Int_t GetEntry(Long64_t entry=0, Int_t getall = 0);
164  virtual Int_t GetEntryExport(Long64_t entry, Int_t getall, TClonesArray *list, Int_t n);
165  Int_t GetEntryOffsetLen() const { return fEntryOffsetLen; }
166  Int_t GetEvent(Long64_t entry=0) {return GetEntry(entry);}
167  const char *GetIconName() const;
168  virtual Int_t GetExpectedType(TClass *&clptr,EDataType &type);
169  virtual TLeaf *GetLeaf(const char *name) const;
170  virtual TFile *GetFile(Int_t mode=0);
171  const char *GetFileName() const {return fFileName.Data();}
172  Int_t GetOffset() const {return fOffset;}
173  Int_t GetReadBasket() const {return fReadBasket;}
174  Long64_t GetReadEntry() const {return fReadEntry;}
175  Int_t GetWriteBasket() const {return fWriteBasket;}
176  Long64_t GetTotalSize(Option_t *option="") const;
177  Long64_t GetTotBytes(Option_t *option="") const;
178  Long64_t GetZipBytes(Option_t *option="") const;
179  Long64_t GetEntryNumber() const {return fEntryNumber;}
180  Long64_t GetFirstEntry() const {return fFirstEntry; }
181  TObjArray *GetListOfBaskets() {return &fBaskets;}
184  Int_t GetMaxBaskets() const {return fMaxBaskets;}
185  Int_t GetNleaves() const {return fNleaves;}
186  Int_t GetSplitLevel() const {return fSplitLevel;}
187  Long64_t GetEntries() const {return fEntries;}
188  TTree *GetTree() const {return fTree;}
189  virtual Int_t GetRow(Int_t row);
190  virtual Bool_t GetMakeClass() const;
191  TBranch *GetMother() const;
192  TBranch *GetSubBranch(const TBranch *br) const;
194  Bool_t IsAutoDelete() const;
195  Bool_t IsFolder() const;
196  virtual void KeepCircular(Long64_t maxEntries);
197  virtual Int_t LoadBaskets();
198  virtual void Print(Option_t *option="") const;
199  virtual void ReadBasket(TBuffer &b);
200  virtual void Refresh(TBranch *b);
201  virtual void Reset(Option_t *option="");
202  virtual void ResetAfterMerge(TFileMergeInfo *);
203  virtual void ResetAddress();
204  virtual void ResetReadEntry() {fReadEntry = -1;}
205  virtual void SetAddress(void *add);
206  virtual void SetObject(void *objadd);
207  virtual void SetAutoDelete(Bool_t autodel=kTRUE);
208  virtual void SetBasketSize(Int_t buffsize);
209  virtual void SetBufferAddress(TBuffer *entryBuffer);
210  void SetCompressionAlgorithm(Int_t algorithm=0);
211  void SetCompressionLevel(Int_t level=1);
212  void SetCompressionSettings(Int_t settings=1);
213  virtual void SetEntries(Long64_t entries);
214  virtual void SetEntryOffsetLen(Int_t len, Bool_t updateSubBranches = kFALSE);
215  virtual void SetFirstEntry( Long64_t entry );
216  virtual void SetFile(TFile *file=0);
217  virtual void SetFile(const char *filename);
218  virtual Bool_t SetMakeClass(Bool_t decomposeObj = kTRUE);
219  virtual void SetOffset(Int_t offset=0) {fOffset=offset;}
220  virtual void SetStatus(Bool_t status=1);
221  virtual void SetTree(TTree *tree) { fTree = tree;}
222  virtual void SetupAddresses();
223  virtual void UpdateAddress() {;}
224  virtual void UpdateFile();
225 
226  static void ResetCount();
227 
228  ClassDef(TBranch,12); //Branch descriptor
229 };
230 
231 //______________________________________________________________________________
233 {
234  return (fCompress < 0) ? -1 : fCompress / 100;
235 }
236 
237 //______________________________________________________________________________
239 {
240  return (fCompress < 0) ? -1 : fCompress % 100;
241 }
242 
243 //______________________________________________________________________________
245 {
246  return (fCompress < 0) ? -1 : fCompress;
247 }
248 
249 #endif
virtual void UpdateAddress()
Definition: TBranch.h:223
virtual TBranch * FindBranch(const char *name)
Return the branch that correspond to the path &#39;branchname&#39;, which can include the name of the tree or...
Definition: TTree.cxx:4589
Int_t fNBaskets
! Number of baskets in memory
Definition: TBranch.h:77
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:32
An array of TObjects.
Definition: TObjArray.h:37
Long64_t * GetBasketEntry() const
Definition: TBranch.h:154
Int_t GetSplitLevel() const
Definition: TBranch.h:186
Int_t fOffset
Offset of this branch.
Definition: TBranch.h:75
long long Long64_t
Definition: RtypesCore.h:69
virtual Int_t GetBasketSize() const
Definition: TBranch.h:156
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TObjArray * GetListOfBaskets()
Definition: TBranch.h:181
Long64_t fEntries
Number of entries.
Definition: TBranch.h:85
virtual Int_t LoadBaskets(Long64_t maxmemory=2000000000)
Read in memory all baskets from all branches up to the limit of maxmemory bytes.
Definition: TTree.cxx:6100
Int_t GetCompressionLevel() const
Definition: TBranch.h:238
const char Option_t
Definition: RtypesCore.h:62
virtual const char * GetIconName() const
Returns mime type name of object.
Definition: TObject.cxx:374
Long64_t fZipBytes
Total number of bytes in all leaves after compression.
Definition: TBranch.h:88
ReadLeaves_t fReadLeaves
! Pointer to the ReadLeaves implementation to use.
Definition: TBranch.h:108
Int_t GetMakeClass() const
Definition: TTree.h:412
const Int_t kMapObject
Definition: TBranch.h:49
#define BIT(n)
Definition: Rtypes.h:75
virtual TLeaf * GetLeaf(const char *branchname, const char *leafname)
Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of fri...
Definition: TTree.cxx:5854
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
TDirectory * fDirectory
! Pointer to directory holding this tree
Definition: TTree.h:114
TBasket * fCurrentBasket
! Pointer to the current basket.
Definition: TBranch.h:84
const Int_t kBranchObject
Definition: TBranch.h:47
TDirectory * GetDirectory() const
Definition: TBranch.h:162
Int_t GetOffset() const
Definition: TBranch.h:172
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition: TTree.cxx:5321
TObjArray fBaskets
-> List of baskets of this branch
Definition: TBranch.h:91
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void Browse(TBrowser *)
Browse content of the TTree.
Definition: TTree.cxx:2520
Int_t fNleaves
! Number of leaves
Definition: TBranch.h:79
Int_t GetCompressionAlgorithm() const
Definition: TBranch.h:232
TObjArray fLeaves
-> List of leaves of this branch
Definition: TBranch.h:90
Long64_t * fBasketSeek
[fMaxBaskets] Addresses of baskets on file
Definition: TBranch.h:94
virtual void KeepCircular()
Keep a maximum of fMaxEntries in memory.
Definition: TTree.cxx:6064
Int_t GetEntryOffsetLen() const
Definition: TBranch.h:165
void SetSkipZip(Bool_t skip=kTRUE)
Definition: TBranch.h:117
Long64_t fFirstBasketEntry
! First entry in the current basket.
Definition: TBranch.h:82
virtual void Refresh()
Refresh contents of this tree and its branches from the current status on disk.
Definition: TTree.cxx:7492
Int_t * fBasketBytes
[fMaxBaskets] Length of baskets on file
Definition: TBranch.h:92
Long64_t fEntryNumber
Current entry number (last one filled in this branch)
Definition: TBranch.h:74
virtual void SetTree(TTree *tree)
Definition: TBranch.h:221
const Int_t kBranchAny
Definition: TBranch.h:48
virtual Int_t FlushBaskets() const
Write to disk all the basket that have not yet been individually written.
Definition: TTree.cxx:4864
Int_t fWriteBasket
Last basket number written.
Definition: TBranch.h:73
Long64_t fTotBytes
Total number of bytes in all leaves before compression.
Definition: TBranch.h:87
Fill Area Attributes class.
Definition: TAttFill.h:19
Int_t * GetBasketBytes() const
Definition: TBranch.h:153
#define ClassDef(name, id)
Definition: Rtypes.h:297
virtual void SetObject(const char *name, const char *title)
Change the name and title of this tree.
Definition: TTree.cxx:8673
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
const Int_t kDoNotProcess
Definition: TBranch.h:45
TObjArray * GetListOfBranches()
Definition: TBranch.h:182
Int_t fMaxBaskets
Maximum number of Baskets so far.
Definition: TBranch.h:76
Long64_t GetEntryNumber() const
Definition: TBranch.h:179
Int_t fSplitLevel
Branch split level.
Definition: TBranch.h:78
A doubly linked list.
Definition: TList.h:43
Int_t Fill()
Definition: TBranch.h:144
TObjArray fLeaves
Direct pointers to individual branch leaves.
Definition: TTree.h:116
Int_t GetEvent(Long64_t entry=0)
Definition: TBranch.h:166
Int_t GetCompressionSettings() const
Definition: TBranch.h:244
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Int_t WriteBasket(TBasket *basket, Int_t where)
Definition: TBranch.h:121
TBuffer * fEntryBuffer
! Buffer used to directly pass the content without streaming
Definition: TBranch.h:101
Int_t GetReadBasket() const
Definition: TBranch.h:173
static Int_t fgCount
! branch counter
Definition: TBranch.h:69
virtual void SetOffset(Int_t offset=0)
Definition: TBranch.h:219
Int_t fBasketSize
Initial Size of Basket Buffer.
Definition: TBranch.h:71
TList * fBrowsables
! List of TVirtualBranchBrowsables used for Browse()
Definition: TBranch.h:103
Long64_t GetFirstEntry() const
Definition: TBranch.h:180
Long64_t fReadEntry
! Number of the entry being processed
Definition: TTree.h:104
Int_t GetWriteBasket() const
Definition: TBranch.h:175
const Int_t kIsClone
Definition: TBranch.h:46
TObjArray fBranches
List of Branches.
Definition: TTree.h:115
FillLeaves_t fFillLeaves
! Pointer to the FillLeaves implementation to use.
Definition: TBranch.h:110
unsigned int UInt_t
Definition: RtypesCore.h:42
Long64_t fNextBasketEntry
! Next entry that will requires us to go to the next basket
Definition: TBranch.h:83
Manages buffers for branches of a Tree.
Definition: TBasket.h:36
Int_t GetMaxBaskets() const
Definition: TBranch.h:184
virtual TLeaf * FindLeaf(const char *name)
Find leaf..
Definition: TTree.cxx:4661
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
const char * GetFileName() const
Definition: TBranch.h:171
void Reset(Detail::TBranchProxy *x)
Bool_t IsFolder() const
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects)...
Definition: TTree.h:461
const Bool_t kFALSE
Definition: RtypesCore.h:92
virtual void SetMakeClass(Int_t make)
Set all the branches in this TTree to be in decomposed object mode (also known as MakeClass mode)...
Definition: TTree.cxx:8616
Bool_t fSkipZip
! After being read, the buffer will not be unzipped.
Definition: TBranch.h:105
Int_t fReadBasket
! Current basket number when reading
Definition: TBranch.h:80
void Print(std::ostream &os, const OptionType &opt)
Describe directory structure in memory.
Definition: TDirectory.h:34
EStatusBits
Definition: TObject.h:57
int type
Definition: TGX11.cxx:120
EDataType
Definition: TDataType.h:28
TTree * fTree
! Pointer to Tree header
Definition: TBranch.h:95
TObjArray * GetListOfLeaves()
Definition: TBranch.h:183
TDirectory * fDirectory
! Pointer to directory where this branch buffers are stored
Definition: TBranch.h:99
virtual void SetBasketSize(const char *bname, Int_t buffsize=16000)
Set a branch&#39;s basket size.
Definition: TTree.cxx:7846
Binding & operator=(OUT(*fun)(void))
virtual void ResetAfterMerge(TFileMergeInfo *)
Resets the state of this TTree after a merge (keep the customization but forget the data)...
Definition: TTree.cxx:7588
typedef void((*Func_t)())
Long64_t fEntries
Number of entries.
Definition: TTree.h:81
Long64_t GetEntries() const
Definition: TBranch.h:187
An array of clone (identical) objects.
Definition: TClonesArray.h:32
TBuffer * GetTransientBuffer(Int_t size)
Returns the transient buffer currently used by this TTree for reading/writing baskets.
Definition: TTree.cxx:923
virtual Long64_t GetTotBytes() const
Definition: TTree.h:431
Class implementing or helping the various TTree cloning method.
Definition: TTreeCloner.h:38
Long64_t * fBasketEntry
[fMaxBaskets] Table of first entry in each basket
Definition: TBranch.h:93
Definition: file.py:1
virtual Long64_t GetZipBytes() const
Definition: TTree.h:459
Long64_t fReadEntry
! Current entry number when reading
Definition: TBranch.h:81
Long64_t GetReadEntry() const
Definition: TBranch.h:174
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
TBranch * fMother
! Pointer to top-level parent branch in the tree.
Definition: TBranch.h:96
TTree * GetTree() const
Definition: TBranch.h:188
Definition: tree.py:1
virtual char * GetAddress() const
Definition: TBranch.h:151
A TTree object has a header with a name and a title.
Definition: TTree.h:78
Int_t fEntryOffsetLen
Initial Length of fEntryOffset table in the basket buffers.
Definition: TBranch.h:72
virtual void DropBaskets()
Remove some baskets from memory.
Definition: TTree.cxx:4302
TObjArray fBranches
-> List of Branches of this branch
Definition: TBranch.h:89
virtual void ResetReadEntry()
Definition: TBranch.h:204
virtual Long64_t SetEntries(Long64_t n=-1)
Change number of entries in the tree.
Definition: TTree.cxx:8484
A TTree is a list of TBranches.
Definition: TBranch.h:57
TBuffer * fTransientBuffer
! Pointer to the current transient buffer.
Definition: TBranch.h:102
Int_t fCompress
Compression level and algorithm.
Definition: TBranch.h:70
TString fFileName
Name of file where buffers are stored ("" if in same file as Tree header)
Definition: TBranch.h:100
const Bool_t kTRUE
Definition: RtypesCore.h:91
TBranch * fParent
! Pointer to parent branch.
Definition: TBranch.h:97
static char * skip(char **buf, const char *delimiters)
Definition: civetweb.c:2039
const Int_t n
Definition: legend1.C:16
Long64_t fFirstEntry
Number of the first entry in this branch.
Definition: TBranch.h:86
Int_t GetNleaves() const
Definition: TBranch.h:185
const char * Data() const
Definition: TString.h:347
char * fAddress
! Address of 1st leaf (variable or object)
Definition: TBranch.h:98