Logo ROOT   6.08/07
Reference Guide
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 
15 A 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 "Riostream.h"
23 
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Default constructor for LeafF.
28 
30 {
31  fLenType = 4;
32  fMinimum = 0;
33  fMaximum = 0;
34  fValue = 0;
35  fPointer = 0;
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Create a LeafF.
40 
41 TLeafF::TLeafF(TBranch *parent, const char *name, const char *type)
42  :TLeaf(parent, name,type)
43 {
44  fLenType = 4;
45  fMinimum = 0;
46  fMaximum = 0;
47  fValue = 0;
48  fPointer = 0;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default destructor for a LeafF.
53 
55 {
56  if (ResetAddress(0,kTRUE)) delete [] fValue;
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Export element from local leaf buffer to ClonesArray.
61 
63 {
64  Float_t *value = fValue;
65  for (Int_t i=0;i<n;i++) {
66  char *first = (char*)list->UncheckedAt(i);
67  Float_t *ff = (Float_t*)&first[fOffset];
68  for (Int_t j=0;j<fLen;j++) {
69  ff[j] = value[j];
70  }
71  value += fLen;
72  }
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// Pack leaf elements in Basket output buffer.
77 
79 {
80  Int_t len = GetLen();
81  if (fPointer) fValue = *fPointer;
82  b.WriteFastArray(fValue,len);
83 }
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Import element from ClonesArray into local leaf buffer.
87 
89 {
90  const Float_t kFloatUndefined = -9999.;
91  Int_t j = 0;
92  char *clone;
93  for (Int_t i=0;i<n;i++) {
94  clone = (char*)list->UncheckedAt(i);
95  if (clone) memcpy(&fValue[j],clone + fOffset, 4*fLen);
96  else memcpy(&fValue[j],&kFloatUndefined, 4*fLen);
97  j += fLen;
98  }
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Prints leaf value.
103 
105 {
106  Float_t *value = (Float_t *)GetValuePointer();
107  printf("%g",value[l]);
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Read leaf elements from Basket input buffer.
112 
114 {
115  if (!fLeafCount && fNdata == 1) {
116  b.ReadFloat(fValue[0]);
117  }else {
118  if (fLeafCount) {
119  Long64_t entry = fBranch->GetReadEntry();
120  if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
121  fLeafCount->GetBranch()->GetEntry(entry);
122  }
123  Int_t len = Int_t(fLeafCount->GetValue());
124  if (len > fLeafCount->GetMaximum()) {
125  printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
126  len = fLeafCount->GetMaximum();
127  }
128  fNdata = len*fLen;
129  b.ReadFastArray(fValue,len*fLen);
130  } else {
132  }
133  }
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// Read leaf elements from Basket input buffer and export buffer to
138 /// TClonesArray objects.
139 
141 {
142  if (n*fLen == 1) {
143  b >> fValue[0];
144  } else {
146  }
147 
148  Float_t *value = fValue;
149  for (Int_t i=0;i<n;i++) {
150  char *first = (char*)list->UncheckedAt(i);
151  Float_t *ff = (Float_t*)&first[fOffset];
152  for (Int_t j=0;j<fLen;j++) {
153  ff[j] = value[j];
154  }
155  value += fLen;
156  }
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// Read a float from std::istream s and store it into the branch buffer.
161 
162 void TLeafF::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
163 {
164  Float_t *value = (Float_t*)GetValuePointer();
165  for (Int_t i=0;i<fLen;i++) s >> value[i];
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// Set leaf buffer data address.
170 
171 void TLeafF::SetAddress(void *add)
172 {
173  if (ResetAddress(add) && (add!= fValue)) {
174  delete [] fValue;
175  }
176 
177  if (add) {
178  if (TestBit(kIndirectAddress)) {
179  fPointer = (Float_t**) add;
180  Int_t ncountmax = fLen;
181  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
182  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
183  ncountmax > fNdata || *fPointer == 0) {
184  if (*fPointer) delete [] *fPointer;
185  if (ncountmax > fNdata) fNdata = ncountmax;
186  *fPointer = new Float_t[fNdata];
187  }
188  fValue = *fPointer;
189  } else {
190  fValue = (Float_t*)add;
191  }
192  } else {
193  fValue = new Float_t[fNdata];
194  fValue[0] = 0;
195  }
196 }
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
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:113
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafF.cxx:171
float Float_t
Definition: RtypesCore.h:53
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:157
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
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:62
Int_t fLenType
Number of bytes for this data type.
Definition: TLeaf.h:43
virtual Double_t GetValue(Int_t i=0) const
Definition: TLeaf.h:122
virtual void * GetValuePointer() const
Definition: TLeafF.h:45
Int_t fLen
Number of fixed length elements.
Definition: TLeaf.h:42
TLeafF()
Default constructor for LeafF.
Definition: TLeafF.cxx:29
virtual Int_t GetLen() const
Return the number of effective elements of this leaf.
Definition: TLeaf.cxx:279
Float_t fMaximum
Maximum value if leaf range is specified.
Definition: TLeafF.h:32
Int_t fNdata
! Number of elements in fAddress data buffer
Definition: TLeaf.h:41
PyObject * fValue
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:1217
A TLeaf for a 32 bit floating point data type.
Definition: TLeafF.h:28
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:140
Data member is a pointer to an array of basic types.
Definition: TLeaf.h:59
Float_t ** fPointer
! Address of pointer to data buffer!
Definition: TLeafF.h:34
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
virtual Int_t GetMaximum() const
Definition: TLeaf.h:76
#define ClassImp(name)
Definition: Rtypes.h:279
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:162
int type
Definition: TGX11.cxx:120
Float_t fMinimum
Minimum value if leaf range is specified.
Definition: TLeafF.h:31
Float_t * fValue
! Pointer to data buffer
Definition: TLeafF.h:33
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafF.cxx:104
Int_t fOffset
Offset in ClonesArray object (if one)
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:88
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition: TLeaf.h:48
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafF.cxx:78
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:304
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition: TLeaf.h:47
Long64_t GetReadEntry() const
Definition: TBranch.h:170
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual ~TLeafF()
Default destructor for a LeafF.
Definition: TLeafF.cxx:54
Definition: first.py:1
virtual void ReadFloat(Float_t &f)=0
TBranch * GetBranch() const
Definition: TLeaf.h:70
A TTree is a list of TBranches.
Definition: TBranch.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16
char name[80]
Definition: TGX11.cxx:109