Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TLeafG.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Enrico Guiraud
3
4/*************************************************************************
5 * Copyright (C) 1995-2020, 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 TLeafG
13\ingroup tree
14
15A TLeaf for a 64 bit Integer data type.
16*/
17
18#include "TLeafG.h"
19#include "TBranch.h"
20#include "TBuffer.h"
21#include "TClonesArray.h"
22#include <iostream>
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor for LeafL.
28
30{
31 fLenType = sizeof(Long_t);
32 fMinimum = 0;
33 fMaximum = 0;
34 fValue = nullptr;
35 fPointer = nullptr;
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Create a LeafL.
40
41TLeafG::TLeafG(TBranch *parent, const char *name, const char *type)
42 :TLeaf(parent, name,type)
43{
44 fLenType = sizeof(Long_t);
45 fMinimum = 0;
46 fMaximum = 0;
47 fValue = nullptr;
48 fPointer = nullptr;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Default destructor for a LeafL.
53
55{
56 if (ResetAddress(nullptr,true)) delete [] fValue;
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Export element from local leaf buffer to ClonesArray.
61
63{
65 for (Int_t i=0;i<n;i++) {
66 char *first = (char*)list->UncheckedAt(i);
67 Long_t *ii = (Long_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 << (ULong_t)fValue[i];
88 } else {
89 b.WriteFastArray(fValue,len);
90 }
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Returns name of leaf type.
95
96const char *TLeafG::GetTypeName() const
97{
98 if (fIsUnsigned) return "ULong_t";
99 return "Long_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)((ULong_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)((ULong_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 true;
135 } else {
136 return false;
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 ULong_t *uvalue = (ULong_t*)GetValuePointer();
163 printf("%lu",uvalue[l]);
164 } else {
166 printf("%ld",value[l]);
167 }
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Read leaf elements from Basket input buffer.
172
174{
175 if (!fLeafCount && fNdata == 1) {
176 b.ReadLong(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 }
184 if (len > fLeafCount->GetMaximum()) {
185 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
187 }
188 fNdata = len*fLen;
189 b.ReadFastArray(fValue,len*fLen);
190 } else {
191 b.ReadFastArray(fValue,fLen);
192 }
193 }
194}
195
196////////////////////////////////////////////////////////////////////////////////
197/// Deserialize input by performing byteswap as needed.
199{
200 if (R__unlikely(fLeafCount)) {return false;}
201 return input_buf.ByteSwapBuffer(fLen*N, kLong_t);
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Read leaf elements from Basket input buffer and export buffer to
206/// TClonesArray objects.
207
209{
210 if (n*fLen == 1) {
211 b >> fValue[0];
212 } else {
213 b.ReadFastArray(fValue,n*fLen);
214 }
216 for (Int_t i=0;i<n;i++) {
217 char *first = (char*)list->UncheckedAt(i);
218 Long_t *ii = (Long_t*)&first[fOffset];
219 for (Int_t j=0;j<fLen;j++) {
220 ii[j] = value[j];
221 }
222 value += fLen;
223 }
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Read a long integer from std::istream s and store it into the branch buffer.
228
229void TLeafG::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
230{
231#if defined(_MSC_VER) && (_MSC_VER<1300)
232 printf("Due to a bug in VC++6, the function TLeafG::ReadValue is dummy\n");
233#else
234 if (fIsUnsigned) {
235 ULong_t *uvalue = (ULong_t*)GetValuePointer();
236 for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
237 } else {
239 for (Int_t i=0;i<fLen;i++) s >> value[i];
240 }
241#endif
242}
243
244////////////////////////////////////////////////////////////////////////////////
245/// Set leaf buffer data address.
246
247void TLeafG::SetAddress(void *add)
248{
249 if (ResetAddress(add) && (add!=fValue)) {
250 delete [] fValue;
251 }
252 if (add) {
254 fPointer = (Long_t**) add;
255 Int_t ncountmax = fLen;
256 if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
257 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
258 ncountmax > fNdata || *fPointer == nullptr) {
259 if (*fPointer) delete [] *fPointer;
260 if (ncountmax > fNdata) fNdata = ncountmax;
261 *fPointer = new Long_t[fNdata];
262 }
263 fValue = *fPointer;
264 } else {
265 fValue = (Long_t*)add;
266 }
267 } else {
268 fValue = new Long_t[fNdata];
269 fValue[0] = 0;
270 }
271}
272
#define R__unlikely(expr)
Definition RConfig.hxx:586
#define b(i)
Definition RSha256.hxx:100
int Int_t
Definition RtypesCore.h:45
char Char_t
Definition RtypesCore.h:37
unsigned long ULong_t
Definition RtypesCore.h:55
long Long_t
Definition RtypesCore.h:54
long double LongDouble_t
Definition RtypesCore.h:61
long long Long64_t
Definition RtypesCore.h:69
#define ClassImp(name)
Definition Rtypes.h:382
@ kLong_t
Definition TDataType.h:30
#define N
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
Bool_t ByteSwapBuffer(Long64_t n, EDataType type)
Byte-swap N primitive-elements in the buffer.
Definition TBuffer.cxx:392
An array of clone (identical) objects.
A TLeaf for a 64 bit Integer data type.
Definition TLeafG.h:27
void ReadValue(std::istream &s, Char_t delim=' ') override
Read a long integer from std::istream s and store it into the branch buffer.
Definition TLeafG.cxx:229
void * GetValuePointer() const override
Definition TLeafG.h:49
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafG.cxx:159
Long_t ** fPointer
! Address of pointer to data buffer
Definition TLeafG.h:33
Long_t fMinimum
Minimum value if leaf range is specified.
Definition TLeafG.h:30
virtual void SetMinimum(Long_t min)
Definition TLeafG.h:59
void ReadBasket(TBuffer &b) override
Read leaf elements from Basket input buffer.
Definition TLeafG.cxx:173
Long_t fMaximum
Maximum value if leaf range is specified.
Definition TLeafG.h:31
bool IncludeRange(TLeaf *) override
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition TLeafG.cxx:127
bool ReadBasketFast(TBuffer &, Long64_t) override
Deserialize input by performing byteswap as needed.
Definition TLeafG.cxx:198
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafG.cxx:78
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafG.cxx:247
const char * GetTypeName() const override
Returns name of leaf type.
Definition TLeafG.cxx:96
Long_t * fValue
! Pointer to data buffer
Definition TLeafG.h:32
void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafG.cxx:208
Double_t GetValue(Int_t i=0) const override
Returns current value of leaf.
Definition TLeafG.cxx:107
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafG.cxx:62
~TLeafG() override
Default destructor for a LeafL.
Definition TLeafG.cxx:54
LongDouble_t GetValueLongDouble(Int_t i=0) const override
Returns current value of leaf.
Definition TLeafG.cxx:118
TLeafG()
Default constructor for LeafL.
Definition TLeafG.cxx:29
virtual void SetMaximum(Long_t max)
Definition TLeafG.h:58
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafG.cxx:143
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:199
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4