Logo ROOT   6.12/07
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"
16 #include "TFormLeafInfoReference.h"
17 
18 /** \class TFormLeafInfoReference
19 A small helper class to implement the following
20 of 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 {
64  TFormLeafInfo::Swap(other);
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 
167 template <typename T>
168 T TFormLeafInfoReference::GetValueImpl(TLeaf *leaf, Int_t instance)
169 {
170  fBranch = leaf->GetBranch();
171  return TFormLeafInfo::GetValueImpl<T>(leaf, instance);
172 }
173 
174 template Double_t TFormLeafInfoReference::GetValueImpl<Double_t>(TLeaf*, Int_t);
175 template Long64_t TFormLeafInfoReference::GetValueImpl<Long64_t>(TLeaf*, Int_t);
176 template 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();
185  return TFormLeafInfo::GetLocalValuePointer(from, instance);
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 
208 template <typename T>
209 T 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 
226 template Double_t TFormLeafInfoReference::ReadValueImpl<Double_t>(char*, Int_t);
227 template Long64_t TFormLeafInfoReference::ReadValueImpl<Long64_t>(char*, Int_t);
228 template LongDouble_t TFormLeafInfoReference::ReadValueImpl<LongDouble_t>(char*, Int_t);
229 
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
Definition: TLeaf.h:32
A small helper class to implement the following of reference objects stored in a TTree.
TFormLeafInfoReference(TClass *classptr, TStreamerElement *element, int off)
Cached pointer to branch object.
long long Long64_t
Definition: RtypesCore.h:69
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
double T(double x)
Definition: ChebyshevPol.h:34
A TLeaf for a general object derived from TObject.
Definition: TLeafObject.h:31
TFormLeafInfoReference & operator=(const TFormLeafInfoReference &orig)
Exception safe assignment operator.
virtual TClass * GetClass() const
Access to target class pointer (if available)
virtual TClass * GetClass() const
Get the class of the underlying data.
TFormLeafInfo * fNext
Definition: TFormLeafInfo.h:69
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define gInterpreter
Definition: TInterpreter.h:526
virtual Int_t GetCounterValue(TLeaf *leaf)
Return the current size of the array container.
virtual Bool_t Update()
We reloading all cached information in case the underlying class information has changed (for example...
virtual Bool_t Update()
TFormLeafInfo overload: Update (and propagate) cached information.
void Swap(TFormLeafInfoReference &other)
Exception safe swap.
virtual Int_t GetCounterValue(TFormLeafInfoReference *info, void *data)=0
void Class()
Definition: Class.C:29
virtual void * GetObject(TFormLeafInfoReference *info, void *data, int instance)=0
virtual Bool_t HasCounter() const
Return true if any of underlying data has a array size counter.
virtual Bool_t HasCounter() const =0
char * GetObjectAddress(TLeafElement *leaf, Int_t &instance)
Returns the the location of the object pointed to.
virtual void * GetPreparedReference(void *data)=0
virtual Bool_t HasCounter() const
Return true if any of underlying data has a array size counter.
virtual ~TFormLeafInfoReference()
Destructor.
TClass * fClass
Definition: TFormLeafInfo.h:62
virtual TFormLeafInfo * DeepCopy() const
Virtual copy constructor.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
virtual void Release()=0
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
T ReadTypedValue(char *where, Int_t instance=0)
long double LongDouble_t
Definition: RtypesCore.h:57
TVirtualRefProxy * GetReferenceProxy() const
Definition: TClass.h:448
A TLeaf for the general case when using the branches created via a TStreamerInfo (i.e.
Definition: TLeafElement.h:30
TBranch * fBranch
Cached pointer to reference proxy.
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...
double Double_t
Definition: RtypesCore.h:55
This class is a small helper class to implement reading a data member on an object stored in a TTree...
Definition: TFormLeafInfo.h:49
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
virtual TClass * GetValueClass(TLeaf *from)
Access to the value class of the reference proxy.
#define org(otri, vertexptr)
Definition: triangle.c:1037
void Swap(TFormLeafInfo &other)
virtual TClass * GetValueClass(void *data) const =0
virtual void * GetLocalValuePointer(TLeaf *leaf, Int_t instance=0)
returns the address of the value pointed to by the TFormLeafInfo.
virtual Bool_t Update()=0
TFormLeafInfo * fCounter
Descriptor of the data pointed to.
Definition: TFormLeafInfo.h:68
TBranch * GetBranch() const
Definition: TLeaf.h:71
virtual Int_t ReadCounterValue(char *where)
Return the size of the underlying array for the current entry in the TTree.
virtual TVirtualRefProxy * Clone() const =0