Logo ROOT   6.18/05
Reference Guide
TLeafD32.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Simon Spies 23/02/19
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, 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 TLeafD32
13\ingroup tree
14
15A TLeaf for a 24 bit truncated floating point data type.
16*/
17
18#include "TLeafD32.h"
19#include "TBranch.h"
20#include "TBuffer.h"
21#include "TClonesArray.h"
22#include "Riostream.h"
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor for LeafD32.
28
30{
31 fLenType = 8;
32 fMinimum = 0;
33 fMaximum = 0;
34 fValue = nullptr;
35 fPointer = nullptr;
36 fElement = nullptr;
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Create a LeafD32.
41
42TLeafD32::TLeafD32(TBranch *parent, const char *name, const char *type) : TLeaf(parent, name, type)
43{
44 fLenType = 8;
45 fMinimum = 0;
46 fMaximum = 0;
47 fValue = nullptr;
48 fPointer = nullptr;
49 fElement = nullptr;
50 fTitle = type;
51
52 if (strchr(type, '['))
53 fElement = new TStreamerElement(Form("%s_Element", name), type, 0, 0, "Double32_t");
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Default destructor for a LeafD32.
58
60{
61 if (ResetAddress(nullptr, kTRUE))
62 delete[] fValue;
63
64 if (fElement)
65 delete fElement;
66}
67
68////////////////////////////////////////////////////////////////////////////////
69/// Export element from local leaf buffer to ClonesArray.
70
72{
73 Int_t j = 0;
74 for (Int_t i = 0; i < n; i++) {
75 memcpy((char *)list->UncheckedAt(i) + fOffset, &fValue[j], 8 * fLen);
76 j += fLen;
77 }
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Pack leaf elements in Basket output buffer.
82
84{
85 Int_t len = GetLen();
86 if (fPointer)
88 b.WriteFastArrayDouble32(fValue, len, fElement);
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Import element from ClonesArray into local leaf buffer.
93
95{
96 const Double32_t kDoubleUndefined = -9999.;
97 Int_t j = 0;
98 for (Int_t i = 0; i < n; i++) {
99 auto clone = (char *)list->UncheckedAt(i);
100 if (clone)
101 memcpy(&fValue[j], clone + fOffset, 8 * fLen);
102 else
103 memcpy(&fValue[j], &kDoubleUndefined, 8 * fLen);
104 j += fLen;
105 }
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Prints leaf value.
110
112{
113 auto value = (Double32_t *)GetValuePointer();
114 printf("%g", value[l]);
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Read leaf elements from Basket input buffer.
119
121{
122 if (!fLeafCount && fNdata == 1) {
123 b.ReadDouble32(fValue, fElement);
124 } else {
125 if (fLeafCount) {
126 Long64_t entry = fBranch->GetReadEntry();
127 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
128 fLeafCount->GetBranch()->GetEntry(entry);
129 }
130 auto len = Int_t(fLeafCount->GetValue());
131 if (len > fLeafCount->GetMaximum()) {
132 printf("ERROR leaf:%s, len=%d and max=%d\n", GetName(), len, fLeafCount->GetMaximum());
133 len = fLeafCount->GetMaximum();
134 }
135 fNdata = len * fLen;
136 b.ReadFastArrayDouble32(fValue, len * fLen, fElement);
137 } else {
138 b.ReadFastArrayDouble32(fValue, fLen, fElement);
139 }
140 }
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Read leaf elements from Basket input buffer and export buffer to
145/// TClonesArray objects.
146
148{
149 b.ReadFastArrayDouble32(fValue, n * fLen, fElement);
150
151 Int_t j = 0;
152 for (Int_t i = 0; i < n; i++) {
153 memcpy((char *)list->UncheckedAt(i) + fOffset, &fValue[j], 8 * fLen);
154 j += fLen;
155 }
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Read a double from std::istream s and store it into the branch buffer.
160
161void TLeafD32::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
162{
163 auto value = (Double32_t *)GetValuePointer();
164 for (Int_t i = 0; i < fLen; i++)
165 s >> value[i];
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// Set leaf buffer data address.
170
171void TLeafD32::SetAddress(void *add)
172{
173 if (ResetAddress(add) && (add != fValue)) {
174 delete[] fValue;
175 }
176 if (add) {
178 fPointer = (Double32_t **)add;
179 Int_t ncountmax = fLen;
180 if (fLeafCount)
181 ncountmax = fLen * (fLeafCount->GetMaximum() + 1);
182 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) || ncountmax > fNdata || *fPointer == nullptr) {
183 if (*fPointer)
184 delete[] * fPointer;
185 if (ncountmax > fNdata)
186 fNdata = ncountmax;
187 *fPointer = new Double32_t[fNdata];
188 }
189 fValue = *fPointer;
190 } else {
191 fValue = (Double32_t *)add;
192 }
193 } else {
194 fValue = new Double32_t[fNdata];
195 fValue[0] = 0;
196 }
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Stream an object of class TLeafD32.
201
202void TLeafD32::Streamer(TBuffer &R__b)
203{
204 if (R__b.IsReading()) {
205 R__b.ReadClassBuffer(TLeafD32::Class(), this);
206
207 if (fTitle.Contains("["))
208 fElement = new TStreamerElement(Form("%s_Element", fName.Data()), fTitle.Data(), 0, 0, "Double32_t");
209 } else {
210 R__b.WriteClassBuffer(TLeafD32::Class(), this);
211 }
212}
void Class()
Definition: Class.C:29
#define b(i)
Definition: RSha256.hxx:100
double Double32_t
Definition: RtypesCore.h:56
int Int_t
Definition: RtypesCore.h:41
char Char_t
Definition: RtypesCore.h:29
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
char * Form(const char *fmt,...)
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
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
Bool_t IsReading() const
Definition: TBuffer.h:85
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
An array of clone (identical) objects.
Definition: TClonesArray.h:32
A TLeaf for a 24 bit truncated floating point data type.
Definition: TLeafD32.h:26
virtual ~TLeafD32()
Default destructor for a LeafD32.
Definition: TLeafD32.cxx:59
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafD32.cxx:171
virtual void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafD32.cxx:94
Double32_t ** fPointer
! Address of pointer to data buffer
Definition: TLeafD32.h:32
virtual void * GetValuePointer() const
Definition: TLeafD32.h:44
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafD32.cxx:111
Double32_t * fValue
! Pointer to data buffer
Definition: TLeafD32.h:31
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafD32.cxx:120
Double32_t fMinimum
Minimum value if leaf range is specified.
Definition: TLeafD32.h:29
Double32_t fMaximum
Maximum value if leaf range is specified.
Definition: TLeafD32.h:30
virtual void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to ClonesArray.
Definition: TLeafD32.cxx:71
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafD32.cxx:83
TStreamerElement * fElement
! StreamerElement used for TBuffer read / write
Definition: TLeafD32.h:33
virtual void ReadValue(std::istream &s, Char_t delim=' ')
Read a double from std::istream s and store it into the branch buffer.
Definition: TLeafD32.cxx:161
virtual void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition: TLeafD32.cxx:147
TLeafD32()
Default constructor for LeafD32.
Definition: TLeafD32.cxx:29
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
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
TBranch * GetBranch() const
Definition: TLeaf.h:99
Int_t fOffset
Offset in ClonesArray object (if one)
Definition: TLeaf.h:60
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
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:336
TString fTitle
Definition: TNamed.h:33
TString fName
Definition: TNamed.h:32
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
const char * Data() const
Definition: TString.h:364
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
const Int_t n
Definition: legend1.C:16
static constexpr double s
auto * l
Definition: textangle.C:4