Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TFormLeafInfoReference.cxx
Go to the documentation of this file.
1// @(#)root/treeplayer:$Id$
2// Author: Markus Frank 01/02/2006
3
4/*************************************************************************
5* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers and al. *
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#include "TError.h"
13#include "TLeafObject.h"
14#include "TInterpreter.h"
15#include "TVirtualRefProxy.h"
17
18/** \class TFormLeafInfoReference
19A small helper class to implement the following
20of reference objects stored in a TTree
21*/
22
23////////////////////////////////////////////////////////////////////////////////
24/// Constructor.
25
27: TFormLeafInfo(cl,off,e), fProxy(0), fBranch(0)
28{
30 if ( !p ) {
31 ::Error("TFormLeafInfoReference","No reference proxy for class %s available",cl->GetName());
32 return;
33 }
34 fProxy = p->Clone();
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Copy constructor.
39
41: TFormLeafInfo(org), fProxy(0), fBranch(org.fBranch)
42{
43 TVirtualRefProxy* p = org.fProxy;
44 if ( !p ) {
45 ::Error("TFormLeafInfoReference","No reference proxy for class %s available",fClass->GetName());
46 return;
47 }
48 fProxy = p->Clone();
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Destructor.
53
55{
56 if ( fProxy ) fProxy->Release();
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Exception safe swap.
61
63{
65 std::swap(fProxy,other.fProxy);
66 std::swap(fBranch,other.fBranch);
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Exception safe assignment operator.
71
73{
74 TFormLeafInfoReference tmp(other);
75 Swap(tmp);
76 return *this;
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// Virtual copy constructor.
81
83{
84 return new TFormLeafInfoReference(*this);
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Access to target class pointer (if available)
89
91{
92 return fNext ? fNext->GetClass() : 0;
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Return true if any of underlying data has a array size counter
97
99{
100 Bool_t result = fProxy ? fProxy->HasCounter() : false;
101 if (fNext) result |= fNext->HasCounter();
102 return fCounter!=0 || result;
103}
104////////////////////////////////////////////////////////////////////////////////
105/// Return the size of the underlying array for the current entry in the TTree.
106
108{
109 Int_t result = 0;
110 if ( where && HasCounter() ) {
111 where = (char*)fProxy->GetPreparedReference(where);
112 if ( where ) {
113 return fProxy->GetCounterValue(this, where);
114 }
115 }
116 gInterpreter->ClearStack();
117 // Get rid of temporary return object.
118 return result;
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Return the current size of the array container
123
125 if ( HasCounter() ) {
126 char *thisobj = 0;
127 Int_t instance = 0;
128 if (leaf->InheritsFrom(TLeafObject::Class()) ) {
129 thisobj = (char*)((TLeafObject*)leaf)->GetObject();
130 } else {
131 thisobj = GetObjectAddress((TLeafElement*)leaf, instance); // instance might be modified
132 }
133 return ReadCounterValue(thisobj);
134 }
135 return 0;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Access to the value class of the reference proxy
140
142{
143 return this->GetValueClass(this->GetLocalValuePointer(leaf,0));
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Access to the value class of the reference proxy
148
150{
151 return fProxy ? fProxy->GetValueClass(obj) : 0;
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// TFormLeafInfo overload: Update (and propagate) cached information
156
158{
159 Bool_t res = this->TFormLeafInfo::Update();
160 if ( fProxy ) fProxy->Update();
161 return res;
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Return result of a leafobject method
166
167template <typename T>
169{
170 fBranch = leaf->GetBranch();
171 return TFormLeafInfo::GetValueImpl<T>(leaf, instance);
172}
173
174template Double_t TFormLeafInfoReference::GetValueImpl<Double_t>(TLeaf*, Int_t);
175template Long64_t TFormLeafInfoReference::GetValueImpl<Long64_t>(TLeaf*, Int_t);
176template LongDouble_t TFormLeafInfoReference::GetValueImpl<LongDouble_t>(TLeaf*, Int_t);
177
178////////////////////////////////////////////////////////////////////////////////
179/// This is implemented here because some compiler want ALL the
180/// signature of an overloaded function to be re-implemented.
181
183{
184 fBranch = from->GetBranch();
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Access value of referenced object
190
192{
193 if (where) {
194 where = (char*)fProxy->GetPreparedReference(where);
195 if (where) {
196 void* result = fProxy->GetObject(this, where, instance);
197 gInterpreter->ClearStack();
198 return result;
199 }
200 }
201 gInterpreter->ClearStack();
202 return 0;
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Execute the method on the given address
207
208template <typename T>
210{
211 T result = 0;
212 if ( where ) {
213 where = (char*)fProxy->GetPreparedReference(where);
214 if ( where ) {
215 void* res = fProxy->GetObject(this, where, instance);
216 if ( res ) {
217 result = (fNext) ? fNext->ReadTypedValue<T>((char*)res,instance) : *(Double_t*)res;
218 }
219 }
220 }
221 gInterpreter->ClearStack();
222 // Get rid of temporary return object.
223 return result;
224}
225
226template Double_t TFormLeafInfoReference::ReadValueImpl<Double_t>(char*, Int_t);
227template Long64_t TFormLeafInfoReference::ReadValueImpl<Long64_t>(char*, Int_t);
228template LongDouble_t TFormLeafInfoReference::ReadValueImpl<LongDouble_t>(char*, Int_t);
229
#define e(i)
Definition RSha256.hxx:103
static Roo_reg_AGKInteg1D instance
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
long double LongDouble_t
Definition RtypesCore.h:61
long long Long64_t
Definition RtypesCore.h:80
winID h TVirtualViewer3D TVirtualGLPainter p
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 result
#define gInterpreter
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
TVirtualRefProxy * GetReferenceProxy() const
Definition TClass.h:483
A small helper class to implement the following of reference objects stored in a TTree.
T ReadValueImpl(char *where, Int_t instance=0)
Execute the method on the given address.
Int_t ReadCounterValue(char *where) override
Return the size of the underlying array for the current entry in the TTree.
TBranch * fBranch
! Cached pointer to branch object
Bool_t HasCounter() const override
Return true if any of underlying data has a array size counter.
void Swap(TFormLeafInfoReference &other)
Exception safe swap.
Proxy * fProxy
! Cached pointer to reference proxy
T GetValueImpl(TLeaf *leaf, Int_t instance=0)
Return result of a leafobject method.
Bool_t Update() override
TFormLeafInfo overload: Update (and propagate) cached information.
TFormLeafInfo * DeepCopy() const override
Virtual copy constructor.
virtual TClass * GetValueClass(TLeaf *from)
Access to the value class of the reference proxy.
TClass * GetClass() const override
Access to target class pointer (if available)
TFormLeafInfoReference(TClass *classptr, TStreamerElement *element, int off)
Initializing constructor.
~TFormLeafInfoReference() override
Default destructor.
TFormLeafInfoReference & operator=(const TFormLeafInfoReference &orig)
Exception safe assignment operator.
void * GetLocalValuePointer(TLeaf *from, Int_t instance=0) override
Return the address of the local value.
Int_t GetCounterValue(TLeaf *leaf) override
Return the current size of the array container.
This class is a small helper class to implement reading a data member on an object stored in a TTree.
TFormLeafInfo * fCounter
TClass * fClass
! This is the class of the data pointed to
char * GetObjectAddress(TLeafElement *leaf, Int_t &instance)
Returns the location of the object pointed to.
virtual Bool_t HasCounter() const
Return true if any of underlying data has a array size counter.
virtual TClass * GetClass() const
Get the class of the underlying data.
TFormLeafInfo * fNext
follow this to grab the inside information
T ReadTypedValue(char *where, Int_t instance=0)
void Swap(TFormLeafInfo &other)
virtual Bool_t Update()
We reloading all cached information in case the underlying class information has changed (for example...
virtual void * GetLocalValuePointer(TLeaf *leaf, Int_t instance=0)
returns the address of the value pointed to by the TFormLeafInfo.
A TLeaf for the general case when using the branches created via a TStreamerInfo (i....
A TLeaf for a general object derived from TObject.
Definition TLeafObject.h:31
static TClass * Class()
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition TLeaf.h:57
TBranch * GetBranch() const
Definition TLeaf.h:116
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:223
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual TClass * GetValueClass(void *data) const =0
virtual void Release()=0
virtual Int_t GetCounterValue(TFormLeafInfoReference *info, void *data)=0
virtual Bool_t HasCounter() const =0
virtual void * GetObject(TFormLeafInfoReference *info, void *data, int instance)=0
virtual void * GetPreparedReference(void *data)=0
virtual Bool_t Update()=0
#define Swap(a, b)
Definition geom.c:201
#define org(otri, vertexptr)
Definition triangle.c:1038