Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
15A 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 <iostream>
23
24
25////////////////////////////////////////////////////////////////////////////////
26/// Default constructor for LeafL.
27
29{
30 fLenType = sizeof(Long64_t);
31 fMinimum = 0;
32 fMaximum = 0;
33 fValue = nullptr;
34 fPointer = nullptr;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Create a LeafL.
39
40TLeafL::TLeafL(TBranch *parent, const char *name, const char *type)
41 :TLeaf(parent, name,type)
42{
43 fLenType = sizeof(Long64_t);
44 fMinimum = 0;
45 fMaximum = 0;
46 fValue = nullptr;
47 fPointer = nullptr;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Default destructor for a LeafL.
52
54{
55 if (ResetAddress(nullptr,true)) delete [] fValue;
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Export element from local leaf buffer to ClonesArray.
60
62{
64 for (Int_t i=0;i<n;i++) {
65 char *first = (char*)list->UncheckedAt(i);
66 Long64_t *ii = (Long64_t*)&first[fOffset];
67 for (Int_t j=0;j<fLen;j++) {
68 ii[j] = value[j];
69 }
70 value += fLen;
71 }
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Pack leaf elements in Basket output buffer.
76
78{
79 Int_t i;
80 Int_t len = GetLen();
81 if (fPointer) fValue = *fPointer;
82 if (IsRange()) {
83 if (fValue[0] > fMaximum) fMaximum = fValue[0];
84 }
85 if (IsUnsigned()) {
86 for (i=0;i<len;i++) b << (ULong64_t)fValue[i];
87 } else {
88 b.WriteFastArray(fValue,len);
89 }
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Returns name of leaf type.
94
95const char *TLeafL::GetTypeName() const
96{
97 if (fIsUnsigned) return "ULong64_t";
98 return "Long64_t";
99}
100
101////////////////////////////////////////////////////////////////////////////////
102/// Returns current value of leaf.
103/// - if leaf is a simple type, i must be set to 0
104/// - if leaf is an array, i is the array element number to be returned
105
107{
108 if (fIsUnsigned) return (Double_t)((ULong64_t)fValue[i]);
109 return fValue[i];
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Returns current value of leaf
114/// - if leaf is a simple type, i must be set to 0
115/// - if leaf is an array, i is the array element number to be returned
116
118{
119 if (fIsUnsigned) return (LongDouble_t)((ULong64_t)fValue[i]);
120 return fValue[i];
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
125
127{
128 if (input) {
129 if (input->GetMaximum() > this->GetMaximum())
130 this->SetMaximum( input->GetMaximum() );
131 if (input->GetMinimum() < this->GetMinimum())
132 this->SetMinimum( input->GetMinimum() );
133 return true;
134 } else {
135 return false;
136 }
137}
138
139////////////////////////////////////////////////////////////////////////////////
140/// Import element from ClonesArray into local leaf buffer.
141
143{
144 const Long_t kIntUndefined = -9999;
145 Int_t j = 0;
146 char *clone;
147 for (Int_t i=0;i<n;i++) {
148 clone = (char*)list->UncheckedAt(i);
149 if (clone)
150 memcpy(&fValue[j],clone + fOffset, 8*fLen);
151 else
152 for (Int_t k = 0; k < fLen; ++k)
153 fValue[j + k] = kIntUndefined;
154 j += fLen;
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Prints leaf value.
160
162{
163 if (fIsUnsigned) {
165 printf("%llu",uvalue[l]);
166 } else {
168 printf("%lld",value[l]);
169 }
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Read leaf elements from Basket input buffer.
174
176{
177 if (!fLeafCount && fNdata == 1) {
178 b.ReadLong64(fValue[0]);
179 } else {
180 if (fLeafCount) {
182 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
184 }
186 if (len > fLeafCount->GetMaximum()) {
187 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
189 }
190 fNdata = len*fLen;
191 b.ReadFastArray(fValue,len*fLen);
192 } else {
193 b.ReadFastArray(fValue,fLen);
194 }
195 }
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Deserialize input by performing byteswap as needed.
201{
202 if (R__unlikely(fLeafCount)) {return false;}
203 return input_buf.ByteSwapBuffer(fLen*N, kLong64_t);
204}
205
206////////////////////////////////////////////////////////////////////////////////
207/// Read leaf elements from Basket input buffer and export buffer to
208/// TClonesArray objects.
209
211{
212 if (n*fLen == 1) {
213 b >> fValue[0];
214 } else {
215 b.ReadFastArray(fValue,n*fLen);
216 }
218 for (Int_t i=0;i<n;i++) {
219 char *first = (char*)list->UncheckedAt(i);
220 Long64_t *ii = (Long64_t*)&first[fOffset];
221 for (Int_t j=0;j<fLen;j++) {
222 ii[j] = value[j];
223 }
224 value += fLen;
225 }
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Read a long integer from std::istream s and store it into the branch buffer.
230
231void TLeafL::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
232{
233#if defined(_MSC_VER) && (_MSC_VER<1300)
234 printf("Due to a bug in VC++6, the function TLeafL::ReadValue is dummy\n");
235#else
236 if (fIsUnsigned) {
238 for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
239 } else {
241 for (Int_t i=0;i<fLen;i++) s >> value[i];
242 }
243#endif
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Set leaf buffer data address.
248
249void TLeafL::SetAddress(void *add)
250{
251 if (ResetAddress(add) && (add!=fValue)) {
252 delete [] fValue;
253 }
254 if (add) {
256 fPointer = (Long64_t**) add;
260 ncountmax > fNdata || *fPointer == nullptr) {
261 if (*fPointer) delete [] *fPointer;
263 *fPointer = new Long64_t[fNdata];
264 }
265 fValue = *fPointer;
266 } else {
267 fValue = (Long64_t*)add;
268 }
269 } else {
270 fValue = new Long64_t[fNdata];
271 fValue[0] = 0;
272 }
273}
274
#define R__unlikely(expr)
Definition RConfig.hxx:594
#define b(i)
Definition RSha256.hxx:100
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
unsigned long long ULong64_t
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:84
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kLong64_t
Definition TDataType.h:32
#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: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.
virtual void SetMaximum(Long64_t max)
Definition TLeafL.h:58
Long64_t * fValue
! Pointer to data buffer
Definition TLeafL.h:32
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafL.cxx:77
Long64_t fMinimum
Minimum value if leaf range is specified.
Definition TLeafL.h:30
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafL.cxx:61
Long64_t ** fPointer
! Address of pointer to data buffer
Definition TLeafL.h:33
bool ReadBasketFast(TBuffer &, Long64_t) override
Deserialize input by performing byteswap as needed.
Definition TLeafL.cxx:200
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafL.cxx:142
void * GetValuePointer() const override
Definition TLeafL.h:49
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafL.cxx:249
bool IncludeRange(TLeaf *) override
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition TLeafL.cxx:126
Double_t GetValue(Int_t i=0) const override
Returns current value of leaf.
Definition TLeafL.cxx:106
const char * GetTypeName() const override
Returns name of leaf type.
Definition TLeafL.cxx:95
LongDouble_t GetValueLongDouble(Int_t i=0) const override
Returns current value of leaf.
Definition TLeafL.cxx:117
~TLeafL() override
Default destructor for a LeafL.
Definition TLeafL.cxx:53
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 TLeafL.cxx:231
void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafL.cxx:210
virtual void SetMinimum(Long64_t min)
Definition TLeafL.h:59
Long64_t fMaximum
Maximum value if leaf range is specified.
Definition TLeafL.h:31
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafL.cxx:161
void ReadBasket(TBuffer &b) override
Read leaf elements from Basket input buffer.
Definition TLeafL.cxx:175
TLeafL()
Default constructor for LeafL.
Definition TLeafL.cxx:28
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
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4