Logo ROOT   6.14/05
Reference Guide
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 \ingroup tree
14 
15 A TLeaf for a 64 bit Integer data type.
16 */
17 
18 #include "TLeafL.h"
19 #include "TBranch.h"
20 #include "TBuffer.h"
21 #include "TClonesArray.h"
22 #include "Riostream.h"
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Default constructor for LeafL.
28 
30 {
31  fLenType = sizeof(Long64_t);
32  fMinimum = 0;
33  fMaximum = 0;
34  fValue = 0;
35  fPointer = 0;
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Create a LeafL.
40 
41 TLeafL::TLeafL(TBranch *parent, const char *name, const char *type)
42  :TLeaf(parent, name,type)
43 {
44  fLenType = sizeof(Long64_t);
45  fMinimum = 0;
46  fMaximum = 0;
47  fValue = 0;
48  fPointer = 0;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default destructor for a LeafL.
53 
55 {
56  if (ResetAddress(0,kTRUE)) delete [] fValue;
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Export element from local leaf buffer to ClonesArray.
61 
63 {
64  Long64_t *value = fValue;
65  for (Int_t i=0;i<n;i++) {
66  char *first = (char*)list->UncheckedAt(i);
67  Long64_t *ii = (Long64_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 << (ULong64_t)fValue[i];
88  } else {
89  b.WriteFastArray(fValue,len);
90  }
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Returns name of leaf type.
95 
96 const char *TLeafL::GetTypeName() const
97 {
98  if (fIsUnsigned) return "ULong64_t";
99  return "Long64_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 (Double_t)((ULong64_t)fValue[i]);
110  return fValue[i];
111 }
112 
113 ////////////////////////////////////////////////////////////////////////////////
114 /// Returns current value of leaf
115 /// - if leaf is a simple type, i must be set to 0
116 /// - if leaf is an array, i is the array element number to be returned
117 
119 {
120  if (fIsUnsigned) return (LongDouble_t)((ULong64_t)fValue[i]);
121  return fValue[i];
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
126 
128 {
129  if (input) {
130  if (input->GetMaximum() > this->GetMaximum())
131  this->SetMaximum( input->GetMaximum() );
132  if (input->GetMinimum() < this->GetMinimum())
133  this->SetMinimum( input->GetMinimum() );
134  return kTRUE;
135  } else {
136  return kFALSE;
137  }
138 }
139 
140 ////////////////////////////////////////////////////////////////////////////////
141 /// Import element from ClonesArray into local leaf buffer.
142 
144 {
145  const Int_t kIntUndefined = -9999;
146  Int_t j = 0;
147  char *clone;
148  for (Int_t i=0;i<n;i++) {
149  clone = (char*)list->UncheckedAt(i);
150  if (clone) memcpy(&fValue[j],clone + fOffset, 8*fLen);
151  else memcpy(&fValue[j],&kIntUndefined, 8*fLen);
152  j += fLen;
153  }
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Prints leaf value.
158 
160 {
161  if (fIsUnsigned) {
162  ULong64_t *uvalue = (ULong64_t*)GetValuePointer();
163  printf("%llu",uvalue[l]);
164  } else {
165  Long64_t *value = (Long64_t*)GetValuePointer();
166  printf("%lld",value[l]);
167  }
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Read leaf elements from Basket input buffer.
172 
174 {
175  if (!fLeafCount && fNdata == 1) {
176  b.ReadLong64(fValue[0]);
177  } else {
178  if (fLeafCount) {
179  Long64_t entry = fBranch->GetReadEntry();
180  if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
181  fLeafCount->GetBranch()->GetEntry(entry);
182  }
183  Int_t len = Int_t(fLeafCount->GetValue());
184  if (len > fLeafCount->GetMaximum()) {
185  printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
186  len = fLeafCount->GetMaximum();
187  }
188  fNdata = len*fLen;
189  b.ReadFastArray(fValue,len*fLen);
190  } else {
192  }
193  }
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Read leaf elements from Basket input buffer and export buffer to
198 /// TClonesArray objects.
199 
201 {
202  if (n*fLen == 1) {
203  b >> fValue[0];
204  } else {
206  }
207  Long64_t *value = fValue;
208  for (Int_t i=0;i<n;i++) {
209  char *first = (char*)list->UncheckedAt(i);
210  Long64_t *ii = (Long64_t*)&first[fOffset];
211  for (Int_t j=0;j<fLen;j++) {
212  ii[j] = value[j];
213  }
214  value += fLen;
215  }
216 }
217 
218 ////////////////////////////////////////////////////////////////////////////////
219 /// Read a long integer from std::istream s and store it into the branch buffer.
220 
221 void TLeafL::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
222 {
223 #if defined(_MSC_VER) && (_MSC_VER<1300)
224  printf("Due to a bug in VC++6, the function TLeafL::ReadValue is dummy\n");
225 #else
226  if (fIsUnsigned) {
227  ULong64_t *uvalue = (ULong64_t*)GetValuePointer();
228  for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
229  } else {
230  Long64_t *value = (Long64_t*)GetValuePointer();
231  for (Int_t i=0;i<fLen;i++) s >> value[i];
232  }
233 #endif
234 }
235 
236 ////////////////////////////////////////////////////////////////////////////////
237 /// Set leaf buffer data address.
238 
239 void TLeafL::SetAddress(void *add)
240 {
241  if (ResetAddress(add) && (add!=fValue)) {
242  delete [] fValue;
243  }
244  if (add) {
245  if (TestBit(kIndirectAddress)) {
246  fPointer = (Long64_t**) add;
247  Int_t ncountmax = fLen;
248  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
249  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
250  ncountmax > fNdata || *fPointer == 0) {
251  if (*fPointer) delete [] *fPointer;
252  if (ncountmax > fNdata) fNdata = ncountmax;
253  *fPointer = new Long64_t[fNdata];
254  }
255  fValue = *fPointer;
256  } else {
257  fValue = (Long64_t*)add;
258  }
259  } else {
260  fValue = new Long64_t[fNdata];
261  fValue[0] = 0;
262  }
263 }
264 
Long64_t fMinimum
Minimum value if leaf range is specified.
Definition: TLeafL.h:30
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 void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafL.cxx:143
long long Long64_t
Definition: RtypesCore.h:69
virtual Double_t GetValue(Int_t i=0) const
Returns current value of leaf.
Definition: TLeafL.cxx:107
Long64_t ** fPointer
! Address of pointer to data buffer
Definition: TLeafL.h:33
virtual void SetMinimum(Long64_t min)
Definition: TLeafL.h:57
virtual Bool_t IsUnsigned() const
Definition: TLeaf.h:100
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
virtual void * GetValuePointer() const
Definition: TLeafL.h:48
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:38
virtual Int_t GetMaximum() const
Definition: TLeafL.h:43
const char * GetTypeName() const
Returns name of leaf type.
Definition: TLeafL.cxx:96
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:131
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:221
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:200
virtual Int_t GetMinimum() const
Definition: TLeafL.h:44
virtual Bool_t IsRange() const
Definition: TLeaf.h:99
Int_t fLen
Number of fixed length elements.
Definition: TLeaf.h:37
Long64_t * fValue
! Pointer to data buffer
Definition: TLeafL.h:32
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafL.cxx:78
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition: TLeaf.cxx:310
Long64_t fMaximum
Maximum value if leaf range is specified.
Definition: TLeafL.h:31
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafL.cxx:159
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafL.cxx:173
Int_t fNdata
! Number of elements in fAddress data buffer
Definition: TLeaf.h:36
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:1310
long double LongDouble_t
Definition: RtypesCore.h:57
virtual Int_t GetMinimum() const
Definition: TLeaf.h:85
virtual LongDouble_t GetValueLongDouble(Int_t i=0) const
Returns current value of leaf.
Definition: TLeafL.cxx:118
TLeafL()
Default constructor for LeafL.
Definition: TLeafL.cxx:29
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual void SetMaximum(Long64_t max)
Definition: TLeafL.h:56
virtual Bool_t IncludeRange(TLeaf *)
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition: TLeafL.cxx:127
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:89
virtual Int_t GetMaximum() const
Definition: TLeaf.h:84
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:58
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:41
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafL.cxx:239
static constexpr double s
virtual void ReadLong64(Long64_t &l)=0
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
virtual ~TLeafL()
Default destructor for a LeafL.
Definition: TLeafL.cxx:54
auto * l
Definition: textangle.C:4
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:335
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:192
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
A TLeaf for a 64 bit Integer data type.
Definition: TLeafL.h:27
Definition: first.py:1
TBranch * GetBranch() const
Definition: TLeaf.h:71
A TTree is a list of TBranches.
Definition: TBranch.h:62
const Bool_t kTRUE
Definition: RtypesCore.h:87
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:62
char name[80]
Definition: TGX11.cxx:109