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