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