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
24
25////////////////////////////////////////////////////////////////////////////////
26/// Default constructor for LeafO.
27
29{
30 fValue = nullptr;
31 fPointer = nullptr;
32 fMinimum = false;
33 fMaximum = false;
34 fLenType = sizeof(bool);
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Create a LeafO.
39
40TLeafO::TLeafO(TBranch *parent, const char *name, const char *type)
41 : TLeaf(parent,name,type)
42{
43 fLenType = sizeof(bool);
44 fMinimum = false;
45 fMaximum = false;
46 fValue = nullptr;
47 fPointer = nullptr;
48}
49
50////////////////////////////////////////////////////////////////////////////////
51/// Default destructor for a LeafO.
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], fLen);
66 j += fLen;
67 }
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Pack leaf elements in Basket output buffer.
72
74{
75 Int_t len = GetLen();
76 if (fPointer) fValue = *fPointer;
77 if (IsRange()) {
78 if (fValue[0] > fMaximum) fMaximum = fValue[0];
79 }
80 b.WriteFastArray(fValue,len);
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Returns name of leaf type.
85
86const char *TLeafO::GetTypeName() const
87{
88 return "Bool_t";
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// Copy/set fMinimum and fMaximum to include/be wide than those of the parameter
93
95{
96 if (input) {
97 if (input->GetMaximum() > this->GetMaximum())
98 this->SetMaximum( input->GetMaximum() );
99 if (input->GetMinimum() < this->GetMinimum())
100 this->SetMinimum( input->GetMinimum() );
101 return true;
102 } else {
103 return false;
104 }
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Import element from ClonesArray into local leaf buffer.
109
111{
112 Int_t j = 0;
113 for (Int_t i=0;i<n;i++) {
114 memcpy(&fValue[j],(char*)list->UncheckedAt(i) + fOffset, fLen);
115 j += fLen;
116 }
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Prints leaf value.
121
123{
124 char *value = (char*)GetValuePointer();
125 printf("%d",(Int_t)value[l]);
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Read leaf elements from Basket input buffer.
130
132{
133 if (!fLeafCount && fNdata == 1) {
134 b.ReadBool(fValue[0]);
135 }else {
136 if (fLeafCount) {
138 if (fLeafCount->GetBranch()->GetReadEntry() != entry) {
140 }
142 if (len > fLeafCount->GetMaximum()) {
143 printf("ERROR leaf:%s, len=%d and max=%d\n",GetName(),len,fLeafCount->GetMaximum());
145 }
146 fNdata = len*fLen;
147 b.ReadFastArray(fValue,len*fLen);
148 } else {
149 b.ReadFastArray(fValue,fLen);
150 }
151 }
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Read leaf elements from Basket input buffer and export buffer to
156/// TClonesArray objects.
157
159{
160 b.ReadFastArray(fValue,n*fLen);
161
162 Int_t j = 0;
163 for (Int_t i=0;i<n;i++) {
164 memcpy((char*)list->UncheckedAt(i) + fOffset,&fValue[j], fLen);
165 j += fLen;
166 }
167}
168
169////////////////////////////////////////////////////////////////////////////////
170/// Read a string from std::istream s and store it into the branch buffer.
171
172void TLeafO::ReadValue(std::istream &s, Char_t /*delim = ' '*/)
173{
174 char *value = (char*)GetValuePointer();
175 for (Int_t i=0;i<fLen;i++) s >> value[i];
176}
177
178////////////////////////////////////////////////////////////////////////////////
179/// Set leaf buffer data address.
180
181void TLeafO::SetAddress(void *add)
182{
183 if (ResetAddress(add)) {
184 delete [] fValue;
185 }
186 if (add) {
188 fPointer = (bool**) add;
192 ncountmax > fNdata || *fPointer == nullptr) {
193 if (*fPointer) delete [] *fPointer;
195 *fPointer = new bool[fNdata];
196 }
197 fValue = *fPointer;
198 } else {
199 fValue = (bool*)add;
200 }
201 } else {
202 fValue = new bool[fNdata];
203 fValue[0] = false;
204 }
205}
#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
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.
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.
void Export(TClonesArray *list, Int_t n) override
Export element from local leaf buffer to ClonesArray.
Definition TLeafO.cxx:61
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:131
void PrintValue(Int_t i=0) const override
Prints leaf value.
Definition TLeafO.cxx:122
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:158
TLeafO()
Default constructor for LeafO.
Definition TLeafO.cxx:28
void FillBasket(TBuffer &b) override
Pack leaf elements in Basket output buffer.
Definition TLeafO.cxx:73
const char * GetTypeName() const override
Returns name of leaf type.
Definition TLeafO.cxx:86
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:94
~TLeafO() override
Default destructor for a LeafO.
Definition TLeafO.cxx:53
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:172
void Import(TClonesArray *list, Int_t n) override
Import element from ClonesArray into local leaf buffer.
Definition TLeafO.cxx:110
void SetAddress(void *add=nullptr) override
Set leaf buffer data address.
Definition TLeafO.cxx:181
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: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
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