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