Logo ROOT   6.18/05
Reference Guide
TLeafB.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 TLeafB
13\ingroup tree
14
15A TLeaf for an 8 bit Integer data type.
16*/
17
18#include "TLeafB.h"
19#include "TBranch.h"
20#include "TBuffer.h"
21#include "TClonesArray.h"
22#include "Riostream.h"
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor.
28
30: TLeaf()
31, fMinimum(0)
32, fMaximum(0)
33, fValue(0)
34, fPointer(0)
35{
36 fLenType = 1;
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Create a LeafB.
41
42TLeafB::TLeafB(TBranch *parent, const char* name, const char* type)
43 : TLeaf(parent, name, type)
44 , fMinimum(0)
45 , fMaximum(0)
46 , fValue(0)
47 , fPointer(0)
48{
49 fLenType = 1;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Destructor.
54
56{
57 if (ResetAddress(0, kTRUE)) {
58 delete[] fValue;
59 fValue = 0;
60 }
61 // Note: We do not own this, the user's object does.
62 fPointer = 0;
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Export element from local leaf buffer to a ClonesArray.
67
69{
70 for (Int_t i = 0, j = 0; i < n; i++, j += fLen) {
71 memcpy(((char*) list->UncheckedAt(i)) + fOffset, &fValue[j], fLen);
72 }
73}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Pack leaf elements into Basket output buffer.
77
79{
80 Int_t len = GetLen();
81 if (fPointer) {
83 }
84 if (IsRange()) {
85 if (fValue[0] > fMaximum) {
86 fMaximum = fValue[0];
87 }
88 }
89 if (IsUnsigned()) {
90 for (Int_t i = 0; i < len; i++) {
91 b << (UChar_t) fValue[i];
92 }
93 } else {
94 b.WriteFastArray(fValue, len);
95 }
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Returns name of leaf type.
100
101const char *TLeafB::GetTypeName() const
102{
103 if (fIsUnsigned) {
104 return "UChar_t";
105 }
106 return "Char_t";
107}
108
109////////////////////////////////////////////////////////////////////////////////
110/// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
111
113{
114 if (input) {
115 if (input->GetMaximum() > this->GetMaximum())
116 this->SetMaximum( input->GetMaximum() );
117 if (input->GetMinimum() < this->GetMinimum())
118 this->SetMinimum( input->GetMinimum() );
119 return kTRUE;
120 } else {
121 return kFALSE;
122 }
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Import element from ClonesArray into local leaf buffer.
127
129{
130 for (Int_t i = 0, j = 0; i < n; i++, j+= fLen) {
131 memcpy(&fValue[j], ((char*) list->UncheckedAt(i)) + fOffset, fLen);
132 }
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Prints leaf value.
137
139{
140 if (fIsUnsigned) {
141 UChar_t *uvalue = (UChar_t*) GetValuePointer();
142 printf("%u", uvalue[l]);
143 } else {
144 Char_t *value = (Char_t*) GetValuePointer();
145 printf("%d", value[l]);
146 }
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Read leaf elements from Basket input buffer.
151
153{
154 if (!fLeafCount && (fNdata == 1)) {
155 b.ReadChar(fValue[0]);
156 } else {
157 if (fLeafCount) {
158 Long64_t entry = fBranch->GetReadEntry();
159 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
160 fLeafCount->GetBranch()->GetEntry(entry);
161 }
162 Int_t len = Int_t(fLeafCount->GetValue());
163 if (len > fLeafCount->GetMaximum()) {
164 Error("ReadBasket", "leaf: '%s' len: %d max: %d", GetName(), len, fLeafCount->GetMaximum());
165 len = fLeafCount->GetMaximum();
166 }
167 fNdata = len * fLen;
168 b.ReadFastArray(fValue, len*fLen);
169 } else {
170 b.ReadFastArray(fValue, fLen);
171 }
172 }
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Read leaf elements from Basket input buffer and export buffer to
177/// TClonesArray objects.
178
180{
181 b.ReadFastArray(fValue, n*fLen);
182
183 for (Int_t i = 0, j = 0; i < n; i++, j += fLen) {
184 memcpy(((char*) list->UncheckedAt(i)) + fOffset, &fValue[j], fLen);
185 }
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Read a 8 bit integer from std::istream s and store it into the branch buffer.
190
191void TLeafB::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
192{
193 if (fIsUnsigned) {
194 UChar_t *uvalue = (UChar_t*)GetValuePointer();
195 for (Int_t i=0;i<fLen;i++) {
196 UShort_t tmp;
197 s >> tmp;
198 uvalue[i] = tmp;
199 }
200 } else {
201 Char_t *value = (Char_t*)GetValuePointer();
202 for (Int_t i=0;i<fLen;i++) {
203 Short_t tmp;
204 s >> tmp;
205 value[i] = tmp;
206 }
207 }
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Set value buffer address.
212
213void TLeafB::SetAddress(void *addr)
214{
215 // Check ownership of the value buffer and
216 // calculate a new size for it.
217 if (ResetAddress(addr)) {
218 // -- We owned the old value buffer, delete it.
219 delete[] fValue;
220 fValue = 0;
221 }
222 if (addr) {
223 // -- We have been provided a new value buffer.
225 // -- The data member is a pointer to an array.
226 fPointer = (Char_t**) addr;
227 // Calculate the maximum size we have ever needed
228 // for the value buffer.
229 Int_t ncountmax = fLen;
230 if (fLeafCount) {
231 ncountmax = (fLeafCount->GetMaximum() + 1) * fLen;
232 }
233 // Reallocate the value buffer if needed.
234 if ((fLeafCount && (Int_t(fLeafCount->GetValue()) < ncountmax)) ||
235 (fNdata < ncountmax) ||
236 (*fPointer == 0)) {
237 // -- Reallocate.
238 // Note:
239 // 1) For a varying length array we do this based on
240 // an indirect estimator of the size of the value
241 // buffer since we have no record of how large it
242 // actually is. If the current length of the
243 // varying length array is less than it has been
244 // in the past, then reallocate the value buffer
245 // to the larger of either the calculated new size
246 // or the maximum size it has ever been.
247 //
248 // 2) The second condition checks if the new value
249 // buffer size calculated by ResetAddress() is
250 // smaller than the most we have ever used, and
251 // if it is, then we increase the new size and
252 // reallocate.
253 //
254 // 3) The third condition is checking to see if we
255 // have been given a value buffer, if not then
256 // we must allocate one.
257 //
258 if (fNdata < ncountmax) {
259 fNdata = ncountmax;
260 }
261 delete[] *fPointer;
262 *fPointer = 0;
263 *fPointer = new Char_t[fNdata];
264 }
265 fValue = *fPointer;
266 } else {
267 // -- The data member is fixed size.
268 // FIXME: What about fPointer???
269 fValue = (char*) addr;
270 }
271 } else {
272 // -- We must create the value buffer ourselves.
273 // Note: We are using the size calculated by ResetAddress().
274 fValue = new char[fNdata];
275 // FIXME: Why initialize at all?
276 fValue[0] = 0;
277 }
278}
279
PyObject * fValue
#define b(i)
Definition: RSha256.hxx:100
unsigned short UShort_t
Definition: RtypesCore.h:36
int Int_t
Definition: RtypesCore.h:41
unsigned char UChar_t
Definition: RtypesCore.h:34
char Char_t
Definition: RtypesCore.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
short Short_t
Definition: RtypesCore.h:35
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
int type
Definition: TGX11.cxx:120
A TTree is a list of TBranches.
Definition: TBranch.h:65
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:1580
Long64_t GetReadEntry() const
Definition: TBranch.h:205
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
An array of clone (identical) objects.
Definition: TClonesArray.h:32
A TLeaf for an 8 bit Integer data type.
Definition: TLeafB.h:26
virtual void FillBasket(TBuffer &b)
Pack leaf elements into Basket output buffer.
Definition: TLeafB.cxx:78
Char_t fMaximum
Maximum value if leaf range is specified.
Definition: TLeafB.h:30
virtual void SetAddress(void *addr=0)
Set value buffer address.
Definition: TLeafB.cxx:213
virtual ~TLeafB()
Destructor.
Definition: TLeafB.cxx:55
virtual void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafB.cxx:128
virtual void ReadBasketExport(TBuffer &, TClonesArray *list, Int_t n)
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition: TLeafB.cxx:179
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafB.cxx:138
virtual void ReadValue(std::istream &s, Char_t delim=' ')
Read a 8 bit integer from std::istream s and store it into the branch buffer.
Definition: TLeafB.cxx:191
virtual void SetMinimum(Char_t min)
Definition: TLeafB.h:55
Char_t * fValue
! Pointer to data buffer
Definition: TLeafB.h:31
virtual void ReadBasket(TBuffer &)
Read leaf elements from Basket input buffer.
Definition: TLeafB.cxx:152
virtual void SetMaximum(Char_t max)
Definition: TLeafB.h:54
Char_t ** fPointer
! Address of a pointer to data buffer!
Definition: TLeafB.h:32
virtual void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to a ClonesArray.
Definition: TLeafB.cxx:68
virtual Bool_t IncludeRange(TLeaf *)
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition: TLeafB.cxx:112
TLeafB()
Default constructor.
Definition: TLeafB.cxx:29
virtual void * GetValuePointer() const
Definition: TLeafB.h:46
const char * GetTypeName() const
Returns name of leaf type.
Definition: TLeafB.cxx:101
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:49
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:162
virtual Bool_t IsRange() const
Definition: TLeaf.h:128
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:59
virtual Int_t GetMaximum() const
Definition: TLeaf.h:113
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition: TLeaf.h:58
Int_t fNdata
! Number of elements in fAddress data buffer.
Definition: TLeaf.h:57
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition: TLeaf.cxx:311
Bool_t fIsUnsigned
(=kTRUE if unsigned, kFALSE otherwise)
Definition: TLeaf.h:62
TBranch * GetBranch() const
Definition: TLeaf.h:99
Int_t fOffset
Offset in ClonesArray object (if one)
Definition: TLeaf.h:60
virtual Int_t GetMinimum() const
Definition: TLeaf.h:114
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:64
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition: TLeaf.h:63
@ kIndirectAddress
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:79
virtual Bool_t IsUnsigned() const
Definition: TLeaf.h:129
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:336
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:90
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:172
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
const Int_t n
Definition: legend1.C:16
static constexpr double s
auto * l
Definition: textangle.C:4