Logo ROOT   6.10/09
Reference Guide
TBranchProxyTemplate.h
Go to the documentation of this file.
1 // @(#)root/treeplayer:$Id$
2 // Author: Philippe Canal 01/06/2004
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, 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 #ifndef ROOT_TBranchProxyTemplate
13 #define ROOT_TBranchProxyTemplate
14 
15 #if R__BRANCHPROXY_GENERATOR_VERSION != 2
16 // Generated source and branch proxy interface are out of sync.
17 # error "Please regenerate this file using TTree::MakeProxy()!"
18 #endif
19 
20 #include "TBranchProxy.h"
21 
22 #define InjecTBranchProxyInterface() \
23  ROOT::Detail::TBranchProxy *GetProxy() { return obj.GetProxy(); } \
24  void Reset() { obj.Reset(); } \
25  bool Setup() { return obj.Setup(); } \
26  bool IsInitialized() { return obj.IsInitialized(); } \
27  bool IsaPointer() const { return obj.IsaPointer(); } \
28  bool Read() { return obj.Read(); }
29 
30 namespace ROOT {
31 namespace Internal {
32  template <class T>
33  class TObjProxy {
35  public:
37 
38  TObjProxy() : obj() {};
39  TObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
40  TObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
41  obj(director,top,name) {};
42  TObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
43  obj(director,top,name,data) {};
44  TObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
45  obj(director,parent, name, top, mid) {};
46  ~TObjProxy() {};
47 
48  Int_t GetOffset() { return obj.GetOffset(); }
49 
50  void Print() {
51  obj.Print();
52  std::cout << "fWhere " << obj.GetWhere() << std::endl;
53  if (obj.GetWhere()) std::cout << "address? " << (T*)obj.GetWhere() << std::endl;
54  }
55 
56  T* GetPtr() {
57  //static T default_val;
58  if (!obj.Read()) return 0; // &default_val;
59  T *temp = (T*)obj.GetStart();
60  // if (temp==0) return &default_val;
61  return temp;
62  }
63 
64  T* operator->() { return GetPtr(); }
65  operator T*() { return GetPtr(); }
66  // operator T&() { return *GetPtr(); }
67 
68  };
69 
70  template <class T>
71  class TClaObjProxy {
73  public:
75 
76  void Print() {
77  obj.Print();
78  std::cout << "obj.GetWhere() " << obj.GetWhere() << std::endl;
79  //if (obj.GetWhere()) std::cout << "value? " << *(T*)obj.GetWhere() << std::endl;
80  }
81 
82  TClaObjProxy() : obj() {};
83  TClaObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
84  TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
85  obj(director,top,name) {};
86  TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
87  obj(director,top,name,data) {};
88  TClaObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
89  obj(director,parent, name, top, mid) {};
91 
92  const TClonesArray* GetPtr() { return obj.GetPtr(); }
93 
94  Int_t GetEntries() { return obj.GetEntries(); }
95 
96  const T* At(UInt_t i) {
97  static T default_val;
98  if (!obj.Read()) return &default_val;
99  if (obj.GetWhere()==0) return &default_val;
100 
101  T* temp = (T*)obj.GetClaStart(i);
102  if (temp) return temp;
103  else return &default_val;
104  }
105 
106  const T* operator [](Int_t i) { return At(i); }
107  const T* operator [](UInt_t i) { return At(i); }
108 
109  };
110 
111  template <class T>
112  class TStlObjProxy {
114  typedef T value_t;
115  public:
117 
118  void Print() {
119  obj.Print();
120  std::cout << "obj.GetWhere() " << obj.GetWhere() << std::endl;
121  //if (obj.GetWhere()) std::cout << "value? " << *(T*)obj.GetWhere() << std::endl;
122  }
123 
124  TStlObjProxy() : obj() {};
125  TStlObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
126  TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
127  obj(director,top,name) {};
128  TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
129  obj(director,top,name,data) {};
130  TStlObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
131  obj(director,parent, name, top, mid) {};
133 
135  return obj.GetPtr();
136  }
137 
138  Int_t GetEntries() { return obj.GetEntries(); }
139 
140  const value_t& At(UInt_t i) {
141  static const value_t default_val;
142  if (!obj.Read()) return default_val;
143  if (obj.GetWhere()==0) return default_val;
144 
145  value_t *temp = (value_t*)obj.GetStlStart(i);
146  if (temp) return *temp;
147  else return default_val;
148  }
149 
150  const value_t& operator [](Int_t i) { return At(i); }
151  const value_t& operator [](UInt_t i) { return At(i); }
152 
153  };
154 
155 
156  template <class T>
158  // Intended to compiled non-split collection
159 
161  typedef typename T::value_type value_t;
162  public:
163 
164  TStlSimpleProxy() : TObjProxy<T>(),fCollection(0) {};
165  TStlSimpleProxy(TBranchProxyDirector *director, const char *name) : TObjProxy<T>(director,name),fCollection(0) {};
166  TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name) :
167  TObjProxy<T>(director,top,name),fCollection(0) {};
168  TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
169  TObjProxy<T>(director,top,name,data),fCollection(0) {};
170  TStlSimpleProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
171  TObjProxy<T>(director,parent, name, top, mid),fCollection(0) {};
172  ~TStlSimpleProxy() { delete fCollection; };
173 
175  if (fCollection==0) {
176  TClass *cl = TClass::GetClass(typeid(T));
177  if (cl && cl->GetCollectionProxy()) {
178  fCollection = cl->GetCollectionProxy()->Generate();
179  }
180  }
181  return fCollection;
182  }
183 
185  T *temp = TObjProxy<T>::GetPtr();
186  if (temp) {
187  GetCollection();
188  if (!fCollection) return 0;
189  TVirtualCollectionProxy::TPushPop helper( fCollection, temp );
190  return fCollection->Size();
191  }
192  return 0;
193  }
194 
195  const value_t At(UInt_t i) {
196  static value_t default_val;
197  T *temp = TObjProxy<T>::GetPtr();
198  if (temp) {
199  GetCollection();
200  if (!fCollection) return 0;
201  TVirtualCollectionProxy::TPushPop helper( fCollection, temp );
202  return *(value_t*)(fCollection->At(i));
203  }
204  else return default_val;
205  }
206 
207  const value_t operator [](Int_t i) { return At(i); }
208  const value_t operator [](UInt_t i) { return At(i); }
209 
211  operator T*() { return TObjProxy<T>::GetPtr(); }
212  // operator T&() { return *GetPtr(); }
213 
214  };
215 
216 } // namespace Internal
217 } // namespace ROOT
218 
219 #endif
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t mid
Definition: TRolke.cxx:630
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TStlObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char *top=0, const char *mid=0)
double T(double x)
Definition: ChebyshevPol.h:34
TObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data)
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2814
virtual void * GetStart(UInt_t=0)
Definition: TBranchProxy.h:197
const value_t & At(UInt_t i)
int Int_t
Definition: RtypesCore.h:41
TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name)
TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name)
TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data)
const TClonesArray * GetPtr()
TStlSimpleProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char *top=0, const char *mid=0)
TObjProxy(TBranchProxyDirector *director, const char *name)
TClaObjProxy(TBranchProxyDirector *director, const char *name)
TStlSimpleProxy(TBranchProxyDirector *director, const char *name)
TClaObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char *top=0, const char *mid=0)
virtual void * GetClaStart(UInt_t i=0)
Definition: TBranchProxy.h:212
TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data)
TVirtualCollectionProxy * GetCollection()
unsigned int UInt_t
Definition: RtypesCore.h:42
TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name)
TStlObjProxy(TBranchProxyDirector *director, const char *name)
TObjProxy(TBranchProxyDirector *director, const char *top, const char *name)
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:71
const TVirtualCollectionProxy * GetPtr()
Definition: TBranchProxy.h:434
TObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char *top=0, const char *mid=0)
TVirtualCollectionProxy * GetCollection()
virtual void * At(UInt_t idx)=0
virtual void * GetStlStart(UInt_t i=0)
Definition: TBranchProxy.h:258
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition: TClass.cxx:2885
virtual UInt_t Size() const =0
const TClonesArray * GetPtr()
Definition: TBranchProxy.h:392
An array of clone (identical) objects.
Definition: TClonesArray.h:32
Base class for all the proxy object.
Definition: TBranchProxy.h:65
TVirtualCollectionProxy * fCollection
TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data)
virtual TVirtualCollectionProxy * Generate() const =0