Logo ROOT   6.08/07
Reference Guide
TLeafO.cxx
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Philippe Canal 20/1/05
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, 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 /** \class TLeafO
13 \ingroup tree
14 
15 A TLeaf for a bool data type.
16 */
17 
18 #include "TLeafO.h"
19 #include "TBranch.h"
20 #include "TBuffer.h"
21 #include "TClonesArray.h"
22 #include "Riostream.h"
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Default constructor for LeafO.
28 
30 {
31  fValue = 0;
32  fPointer = 0;
33  fMinimum = 0;
34  fMaximum = 0;
35  fLenType = sizeof(Bool_t);
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Create a LeafO.
40 
41 TLeafO::TLeafO(TBranch *parent, const char *name, const char *type)
42  : TLeaf(parent,name,type)
43 {
44  fLenType = sizeof(Bool_t);
45  fMinimum = 0;
46  fMaximum = 0;
47  fValue = 0;
48  fPointer = 0;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default destructor for a LeafO.
53 
55 {
56  if (ResetAddress(0,kTRUE)) delete [] fValue;
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Export element from local leaf buffer to ClonesArray.
61 
63 {
64  Int_t j = 0;
65  for (Int_t i=0;i<n;i++) {
66  memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
67  j += fLen;
68  }
69 }
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Pack leaf elements in Basket output buffer.
73 
75 {
76  Int_t len = GetLen();
77  if (fPointer) fValue = *fPointer;
78  if (IsRange()) {
79  if (fValue[0] > fMaximum) fMaximum = fValue[0];
80  }
81  b.WriteFastArray(fValue,len);
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Returns name of leaf type.
86 
87 const char *TLeafO::GetTypeName() const
88 {
89  return "Bool_t";
90 }
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Import element from ClonesArray into local leaf buffer.
94 
96 {
97  Int_t j = 0;
98  for (Int_t i=0;i<n;i++) {
99  memcpy(&fValue[j],(char*)list->UncheckedAt(i) + fOffset, fLen);
100  j += fLen;
101  }
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Prints leaf value.
106 
108 {
109  char *value = (char*)GetValuePointer();
110  printf("%d",(Int_t)value[l]);
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Read leaf elements from Basket input buffer.
115 
117 {
118  if (!fLeafCount && fNdata == 1) {
119  b.ReadBool(fValue[0]);
120  }else {
121  if (fLeafCount) {
122  Long64_t entry = fBranch->GetReadEntry();
123  if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
124  fLeafCount->GetBranch()->GetEntry(entry);
125  }
126  Int_t len = Int_t(fLeafCount->GetValue());
127  if (len > fLeafCount->GetMaximum()) {
128  printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
129  len = fLeafCount->GetMaximum();
130  }
131  fNdata = len*fLen;
132  b.ReadFastArray(fValue,len*fLen);
133  } else {
135  }
136  }
137 }
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 /// Read leaf elements from Basket input buffer and export buffer to
141 /// TClonesArray objects.
142 
144 {
146 
147  Int_t j = 0;
148  for (Int_t i=0;i<n;i++) {
149  memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
150  j += fLen;
151  }
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Read a string from std::istream s and store it into the branch buffer.
156 
157 void TLeafO::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
158 {
159  char *value = (char*)GetValuePointer();
160  s >> value;
161 }
162 
163 ////////////////////////////////////////////////////////////////////////////////
164 /// Set leaf buffer data address.
165 
166 void TLeafO::SetAddress(void *add)
167 {
168  if (ResetAddress(add)) {
169  delete [] fValue;
170  }
171  if (add) {
172  if (TestBit(kIndirectAddress)) {
173  fPointer = (Bool_t**) add;
174  Int_t ncountmax = fLen;
175  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
176  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
177  ncountmax > fNdata || *fPointer == 0) {
178  if (*fPointer) delete [] *fPointer;
179  if (ncountmax > fNdata) fNdata = ncountmax;
180  *fPointer = new Bool_t[fNdata];
181  }
182  fValue = *fPointer;
183  } else {
184  fValue = (Bool_t*)add;
185  }
186  } else {
187  fValue = new Bool_t[fNdata];
188  fValue[0] = 0;
189  }
190 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
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
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafO.cxx:107
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
A TLeaf for a bool data type.
Definition: TLeafO.h:28
virtual void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition: TLeafO.cxx:143
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:43
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafO.cxx:166
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:122
virtual Bool_t IsRange() const
Definition: TLeaf.h:90
Int_t fLen
Number of fixed length elements.
Definition: TLeaf.h:42
Bool_t ** fPointer
! Address of a pointer to data buffer!
Definition: TLeafO.h:34
virtual Int_t GetLen() const
Return the number of effective elements of this leaf.
Definition: TLeaf.cxx:279
virtual void ReadBool(Bool_t &b)=0
Int_t fNdata
! Number of elements in fAddress data buffer
Definition: TLeaf.h:41
PyObject * fValue
Bool_t * fValue
! Pointer to data buffer
Definition: TLeafO.h:33
Bool_t fMaximum
Maximum value if leaf range is specified.
Definition: TLeafO.h:32
TLine * l
Definition: textangle.C:4
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all leaves of entry and return total number of bytes read.
Definition: TBranch.cxx:1217
virtual void * GetValuePointer() const
Definition: TLeafO.h:47
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
virtual ~TLeafO()
Default destructor for a LeafO.
Definition: TLeafO.cxx:54
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:59
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafO.cxx:74
virtual void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to ClonesArray.
Definition: TLeafO.cxx:62
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
virtual Int_t GetMaximum() const
Definition: TLeaf.h:76
#define ClassImp(name)
Definition: Rtypes.h:279
virtual void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafO.cxx:95
int type
Definition: TGX11.cxx:120
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafO.cxx:116
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
virtual void ReadValue(std::istream &s, Char_t delim=' ')
Read a string from std::istream s and store it into the branch buffer.
Definition: TLeafO.cxx:157
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
Bool_t fMinimum
Minimum value if leaf range is specified.
Definition: TLeafO.h:31
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition: TLeaf.h:47
Long64_t GetReadEntry() const
Definition: TBranch.h:170
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
const char * GetTypeName() const
Returns name of leaf type.
Definition: TLeafO.cxx:87
TBranch * GetBranch() const
Definition: TLeaf.h:70
A TTree is a list of TBranches.
Definition: TBranch.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109
TLeafO()
Default constructor for LeafO.
Definition: TLeafO.cxx:29