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
TLeafO.cxx
Go to the documentation of this file.
1 // @(#)root/tree:$Id$
2 // Author: Philippe Canal 20/1/05
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, 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 TLeafO
13 A TLeaf for a bool data type.
14 */
15 
16 #include "TLeafO.h"
17 #include "TBranch.h"
18 #include "TClonesArray.h"
19 #include "Riostream.h"
20 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// Default constructor for LeafO.
25 
26 TLeafO::TLeafO(): TLeaf()
27 {
28  fValue = 0;
29  fPointer = 0;
30  fMinimum = 0;
31  fMaximum = 0;
32  fLenType = sizeof(Bool_t);
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Create a LeafO.
37 
38 TLeafO::TLeafO(TBranch *parent, const char *name, const char *type)
39  : TLeaf(parent,name,type)
40 {
41  fLenType = sizeof(Bool_t);
42  fMinimum = 0;
43  fMaximum = 0;
44  fValue = 0;
45  fPointer = 0;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Default destructor for a LeafO.
50 
52 {
53  if (ResetAddress(0,kTRUE)) delete [] fValue;
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Export element from local leaf buffer to ClonesArray.
58 
60 {
61  Int_t j = 0;
62  for (Int_t i=0;i<n;i++) {
63  memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
64  j += fLen;
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Pack leaf elements in Basket output buffer.
70 
72 {
73  Int_t len = GetLen();
74  if (fPointer) fValue = *fPointer;
75  if (IsRange()) {
76  if (fValue[0] > fMaximum) fMaximum = fValue[0];
77  }
78  b.WriteFastArray(fValue,len);
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Returns name of leaf type.
83 
84 const char *TLeafO::GetTypeName() const
85 {
86  return "Bool_t";
87 }
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Import element from ClonesArray into local leaf buffer.
91 
93 {
94  Int_t j = 0;
95  for (Int_t i=0;i<n;i++) {
96  memcpy(&fValue[j],(char*)list->UncheckedAt(i) + fOffset, fLen);
97  j += fLen;
98  }
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Prints leaf value.
103 
105 {
106  char *value = (char*)GetValuePointer();
107  printf("%d",(Int_t)value[l]);
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Read leaf elements from Basket input buffer.
112 
114 {
115  if (!fLeafCount && fNdata == 1) {
116  b.ReadBool(fValue[0]);
117  }else {
118  if (fLeafCount) {
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 {
143 
144  Int_t j = 0;
145  for (Int_t i=0;i<n;i++) {
146  memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
147  j += fLen;
148  }
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Read a string from std::istream s and store it into the branch buffer.
153 
154 void TLeafO::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
155 {
156  char *value = (char*)GetValuePointer();
157  s >> value;
158 }
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Set leaf buffer data address.
162 
163 void TLeafO::SetAddress(void *add)
164 {
165  if (ResetAddress(add)) {
166  delete [] fValue;
167  }
168  if (add) {
169  if (TestBit(kIndirectAddress)) {
170  fPointer = (Bool_t**) add;
171  Int_t ncountmax = fLen;
172  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
173  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
174  ncountmax > fNdata || *fPointer == 0) {
175  if (*fPointer) delete [] *fPointer;
176  if (ncountmax > fNdata) fNdata = ncountmax;
177  *fPointer = new Bool_t[fNdata];
178  }
179  fValue = *fPointer;
180  } else {
181  fValue = (Bool_t*)add;
182  }
183  } else {
184  fValue = new Bool_t[fNdata];
185  fValue[0] = 0;
186  }
187 }
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
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
A TLeaf for a bool data type.
Definition: TLeafO.h:28
TBranch * GetBranch() const
Definition: TLeaf.h:70
virtual void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition: TLeafO.cxx:140
Int_t fLenType
Definition: TLeaf.h:43
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafO.cxx:163
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafO.cxx:104
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
virtual void * GetValuePointer() const
Definition: TLeafO.h:47
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
Bool_t ** fPointer
Pointer to data buffer.
Definition: TLeafO.h:34
virtual void ReadBool(Bool_t &b)=0
Int_t fNdata
Definition: TLeaf.h:41
PyObject * fValue
Bool_t * fValue
Definition: TLeafO.h:33
Bool_t fMaximum
Definition: TLeafO.h:32
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
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 ~TLeafO()
Default destructor for a LeafO.
Definition: TLeafO.cxx:51
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafO.cxx:71
virtual void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to ClonesArray.
Definition: TLeafO.cxx:59
virtual void ReadValue(std::istream &s, Char_t delim= ' ')
Read a string from std::istream s and store it into the branch buffer.
Definition: TLeafO.cxx:154
virtual void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafO.cxx:92
int type
Definition: TGX11.cxx:120
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
ClassImp(TLeafO) TLeafO
Default constructor for LeafO.
Definition: TLeafO.cxx:21
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafO.cxx:113
#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
const char * GetTypeName() const
Returns name of leaf type.
Definition: TLeafO.cxx:84
TBranch * fBranch
Definition: TLeaf.h:48
virtual Bool_t IsRange() const
Definition: TLeaf.h:90
Int_t ResetAddress(void *add, Bool_t destructor=kFALSE)
Helper routine for TLeafX::SetAddress.
Definition: TLeaf.cxx:301
Bool_t fMinimum
Definition: TLeafO.h:31
TLeaf * fLeafCount
Definition: TLeaf.h:47
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
TLeafO()
Address of a pointer to data buffer!