Logo ROOT   6.18/05
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 "TBranch.h"
45
46class TClonesArray;
47class TBrowser;
48
49class TLeaf : public TNamed {
50
51private:
52
53 virtual Int_t GetOffsetHeaderSize() const {return 0;}
54
55protected:
56
57 Int_t fNdata; ///<! Number of elements in fAddress data buffer.
58 Int_t fLen; ///< Number of fixed length elements in the leaf's data.
59 Int_t fLenType; ///< Number of bytes for this data type
60 Int_t fOffset; ///< Offset in ClonesArray object (if one)
61 Bool_t fIsRange; ///< (=kTRUE if leaf has a range, kFALSE otherwise)
62 Bool_t fIsUnsigned; ///< (=kTRUE if unsigned, kFALSE otherwise)
63 TLeaf *fLeafCount; ///< Pointer to Leaf count if variable length (we do not own the counter)
64 TBranch *fBranch; ///<! Pointer to supporting branch (we do not own the branch)
65
66 TLeaf(const TLeaf&);
67 TLeaf& operator=(const TLeaf&);
68
69 template <typename T> struct GetValueHelper {
70 static T Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValue(i); }
71 };
72
73 Int_t *GenerateOffsetArrayBase(Int_t base, Int_t events) const; // For leaves containing fixed-size objects (no
74 // polymorphism!), this will generate an appropriate
75 // offset array.
76
77public:
79 kIndirectAddress = BIT(11), ///< Data member is a pointer to an array of basic types.
80 kNewValue = BIT(12) ///< Set if we own the value buffer and so must delete it ourselves.
81 };
82
83 enum class DeserializeType {
84 kInvalid = 0, // Invalid deserialization information.
85 kDestructive, // Deserialization of this Leaf requires a separate output buffer.
86 kInPlace, // Deserialization can be done directly in the input buffer.
87 kZeroCopy, // In-memory and on-disk representation of this object are identical.
88 };
89
90 TLeaf();
91 TLeaf(TBranch *parent, const char *name, const char *type);
92 virtual ~TLeaf();
93
94 virtual void Browse(TBrowser *b);
95 virtual Bool_t CanGenerateOffsetArray() {return fLeafCount;} // overload and return true if this leaf can generate its own offset array.
96 virtual void Export(TClonesArray *, Int_t) {}
97 virtual void FillBasket(TBuffer &b);
98 virtual Int_t *GenerateOffsetArray(Int_t base, Int_t events) { return GenerateOffsetArrayBase(base, events); }
99 TBranch *GetBranch() const { return fBranch; }
101 /// If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has variable size,
102 /// return a pointer to the TLeaf that stores such size. Return a nullptr otherwise.
103 virtual TLeaf *GetLeafCount() const { return fLeafCount; }
104 virtual TLeaf *GetLeafCounter(Int_t &countval) const;
105 virtual Int_t GetLen() const;
106 /// Return the fixed length of this leaf.
107 /// If the leaf stores a fixed-length array, this is the size of the array.
108 /// If the leaf stores a non-array or a variable-sized array, this method returns 1.
109 /// If the leaf stores an array with 2 or more dimensions, this method returns the total number of elements in the
110 /// dimensions with static length: for example for float[3][2][] it would return 6.
111 virtual Int_t GetLenStatic() const { return fLen; }
112 virtual Int_t GetLenType() const { return fLenType; }
113 virtual Int_t GetMaximum() const { return 0; }
114 virtual Int_t GetMinimum() const { return 0; }
115 virtual Int_t GetNdata() const { return fNdata; }
116 virtual Int_t GetOffset() const { return fOffset; }
117 virtual void *GetValuePointer() const { return 0; }
118 virtual const char *GetTypeName() const { return ""; }
119
120 virtual Double_t GetValue(Int_t i = 0) const;
121 virtual Long64_t GetValueLong64(Int_t i = 0) const { return GetValue(i); } // overload only when it matters.
122 virtual LongDouble_t GetValueLongDouble(Int_t i = 0) const { return GetValue(i); } // overload only when it matters.
123 template <typename T> T GetTypedValue(Int_t i = 0) const { return GetValueHelper<T>::Exec(this, i); }
124
125 virtual Bool_t IncludeRange(TLeaf *) { return kFALSE; } // overload to copy/set fMinimum and fMaximum to include/be wide than those of the parameter
126 virtual void Import(TClonesArray *, Int_t) {}
127 virtual Bool_t IsOnTerminalBranch() const { return kTRUE; }
128 virtual Bool_t IsRange() const { return fIsRange; }
129 virtual Bool_t IsUnsigned() const { return fIsUnsigned; }
130 virtual void PrintValue(Int_t i = 0) const;
131 virtual void ReadBasket(TBuffer &) {}
133 virtual bool ReadBasketFast(TBuffer&, Long64_t) { return false; } // Read contents of leaf into a user-provided buffer.
134 virtual bool ReadBasketSerialized(TBuffer&, Long64_t) { return false; } // Read contents of leaf into a user-provided buffer
135 virtual void ReadValue(std::istream & /*s*/, Char_t /*delim*/ = ' ') {
136 Error("ReadValue", "Not implemented!");
137 }
138 Int_t ResetAddress(void *add, Bool_t destructor = kFALSE);
139 virtual void SetAddress(void *add = 0);
140 virtual void SetBranch(TBranch *branch) { fBranch = branch; }
141 virtual void SetLeafCount(TLeaf *leaf);
142 virtual void SetLen(Int_t len = 1) { fLen = len; }
143 virtual void SetOffset(Int_t offset = 0) { fOffset = offset; }
144 virtual void SetRange(Bool_t range = kTRUE) { fIsRange = range; }
145 virtual void SetUnsigned() { fIsUnsigned = kTRUE; }
146
147 ClassDef(TLeaf, 2); // Leaf: description of a Branch data type
148};
149
150
151template <> struct TLeaf::GetValueHelper<Long64_t> {
152 static Long64_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLong64(i); }
153};
154template <> struct TLeaf::GetValueHelper<ULong64_t> {
155 static ULong64_t Exec(const TLeaf *leaf, Int_t i = 0) { return (ULong64_t)leaf->GetValueLong64(i); }
156};
158 static LongDouble_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLongDouble(i); }
159};
160
161
162inline Double_t TLeaf::GetValue(Int_t /*i = 0*/) const { return 0.0; }
163inline void TLeaf::PrintValue(Int_t /* i = 0*/) const {}
164inline void TLeaf::SetAddress(void* /* add = 0 */) {}
165
166#endif
#define b(i)
Definition: RSha256.hxx:100
int Int_t
Definition: RtypesCore.h:41
char Char_t
Definition: RtypesCore.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
long double LongDouble_t
Definition: RtypesCore.h:57
long long Long64_t
Definition: RtypesCore.h:69
unsigned long long ULong64_t
Definition: RtypesCore.h:70
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
#define BIT(n)
Definition: Rtypes.h:83
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
@ kInvalid
Definition: TSystem.h:80
A TTree is a list of TBranches.
Definition: TBranch.h:65
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
An array of clone (identical) objects.
Definition: TClonesArray.h:32
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:49
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:162
virtual void * GetValuePointer() const
Definition: TLeaf.h:117
virtual Bool_t IsRange() const
Definition: TLeaf.h:128
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:59
virtual bool ReadBasketSerialized(TBuffer &, Long64_t)
Definition: TLeaf.h:134
virtual void SetLen(Int_t len=1)
Definition: TLeaf.h:142
virtual Bool_t IsOnTerminalBranch() const
Definition: TLeaf.h:127
virtual Int_t GetLenType() const
Definition: TLeaf.h:112
T GetTypedValue(Int_t i=0) const
Definition: TLeaf.h:123
virtual void ReadValue(std::istream &, Char_t=' ')
Definition: TLeaf.h:135
virtual Int_t GetMaximum() const
Definition: TLeaf.h:113
virtual const char * GetTypeName() const
Definition: TLeaf.h:118
virtual LongDouble_t GetValueLongDouble(Int_t i=0) const
Definition: TLeaf.h:122
virtual void Browse(TBrowser *b)
Browse the content of this leaf.
Definition: TLeaf.cxx:126
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition: TLeaf.h:58
Int_t fNdata
! Number of elements in fAddress data buffer.
Definition: TLeaf.h:57
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition: TLeaf.cxx:311
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:103
virtual Bool_t IncludeRange(TLeaf *)
Definition: TLeaf.h:125
virtual void Export(TClonesArray *, Int_t)
Definition: TLeaf.h:96
virtual DeserializeType GetDeserializeType() const
Definition: TLeaf.h:100
virtual void ReadBasketExport(TBuffer &, TClonesArray *, Int_t)
Definition: TLeaf.h:132
Bool_t fIsUnsigned
(=kTRUE if unsigned, kFALSE otherwise)
Definition: TLeaf.h:62
virtual ~TLeaf()
Destructor.
Definition: TLeaf.cxx:110
TLeaf & operator=(const TLeaf &)
Assignment operator.
Definition: TLeaf.cxx:91
virtual void SetAddress(void *add=0)
Definition: TLeaf.h:164
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:198
DeserializeType
Definition: TLeaf.h:83
virtual Long64_t GetValueLong64(Int_t i=0) const
Definition: TLeaf.h:121
virtual void SetRange(Bool_t range=kTRUE)
Definition: TLeaf.h:144
Int_t * GenerateOffsetArrayBase(Int_t base, Int_t events) const
If the class supports it, generate an offset array base.
Definition: TLeaf.cxx:157
virtual Int_t GetNdata() const
Definition: TLeaf.h:115
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeaf.cxx:149
TLeaf()
Definition: TLeaf.cxx:32
TBranch * GetBranch() const
Definition: TLeaf.h:99
virtual void SetOffset(Int_t offset=0)
Definition: TLeaf.h:143
Int_t fOffset
Offset in ClonesArray object (if one)
Definition: TLeaf.h:60
virtual bool ReadBasketFast(TBuffer &, Long64_t)
Definition: TLeaf.h:133
virtual Int_t GetOffsetHeaderSize() const
Definition: TLeaf.h:53
virtual Int_t GetMinimum() const
Definition: TLeaf.h:114
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:64
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition: TLeaf.h:63
virtual void SetBranch(TBranch *branch)
Definition: TLeaf.h:140
Bool_t fIsRange
(=kTRUE if leaf has a range, kFALSE otherwise)
Definition: TLeaf.h:61
@ kNewValue
Set if we own the value buffer and so must delete it ourselves.
Definition: TLeaf.h:80
@ kIndirectAddress
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:79
virtual void SetLeafCount(TLeaf *leaf)
Set the leaf count of this leaf.
Definition: TLeaf.cxx:372
virtual void SetUnsigned()
Definition: TLeaf.h:145
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
Definition: TLeaf.h:111
virtual Bool_t CanGenerateOffsetArray()
Definition: TLeaf.h:95
virtual Int_t GetOffset() const
Definition: TLeaf.h:116
virtual Bool_t IsUnsigned() const
Definition: TLeaf.h:129
virtual void ReadBasket(TBuffer &)
Definition: TLeaf.h:131
virtual Int_t * GenerateOffsetArray(Int_t base, Int_t events)
Definition: TLeaf.h:98
virtual void Import(TClonesArray *, Int_t)
Definition: TLeaf.h:126
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:336
virtual void PrintValue(Int_t i=0) const
Definition: TLeaf.h:163
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
EStatusBits
Definition: TObject.h:57
double T(double x)
Definition: ChebyshevPol.h:34
static Long64_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:152
static LongDouble_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:158
static ULong64_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:155
static T Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:70