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