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