Loading [MathJax]/extensions/tex2jax.js
ROOT  6.06/09
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 A TLeaf for a 32 bit floating point data type.
14 */
15 
16 #include "TLeafF.h"
17 #include "TBranch.h"
18 #include "TClonesArray.h"
19 #include "Riostream.h"
20 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// Default constructor for LeafF.
25 
26 TLeafF::TLeafF(): TLeaf()
27 {
28  fLenType = 4;
29  fMinimum = 0;
30  fMaximum = 0;
31  fValue = 0;
32  fPointer = 0;
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Create a LeafF.
37 
38 TLeafF::TLeafF(TBranch *parent, const char *name, const char *type)
39  :TLeaf(parent, name,type)
40 {
41  fLenType = 4;
42  fMinimum = 0;
43  fMaximum = 0;
44  fValue = 0;
45  fPointer = 0;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Default destructor for a LeafF.
50 
52 {
53  if (ResetAddress(0,kTRUE)) delete [] fValue;
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Export element from local leaf buffer to ClonesArray.
58 
60 {
61  Float_t *value = fValue;
62  for (Int_t i=0;i<n;i++) {
63  char *first = (char*)list->UncheckedAt(i);
64  Float_t *ff = (Float_t*)&first[fOffset];
65  for (Int_t j=0;j<fLen;j++) {
66  ff[j] = value[j];
67  }
68  value += fLen;
69  }
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Pack leaf elements in Basket output buffer.
74 
76 {
77  Int_t len = GetLen();
78  if (fPointer) fValue = *fPointer;
79  b.WriteFastArray(fValue,len);
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Import element from ClonesArray into local leaf buffer.
84 
86 {
87  const Float_t kFloatUndefined = -9999.;
88  Int_t j = 0;
89  char *clone;
90  for (Int_t i=0;i<n;i++) {
91  clone = (char*)list->UncheckedAt(i);
92  if (clone) memcpy(&fValue[j],clone + fOffset, 4*fLen);
93  else memcpy(&fValue[j],&kFloatUndefined, 4*fLen);
94  j += fLen;
95  }
96 }
97 
98 ////////////////////////////////////////////////////////////////////////////////
99 /// Prints leaf value.
100 
102 {
104  printf("%g",value[l]);
105 }
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Read leaf elements from Basket input buffer.
109 
111 {
112  if (!fLeafCount && fNdata == 1) {
113  b.ReadFloat(fValue[0]);
114  }else {
115  if (fLeafCount) {
117  if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
118  fLeafCount->GetBranch()->GetEntry(entry);
119  }
120  Int_t len = Int_t(fLeafCount->GetValue());
121  if (len > fLeafCount->GetMaximum()) {
122  printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
123  len = fLeafCount->GetMaximum();
124  }
125  fNdata = len*fLen;
126  b.ReadFastArray(fValue,len*fLen);
127  } else {
129  }
130  }
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Read leaf elements from Basket input buffer and export buffer to
135 /// TClonesArray objects.
136 
138 {
139  if (n*fLen == 1) {
140  b >> fValue[0];
141  } else {
143  }
144 
145  Float_t *value = fValue;
146  for (Int_t i=0;i<n;i++) {
147  char *first = (char*)list->UncheckedAt(i);
148  Float_t *ff = (Float_t*)&first[fOffset];
149  for (Int_t j=0;j<fLen;j++) {
150  ff[j] = value[j];
151  }
152  value += fLen;
153  }
154 }
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Read a float from std::istream s and store it into the branch buffer.
158 
159 void TLeafF::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
160 {
162  for (Int_t i=0;i<fLen;i++) s >> value[i];
163 }
164 
165 ////////////////////////////////////////////////////////////////////////////////
166 /// Set leaf buffer data address.
167 
168 void TLeafF::SetAddress(void *add)
169 {
170  if (ResetAddress(add) && (add!= fValue)) {
171  delete [] fValue;
172  }
173 
174  if (add) {
175  if (TestBit(kIndirectAddress)) {
176  fPointer = (Float_t**) add;
177  Int_t ncountmax = fLen;
178  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
179  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
180  ncountmax > fNdata || *fPointer == 0) {
181  if (*fPointer) delete [] *fPointer;
182  if (ncountmax > fNdata) fNdata = ncountmax;
183  *fPointer = new Float_t[fNdata];
184  }
185  fValue = *fPointer;
186  } else {
187  fValue = (Float_t*)add;
188  }
189  } else {
190  fValue = new Float_t[fNdata];
191  fValue[0] = 0;
192  }
193 }
virtual Int_t GetLen() const
Return the number of effective elements of this leaf.
Definition: TLeaf.cxx:276
Long64_t GetReadEntry() const
Definition: TBranch.h:169
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:37
long long Long64_t
Definition: RtypesCore.h:69
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafF.cxx:110
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafF.cxx:168
float Float_t
Definition: RtypesCore.h:53
virtual void ReadValue(std::istream &s, Char_t delim= ' ')
Read a float from std::istream s and store it into the branch buffer.
Definition: TLeafF.cxx:159
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
int Int_t
Definition: RtypesCore.h:41
virtual void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to ClonesArray.
Definition: TLeafF.cxx:59
TBranch * GetBranch() const
Definition: TLeaf.h:70
Int_t fLenType
Definition: TLeaf.h:43
virtual void * GetValuePointer() const
Definition: TLeafF.h:45
Int_t fLen
Number of elements in fAddress data buffer.
Definition: TLeaf.h:42
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:122
TLeafF()
Addresss of pointer to data buffer!
virtual Int_t GetMaximum() const
Definition: TLeaf.h:76
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
ClassImp(TLeafF) TLeafF
Default constructor for LeafF.
Definition: TLeafF.cxx:21
Float_t fMaximum
Definition: TLeafF.h:32
Int_t fNdata
Definition: TLeaf.h:41
PyObject * fValue
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
TLine * l
Definition: textangle.C:4
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:1198
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
A TLeaf for a 32 bit floating point data type.
Definition: TLeafF.h:28
Long64_t entry
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
virtual void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition: TLeafF.cxx:137
Float_t ** fPointer
Pointer to data buffer.
Definition: TLeafF.h:34
int type
Definition: TGX11.cxx:120
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Float_t fMinimum
Definition: TLeafF.h:31
Float_t * fValue
Definition: TLeafF.h:33
#define name(a, b)
Definition: linkTestLib0.cpp:5
Int_t fOffset
Definition: TLeaf.h:44
char Char_t
Definition: RtypesCore.h:29
An array of clone (identical) objects.
Definition: TClonesArray.h:32
virtual void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafF.cxx:85
TBranch * fBranch
Definition: TLeaf.h:48
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafF.cxx:75
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:301
TLeaf * fLeafCount
Definition: TLeaf.h:47
virtual ~TLeafF()
Default destructor for a LeafF.
Definition: TLeafF.cxx:51
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafF.cxx:101
virtual void ReadFloat(Float_t &f)=0
A TTree is a list of TBranches.
Definition: TBranch.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
float value
Definition: math.cpp:443
const Int_t n
Definition: legend1.C:16