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
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
51 auto bracket = strchr(type, '[');
52 if (bracket) {
54 fElement = new TStreamerElement(Form("%s_Element", name), bracket, 0, 0, "Double32_t");
55 }
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Default destructor for a LeafD32.
60
62{
63 if (ResetAddress(nullptr, true))
64 delete[] fValue;
65
66 if (fElement)
67 delete fElement;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Export element from local leaf buffer to ClonesArray.
72
74{
75 Int_t j = 0;
76 for (Int_t i = 0; i < n; i++) {
77 memcpy((char *)list->UncheckedAt(i) + fOffset, &fValue[j], 8 * fLen);
78 j += fLen;
79 }
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Pack leaf elements in Basket output buffer.
84
86{
87 Int_t len = GetLen();
88 if (fPointer)
90 b.WriteFastArrayDouble32(fValue, len, fElement);
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Import element from ClonesArray into local leaf buffer.
95
97{
98 const Double32_t kDoubleUndefined = -9999.;
99 Int_t j = 0;
100 for (Int_t i = 0; i < n; i++) {
101 auto clone = (char *)list->UncheckedAt(i);
102 if (clone)
103 memcpy(&fValue[j], clone + fOffset, 8 * fLen);
104 else
105 for (Int_t k = 0; k < fLen; ++k)
107 j += fLen;
108 }
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Prints leaf value.
113
115{
116 auto value = (Double32_t *)GetValuePointer();
117 printf("%g", value[l]);
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Read leaf elements from Basket input buffer.
122
124{
125 if (!fLeafCount && fNdata == 1) {
126 b.ReadDouble32(fValue, fElement);
127 } else {
128 if (fLeafCount) {
130 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
132 }
133 auto len = Int_t(fLeafCount->GetValue());
134 if (len > fLeafCount->GetMaximum()) {
135 printf("ERROR leaf:%s, len=%d and max=%d\n", GetName(), len, fLeafCount->GetMaximum());
137 }
138 fNdata = len * fLen;
139 b.ReadFastArrayDouble32(fValue, len * fLen, fElement);
140 } else {
141 b.ReadFastArrayDouble32(fValue, fLen, fElement);
142 }
143 }
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Read leaf elements from Basket input buffer and export buffer to
148/// TClonesArray objects.
149
151{
152 b.ReadFastArrayDouble32(fValue, n * fLen, fElement);
153
154 Int_t j = 0;
155 for (Int_t i = 0; i < n; i++) {
156 memcpy((char *)list->UncheckedAt(i) + fOffset, &fValue[j], 8 * fLen);
157 j += fLen;
158 }
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Read a double from std::istream s and store it into the branch buffer.
163
164void TLeafD32::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
165{
166 auto value = (Double32_t *)GetValuePointer();
167 for (Int_t i = 0; i < fLen; i++)
168 s >> value[i];
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Set leaf buffer data address.
173
174void TLeafD32::SetAddress(void *add)
175{
176 if (ResetAddress(add) && (add != fValue)) {
177 delete[] fValue;
178 }
179 if (add) {
181 fPointer = (Double32_t **)add;
183 if (fLeafCount)
184 ncountmax = fLen * (fLeafCount->GetMaximum() + 1);
185 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) || ncountmax > fNdata || *fPointer == nullptr) {
186 if (*fPointer)
187 delete[] * fPointer;
188 if (ncountmax > fNdata)
190 *fPointer = new Double32_t[fNdata];
191 }
192 fValue = *fPointer;
193 } else {
194 fValue = (Double32_t *)add;
195 }
196 } else {
197 fValue = new Double32_t[fNdata];
198 fValue[0] = 0;
199 }
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Stream an object of class TLeafD32.
204
206{
207 if (R__b.IsReading()) {
208 delete fElement;
209 fElement = nullptr;
211 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
212 R__b.ReadClassBuffer(TLeafD32::Class(), this, R__v, R__s, R__c);
213 if (R__v < 2 && fTitle.BeginsWith("d[")) {
214 fTitle.Prepend('/');
215 }
216 if (fTitle.Contains("/d[")) {
217 auto slash = fTitle.First("/");
218 TString bracket = fTitle(slash + 2, fTitle.Length() - slash - 2);
219 fElement = new TStreamerElement(Form("%s_Element", fName.Data()), bracket.Data(), 0, 0, "Double32_t");
220 }
221 } else {
222 R__b.WriteClassBuffer(TLeafD32::Class(), this);
223 }
224}
#define b(i)
Definition RSha256.hxx:100
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
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 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
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2495
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.
~TLeafD32() override
Default destructor for a LeafD32.
Definition TLeafD32.cxx:61
void ReadValue(std::istream &s, Char_t delim=' ') override
Read a double from std::istream s and store it into the branch buffer.
Definition TLeafD32.cxx:164
void Streamer(TBuffer &) override
Stream an object of class TLeafD32.
Definition TLeafD32.cxx:205
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafD32.cxx:85
Double32_t ** fPointer
! Address of pointer to data buffer
Definition TLeafD32.h:34
void * GetValuePointer() const override
Definition TLeafD32.h:47
Double32_t * fValue
! Pointer to data buffer
Definition TLeafD32.h:33
Double32_t fMinimum
Minimum value if leaf range is specified.
Definition TLeafD32.h:31
void ReadBasket(TBuffer &b) override
Read leaf elements from Basket input buffer.
Definition TLeafD32.cxx:123
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafD32.cxx:114
Double32_t fMaximum
Maximum value if leaf range is specified.
Definition TLeafD32.h:32
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafD32.cxx:96
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafD32.cxx:73
void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafD32.cxx:150
TStreamerElement * fElement
! StreamerElement used for TBuffer read / write
Definition TLeafD32.h:35
static TClass * Class()
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafD32.cxx:174
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: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: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
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
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
TString fTitle
Definition TNamed.h:33
TString fName
Definition TNamed.h:32
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
Describe one element (data member) to be Streamed.
Basic string class.
Definition TString.h:138
Ssiz_t Length() const
Definition TString.h:425
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition TString.cxx:545
const char * Data() const
Definition TString.h:384
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition TString.h:631
TString & Prepend(const char *cs)
Definition TString.h:681
TString & Append(const char *cs)
Definition TString.h:580
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
const Int_t n
Definition legend1.C:16
TCanvas * slash()
Definition slash.C:1
TLine l
Definition textangle.C:4