Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
15A 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 <iostream>
23
24
25////////////////////////////////////////////////////////////////////////////////
26/// Default constructor for LeafS.
27
29{
30 fValue = nullptr;
31 fPointer = nullptr;
32 fMinimum = 0;
33 fMaximum = 0;
34 fLenType = 2;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Create a LeafS.
39
40TLeafS::TLeafS(TBranch *parent, const char *name, const char *type)
41 :TLeaf(parent,name,type)
42{
43 fLenType = 2;
44 fMinimum = 0;
45 fMaximum = 0;
46 fValue = nullptr;
47 fPointer = nullptr;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Default destructor for a LeafS.
52
54{
55 if (ResetAddress(nullptr,true)) delete [] fValue;
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Export element from local leaf buffer to ClonesArray.
60
62{
63 Int_t j = 0;
64 for (Int_t i=0;i<n;i++) {
65 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 2*fLen);
66 j += fLen;
67 }
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Pack leaf elements in Basket output buffer.
72
74{
75 Int_t i;
76 Int_t len = GetLen();
77 if (fPointer) fValue = *fPointer;
78 if (IsRange()) {
79 if (fValue[0] > fMaximum) fMaximum = fValue[0];
80 }
81 if (IsUnsigned()) {
82 for (i=0;i<len;i++) b << (UShort_t)fValue[i];
83 } else {
84 b.WriteFastArray(fValue,len);
85 }
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Returns name of leaf type.
90
91const char *TLeafS::GetTypeName() const
92{
93 if (fIsUnsigned) return "UShort_t";
94 return "Short_t";
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Returns current value of leaf.
99/// - if leaf is a simple type, i must be set to 0
100/// - if leaf is an array, i is the array element number to be returned
101
103{
104 if (fIsUnsigned) return (UShort_t)fValue[i];
105 return fValue[i];
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
110
112{
113 if (input) {
114 if (input->GetMaximum() > this->GetMaximum())
115 this->SetMaximum( input->GetMaximum() );
116 if (input->GetMinimum() < this->GetMinimum())
117 this->SetMinimum( input->GetMinimum() );
118 return true;
119 } else {
120 return false;
121 }
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Import element from ClonesArray into local leaf buffer.
126
128{
129 const Short_t kShortUndefined = -9999;
130 Int_t j = 0;
131 char *clone;
132 for (Int_t i=0;i<n;i++) {
133 clone = (char*)list->UncheckedAt(i);
134 if (clone)
135 memcpy(&fValue[j],clone + fOffset, 2*fLen);
136 else
137 for (Int_t k = 0; k < fLen; ++k)
138 fValue[j + k] = kShortUndefined;
139 j += fLen;
140 }
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Prints leaf value.
145
147{
148 if (fIsUnsigned) {
150 printf("%u",uvalue[l]);
151 } else {
153 printf("%d",value[l]);
154 }
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Read leaf elements from Basket input buffer.
159
161{
162 if (!fLeafCount && fNdata == 1) {
163 b.ReadShort(fValue[0]);
164 }else {
165 if (fLeafCount) {
167 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
169 }
171 if (len > fLeafCount->GetMaximum()) {
172 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
174 }
175 fNdata = len*fLen;
176 b.ReadFastArray(fValue,len*fLen);
177 } else {
178 b.ReadFastArray(fValue,fLen);
179 }
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Deserialize input by performing byteswap as needed.
186{
187 if (R__unlikely(fLeafCount)) {return false;}
188 return input_buf.ByteSwapBuffer(fLen*N, kShort_t);
189}
190
191////////////////////////////////////////////////////////////////////////////////
192/// Read leaf elements from Basket input buffer and export buffer to
193/// TClonesArray objects.
194
196{
197 if (n*fLen == 1) {
198 b >> fValue[0];
199 } else {
200 b.ReadFastArray(fValue,n*fLen);
201 }
202
203 Int_t j = 0;
204 for (Int_t i=0;i<n;i++) {
205 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], 2*fLen);
206 j += fLen;
207 }
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Read a integer integer from std::istream s and store it into the branch buffer.
212
213void TLeafS::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
214{
215 if (fIsUnsigned) {
217 for (Int_t i=0;i<fLen;i++) s >> uvalue[i];
218 } else {
220 for (Int_t i=0;i<fLen;i++) s >> value[i];
221 }
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Set leaf buffer data address.
226
227void TLeafS::SetAddress(void *add)
228{
229 if (ResetAddress(add) && (add!=fValue)) {
230 delete [] fValue;
231 }
232 if (add) {
234 fPointer = (Short_t**) add;
238 ncountmax > fNdata || *fPointer == nullptr) {
239 if (*fPointer) delete [] *fPointer;
241 *fPointer = new Short_t[fNdata];
242 }
243 fValue = *fPointer;
244 } else {
245 fValue = (Short_t*)add;
246 }
247 } else {
248 fValue = new Short_t[fNdata];
249 fValue[0] = 0;
250 }
251}
#define R__unlikely(expr)
Definition RConfig.hxx:594
#define b(i)
Definition RSha256.hxx:100
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
char Char_t
Character 1 byte (char)
Definition RtypesCore.h:51
short Short_t
Signed Short integer 2 bytes (short)
Definition RtypesCore.h:53
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ kShort_t
Definition TDataType.h:29
#define N
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
A TTree is a list of TBranches.
Definition TBranch.h:93
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:1705
Long64_t GetReadEntry() const
Definition TBranch.h:237
Buffer base class used for serializing objects.
Definition TBuffer.h:43
An array of clone (identical) objects.
Short_t fMaximum
Maximum value if leaf range is specified.
Definition TLeafS.h:30
Short_t fMinimum
Minimum value if leaf range is specified.
Definition TLeafS.h:29
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafS.cxx:73
virtual void SetMinimum(Short_t min)
Definition TLeafS.h:56
void * GetValuePointer() const override
Definition TLeafS.h:46
void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafS.cxx:195
const char * GetTypeName() const override
Returns name of leaf type.
Definition TLeafS.cxx:91
Short_t * fValue
! Pointer to data buffer
Definition TLeafS.h:31
void ReadValue(std::istream &s, Char_t delim=' ') override
Read a integer integer from std::istream s and store it into the branch buffer.
Definition TLeafS.cxx:213
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafS.cxx:227
void ReadBasket(TBuffer &b) override
Read leaf elements from Basket input buffer.
Definition TLeafS.cxx:160
virtual void SetMaximum(Short_t max)
Definition TLeafS.h:55
TLeafS()
Default constructor for LeafS.
Definition TLeafS.cxx:28
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafS.cxx:127
bool ReadBasketFast(TBuffer &, Long64_t) override
Deserialize input by performing byteswap as needed.
Definition TLeafS.cxx:185
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafS.cxx:146
Short_t ** fPointer
! Address of pointer to data buffer
Definition TLeafS.h:32
~TLeafS() override
Default destructor for a LeafS.
Definition TLeafS.cxx:53
Double_t GetValue(Int_t i=0) const override
Returns current value of leaf.
Definition TLeafS.cxx:102
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafS.cxx:61
bool IncludeRange(TLeaf *) override
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition TLeafS.cxx:111
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
virtual Double_t GetValue(Int_t i=0) const
Definition TLeaf.h:183
Int_t fLenType
Number of bytes for this data type.
Definition TLeaf.h:73
virtual Int_t GetMaximum() const
Definition TLeaf.h:134
virtual bool IsUnsigned() const
Definition TLeaf.h:150
Int_t fLen
Number of fixed length elements in the leaf's data.
Definition TLeaf.h:72
Int_t fNdata
! Number of elements in fAddress data buffer.
Definition TLeaf.h:71
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
Definition TLeaf.cxx:405
Int_t ResetAddress(void *add, bool calledFromDestructor=false)
Helper routine for TLeafX::SetAddress.
Definition TLeaf.cxx:430
TBranch * GetBranch() const
Definition TLeaf.h:116
Int_t fOffset
Offset in ClonesArray object (if one)
Definition TLeaf.h:74
virtual Int_t GetMinimum() const
Definition TLeaf.h:135
TBranch * fBranch
! Pointer to supporting branch (we do not own the branch)
Definition TLeaf.h:78
bool fIsUnsigned
(=true if unsigned, false otherwise)
Definition TLeaf.h:76
TLeaf * fLeafCount
Pointer to Leaf count if variable length (we do not own the counter)
Definition TLeaf.h:77
@ kIndirectAddress
Data member is a pointer to an array of basic types.
Definition TLeaf.h:95
virtual bool IsRange() const
Definition TLeaf.h:149
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:202
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4