ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 A TLeaf for a 64 bit floating point data type.
14 */
15 
16 #include "TLeafD.h"
17 #include "TBranch.h"
18 #include "TBuffer.h"
19 #include "TClonesArray.h"
20 #include "Riostream.h"
21 
23 
24 ////////////////////////////////////////////////////////////////////////////////
25 /// Default constructor for LeafD.
26 
27 TLeafD::TLeafD(): TLeaf()
28 {
29  fLenType = 8;
30  fMinimum = 0;
31  fMaximum = 0;
32  fValue = 0;
33  fPointer = 0;
34 }
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 /// Create a LeafD.
38 
39 TLeafD::TLeafD(TBranch *parent, const char *name, const char *type)
40  :TLeaf(parent, name,type)
41 {
42  fLenType = 8;
43  fMinimum = 0;
44  fMaximum = 0;
45  fValue = 0;
46  fPointer = 0;
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Default destructor for a LeafD.
51 
53 {
54  if (ResetAddress(0,kTRUE)) delete [] fValue;
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Export element from local leaf buffer to ClonesArray.
59 
61 {
62  Int_t j = 0;
63  for (Int_t i=0;i<n;i++) {
64  memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 8*fLen);
65  j += fLen;
66  }
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Pack leaf elements in Basket output buffer.
71 
73 {
74  Int_t len = GetLen();
75  if (fPointer) fValue = *fPointer;
76  b.WriteFastArray(fValue,len);
77 }
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// Import element from ClonesArray into local leaf buffer.
81 
83 {
84  const Double_t kDoubleUndefined = -9999.;
85  Int_t j = 0;
86  char *clone;
87  for (Int_t i=0;i<n;i++) {
88  clone = (char*)list->UncheckedAt(i);
89  if (clone) memcpy(&fValue[j],clone + fOffset, 8*fLen);
90  else memcpy(&fValue[j],&kDoubleUndefined, 8*fLen);
91  j += fLen;
92  }
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Prints leaf value.
97 
99 {
101  printf("%g",value[l]);
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Read leaf elements from Basket input buffer.
106 
108 {
109  if (!fLeafCount && fNdata == 1) {
110  b.ReadDouble(fValue[0]);
111  }else {
112  if (fLeafCount) {
114  if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
115  fLeafCount->GetBranch()->GetEntry(entry);
116  }
117  Int_t len = Int_t(fLeafCount->GetValue());
118  if (len > fLeafCount->GetMaximum()) {
119  printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
120  len = fLeafCount->GetMaximum();
121  }
122  fNdata = len*fLen;
123  b.ReadFastArray(fValue,len*fLen);
124  } else {
126  }
127  }
128 }
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Read leaf elements from Basket input buffer and export buffer to
132 /// TClonesArray objects.
133 
135 {
137 
138  Int_t j = 0;
139  for (Int_t i=0;i<n;i++) {
140  memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 8*fLen);
141  j += fLen;
142  }
143 }
144 
145 ////////////////////////////////////////////////////////////////////////////////
146 /// Read a double from std::istream s and store it into the branch buffer.
147 
148 void TLeafD::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
149 {
151  for (Int_t i=0;i<fLen;i++) s >> value[i];
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Set leaf buffer data address.
156 
157 void TLeafD::SetAddress(void *add)
158 {
159  if (ResetAddress(add) && (add!= fValue)) {
160  delete [] fValue;
161  }
162  if (add) {
163  if (TestBit(kIndirectAddress)) {
164  fPointer = (Double_t**) add;
165  Int_t ncountmax = fLen;
166  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
167  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
168  ncountmax > fNdata || *fPointer == 0) {
169  if (*fPointer) delete [] *fPointer;
170  if (ncountmax > fNdata) fNdata = ncountmax;
171  *fPointer = new Double_t[fNdata];
172  }
173  fValue = *fPointer;
174  } else {
175  fValue = (Double_t*)add;
176  }
177  } else {
178  fValue = new Double_t[fNdata];
179  fValue[0] = 0;
180  }
181 }
Double_t * fValue
Definition: TLeafD.h:33
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
A TLeaf for a 64 bit floating point data type.
Definition: TLeafD.h:28
long long Long64_t
Definition: RtypesCore.h:69
virtual ~TLeafD()
Default destructor for a LeafD.
Definition: TLeafD.cxx:52
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafD.cxx:72
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:134
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
int Int_t
Definition: RtypesCore.h:41
TBranch * GetBranch() const
Definition: TLeaf.h:70
Int_t fLenType
Definition: TLeaf.h:43
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafD.cxx:157
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafD.cxx:98
virtual void * GetValuePointer() const
Definition: TLeafD.h:45
virtual void ReadDouble(Double_t &d)=0
virtual void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafD.cxx:82
Double_t ** fPointer
Pointer to data buffer.
Definition: TLeafD.h:34
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
virtual Int_t GetMaximum() const
Definition: TLeaf.h:76
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
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:1199
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
Long64_t entry
Double_t fMinimum
Definition: TLeafD.h:31
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
double Double_t
Definition: RtypesCore.h:55
int type
Definition: TGX11.cxx:120
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafD.cxx:107
#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 ReadValue(std::istream &s, Char_t delim= ' ')
Read a double from std::istream s and store it into the branch buffer.
Definition: TLeafD.cxx:148
Double_t fMaximum
Definition: TLeafD.h:32
TBranch * fBranch
Definition: TLeaf.h:48
ClassImp(TLeafD) TLeafD
Default constructor for LeafD.
Definition: TLeafD.cxx:22
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 void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to ClonesArray.
Definition: TLeafD.cxx:60
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
TLeafD()
Address of pointer to data buffer.