Logo ROOT  
Reference Guide
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 availible",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 availible",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);
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>
168T TFormLeafInfoReference::GetValueImpl(TLeaf *leaf, Int_t instance)
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>
209T TFormLeafInfoReference::ReadValueImpl(char *where, Int_t instance)
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
void Class()
Definition: Class.C:29
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:43
double Double_t
Definition: RtypesCore.h:57
long double LongDouble_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:71
#define gInterpreter
Definition: TInterpreter.h:556
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TVirtualRefProxy * GetReferenceProxy() const
Definition: TClass.h:480
A small helper class to implement the following of reference objects stored in a TTree.
virtual Int_t ReadCounterValue(char *where)
Return the size of the underlying array for the current entry in the TTree.
TBranch * fBranch
Cached pointer to reference proxy.
void Swap(TFormLeafInfoReference &other)
Exception safe swap.
virtual Int_t GetCounterValue(TLeaf *leaf)
Return the current size of the array container.
virtual TFormLeafInfo * DeepCopy() const
Virtual copy constructor.
virtual TClass * GetValueClass(TLeaf *from)
Access to the value class of the reference proxy.
virtual ~TFormLeafInfoReference()
Destructor.
virtual TClass * GetClass() const
Access to target class pointer (if available)
TFormLeafInfoReference(TClass *classptr, TStreamerElement *element, int off)
Cached pointer to branch object.
virtual Bool_t Update()
TFormLeafInfo overload: Update (and propagate) cached information.
virtual Bool_t HasCounter() const
Return true if any of underlying data has a array size counter.
virtual void * GetLocalValuePointer(TLeaf *from, Int_t instance=0)
This is implemented here because some compiler want ALL the signature of an overloaded function to be...
TFormLeafInfoReference & operator=(const TFormLeafInfoReference &orig)
Exception safe assignment operator.
This class is a small helper class to implement reading a data member on an object stored in a TTree.
Definition: TFormLeafInfo.h:49
TFormLeafInfo * fCounter
Descriptor of the data pointed to.
Definition: TFormLeafInfo.h:68
TClass * fClass
Definition: TFormLeafInfo.h:62
char * GetObjectAddress(TLeafElement *leaf, Int_t &instance)
Returns the 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
Definition: TFormLeafInfo.h:69
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....
Definition: TLeafElement.h:32
A TLeaf for a general object derived from TObject.
Definition: TLeafObject.h:31
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:49
TBranch * GetBranch() const
Definition: TLeaf.h:107
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
virtual TClass * GetValueClass(void *data) const =0
virtual void Release()=0
virtual Int_t GetCounterValue(TFormLeafInfoReference *info, void *data)=0
virtual TVirtualRefProxy * Clone() const =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
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
double T(double x)
Definition: ChebyshevPol.h:34
static Roo_reg_AGKInteg1D instance
#define org(otri, vertexptr)
Definition: triangle.c:1037