ROOT  6.06/09
Reference Guide
TLeafS.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 TLeafS
13 A TLeaf for a 16 bit Integer data type.
14 */
15 
16 #include "TLeafS.h"
17 #include "TBranch.h"
18 #include "TClonesArray.h"
19 #include "Riostream.h"
20 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// Default constructor for LeafS.
25 
26 TLeafS::TLeafS(): TLeaf()
27 {
28  fValue = 0;
29  fPointer = 0;
30  fMinimum = 0;
31  fMaximum = 0;
32  fLenType = 2;
33 }
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 /// Create a LeafS.
37 
38 TLeafS::TLeafS(TBranch *parent, const char *name, const char *type)
39  :TLeaf(parent,name,type)
40 {
41  fLenType = 2;
42  fMinimum = 0;
43  fMaximum = 0;
44  fValue = 0;
45  fPointer = 0;
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Default destructor for a LeafS.
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], 2*fLen);
64  j += fLen;
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Pack leaf elements in Basket output buffer.
70 
72 {
73  Int_t i;
74  Int_t len = GetLen();
75  if (fPointer) fValue = *fPointer;
76  if (IsRange()) {
77  if (fValue[0] > fMaximum) fMaximum = fValue[0];
78  }
79  if (IsUnsigned()) {
80  for (i=0;i<len;i++) b << (UShort_t)fValue[i];
81  } else {
82  b.WriteFastArray(fValue,len);
83  }
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Returns name of leaf type.
88 
89 const char *TLeafS::GetTypeName() const
90 {
91  if (fIsUnsigned) return "UShort_t";
92  return "Short_t";
93 }
94 
95 ////////////////////////////////////////////////////////////////////////////////
96 /// Returns current value of leaf.
97 /// - if leaf is a simple type, i must be set to 0
98 /// - if leaf is an array, i is the array element number to be returned
99 
101 {
102  if (fIsUnsigned) return (UShort_t)fValue[i];
103  return fValue[i];
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Import element from ClonesArray into local leaf buffer.
108 
110 {
111  const Short_t kShortUndefined = -9999;
112  Int_t j = 0;
113  char *clone;
114  for (Int_t i=0;i<n;i++) {
115  clone = (char*)list->UncheckedAt(i);
116  if (clone) memcpy(&fValue[j],clone + fOffset, 2*fLen);
117  else memcpy(&fValue[j],&kShortUndefined, 2*fLen);
118  j += fLen;
119  }
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Prints leaf value.
124 
126 {
127  if (fIsUnsigned) {
128  UShort_t *uvalue = (UShort_t*)GetValuePointer();
129  printf("%u",uvalue[l]);
130  } else {
132  printf("%d",value[l]);
133  }
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// Read leaf elements from Basket input buffer.
138 
140 {
141  if (!fLeafCount && fNdata == 1) {
142  b.ReadShort(fValue[0]);
143  }else {
144  if (fLeafCount) {
146  if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
147  fLeafCount->GetBranch()->GetEntry(entry);
148  }
149  Int_t len = Int_t(fLeafCount->GetValue());
150  if (len > fLeafCount->GetMaximum()) {
151  printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
152  len = fLeafCount->GetMaximum();
153  }
154  fNdata = len*fLen;
155  b.ReadFastArray(fValue,len*fLen);
156  } else {
158  }
159  }
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Read leaf elements from Basket input buffer and export buffer to
164 /// TClonesArray objects.
165 
167 {
168  if (n*fLen == 1) {
169  b >> fValue[0];
170  } else {
172  }
173 
174  Int_t j = 0;
175  for (Int_t i=0;i<n;i++) {
176  memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 2*fLen);
177  j += fLen;
178  }
179 }
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 /// Read a integer integer from std::istream s and store it into the branch buffer.
183 
184 void TLeafS::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
185 {
186  if (fIsUnsigned) {
187  UShort_t *uvalue = (UShort_t*)GetValuePointer();
188  for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
189  } else {
191  for (Int_t i=0;i<fLen;i++) s >> value[i];
192  }
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Set leaf buffer data address.
197 
198 void TLeafS::SetAddress(void *add)
199 {
200  if (ResetAddress(add) && (add!=fValue)) {
201  delete [] fValue;
202  }
203  if (add) {
204  if (TestBit(kIndirectAddress)) {
205  fPointer = (Short_t**) add;
206  Int_t ncountmax = fLen;
207  if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
208  if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
209  ncountmax > fNdata || *fPointer == 0) {
210  if (*fPointer) delete [] *fPointer;
211  if (ncountmax > fNdata) fNdata = ncountmax;
212  *fPointer = new Short_t[fNdata];
213  }
214  fValue = *fPointer;
215  } else {
216  fValue = (Short_t*)add;
217  }
218  } else {
219  fValue = new Short_t[fNdata];
220  fValue[0] = 0;
221  }
222 }
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
virtual void ReadValue(std::istream &s, Char_t delim= ' ')
Read a integer integer from std::istream s and store it into the branch buffer.
Definition: TLeafS.cxx:184
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 Bool_t IsUnsigned() const
Definition: TLeaf.h:91
unsigned short UShort_t
Definition: RtypesCore.h:36
Buffer base class used for serializing objects.
Definition: TBuffer.h:40
TLeafS()
Address of pointer to data buffer.
virtual void ReadShort(Short_t &s)=0
int Int_t
Definition: RtypesCore.h:41
TBranch * GetBranch() const
Definition: TLeaf.h:70
Int_t fLenType
Definition: TLeaf.h:43
virtual void * GetValuePointer() const
Definition: TLeafS.h:47
virtual void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n)
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition: TLeafS.cxx:166
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 void Import(TClonesArray *list, Int_t n)
Import element from ClonesArray into local leaf buffer.
Definition: TLeafS.cxx:109
Short_t fMaximum
Definition: TLeafS.h:32
virtual Int_t GetMaximum() const
Definition: TLeaf.h:76
TObject * UncheckedAt(Int_t i) const
Definition: TObjArray.h:91
virtual void ReadBasket(TBuffer &b)
Read leaf elements from Basket input buffer.
Definition: TLeafS.cxx:139
virtual void SetAddress(void *add=0)
Set leaf buffer data address.
Definition: TLeafS.cxx:198
Double_t GetValue(Int_t i=0) const
Returns current value of leaf.
Definition: TLeafS.cxx:100
Short_t * fValue
Definition: TLeafS.h:33
Int_t fNdata
Definition: TLeaf.h:41
PyObject * fValue
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:173
virtual void Export(TClonesArray *list, Int_t n)
Export element from local leaf buffer to ClonesArray.
Definition: TLeafS.cxx:59
short Short_t
Definition: RtypesCore.h:35
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
const char * GetTypeName() const
Returns name of leaf type.
Definition: TLeafS.cxx:89
virtual void PrintValue(Int_t i=0) const
Prints leaf value.
Definition: TLeafS.cxx:125
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)
Bool_t fIsUnsigned
Definition: TLeaf.h:46
Short_t ** fPointer
Pointer to data buffer.
Definition: TLeafS.h:34
#define name(a, b)
Definition: linkTestLib0.cpp:5
Int_t fOffset
Definition: TLeaf.h:44
char Char_t
Definition: RtypesCore.h:29
A TLeaf for a 16 bit Integer data type.
Definition: TLeafS.h:28
An array of clone (identical) objects.
Definition: TClonesArray.h:32
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
TLeaf * fLeafCount
Definition: TLeaf.h:47
virtual void FillBasket(TBuffer &b)
Pack leaf elements in Basket output buffer.
Definition: TLeafS.cxx:71
A TTree is a list of TBranches.
Definition: TBranch.h:58
const Bool_t kTRUE
Definition: Rtypes.h:91
ClassImp(TLeafS) TLeafS
Default constructor for LeafS.
Definition: TLeafS.cxx:21
Short_t fMinimum
Definition: TLeafS.h:31
float value
Definition: math.cpp:443
const Int_t n
Definition: legend1.C:16
virtual ~TLeafS()
Default destructor for a LeafS.
Definition: TLeafS.cxx:51