Logo ROOT   6.10/09
Reference Guide
TLeafI.cxx
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 /** \class TLeafI
13 \ingroup tree
14 
15 A TLeaf for an Integer data type.
16 */
17 
18 #include "TLeafI.h"
19 #include "TBranch.h"
20 #include "TBuffer.h"
21 #include "TClonesArray.h"
22 #include "Riostream.h"
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Default constructor for LeafI.
28 
30 {
31  fLenType = 4;
32  fMinimum = 0;
33  fMaximum = 0;
34  fValue = 0;
35  fPointer = 0;
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Create a LeafI.
40 
41 TLeafI::TLeafI(TBranch *parent, const char *name, const char *type)
42  :TLeaf(parent, name,type)
43 {
44  fLenType = 4;
45  fMinimum = 0;
46  fMaximum = 0;
47  fValue = 0;
48  fPointer = 0;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default destructor for a LeafI.
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 *value = fValue;
65  for (Int_t i=0;i<n;i++) {
66  char *first = (char*)list->UncheckedAt(i);
67  Int_t *ii = (Int_t*)&first[fOffset];
68  for (Int_t j=0;j<fLen;j++) {
69  ii[j] = value[j];
70  }
71  value += fLen;
72  }
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// Pack leaf elements in Basket output buffer.
77 
79 {
80  Int_t i;
81  Int_t len = GetLen();
82  if (fPointer) fValue = *fPointer;
83  if (IsRange()) {
84  if (fValue[0] > fMaximum) fMaximum = fValue[0];
85  }
86  if (IsUnsigned()) {
87  for (i=0;i<len;i++) b << (UInt_t)fValue[i];
88  } else {
89  b.WriteFastArray(fValue,len);
90  }
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Returns name of leaf type.
95 
96 const char *TLeafI::GetTypeName() const
97 {
98  if (fIsUnsigned) return "UInt_t";
99  return "Int_t";
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Returns current value of leaf
104 /// - if leaf is a simple type, i must be set to 0
105 /// - if leaf is an array, i is the array element number to be returned
106 
108 {
109  if (fIsUnsigned) return (UInt_t)fValue[i];
110  return fValue[i];
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Import element from ClonesArray into local leaf buffer.
115 
117 {
118  const Int_t kIntUndefined = -9999;
119  Int_t j = 0;
120  char *clone;
121  for (Int_t i=0;i<n;i++) {
122  clone = (char*)list->UncheckedAt(i);
123  if (clone) memcpy(&fValue[j],clone + fOffset, 4*fLen);
124  else memcpy(&fValue[j],&kIntUndefined, 4*fLen);
125  j += fLen;
126  }
127 }
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 /// Prints leaf value.
131 
133 {
134  if (fIsUnsigned) {
135  UInt_t *uvalue = (UInt_t*)GetValuePointer();
136  printf("%u",uvalue[l]);
137  } else {
138  Int_t *value = (Int_t*)GetValuePointer();
139  printf("%d",value[l]);
140  }
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Read leaf elements from Basket input buffer.
145 
147 {
148  if (!fLeafCount && fNdata == 1) {
149  b.ReadInt(fValue[0]);
150  } else {
151  if (fLeafCount) {
152  Long64_t entry = fBranch->GetReadEntry();
153  if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
154  fLeafCount->GetBranch()->GetEntry(entry);
155  }
156  Int_t len = Int_t(fLeafCount->GetValue());
157  if (len > fLeafCount->GetMaximum()) {
158  printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
159  len = fLeafCount->GetMaximum();
160  }
161  fNdata = len*fLen;
162  b.ReadFastArray(fValue,len*fLen);
163  } else {
165  }
166  }
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// Read leaf elements from Basket input buffer and export buffer to
171 /// TClonesArray objects.
172 
174 {
175  if (n*fLen == 1) {
176  b >> fValue[0];
177  } else {
179  }
180  Int_t *value = fValue;
181  for (Int_t i=0;i<n;i++) {
182  char *first = (char*)list->UncheckedAt(i);
183  Int_t *ii = (Int_t*)&first[fOffset];
184  for (Int_t j=0;j<fLen;j++) {
185  ii[j] = value[j];
186  }
187  value += fLen;
188  }
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Read an integer from std::istream s and store it into the branch buffer.
193 
194 void TLeafI::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
195 {
196  if (fIsUnsigned) {
197  UInt_t *uvalue = (UInt_t*)GetValuePointer();
198  for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
199  } else {
200  Int_t *value = (Int_t*)GetValuePointer();
201  for (Int_t i=0;i<fLen;i++) s >> value[i];
202  }
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Set leaf buffer data address.
207 
208 void TLeafI::SetAddress(void *add)
209 {
210  if (ResetAddress(add) && (add!= fValue)) {
211  delete [] fValue;
212  }
213  if (add) {
214  if (TestBit(kIndirectAddress)) {
215  fPointer = (Int_t**) add;
216  Int_t ncountmax = fLen;
217  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
218  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
219  ncountmax > fNdata || *fPointer == 0) {
220  if (*fPointer) delete [] *fPointer;
221  if (ncountmax > fNdata) fNdata = ncountmax;
222  *fPointer = new Int_t[fNdata];
223  }
224  fValue = *fPointer;
225  } else {
226  fValue = (Int_t*)add;
227  }
228  } else {
229  fValue = new Int_t[fNdata];
230  fValue[0] = 0;
231  }
232 }
233 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:32
virtual ~TLeafI()
Default destructor for a LeafI.
Definition: TLeafI.cxx:54
long long Long64_t
Definition: RtypesCore.h:69
Double_t GetValue(Int_t i=0) const
Returns current value of leaf.
Definition: TLeafI.cxx:107
Int_t fMaximum
Maximum value if leaf range is specified.
Definition: TLeafI.h:31
TLeafI()
Default constructor for LeafI.
Definition: TLeafI.cxx:29
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
const char * GetTypeName() const
Returns name of leaf type.
Definition: TLeafI.cxx:96
virtual Bool_t IsUnsigned() const
Definition: TLeaf.h:86
Int_t * fValue
! Pointer to data buffer
Definition: TLeafI.h:32
Int_t ** fPointer
! Address of pointer to data buffer
Definition: TLeafI.h:33
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:54
int Int_t
Definition: RtypesCore.h:41
virtual void ReadValue(std::istream &s, Char_t delim=' ')
Read an integer from std::istream s and store it into the branch buffer.
Definition: TLeafI.cxx:194
Int_t fMinimum
Minimum value if leaf range is specified.
Definition: TLeafI.h:30
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:38
virtual void ReadInt(Int_t &i)=0
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafI.cxx:132
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:117
virtual Bool_t IsRange() const
Definition: TLeaf.h:85
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafI.cxx:208
Int_t fLen
Number of fixed length elements.
Definition: TLeaf.h:37
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafI.cxx:146
virtual void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafI.cxx:116
virtual Int_t GetLen() const
Return the number of effective elements of this leaf.
Definition: TLeaf.cxx:279
virtual void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to ClonesArray.
Definition: TLeafI.cxx:62
Int_t fNdata
! Number of elements in fAddress data buffer
Definition: TLeaf.h:36
PyObject * fValue
unsigned int UInt_t
Definition: RtypesCore.h:42
TLine * l
Definition: textangle.C:4
virtual void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition: TLeafI.cxx:173
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:1291
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:89
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafI.cxx:78
virtual Int_t GetMaximum() const
Definition: TLeaf.h:71
#define ClassImp(name)
Definition: Rtypes.h:336
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
Bool_t fIsUnsigned
(=kTRUE if unsigned, kFALSE otherwise)
Definition: TLeaf.h:41
Int_t fOffset
Offset in ClonesArray object (if one)
Definition: TLeaf.h:39
char Char_t
Definition: RtypesCore.h:29
An array of clone (identical) objects.
Definition: TClonesArray.h:32
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:43
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:42
Long64_t GetReadEntry() const
Definition: TBranch.h:174
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
Definition: first.py:1
TBranch * GetBranch() const
Definition: TLeaf.h:65
A TTree is a list of TBranches.
Definition: TBranch.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:91
const Int_t n
Definition: legend1.C:16
A TLeaf for an Integer data type.
Definition: TLeafI.h:27
virtual void * GetValuePointer() const
Definition: TLeafI.h:46