Logo ROOT   6.16/01
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. //
22// A TLeaf describes the branch data types. //
23// //
24//////////////////////////////////////////////////////////////////////////
25
26
27#include "TBranch.h"
28
29class TClonesArray;
30class TBrowser;
31
32class TLeaf : public TNamed {
33
34private:
35
36 virtual Int_t GetOffsetHeaderSize() const {return 0;}
37
38protected:
39
40 Int_t fNdata; ///<! Number of elements in fAddress data buffer
41 Int_t fLen; ///< Number of fixed length elements
42 Int_t fLenType; ///< Number of bytes for this data type
43 Int_t fOffset; ///< Offset in ClonesArray object (if one)
44 Bool_t fIsRange; ///< (=kTRUE if leaf has a range, kFALSE otherwise)
45 Bool_t fIsUnsigned; ///< (=kTRUE if unsigned, kFALSE otherwise)
46 TLeaf *fLeafCount; ///< Pointer to Leaf count if variable length (we do not own the counter)
47 TBranch *fBranch; ///<! Pointer to supporting branch (we do not own the branch)
48
49 TLeaf(const TLeaf&);
50 TLeaf& operator=(const TLeaf&);
51
52 template <typename T> struct GetValueHelper {
53 static T Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValue(i); }
54 };
55
56 Int_t *GenerateOffsetArrayBase(Int_t base, Int_t events) const; // For leaves containing fixed-size objects (no
57 // polymorphism!), this will generate an appropriate
58 // offset array.
59
60public:
62 kIndirectAddress = BIT(11), ///< Data member is a pointer to an array of basic types.
63 kNewValue = BIT(12) ///< Set if we own the value buffer and so must delete it ourselves.
64 };
65
66 TLeaf();
67 TLeaf(TBranch *parent, const char *name, const char *type);
68 virtual ~TLeaf();
69
70 virtual void Browse(TBrowser *b);
71 virtual Bool_t CanGenerateOffsetArray() {return fLeafCount;} // overload and return true if this leaf can generate its own offset array.
72 virtual void Export(TClonesArray *, Int_t) {}
73 virtual void FillBasket(TBuffer &b);
74 virtual Int_t *GenerateOffsetArray(Int_t base, Int_t events) { return GenerateOffsetArrayBase(base, events); }
75 TBranch *GetBranch() const { return fBranch; }
76 /// If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has variable size,
77 /// return a pointer to the TLeaf that stores such size. Return a nullptr otherwise.
78 virtual TLeaf *GetLeafCount() const { return fLeafCount; }
79 virtual TLeaf *GetLeafCounter(Int_t &countval) const;
80 virtual Int_t GetLen() const;
81 /// Return the fixed length of this leaf.
82 /// If the leaf stores a fixed-length array, this is the size of the array.
83 /// If the leaf stores a non-array or a variable-sized array, this method returns 1.
84 /// If the leaf stores an array with 2 or more dimensions, this method returns the total number of elements in the
85 /// dimensions with static length: for example for float[3][2][] it would return 6.
86 virtual Int_t GetLenStatic() const { return fLen; }
87 virtual Int_t GetLenType() const { return fLenType; }
88 virtual Int_t GetMaximum() const { return 0; }
89 virtual Int_t GetMinimum() const { return 0; }
90 virtual Int_t GetNdata() const { return fNdata; }
91 virtual Int_t GetOffset() const { return fOffset; }
92 virtual void *GetValuePointer() const { return 0; }
93 virtual const char *GetTypeName() const { return ""; }
94
95 virtual Double_t GetValue(Int_t i = 0) const;
96 virtual Long64_t GetValueLong64(Int_t i = 0) const { return GetValue(i); } // overload only when it matters.
97 virtual LongDouble_t GetValueLongDouble(Int_t i = 0) const { return GetValue(i); } // overload only when it matters.
98 template <typename T> T GetTypedValue(Int_t i = 0) const { return GetValueHelper<T>::Exec(this, i); }
99
100 virtual Bool_t IncludeRange(TLeaf *) { return kFALSE; } // overload to copy/set fMinimum and fMaximum to include/be wide than those of the parameter
101 virtual void Import(TClonesArray *, Int_t) {}
102 virtual Bool_t IsOnTerminalBranch() const { return kTRUE; }
103 virtual Bool_t IsRange() const { return fIsRange; }
104 virtual Bool_t IsUnsigned() const { return fIsUnsigned; }
105 virtual void PrintValue(Int_t i = 0) const;
106 virtual void ReadBasket(TBuffer &) {}
108 virtual void ReadValue(std::istream & /*s*/, Char_t /*delim*/ = ' ') {
109 Error("ReadValue", "Not implemented!");
110 }
111 Int_t ResetAddress(void *add, Bool_t destructor = kFALSE);
112 virtual void SetAddress(void *add = 0);
113 virtual void SetBranch(TBranch *branch) { fBranch = branch; }
114 virtual void SetLeafCount(TLeaf *leaf);
115 virtual void SetLen(Int_t len = 1) { fLen = len; }
116 virtual void SetOffset(Int_t offset = 0) { fOffset = offset; }
117 virtual void SetRange(Bool_t range = kTRUE) { fIsRange = range; }
118 virtual void SetUnsigned() { fIsUnsigned = kTRUE; }
119
120 ClassDef(TLeaf, 2); // Leaf: description of a Branch data type
121};
122
123
124template <> struct TLeaf::GetValueHelper<Long64_t> {
125 static Long64_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLong64(i); }
126};
127template <> struct TLeaf::GetValueHelper<ULong64_t> {
128 static ULong64_t Exec(const TLeaf *leaf, Int_t i = 0) { return (ULong64_t)leaf->GetValueLong64(i); }
129};
131 static LongDouble_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLongDouble(i); }
132};
133
134
135inline Double_t TLeaf::GetValue(Int_t /*i = 0*/) const { return 0.0; }
136inline void TLeaf::PrintValue(Int_t /* i = 0*/) const {}
137inline void TLeaf::SetAddress(void* /* add = 0 */) {}
138
139#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:324
#define BIT(n)
Definition: Rtypes.h:82
int type
Definition: TGX11.cxx:120
A TTree is a list of TBranches.
Definition: TBranch.h:64
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:37
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
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:32
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:135
virtual void * GetValuePointer() const
Definition: TLeaf.h:92
virtual Bool_t IsRange() const
Definition: TLeaf.h:103
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:42
virtual void SetLen(Int_t len=1)
Definition: TLeaf.h:115
virtual Bool_t IsOnTerminalBranch() const
Definition: TLeaf.h:102
virtual Int_t GetLenType() const
Definition: TLeaf.h:87
T GetTypedValue(Int_t i=0) const
Definition: TLeaf.h:98
virtual void ReadValue(std::istream &, Char_t=' ')
Definition: TLeaf.h:108
virtual Int_t GetMaximum() const
Definition: TLeaf.h:88
virtual const char * GetTypeName() const
Definition: TLeaf.h:93
virtual LongDouble_t GetValueLongDouble(Int_t i=0) const
Definition: TLeaf.h:97
virtual void Browse(TBrowser *b)
Browse the content of this leaf.
Definition: TLeaf.cxx:126
Int_t fLen
Number of fixed length elements.
Definition: TLeaf.h:41
Int_t fNdata
! Number of elements in fAddress data buffer
Definition: TLeaf.h:40
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:78
virtual Bool_t IncludeRange(TLeaf *)
Definition: TLeaf.h:100
virtual void Export(TClonesArray *, Int_t)
Definition: TLeaf.h:72
virtual void ReadBasketExport(TBuffer &, TClonesArray *, Int_t)
Definition: TLeaf.h:107
Bool_t fIsUnsigned
(=kTRUE if unsigned, kFALSE otherwise)
Definition: TLeaf.h:45
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:137
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
virtual Long64_t GetValueLong64(Int_t i=0) const
Definition: TLeaf.h:96
virtual void SetRange(Bool_t range=kTRUE)
Definition: TLeaf.h:117
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:90
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:75
virtual void SetOffset(Int_t offset=0)
Definition: TLeaf.h:116
Int_t fOffset
Offset in ClonesArray object (if one)
Definition: TLeaf.h:43
virtual Int_t GetOffsetHeaderSize() const
Definition: TLeaf.h:36
virtual Int_t GetMinimum() const
Definition: TLeaf.h:89
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:47
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition: TLeaf.h:46
virtual void SetBranch(TBranch *branch)
Definition: TLeaf.h:113
Bool_t fIsRange
(=kTRUE if leaf has a range, kFALSE otherwise)
Definition: TLeaf.h:44
@ kNewValue
Set if we own the value buffer and so must delete it ourselves.
Definition: TLeaf.h:63
@ kIndirectAddress
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:62
virtual void SetLeafCount(TLeaf *leaf)
Set the leaf count of this leaf.
Definition: TLeaf.cxx:372
virtual void SetUnsigned()
Definition: TLeaf.h:118
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
Definition: TLeaf.h:86
virtual Bool_t CanGenerateOffsetArray()
Definition: TLeaf.h:71
virtual Int_t GetOffset() const
Definition: TLeaf.h:91
virtual Bool_t IsUnsigned() const
Definition: TLeaf.h:104
virtual void ReadBasket(TBuffer &)
Definition: TLeaf.h:106
virtual Int_t * GenerateOffsetArray(Int_t base, Int_t events)
Definition: TLeaf.h:74
virtual void Import(TClonesArray *, Int_t)
Definition: TLeaf.h:101
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:136
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:125
static LongDouble_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:131
static ULong64_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:128
static T Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:53