Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <iostream>
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor.
28
30: TLeaf()
31, fMinimum(0)
32, fMaximum(0)
33, fValue(nullptr)
34, fPointer(nullptr)
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(nullptr)
47 , fPointer(nullptr)
48{
49 fLenType = 1;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Destructor.
54
56{
57 if (ResetAddress(nullptr, true)) {
58 delete[] fValue;
59 fValue = nullptr;
60 }
61 // Note: We do not own this, the user's object does.
62 fPointer = nullptr;
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 true;
120 } else {
121 return false;
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 {
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 }
163 if (len > fLeafCount->GetMaximum()) {
164 Error("ReadBasket", "leaf: '%s' len: %d max: %d", GetName(), 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 {
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 = nullptr;
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 == nullptr)) {
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 = nullptr;
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
#define b(i)
Definition RSha256.hxx:100
unsigned short UShort_t
Definition RtypesCore.h:40
int Int_t
Definition RtypesCore.h:45
unsigned char UChar_t
Definition RtypesCore.h:38
char Char_t
Definition RtypesCore.h:37
short Short_t
Definition RtypesCore.h:39
long long Long64_t
Definition RtypesCore.h:80
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
A TTree is a list of TBranches.
Definition TBranch.h:93
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:1706
Long64_t GetReadEntry() const
Definition TBranch.h:237
Buffer base class used for serializing objects.
Definition TBuffer.h:43
An array of clone (identical) objects.
A TLeaf for an 8 bit Integer data type.
Definition TLeafB.h:26
Char_t fMaximum
Maximum value if leaf range is specified.
Definition TLeafB.h:30
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafB.cxx:138
~TLeafB() override
Destructor.
Definition TLeafB.cxx:55
void ReadValue(std::istream &s, Char_t delim=' ') override
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
const char * GetTypeName() const override
Returns name of leaf type.
Definition TLeafB.cxx:101
void * GetValuePointer() const override
Definition TLeafB.h:46
virtual void SetMaximum(Char_t max)
Definition TLeafB.h:54
Char_t ** fPointer
! Address of a pointer to data buffer!
Definition TLeafB.h:32
void ReadBasket(TBuffer &) override
Read leaf elements from Basket input buffer.
Definition TLeafB.cxx:152
void SetAddress(void *addr=nullptr) override
Set value buffer address.
Definition TLeafB.cxx:213
TLeafB()
Default constructor.
Definition TLeafB.cxx:29
void FillBasket(TBuffer &b) override
Pack leaf elements into Basket output buffer.
Definition TLeafB.cxx:78
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to a ClonesArray.
Definition TLeafB.cxx:68
void ReadBasketExport(TBuffer &, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafB.cxx:179
bool IncludeRange(TLeaf *) override
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition TLeafB.cxx:112
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafB.cxx:128
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
virtual Double_t GetValue(Int_t i=0) const
Definition TLeaf.h:183
Int_t fLenType
Number of bytes for this data type.
Definition TLeaf.h:73
virtual Int_t GetMaximum() const
Definition TLeaf.h:134
virtual bool IsUnsigned() const
Definition TLeaf.h:150
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition TLeaf.h:72
Int_t fNdata
! Number of elements in fAddress data buffer.
Definition TLeaf.h:71
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition TLeaf.cxx:404
Int_t ResetAddress(void *add, bool calledFromDestructor=false)
Helper routine for TLeafX::SetAddress.
Definition TLeaf.cxx:429
TBranch * GetBranch() const
Definition TLeaf.h:116
Int_t fOffset
Offset in ClonesArray object (if one)
Definition TLeaf.h:74
virtual Int_t GetMinimum() const
Definition TLeaf.h:135
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition TLeaf.h:78
bool fIsUnsigned
(=true if unsigned, false otherwise)
Definition TLeaf.h:76
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition TLeaf.h:77
@ kIndirectAddress
Data member is a pointer to an array of basic types.
Definition TLeaf.h:95
virtual bool IsRange() const
Definition TLeaf.h:149
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:201
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4