Logo ROOT  
Reference Guide
TLeaf.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_TLeaf
13 #define ROOT_TLeaf
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TLeaf //
19 // //
20 // A TTree object is a list of TBranch. //
21 // A TBranch object is a list of TLeaf. In most cases, the TBranch //
22 // will have one TLeaf. //
23 // A TLeaf describes the branch data types and holds the data. //
24 // //
25 // A few notes about the data held by the leaf. It can contain: //
26 // 1 a single object or primitive (e.g., one float), //
27 // 2 a fixed-number of objects (e.g., each entry has two floats). //
28 // The number of elements per entry is saved in `fLen`. //
29 // 3 a dynamic number of primitives. The number of objects in each //
30 // entry is saved in the `fLeafCount` branch. //
31 // //
32 // Note options (2) and (3) can combined - if fLeafCount says an entry //
33 // has 3 elements and fLen is 2, then there will be 6 objects in that //
34 // entry. //
35 // //
36 // Additionally, `fNdata` is transient and generated on read to //
37 // determine the necessary size of a buffer to hold event data; //
38 // depending on the call-site, it may be sized larger than the number //
39 // of elements //
40 // //
41 //////////////////////////////////////////////////////////////////////////
42 
43 
44 #include "TNamed.h"
45 
46 #include <vector>
47 
48 #ifdef R__LESS_INCLUDES
49 class TBranch;
50 #else
51 #include "TBranch.h"
52 #endif
53 
54 class TClonesArray;
55 class TBrowser;
56 
57 class TLeaf : public TNamed {
58 
59 private:
60 
61  virtual Int_t GetOffsetHeaderSize() const {return 0;}
62 
63 protected:
64 
65  using Counts_t = std::vector<Int_t>;
66  struct LeafCountValues {
68  Long64_t fStartEntry{-1}; ///<! entry number of corresponding to element 0 of the vector.
69  };
70 
71  Int_t fNdata; ///<! Number of elements in fAddress data buffer.
72  Int_t fLen; ///< Number of fixed length elements in the leaf's data.
73  Int_t fLenType; ///< Number of bytes for this data type
74  Int_t fOffset; ///< Offset in ClonesArray object (if one)
75  Bool_t fIsRange; ///< (=kTRUE if leaf has a range, kFALSE otherwise). This is equivalent to being a 'leafcount'. For a TLeafElement the range information is actually store in the TBranchElement.
76  Bool_t fIsUnsigned; ///< (=kTRUE if unsigned, kFALSE otherwise)
77  TLeaf *fLeafCount; ///< Pointer to Leaf count if variable length (we do not own the counter)
78  TBranch *fBranch; ///<! Pointer to supporting branch (we do not own the branch)
79  LeafCountValues *fLeafCountValues; ///<! Cache of collection/array sizes
80 
81  TLeaf(const TLeaf&);
82  TLeaf& operator=(const TLeaf&);
83 
84  template <typename T> struct GetValueHelper {
85  static T Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValue(i); }
86  };
87 
88  Int_t *GenerateOffsetArrayBase(Int_t base, Int_t events) const; // For leaves containing fixed-size objects (no
89  // polymorphism!), this will generate an appropriate
90  // offset array.
91 
92 
93 public:
94  enum EStatusBits {
95  kIndirectAddress = BIT(11), ///< Data member is a pointer to an array of basic types.
96  kNewValue = BIT(12) ///< Set if we own the value buffer and so must delete it ourselves.
97  };
98 
99  enum class DeserializeType {
100  kInvalid = 0, // Invalid deserialization information.
101  kDestructive, // Deserialization of this Leaf requires a separate output buffer.
102  kInPlace, // Deserialization can be done directly in the input buffer.
103  kZeroCopy, // In-memory and on-disk representation of this object are identical.
104  };
105 
106  TLeaf();
107  TLeaf(TBranch *parent, const char *name, const char *type);
108  virtual ~TLeaf();
109 
110  virtual void Browse(TBrowser *b);
111  virtual Bool_t CanGenerateOffsetArray() {return fLeafCount;} // overload and return true if this leaf can generate its own offset array.
112  virtual void Export(TClonesArray *, Int_t) {}
113  virtual void FillBasket(TBuffer &b);
114  virtual Int_t *GenerateOffsetArray(Int_t base, Int_t events) { return GenerateOffsetArrayBase(base, events); }
115  TBranch *GetBranch() const { return fBranch; }
117  virtual TString GetFullName() const;
118  /// If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has variable size,
119  /// return a pointer to the TLeaf that stores such size. Return a nullptr otherwise.
120  virtual TLeaf *GetLeafCount() const { return fLeafCount; }
121  virtual TLeaf *GetLeafCounter(Int_t &countval) const;
122 
123  virtual const Counts_t *GetLeafCountValues(Long64_t start, Long64_t len);
124 
125  virtual Int_t GetLen() const;
126  /// Return the fixed length of this leaf.
127  /// If the leaf stores a fixed-length array, this is the size of the array.
128  /// If the leaf stores a non-array or a variable-sized array, this method returns 1.
129  /// If the leaf stores an array with 2 or more dimensions, this method returns the total number of elements in the
130  /// dimensions with static length: for example for float[3][2][] it would return 6.
131  virtual Int_t GetLenStatic() const { return fLen; }
132  virtual Int_t GetLenType() const { return fLenType; }
133  virtual Int_t GetMaximum() const { return 0; }
134  virtual Int_t GetMinimum() const { return 0; }
135  virtual Int_t GetNdata() const { return fNdata; }
136  virtual Int_t GetOffset() const { return fOffset; }
137  virtual void *GetValuePointer() const { return 0; }
138  virtual const char *GetTypeName() const { return ""; }
139 
140  virtual Double_t GetValue(Int_t i = 0) const;
141  virtual Long64_t GetValueLong64(Int_t i = 0) const { return GetValue(i); } // overload only when it matters.
142  virtual LongDouble_t GetValueLongDouble(Int_t i = 0) const { return GetValue(i); } // overload only when it matters.
143  template <typename T> T GetTypedValue(Int_t i = 0) const { return GetValueHelper<T>::Exec(this, i); }
144 
145  virtual Bool_t IncludeRange(TLeaf *) { return kFALSE; } // overload to copy/set fMinimum and fMaximum to include/be wide than those of the parameter
146  virtual void Import(TClonesArray *, Int_t) {}
147  virtual Bool_t IsOnTerminalBranch() const { return kTRUE; }
148  virtual Bool_t IsRange() const { return fIsRange; }
149  virtual Bool_t IsUnsigned() const { return fIsUnsigned; }
150  virtual void PrintValue(Int_t i = 0) const;
151  virtual void ReadBasket(TBuffer &) {}
153  virtual bool ReadBasketFast(TBuffer&, Long64_t) { return false; } // Read contents of leaf into a user-provided buffer.
154  virtual bool ReadBasketSerialized(TBuffer&, Long64_t) { return false; } // Read contents of leaf into a user-provided buffer
155  virtual void ReadValue(std::istream & /*s*/, Char_t /*delim*/ = ' ') {
156  Error("ReadValue", "Not implemented!");
157  }
158  Int_t ResetAddress(void *add, Bool_t destructor = kFALSE);
159  virtual void SetAddress(void *add = 0);
160  virtual void SetBranch(TBranch *branch) { fBranch = branch; }
161  virtual void SetLeafCount(TLeaf *leaf);
162  virtual void SetLen(Int_t len = 1) { fLen = len; }
163  virtual void SetOffset(Int_t offset = 0) { fOffset = offset; }
164  virtual void SetRange(Bool_t range = kTRUE) { fIsRange = range; }
165  virtual void SetUnsigned() { fIsUnsigned = kTRUE; }
166 
167  ClassDef(TLeaf, 2); // Leaf: description of a Branch data type
168 };
169 
170 
171 template <> struct TLeaf::GetValueHelper<Long64_t> {
172  static Long64_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLong64(i); }
173 };
174 template <> struct TLeaf::GetValueHelper<ULong64_t> {
175  static ULong64_t Exec(const TLeaf *leaf, Int_t i = 0) { return (ULong64_t)leaf->GetValueLong64(i); }
176 };
177 template <> struct TLeaf::GetValueHelper<LongDouble_t> {
178  static LongDouble_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLongDouble(i); }
179 };
180 
181 
182 inline Double_t TLeaf::GetValue(Int_t /*i = 0*/) const { return 0.0; }
183 inline void TLeaf::PrintValue(Int_t /* i = 0*/) const {}
184 inline void TLeaf::SetAddress(void* /* add = 0 */) {}
185 
186 #endif
TLeaf::IsUnsigned
virtual Bool_t IsUnsigned() const
Definition: TLeaf.h:149
TBrowser
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TLeaf::GetLeafCounter
virtual TLeaf * GetLeafCounter(Int_t &countval) const
Return a pointer to the counter of this leaf (if any) or store the number of elements that the leaf c...
Definition: TLeaf.cxx:226
TLeaf::PrintValue
virtual void PrintValue(Int_t i=0) const
Definition: TLeaf.h:183
TLeaf::GetValueLong64
virtual Long64_t GetValueLong64(Int_t i=0) const
Definition: TLeaf.h:141
TLeaf::SetRange
virtual void SetRange(Bool_t range=kTRUE)
Definition: TLeaf.h:164
TLeaf::GetLeafCountValues
virtual const Counts_t * GetLeafCountValues(Long64_t start, Long64_t len)
If this branch is a branch count, return the set of collection size for the entry range requested sta...
Definition: TLeaf.cxx:341
TLeaf::Counts_t
std::vector< Int_t > Counts_t
Definition: TLeaf.h:65
TLeaf::GetValueHelper::Exec
static T Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:85
TBranch.h
TNamed.h
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TLeaf::GetTypeName
virtual const char * GetTypeName() const
Definition: TLeaf.h:138
TLeaf::Import
virtual void Import(TClonesArray *, Int_t)
Definition: TLeaf.h:146
Int_t
int Int_t
Definition: RtypesCore.h:45
TLeaf::LeafCountValues
Definition: TLeaf.h:66
TLeaf::SetLen
virtual void SetLen(Int_t len=1)
Definition: TLeaf.h:162
TLeaf::GetValueLongDouble
virtual LongDouble_t GetValueLongDouble(Int_t i=0) const
Definition: TLeaf.h:142
TLeaf::GetOffsetHeaderSize
virtual Int_t GetOffsetHeaderSize() const
Definition: TLeaf.h:61
TLeaf::SetAddress
virtual void SetAddress(void *add=0)
Definition: TLeaf.h:184
TLeaf::GetValue
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:182
TLeaf::GenerateOffsetArray
virtual Int_t * GenerateOffsetArray(Int_t base, Int_t events)
Definition: TLeaf.h:114
TLeaf::GetValueHelper< LongDouble_t >::Exec
static LongDouble_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:178
TBuffer
Buffer base class used for serializing objects.
Definition: TBuffer.h:43
TLeaf::GetFullName
virtual TString GetFullName() const
Return the full name (including the parent's branch names) of the leaf.
Definition: TLeaf.cxx:201
TLeaf::GetLenType
virtual Int_t GetLenType() const
Definition: TLeaf.h:132
TLeaf::GetOffset
virtual Int_t GetOffset() const
Definition: TLeaf.h:136
TString
Basic string class.
Definition: TString.h:136
TLeaf::GenerateOffsetArrayBase
Int_t * GenerateOffsetArrayBase(Int_t base, Int_t events) const
If the class supports it, generate an offset array base.
Definition: TLeaf.cxx:165
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
b
#define b(i)
Definition: RSha256.hxx:100
bool
TLeaf::LeafCountValues::fStartEntry
Long64_t fStartEntry
! entry number of corresponding to element 0 of the vector.
Definition: TLeaf.h:68
TLeaf::IncludeRange
virtual Bool_t IncludeRange(TLeaf *)
Definition: TLeaf.h:145
TLeaf::fLenType
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:73
TBranch
A TTree is a list of TBranches.
Definition: TBranch.h:89
TLeaf::SetBranch
virtual void SetBranch(TBranch *branch)
Definition: TLeaf.h:160
TLeaf::LeafCountValues::fValues
Counts_t fValues
Definition: TLeaf.h:67
TLeaf::Export
virtual void Export(TClonesArray *, Int_t)
Definition: TLeaf.h:112
TLeaf::ReadBasketFast
virtual bool ReadBasketFast(TBuffer &, Long64_t)
Definition: TLeaf.h:153
TLeaf::FillBasket
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeaf.cxx:157
TLeaf::kNewValue
@ kNewValue
Set if we own the value buffer and so must delete it ourselves.
Definition: TLeaf.h:96
TLeaf::DeserializeType::kDestructive
@ kDestructive
TLeaf::GetDeserializeType
virtual DeserializeType GetDeserializeType() const
Definition: TLeaf.h:116
TLeaf::GetValueHelper< Long64_t >::Exec
static Long64_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:172
TLeaf
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:57
TLeaf::GetLeafCount
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
Definition: TLeaf.h:120
TLeaf::fLen
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition: TLeaf.h:72
TLeaf::fLeafCountValues
LeafCountValues * fLeafCountValues
! Cache of collection/array sizes
Definition: TLeaf.h:79
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TLeaf::DeserializeType::kInvalid
@ kInvalid
TLeaf::kIndirectAddress
@ kIndirectAddress
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:95
BIT
#define BIT(n)
Definition: Rtypes.h:85
TLeaf::SetLeafCount
virtual void SetLeafCount(TLeaf *leaf)
Set the leaf count of this leaf.
Definition: TLeaf.cxx:442
TLeaf::ReadBasketSerialized
virtual bool ReadBasketSerialized(TBuffer &, Long64_t)
Definition: TLeaf.h:154
TLeaf::IsRange
virtual Bool_t IsRange() const
Definition: TLeaf.h:148
TLeaf::fIsRange
Bool_t fIsRange
(=kTRUE if leaf has a range, kFALSE otherwise). This is equivalent to being a 'leafcount'....
Definition: TLeaf.h:75
TLeaf::CanGenerateOffsetArray
virtual Bool_t CanGenerateOffsetArray()
Definition: TLeaf.h:111
TLeaf::fIsUnsigned
Bool_t fIsUnsigned
(=kTRUE if unsigned, kFALSE otherwise)
Definition: TLeaf.h:76
TLeaf::SetOffset
virtual void SetOffset(Int_t offset=0)
Definition: TLeaf.h:163
TLeaf::GetValuePointer
virtual void * GetValuePointer() const
Definition: TLeaf.h:137
TLeaf::ResetAddress
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:406
TLeaf::DeserializeType::kInPlace
@ kInPlace
TLeaf::fOffset
Int_t fOffset
Offset in ClonesArray object (if one)
Definition: TLeaf.h:74
TLeaf::GetLenStatic
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
Definition: TLeaf.h:131
TLeaf::GetValueHelper< ULong64_t >::Exec
static ULong64_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:175
TLeaf::fNdata
Int_t fNdata
! Number of elements in fAddress data buffer.
Definition: TLeaf.h:71
TLeaf::GetLen
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition: TLeaf.cxx:381
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
TLeaf::GetBranch
TBranch * GetBranch() const
Definition: TLeaf.h:115
TLeaf::GetMaximum
virtual Int_t GetMaximum() const
Definition: TLeaf.h:133
LongDouble_t
long double LongDouble_t
Definition: RtypesCore.h:61
Double_t
double Double_t
Definition: RtypesCore.h:59
TLeaf::TLeaf
TLeaf()
Definition: TLeaf.cxx:32
TLeaf::GetMinimum
virtual Int_t GetMinimum() const
Definition: TLeaf.h:134
TLeaf::ReadBasketExport
virtual void ReadBasketExport(TBuffer &, TClonesArray *, Int_t)
Definition: TLeaf.h:152
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TLeaf::ReadBasket
virtual void ReadBasket(TBuffer &)
Definition: TLeaf.h:151
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
TLeaf::fLeafCount
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition: TLeaf.h:77
TLeaf::operator=
TLeaf & operator=(const TLeaf &)
Assignment operator.
Definition: TLeaf.cxx:94
TLeaf::DeserializeType::kZeroCopy
@ kZeroCopy
TLeaf::ReadValue
virtual void ReadValue(std::istream &, Char_t=' ')
Definition: TLeaf.h:155
type
int type
Definition: TGX11.cxx:121
TLeaf::DeserializeType
DeserializeType
Definition: TLeaf.h:99
TLeaf::SetUnsigned
virtual void SetUnsigned()
Definition: TLeaf.h:165
TLeaf::GetValueHelper
Definition: TLeaf.h:84
Char_t
char Char_t
Definition: RtypesCore.h:33
TLeaf::Browse
virtual void Browse(TBrowser *b)
Browse the content of this leaf.
Definition: TLeaf.cxx:134
TClonesArray
An array of clone (identical) objects.
Definition: TClonesArray.h:29
TObject::EStatusBits
EStatusBits
Definition: TObject.h:57
TLeaf::GetTypedValue
T GetTypedValue(Int_t i=0) const
Definition: TLeaf.h:143
TLeaf::GetNdata
virtual Int_t GetNdata() const
Definition: TLeaf.h:135
TLeaf::fBranch
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:78
TLeaf::IsOnTerminalBranch
virtual Bool_t IsOnTerminalBranch() const
Definition: TLeaf.h:147
int
TLeaf::~TLeaf
virtual ~TLeaf()
Destructor.
Definition: TLeaf.cxx:117