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
52 auto bracket = strchr(type, '[');
53 if (bracket) {
55 fElement = new TStreamerElement(Form("%s_Element", name), bracket, 0, 0, "Double32_t");
56 }
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Default destructor for a LeafD32.
61
63{
64 if (ResetAddress(nullptr, true))
65 delete[] fValue;
66
67 if (fElement)
68 delete fElement;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Export element from local leaf buffer to ClonesArray.
73
75{
76 Int_t j = 0;
77 for (Int_t i = 0; i < n; i++) {
78 memcpy((char *)list->UncheckedAt(i) + fOffset, &fValue[j], 8 * fLen);
79 j += fLen;
80 }
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Pack leaf elements in Basket output buffer.
85
87{
88 Int_t len = GetLen();
89 if (fPointer)
91 b.WriteFastArrayDouble32(fValue, len, fElement);
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Import element from ClonesArray into local leaf buffer.
96
98{
99 const Double32_t kDoubleUndefined = -9999.;
100 Int_t j = 0;
101 for (Int_t i = 0; i < n; i++) {
102 auto clone = (char *)list->UncheckedAt(i);
103 if (clone)
104 memcpy(&fValue[j], clone + fOffset, 8 * fLen);
105 else
106 for (Int_t k = 0; k < fLen; ++k)
108 j += fLen;
109 }
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Prints leaf value.
114
116{
117 auto value = (Double32_t *)GetValuePointer();
118 printf("%g", value[l]);
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Read leaf elements from Basket input buffer.
123
125{
126 if (!fLeafCount && fNdata == 1) {
127 b.ReadDouble32(fValue, fElement);
128 } else {
129 if (fLeafCount) {
131 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
133 }
134 auto len = Int_t(fLeafCount->GetValue());
135 if (len > fLeafCount->GetMaximum()) {
136 printf("ERROR leaf:%s, len=%d and max=%d\n", GetName(), len, fLeafCount->GetMaximum());
138 }
139 fNdata = len * fLen;
140 b.ReadFastArrayDouble32(fValue, len * fLen, fElement);
141 } else {
142 b.ReadFastArrayDouble32(fValue, fLen, fElement);
143 }
144 }
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Read leaf elements from Basket input buffer and export buffer to
149/// TClonesArray objects.
150
152{
153 b.ReadFastArrayDouble32(fValue, n * fLen, fElement);
154
155 Int_t j = 0;
156 for (Int_t i = 0; i < n; i++) {
157 memcpy((char *)list->UncheckedAt(i) + fOffset, &fValue[j], 8 * fLen);
158 j += fLen;
159 }
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Read a double from std::istream s and store it into the branch buffer.
164
165void TLeafD32::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
166{
167 auto value = (Double32_t *)GetValuePointer();
168 for (Int_t i = 0; i < fLen; i++)
169 s >> value[i];
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Set leaf buffer data address.
174
175void TLeafD32::SetAddress(void *add)
176{
177 if (ResetAddress(add) && (add != fValue)) {
178 delete[] fValue;
179 }
180 if (add) {
182 fPointer = (Double32_t **)add;
184 if (fLeafCount)
185 ncountmax = fLen * (fLeafCount->GetMaximum() + 1);
186 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) || ncountmax > fNdata || *fPointer == nullptr) {
187 if (*fPointer)
188 delete[] * fPointer;
189 if (ncountmax > fNdata)
191 *fPointer = new Double32_t[fNdata];
192 }
193 fValue = *fPointer;
194 } else {
195 fValue = (Double32_t *)add;
196 }
197 } else {
198 fValue = new Double32_t[fNdata];
199 fValue[0] = 0;
200 }
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Stream an object of class TLeafD32.
205
207{
208 if (R__b.IsReading()) {
209 delete fElement;
210 fElement = nullptr;
212 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
213 R__b.ReadClassBuffer(TLeafD32::Class(), this, R__v, R__s, R__c);
214 if (R__v < 2 && fTitle.BeginsWith("d[")) {
215 fTitle.Prepend('/');
216 }
217 if (fTitle.Contains("/d[")) {
218 auto slash = fTitle.First("/");
219 TString bracket = fTitle(slash + 2, fTitle.Length() - slash - 2);
220 fElement = new TStreamerElement(Form("%s_Element", fName.Data()), bracket.Data(), 0, 0, "Double32_t");
221 }
222 } else {
223 R__b.WriteClassBuffer(TLeafD32::Class(), this);
224 }
225}
#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
#define ClassImp(name)
Definition Rtypes.h:376
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:2496
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
An array of clone (identical) objects.
A TLeaf for a 24 bit truncated floating point data type.
Definition TLeafD32.h:28
~TLeafD32() override
Default destructor for a LeafD32.
Definition TLeafD32.cxx:62
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:165
void Streamer(TBuffer &) override
Stream an object of class TLeafD32.
Definition TLeafD32.cxx:206
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafD32.cxx:86
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:124
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafD32.cxx:115
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:97
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafD32.cxx:74
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:151
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:175
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:406
Int_t ResetAddress(void *add, bool calledFromDestructor=false)
Helper routine for TLeafX::SetAddress.
Definition TLeaf.cxx:431
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:546
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