Logo ROOT   6.07/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 #ifndef ROOT_TBranchProxy
21 #include "TBranchProxy.h"
22 #endif
23 
24 #define InjecTBranchProxyInterface() \
25  ROOT::Detail::TBranchProxy *GetProxy() { return obj.GetProxy(); } \
26  void Reset() { obj.Reset(); } \
27  bool Setup() { return obj.Setup(); } \
28  bool IsInitialized() { return obj.IsInitialized(); } \
29  bool IsaPointer() const { return obj.IsaPointer(); } \
30  bool Read() { return obj.Read(); }
31 
32 namespace ROOT {
33 namespace Internal {
34  template <class T>
35  class TObjProxy {
37  public:
39 
40  TObjProxy() : obj() {};
41  TObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
42  TObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
43  obj(director,top,name) {};
44  TObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
45  obj(director,top,name,data) {};
46  TObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
47  obj(director,parent, name, top, mid) {};
48  ~TObjProxy() {};
49 
50  Int_t GetOffset() { return obj.GetOffset(); }
51 
52  void Print() {
53  obj.Print();
54  std::cout << "fWhere " << obj.GetWhere() << std::endl;
55  if (obj.GetWhere()) std::cout << "address? " << (T*)obj.GetWhere() << std::endl;
56  }
57 
58  T* GetPtr() {
59  //static T default_val;
60  if (!obj.Read()) return 0; // &default_val;
61  T *temp = (T*)obj.GetStart();
62  // if (temp==0) return &default_val;
63  return temp;
64  }
65 
66  T* operator->() { return GetPtr(); }
67  operator T*() { return GetPtr(); }
68  // operator T&() { return *GetPtr(); }
69 
70  };
71 
72  template <class T>
73  class TClaObjProxy {
75  public:
77 
78  void Print() {
79  obj.Print();
80  std::cout << "obj.GetWhere() " << obj.GetWhere() << std::endl;
81  //if (obj.GetWhere()) std::cout << "value? " << *(T*)obj.GetWhere() << std::endl;
82  }
83 
84  TClaObjProxy() : obj() {};
85  TClaObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
86  TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
87  obj(director,top,name) {};
88  TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
89  obj(director,top,name,data) {};
90  TClaObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
91  obj(director,parent, name, top, mid) {};
93 
94  const TClonesArray* GetPtr() { return obj.GetPtr(); }
95 
96  Int_t GetEntries() { return obj.GetEntries(); }
97 
98  const T* At(UInt_t i) {
99  static T default_val;
100  if (!obj.Read()) return &default_val;
101  if (obj.GetWhere()==0) return &default_val;
102 
103  T* temp = (T*)obj.GetClaStart(i);
104  if (temp) return temp;
105  else return &default_val;
106  }
107 
108  const T* operator [](Int_t i) { return At(i); }
109  const T* operator [](UInt_t i) { return At(i); }
110 
111  };
112 
113  template <class T>
114  class TStlObjProxy {
116  typedef T value_t;
117  public:
119 
120  void Print() {
121  obj.Print();
122  std::cout << "obj.GetWhere() " << obj.GetWhere() << std::endl;
123  //if (obj.GetWhere()) std::cout << "value? " << *(T*)obj.GetWhere() << std::endl;
124  }
125 
126  TStlObjProxy() : obj() {};
127  TStlObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
128  TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
129  obj(director,top,name) {};
130  TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
131  obj(director,top,name,data) {};
132  TStlObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
133  obj(director,parent, name, top, mid) {};
135 
137  return obj.GetPtr();
138  }
139 
140  Int_t GetEntries() { return obj.GetEntries(); }
141 
142  const value_t& At(UInt_t i) {
143  static const value_t default_val;
144  if (!obj.Read()) return default_val;
145  if (obj.GetWhere()==0) return default_val;
146 
147  value_t *temp = (value_t*)obj.GetStlStart(i);
148  if (temp) return *temp;
149  else return default_val;
150  }
151 
152  const value_t& operator [](Int_t i) { return At(i); }
153  const value_t& operator [](UInt_t i) { return At(i); }
154 
155  };
156 
157 
158  template <class T>
160  // Intended to compiled non-split collection
161 
163  typedef typename T::value_type value_t;
164  public:
165 
166  TStlSimpleProxy() : TObjProxy<T>(),fCollection(0) {};
167  TStlSimpleProxy(TBranchProxyDirector *director, const char *name) : TObjProxy<T>(director,name),fCollection(0) {};
168  TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name) :
169  TObjProxy<T>(director,top,name),fCollection(0) {};
170  TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
171  TObjProxy<T>(director,top,name,data),fCollection(0) {};
172  TStlSimpleProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
173  TObjProxy<T>(director,parent, name, top, mid),fCollection(0) {};
174  ~TStlSimpleProxy() { delete fCollection; };
175 
177  if (fCollection==0) {
178  TClass *cl = TClass::GetClass(typeid(T));
179  if (cl && cl->GetCollectionProxy()) {
180  fCollection = cl->GetCollectionProxy()->Generate();
181  }
182  }
183  return fCollection;
184  }
185 
187  T *temp = TObjProxy<T>::GetPtr();
188  if (temp) {
189  GetCollection();
190  if (!fCollection) return 0;
191  TVirtualCollectionProxy::TPushPop helper( fCollection, temp );
192  return fCollection->Size();
193  }
194  return 0;
195  }
196 
197  const value_t At(UInt_t i) {
198  static value_t default_val;
199  T *temp = TObjProxy<T>::GetPtr();
200  if (temp) {
201  GetCollection();
202  if (!fCollection) return 0;
203  TVirtualCollectionProxy::TPushPop helper( fCollection, temp );
204  return *(value_t*)(fCollection->At(i));
205  }
206  else return default_val;
207  }
208 
209  const value_t operator [](Int_t i) { return At(i); }
210  const value_t operator [](UInt_t i) { return At(i); }
211 
213  operator T*() { return TObjProxy<T>::GetPtr(); }
214  // operator T&() { return *GetPtr(); }
215 
216  };
217 
218 } // namespace Internal
219 } // namespace ROOT
220 
221 #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
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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)
virtual void * GetStart(UInt_t=0)
Definition: TBranchProxy.h:205
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)
virtual TVirtualCollectionProxy * Generate() const =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:220
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:81
const TVirtualCollectionProxy * GetPtr()
Definition: TBranchProxy.h:442
TObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char *top=0, const char *mid=0)
void * GetWhere() const
Definition: TBranchProxy.h:200
TVirtualCollectionProxy * GetCollection()
virtual void * At(UInt_t idx)=0
virtual void * GetStlStart(UInt_t i=0)
Definition: TBranchProxy.h:266
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:2882
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Definition: TClass.cxx:2811
const TClonesArray * GetPtr()
Definition: TBranchProxy.h:400
An array of clone (identical) objects.
Definition: TClonesArray.h:32
Base class for all the proxy object.
Definition: TBranchProxy.h:81
TVirtualCollectionProxy * fCollection
TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data)
char name[80]
Definition: TGX11.cxx:109
virtual UInt_t Size() const =0