Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TLeafF.cxx
Go to the documentation of this file.
1// @(#)root/tree:$Id$
2// Author: Rene Brun 12/01/96
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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 TLeafF
13\ingroup tree
14
15A TLeaf for a 32 bit floating point data type.
16*/
17
18#include "TLeafF.h"
19#include "TBranch.h"
20#include "TBuffer.h"
21#include "TClonesArray.h"
22#include <iostream>
23
24
25////////////////////////////////////////////////////////////////////////////////
26/// Default constructor for LeafF.
27
29{
30 fLenType = 4;
31 fMinimum = 0;
32 fMaximum = 0;
33 fValue = nullptr;
34 fPointer = nullptr;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Create a LeafF.
39
40TLeafF::TLeafF(TBranch *parent, const char *name, const char *type)
41 :TLeaf(parent, name,type)
42{
43 fLenType = 4;
44 fMinimum = 0;
45 fMaximum = 0;
46 fValue = nullptr;
47 fPointer = nullptr;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Default destructor for a LeafF.
52
54{
55 if (ResetAddress(nullptr,true)) delete [] fValue;
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Export element from local leaf buffer to ClonesArray.
60
62{
63 Float_t *value = fValue;
64 for (Int_t i=0;i<n;i++) {
65 char *first = (char*)list->UncheckedAt(i);
66 Float_t *ff = (Float_t*)&first[fOffset];
67 for (Int_t j=0;j<fLen;j++) {
68 ff[j] = value[j];
69 }
70 value += fLen;
71 }
72}
73
74////////////////////////////////////////////////////////////////////////////////
75/// Pack leaf elements in Basket output buffer.
76
78{
79 Int_t len = GetLen();
80 if (fPointer) fValue = *fPointer;
81 b.WriteFastArray(fValue,len);
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Import element from ClonesArray into local leaf buffer.
86
88{
89 const Float_t kFloatUndefined = -9999.;
90 Int_t j = 0;
91 char *clone;
92 for (Int_t i=0;i<n;i++) {
93 clone = (char*)list->UncheckedAt(i);
94 if (clone)
95 memcpy(&fValue[j],clone + fOffset, 4*fLen);
96 else
97 for (Int_t k = 0; k < fLen; ++k)
98 fValue[j + k] = kFloatUndefined;
99 j += fLen;
100 }
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Prints leaf value.
105
107{
108 Float_t *value = (Float_t *)GetValuePointer();
109 printf("%g",value[l]);
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Read leaf elements from Basket input buffer.
114
116{
117 if (!fLeafCount && fNdata == 1) {
118 b.ReadFloat(fValue[0]);
119 }else {
120 if (fLeafCount) {
121 Long64_t entry = fBranch->GetReadEntry();
122 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
123 fLeafCount->GetBranch()->GetEntry(entry);
124 }
125 Int_t len = Int_t(fLeafCount->GetValue());
126 if (len > fLeafCount->GetMaximum()) {
127 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
128 len = fLeafCount->GetMaximum();
129 }
130 fNdata = len*fLen;
131 b.ReadFastArray(fValue,len*fLen);
132 } else {
133 b.ReadFastArray(fValue,fLen);
134 }
135 }
136}
137
138// Deserialize N events from an input buffer.
140 if (R__unlikely(fLeafCount)) {return false;}
141 return input_buf.ByteSwapBuffer(fLen*N, kFloat_t);
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Read leaf elements from Basket input buffer and export buffer to
146/// TClonesArray objects.
147
149{
150 if (n*fLen == 1) {
151 b >> fValue[0];
152 } else {
153 b.ReadFastArray(fValue,n*fLen);
154 }
155
156 Float_t *value = fValue;
157 for (Int_t i=0;i<n;i++) {
158 char *first = (char*)list->UncheckedAt(i);
159 Float_t *ff = (Float_t*)&first[fOffset];
160 for (Int_t j=0;j<fLen;j++) {
161 ff[j] = value[j];
162 }
163 value += fLen;
164 }
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Read a float from std::istream s and store it into the branch buffer.
169
170void TLeafF::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
171{
172 Float_t *value = (Float_t*)GetValuePointer();
173 for (Int_t i=0;i<fLen;i++) s >> value[i];
174}
175
176////////////////////////////////////////////////////////////////////////////////
177/// Set leaf buffer data address.
178
179void TLeafF::SetAddress(void *add)
180{
181 if (ResetAddress(add) && (add!= fValue)) {
182 delete [] fValue;
183 }
184
185 if (add) {
187 fPointer = (Float_t**) add;
188 Int_t ncountmax = fLen;
189 if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
190 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
191 ncountmax > fNdata || *fPointer == nullptr) {
192 if (*fPointer) delete [] *fPointer;
193 if (ncountmax > fNdata) fNdata = ncountmax;
194 *fPointer = new Float_t[fNdata];
195 }
196 fValue = *fPointer;
197 } else {
198 fValue = (Float_t*)add;
199 }
200 } else {
201 fValue = new Float_t[fNdata];
202 fValue[0] = 0;
203 }
204}
#define R__unlikely(expr)
Definition RConfig.hxx:586
#define b(i)
Definition RSha256.hxx:100
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
char Char_t
Character 1 byte (char).
Definition RtypesCore.h:51
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
@ kFloat_t
Definition TDataType.h:31
#define N
char name[80]
Definition TGX11.cxx:148
A TTree is a list of TBranches.
Definition TBranch.h:93
Buffer base class used for serializing objects.
Definition TBuffer.h:43
Bool_t ByteSwapBuffer(Long64_t n, EDataType type)
Byte-swap N primitive-elements in the buffer.
Definition TBuffer.cxx:393
void ReadValue(std::istream &s, Char_t delim=' ') override
Read a float from std::istream s and store it into the branch buffer.
Definition TLeafF.cxx:170
Float_t fMaximum
Maximum value if leaf range is specified.
Definition TLeafF.h:30
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafF.cxx:77
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafF.cxx:179
Float_t fMinimum
Minimum value if leaf range is specified.
Definition TLeafF.h:29
void * GetValuePointer() const override
Definition TLeafF.h:44
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafF.cxx:87
TLeafF()
Default constructor for LeafF.
Definition TLeafF.cxx:28
bool ReadBasketFast(TBuffer &, Long64_t) override
Definition TLeafF.cxx:139
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafF.cxx:61
Float_t * fValue
! Pointer to data buffer
Definition TLeafF.h:31
void ReadBasket(TBuffer &b) override
Read leaf elements from Basket input buffer.
Definition TLeafF.cxx:115
void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafF.cxx:148
Float_t ** fPointer
! Address of pointer to data buffer!
Definition TLeafF.h:32
~TLeafF() override
Default destructor for a LeafF.
Definition TLeafF.cxx:53
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafF.cxx:106
TLeaf(const TLeaf &)
Copy constructor.
Definition TLeaf.cxx:99
Int_t fLenType
Number of bytes for this data type.
Definition TLeaf.h:76
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition TLeaf.h:75
Int_t fNdata
! Number of elements in fAddress data buffer.
Definition TLeaf.h:74
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
Int_t fOffset
Offset in ClonesArray object (if one).
Definition TLeaf.h:77
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition TLeaf.h:81
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter).
Definition TLeaf.h:80
@ kIndirectAddress
Data member is a pointer to an array of basic types.
Definition TLeaf.h:98
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
friend class TClonesArray
Definition TObject.h:245
Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4