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