Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TLeafF16.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 TLeafF16
13\ingroup tree
14
15A TLeaf for a 24 bit truncated floating point data type.
16*/
17
18#include "TLeafF16.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 LeafF16.
28
30{
31 fLenType = 4;
32 fMinimum = 0;
33 fMaximum = 0;
34 fValue = nullptr;
35 fPointer = nullptr;
36 fElement = nullptr;
37}
38
39////////////////////////////////////////////////////////////////////////////////
40/// Create a LeafF16.
41
42TLeafF16::TLeafF16(TBranch *parent, const char *name, const char *type) : TLeaf(parent, name, type)
43{
44 fLenType = 4;
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, "Float16_t");
55 }
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Default destructor for a LeafF16.
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{
76 for (Int_t i = 0; i < n; i++) {
77 auto first = (char *)list->UncheckedAt(i);
78 auto ff = (Float16_t *)&first[fOffset];
79 for (Int_t j = 0; j < fLen; j++) {
80 ff[j] = value[j];
81 }
82 value += fLen;
83 }
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Pack leaf elements in Basket output buffer.
88
90{
91 Int_t len = GetLen();
92 if (fPointer)
94 b.WriteFastArrayFloat16(fValue, len, fElement);
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Import element from ClonesArray into local leaf buffer.
99
101{
102 const Float16_t kFloatUndefined = -9999.;
103 Int_t j = 0;
104 for (Int_t i = 0; i < n; i++) {
105 auto clone = (char *)list->UncheckedAt(i);
106 if (clone)
107 memcpy(&fValue[j], clone + fOffset, 4 * fLen);
108 else
109 for (Int_t k = 0; k < fLen; ++k)
110 fValue[j + k] = kFloatUndefined;
111 j += fLen;
112 }
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Prints leaf value.
117
119{
120 auto value = (Float16_t *)GetValuePointer();
121 printf("%g", value[l]);
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Read leaf elements from Basket input buffer.
126
128{
129 if (!fLeafCount && fNdata == 1) {
130 b.ReadFloat16(fValue, fElement);
131 } else {
132 if (fLeafCount) {
134 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
136 }
137 auto len = Int_t(fLeafCount->GetValue());
138 if (len > fLeafCount->GetMaximum()) {
139 printf("ERROR leaf:%s, len=%d and max=%d\n", GetName(), len, fLeafCount->GetMaximum());
141 }
142 fNdata = len * fLen;
143 b.ReadFastArrayFloat16(fValue, len * fLen, fElement);
144 } else {
145 b.ReadFastArrayFloat16(fValue, fLen, fElement);
146 }
147 }
148}
149
150////////////////////////////////////////////////////////////////////////////////
151/// Read leaf elements from Basket input buffer and export buffer to
152/// TClonesArray objects.
153
155{
156 if (n * fLen == 1) {
157 b.ReadFloat16(fValue, fElement);
158 } else {
159 b.ReadFastArrayFloat16(fValue, n * fLen, fElement);
160 }
161
163 for (Int_t i = 0; i < n; i++) {
164 auto first = (char *)list->UncheckedAt(i);
165 auto ff = (Float16_t *)&first[fOffset];
166 for (Int_t j = 0; j < fLen; j++) {
167 ff[j] = value[j];
168 }
169 value += fLen;
170 }
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Read a float from std::istream s and store it into the branch buffer.
175
176void TLeafF16::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
177{
178 auto value = (Float16_t *)GetValuePointer();
179 for (Int_t i = 0; i < fLen; i++)
180 s >> value[i];
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Set leaf buffer data address.
185
186void TLeafF16::SetAddress(void *add)
187{
188 if (ResetAddress(add) && (add != fValue)) {
189 delete[] fValue;
190 }
191
192 if (add) {
194 fPointer = (Float16_t **)add;
196 if (fLeafCount)
197 ncountmax = fLen * (fLeafCount->GetMaximum() + 1);
198 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) || ncountmax > fNdata || *fPointer == nullptr) {
199 if (*fPointer)
200 delete[] * fPointer;
201 if (ncountmax > fNdata)
203 *fPointer = new Float16_t[fNdata];
204 }
205 fValue = *fPointer;
206 } else {
207 fValue = (Float16_t *)add;
208 }
209 } else {
210 fValue = new Float16_t[fNdata];
211 fValue[0] = 0;
212 }
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Stream an object of class TLeafF16.
217
219{
220 if (R__b.IsReading()) {
221 delete fElement;
222 fElement = nullptr;
224 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
225 R__b.ReadClassBuffer(TLeafF16::Class(), this, R__v, R__s, R__c);
226 if (R__v < 2 && fTitle.BeginsWith("f[")) {
227 fTitle.Prepend('/');
228 }
229 if (fTitle.Contains("/f[")) {
230 auto slash = fTitle.First("/");
231 TString bracket = fTitle(slash + 2, fTitle.Length() - slash - 2);
232 fElement = new TStreamerElement(Form("%s_Element", fName.Data()), bracket.Data(), 0, 0, "Float16_t");
233 }
234 } else {
235 R__b.WriteClassBuffer(TLeafF16::Class(), this);
236 }
237}
#define b(i)
Definition RSha256.hxx:100
float Float16_t
Float 4 bytes in memory, written to disk as 3 bytes (24-bits) by default or as a 4 bytes fixed-point-...
Definition RtypesCore.h:72
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.
~TLeafF16() override
Default destructor for a LeafF16.
Definition TLeafF16.cxx:61
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafF16.cxx:100
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafF16.cxx:73
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafF16.cxx:186
void ReadBasket(TBuffer &b) override
Read leaf elements from Basket input buffer.
Definition TLeafF16.cxx:127
void ReadValue(std::istream &s, Char_t delim=' ') override
Read a float from std::istream s and store it into the branch buffer.
Definition TLeafF16.cxx:176
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafF16.cxx:89
void * GetValuePointer() const override
Definition TLeafF16.h:46
void Streamer(TBuffer &) override
Stream an object of class TLeafF16.
Definition TLeafF16.cxx:218
Float16_t ** fPointer
! Address of pointer to data buffer!
Definition TLeafF16.h:33
TStreamerElement * fElement
! StreamerElement used for TBuffer read / write
Definition TLeafF16.h:34
Float16_t fMaximum
Maximum value if leaf range is specified.
Definition TLeafF16.h:31
Float16_t * fValue
! Pointer to data buffer
Definition TLeafF16.h:32
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafF16.cxx:118
TLeafF16()
Default constructor for LeafF16.
Definition TLeafF16.cxx:29
void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafF16.cxx:154
static TClass * Class()
Float16_t fMinimum
Minimum value if leaf range is specified.
Definition TLeafF16.h: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: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