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