Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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\ingroup tree
14
15A TLeaf for a bool data type.
16*/
17
18#include "TLeafO.h"
19#include "TBranch.h"
20#include "TBuffer.h"
21#include "TClonesArray.h"
22#include <iostream>
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Default constructor for LeafO.
28
30{
31 fValue = nullptr;
32 fPointer = nullptr;
33 fMinimum = false;
34 fMaximum = false;
35 fLenType = sizeof(bool);
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Create a LeafO.
40
41TLeafO::TLeafO(TBranch *parent, const char *name, const char *type)
42 : TLeaf(parent,name,type)
43{
44 fLenType = sizeof(bool);
45 fMinimum = false;
46 fMaximum = false;
47 fValue = nullptr;
48 fPointer = nullptr;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Default destructor for a LeafO.
53
55{
56 if (ResetAddress(nullptr,true)) 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], fLen);
67 j += fLen;
68 }
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Pack leaf elements in Basket output buffer.
73
75{
76 Int_t len = GetLen();
77 if (fPointer) fValue = *fPointer;
78 if (IsRange()) {
79 if (fValue[0] > fMaximum) fMaximum = fValue[0];
80 }
81 b.WriteFastArray(fValue,len);
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Returns name of leaf type.
86
87const char *TLeafO::GetTypeName() const
88{
89 return "Bool_t";
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
94
96{
97 if (input) {
98 if (input->GetMaximum() > this->GetMaximum())
99 this->SetMaximum( input->GetMaximum() );
100 if (input->GetMinimum() < this->GetMinimum())
101 this->SetMinimum( input->GetMinimum() );
102 return true;
103 } else {
104 return false;
105 }
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Import element from ClonesArray into local leaf buffer.
110
112{
113 Int_t j = 0;
114 for (Int_t i=0;i<n;i++) {
115 memcpy(&fValue[j],(char*)list->UncheckedAt(i) + fOffset, fLen);
116 j += fLen;
117 }
118}
119
120////////////////////////////////////////////////////////////////////////////////
121/// Prints leaf value.
122
124{
125 char *value = (char*)GetValuePointer();
126 printf("%d",(Int_t)value[l]);
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Read leaf elements from Basket input buffer.
131
133{
134 if (!fLeafCount && fNdata == 1) {
135 b.ReadBool(fValue[0]);
136 }else {
137 if (fLeafCount) {
138 Long64_t entry = fBranch->GetReadEntry();
139 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
140 fLeafCount->GetBranch()->GetEntry(entry);
141 }
143 if (len > fLeafCount->GetMaximum()) {
144 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
146 }
147 fNdata = len*fLen;
148 b.ReadFastArray(fValue,len*fLen);
149 } else {
150 b.ReadFastArray(fValue,fLen);
151 }
152 }
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Read leaf elements from Basket input buffer and export buffer to
157/// TClonesArray objects.
158
160{
161 b.ReadFastArray(fValue,n*fLen);
162
163 Int_t j = 0;
164 for (Int_t i=0;i<n;i++) {
165 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
166 j += fLen;
167 }
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Read a string from std::istream s and store it into the branch buffer.
172
173void TLeafO::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
174{
175 char *value = (char*)GetValuePointer();
176 for (Int_t i=0;i<fLen;i++) s >> value[i];
177}
178
179////////////////////////////////////////////////////////////////////////////////
180/// Set leaf buffer data address.
181
182void TLeafO::SetAddress(void *add)
183{
184 if (ResetAddress(add)) {
185 delete [] fValue;
186 }
187 if (add) {
189 fPointer = (bool**) add;
190 Int_t ncountmax = fLen;
191 if (fLeafCount) ncountmax = fLen*(fLeafCount->GetMaximum() + 1);
192 if ((fLeafCount && ncountmax > Int_t(fLeafCount->GetValue())) ||
193 ncountmax > fNdata || *fPointer == nullptr) {
194 if (*fPointer) delete [] *fPointer;
195 if (ncountmax > fNdata) fNdata = ncountmax;
196 *fPointer = new bool[fNdata];
197 }
198 fValue = *fPointer;
199 } else {
200 fValue = (bool*)add;
201 }
202 } else {
203 fValue = new bool[fNdata];
204 fValue[0] = false;
205 }
206}
#define b(i)
Definition RSha256.hxx:100
int Int_t
Definition RtypesCore.h:45
char Char_t
Definition RtypesCore.h:37
long long Long64_t
Definition RtypesCore.h:80
#define ClassImp(name)
Definition Rtypes.h:377
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:1706
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.
A TLeaf for a bool data type.
Definition TLeafO.h:26
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafO.cxx:62
void * GetValuePointer() const override
Definition TLeafO.h:46
bool ** fPointer
! Address of a pointer to data buffer!
Definition TLeafO.h:32
bool * fValue
! Pointer to data buffer
Definition TLeafO.h:31
virtual void SetMaximum(bool max)
Definition TLeafO.h:54
bool fMaximum
Maximum value if leaf range is specified.
Definition TLeafO.h:30
void ReadBasket(TBuffer &b) override
Read leaf elements from Basket input buffer.
Definition TLeafO.cxx:132
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafO.cxx:123
bool fMinimum
Minimum value if leaf range is specified.
Definition TLeafO.h:29
void ReadBasketExport(TBuffer &b, TClonesArray *list, Int_t n) override
Read leaf elements from Basket input buffer and export buffer to TClonesArray objects.
Definition TLeafO.cxx:159
TLeafO()
Default constructor for LeafO.
Definition TLeafO.cxx:29
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafO.cxx:74
const char * GetTypeName() const override
Returns name of leaf type.
Definition TLeafO.cxx:87
virtual void SetMinimum(bool min)
Definition TLeafO.h:55
bool IncludeRange(TLeaf *) override
Copy/set fMinimum and fMaximum to include/be wide than those of the parameter.
Definition TLeafO.cxx:95
~TLeafO() override
Default destructor for a LeafO.
Definition TLeafO.cxx:54
void ReadValue(std::istream &s, Char_t delim=' ') override
Read a string from std::istream s and store it into the branch buffer.
Definition TLeafO.cxx:173
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafO.cxx:111
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafO.cxx:182
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
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:404
Int_t ResetAddress(void *add, bool calledFromDestructor=false)
Helper routine for TLeafX::SetAddress.
Definition TLeaf.cxx:429
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
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:47
TObject * UncheckedAt(Int_t i) const
Definition TObjArray.h:84
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
const Int_t n
Definition legend1.C:16
TLine l
Definition textangle.C:4