Logo ROOT   6.08/07
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 #ifndef ROOT_TBranch
28 #include "TBranch.h"
29 #endif
30 #ifndef ROOT_Riosfwd
31 #include "Riosfwd.h"
32 #endif
33 
34 class TClonesArray;
35 class TBrowser;
36 
37 class TLeaf : public TNamed {
38 
39 protected:
40 
41  Int_t fNdata; ///<! Number of elements in fAddress data buffer
42  Int_t fLen; ///< Number of fixed length elements
43  Int_t fLenType; ///< Number of bytes for this data type
44  Int_t fOffset; ///< Offset in ClonesArray object (if one)
45  Bool_t fIsRange; ///< (=kTRUE if leaf has a range, kFALSE otherwise)
46  Bool_t fIsUnsigned; ///< (=kTRUE if unsigned, kFALSE otherwise)
47  TLeaf *fLeafCount; ///< Pointer to Leaf count if variable length (we do not own the counter)
48  TBranch *fBranch; ///<! Pointer to supporting branch (we do not own the branch)
49 
50  TLeaf(const TLeaf&);
51  TLeaf& operator=(const TLeaf&);
52 
53  template <typename T> struct GetValueHelper {
54  static T Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValue(i); }
55  };
56 
57 public:
58  enum {
59  kIndirectAddress = BIT(11), ///< Data member is a pointer to an array of basic types.
60  kNewValue = BIT(12) ///< Set if we own the value buffer and so must delete it ourselves.
61  };
62 
63  TLeaf();
64  TLeaf(TBranch *parent, const char* name, const char* type);
65  virtual ~TLeaf();
66 
67  virtual void Browse(TBrowser* b);
68  virtual void Export(TClonesArray*, Int_t) {}
69  virtual void FillBasket(TBuffer& b);
70  TBranch *GetBranch() const { return fBranch; }
71  virtual TLeaf *GetLeafCount() const { return fLeafCount; }
72  virtual TLeaf *GetLeafCounter(Int_t& countval) const;
73  virtual Int_t GetLen() const;
74  virtual Int_t GetLenStatic() const { return fLen; }
75  virtual Int_t GetLenType() const { return fLenType; }
76  virtual Int_t GetMaximum() const { return 0; }
77  virtual Int_t GetMinimum() const { return 0; }
78  virtual Int_t GetNdata() const { return fNdata; }
79  virtual Int_t GetOffset() const { return fOffset; }
80  virtual void *GetValuePointer() const { return 0; }
81  virtual const char *GetTypeName() const { return ""; }
82 
83  virtual Double_t GetValue(Int_t i = 0) const;
84  virtual Long64_t GetValueLong64(Int_t i = 0) const { return GetValue(i); } //overload only when it matters.
85  virtual LongDouble_t GetValueLongDouble(Int_t i = 0) const { return GetValue(i); } // overload only when it matters.
86  template <typename T > T GetTypedValue(Int_t i = 0) const { return GetValueHelper<T>::Exec(this, i); }
87 
88  virtual void Import(TClonesArray*, Int_t) {}
89  virtual Bool_t IsOnTerminalBranch() const { return kTRUE; }
90  virtual Bool_t IsRange() const { return fIsRange; }
91  virtual Bool_t IsUnsigned() const { return fIsUnsigned; }
92  virtual void PrintValue(Int_t i = 0) const;
93  virtual void ReadBasket(TBuffer&) {}
95  virtual void ReadValue(std::istream& /*s*/, Char_t /*delim*/ = ' ') {
96  Error("ReadValue", "Not implemented!");
97  }
98  Int_t ResetAddress(void* add, Bool_t destructor = kFALSE);
99  virtual void SetAddress(void* add = 0);
100  virtual void SetBranch(TBranch* branch) { fBranch = branch; }
101  virtual void SetLeafCount(TLeaf* leaf);
102  virtual void SetLen(Int_t len = 1) { fLen = len; }
103  virtual void SetOffset(Int_t offset = 0) { fOffset = offset; }
104  virtual void SetRange(Bool_t range = kTRUE) { fIsRange = range; }
105  virtual void SetUnsigned() { fIsUnsigned = kTRUE; }
106 
107  ClassDef(TLeaf,2); //Leaf: description of a Branch data type
108 };
109 
110 
111 template <> struct TLeaf::GetValueHelper<Long64_t> {
112  static Long64_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLong64(i); }
113 };
114 template <> struct TLeaf::GetValueHelper<ULong64_t> {
115  static ULong64_t Exec(const TLeaf *leaf, Int_t i = 0) { return (ULong64_t)leaf->GetValueLong64(i); }
116 };
117 template <> struct TLeaf::GetValueHelper<LongDouble_t> {
118  static LongDouble_t Exec(const TLeaf *leaf, Int_t i = 0) { return leaf->GetValueLongDouble(i); }
119 };
120 
121 
122 inline Double_t TLeaf::GetValue(Int_t /*i = 0*/) const { return 0.0; }
123 inline void TLeaf::PrintValue(Int_t /* i = 0*/) const {}
124 inline void TLeaf::SetAddress(void* /* add = 0 */) {}
125 
126 #endif
virtual ~TLeaf()
Destructor.
Definition: TLeaf.cxx:110
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:37
long long Long64_t
Definition: RtypesCore.h:69
double T(double x)
Definition: ChebyshevPol.h:34
#define BIT(n)
Definition: Rtypes.h:120
virtual Bool_t IsUnsigned() const
Definition: TLeaf.h:91
virtual const char * GetTypeName() const
Definition: TLeaf.h:81
virtual TLeaf * GetLeafCounter(Int_t &countval) const
Return a pointer to the counter of this leaf.
Definition: TLeaf.cxx:168
virtual void PrintValue(Int_t i=0) const
Definition: TLeaf.h:123
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual Int_t GetOffset() const
Definition: TLeaf.h:79
virtual void Import(TClonesArray *, Int_t)
Definition: TLeaf.h:88
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Long64_t GetValueLong64(Int_t i=0) const
Definition: TLeaf.h:84
static Long64_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:112
virtual LongDouble_t GetValueLongDouble(Int_t i=0) const
Definition: TLeaf.h:85
Set if we own the value buffer and so must delete it ourselves.
Definition: TLeaf.h:60
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:43
static ULong64_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:115
virtual void SetRange(Bool_t range=kTRUE)
Definition: TLeaf.h:104
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:122
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual void SetLen(Int_t len=1)
Definition: TLeaf.h:102
virtual Bool_t IsRange() const
Definition: TLeaf.h:90
virtual Int_t GetLenType() const
Definition: TLeaf.h:75
virtual void SetBranch(TBranch *branch)
Definition: TLeaf.h:100
Int_t fLen
Number of fixed length elements.
Definition: TLeaf.h:42
virtual void Export(TClonesArray *, Int_t)
Definition: TLeaf.h:68
virtual void SetAddress(void *add=0)
Definition: TLeaf.h:124
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeaf.cxx:149
Using a TBrowser one can browse all ROOT objects.
Definition: TBrowser.h:41
virtual Int_t GetLen() const
Return the number of effective elements of this leaf.
Definition: TLeaf.cxx:279
Int_t fNdata
! Number of elements in fAddress data buffer
Definition: TLeaf.h:41
static T Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:54
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:925
virtual TLeaf * GetLeafCount() const
Definition: TLeaf.h:71
virtual void * GetValuePointer() const
Definition: TLeaf.h:80
long double LongDouble_t
Definition: RtypesCore.h:57
virtual Int_t GetMinimum() const
Definition: TLeaf.h:77
virtual void SetLeafCount(TLeaf *leaf)
Set the leaf count of this leaf.
Definition: TLeaf.cxx:340
virtual Int_t GetLenStatic() const
Definition: TLeaf.h:74
virtual void SetOffset(Int_t offset=0)
Definition: TLeaf.h:103
static LongDouble_t Exec(const TLeaf *leaf, Int_t i=0)
Definition: TLeaf.h:118
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:59
virtual Int_t GetMaximum() const
Definition: TLeaf.h:76
double Double_t
Definition: RtypesCore.h:55
virtual void Browse(TBrowser *b)
Browse the content of this leaf.
Definition: TLeaf.cxx:126
int type
Definition: TGX11.cxx:120
unsigned long long ULong64_t
Definition: RtypesCore.h:70
Bool_t fIsUnsigned
(=kTRUE if unsigned, kFALSE otherwise)
Definition: TLeaf.h:46
virtual void ReadBasket(TBuffer &)
Definition: TLeaf.h:93
virtual void SetUnsigned()
Definition: TLeaf.h:105
virtual void ReadBasketExport(TBuffer &, TClonesArray *, Int_t)
Definition: TLeaf.h:94
virtual void ReadValue(std::istream &, Char_t=' ')
Definition: TLeaf.h:95
Int_t fOffset
Offset in ClonesArray object (if one)
Definition: TLeaf.h:44
char Char_t
Definition: RtypesCore.h:29
An array of clone (identical) objects.
Definition: TClonesArray.h:32
Bool_t fIsRange
(=kTRUE if leaf has a range, kFALSE otherwise)
Definition: TLeaf.h:45
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:48
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:304
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition: TLeaf.h:47
TLeaf()
Definition: TLeaf.cxx:32
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
TLeaf & operator=(const TLeaf &)
Assignment operator.
Definition: TLeaf.cxx:91
TBranch * GetBranch() const
Definition: TLeaf.h:70
A TTree is a list of TBranches.
Definition: TBranch.h:58
virtual Bool_t IsOnTerminalBranch() const
Definition: TLeaf.h:89
const Bool_t kTRUE
Definition: Rtypes.h:91
T GetTypedValue(Int_t i=0) const
Definition: TLeaf.h:86
char name[80]
Definition: TGX11.cxx:109
virtual Int_t GetNdata() const
Definition: TLeaf.h:78