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