Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 // NOTE: This header is only used by selectors, to verify that the selector
13 // source matches the ROOT interface. It should not end up in the
14 // dictionary nor in the PCH, so it should not be added to the list
15 // of headers of the TreePlayer library.
16 
17 #ifndef ROOT_TBranchProxyTemplate
18 #define ROOT_TBranchProxyTemplate
19 
20 #if R__BRANCHPROXY_GENERATOR_VERSION != 2
21 // Generated source and branch proxy interface are out of sync.
22 # error "Please regenerate this file using TTree::MakeProxy()!"
23 #endif
24 
25 #include "TBranchProxy.h"
26 
27 #define InjecTBranchProxyInterface() \
28  ROOT::Detail::TBranchProxy *GetProxy() { return obj.GetProxy(); } \
29  void Reset() { obj.Reset(); } \
30  bool Setup() { return obj.Setup(); } \
31  bool IsInitialized() { return obj.IsInitialized(); } \
32  bool IsaPointer() const { return obj.IsaPointer(); } \
33  bool Read() { return obj.Read(); }
34 
35 namespace ROOT {
36 namespace Internal {
37  template <class T>
38  class TObjProxy {
39  Detail::TBranchProxy obj;
40  public:
41  InjecTBranchProxyInterface();
42 
43  TObjProxy() : obj() {};
44  TObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
45  TObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
46  obj(director,top,name) {};
47  TObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
48  obj(director,top,name,data) {};
49  TObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
50  obj(director,parent, name, top, mid) {};
51  ~TObjProxy() {};
52 
53  Int_t GetOffset() { return obj.GetOffset(); }
54 
55  void Print() {
56  obj.Print();
57  std::cout << "fWhere " << obj.GetWhere() << std::endl;
58  if (obj.GetWhere()) std::cout << "address? " << (T*)obj.GetWhere() << std::endl;
59  }
60 
61  T* GetPtr() {
62  //static T default_val;
63  if (!obj.Read()) return 0; // &default_val;
64  T *temp = (T*)obj.GetStart();
65  // if (temp==0) return &default_val;
66  return temp;
67  }
68 
69  T* operator->() { return GetPtr(); }
70  operator T*() { return GetPtr(); }
71  // operator T&() { return *GetPtr(); }
72 
73  };
74 
75  template <class T>
76  class TClaObjProxy {
77  TClaProxy obj;
78  public:
79  InjecTBranchProxyInterface();
80 
81  void Print() {
82  obj.Print();
83  std::cout << "obj.GetWhere() " << obj.GetWhere() << std::endl;
84  //if (obj.GetWhere()) std::cout << "value? " << *(T*)obj.GetWhere() << std::endl;
85  }
86 
87  TClaObjProxy() : obj() {};
88  TClaObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
89  TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
90  obj(director,top,name) {};
91  TClaObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
92  obj(director,top,name,data) {};
93  TClaObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
94  obj(director,parent, name, top, mid) {};
95  ~TClaObjProxy() {};
96 
97  const TClonesArray* GetPtr() { return obj.GetPtr(); }
98 
99  Int_t GetEntries() { return obj.GetEntries(); }
100 
101  const T* At(UInt_t i) {
102  static T default_val;
103  if (!obj.Read()) return &default_val;
104  if (obj.GetWhere()==0) return &default_val;
105 
106  T* temp = (T*)obj.GetClaStart(i);
107  if (temp) return temp;
108  else return &default_val;
109  }
110 
111  const T* operator [](Int_t i) { return At(i); }
112  const T* operator [](UInt_t i) { return At(i); }
113 
114  };
115 
116  template <class T>
117  class TStlObjProxy {
118  TStlProxy obj;
119  typedef T value_t;
120  public:
121  InjecTBranchProxyInterface();
122 
123  void Print() {
124  obj.Print();
125  std::cout << "obj.GetWhere() " << obj.GetWhere() << std::endl;
126  //if (obj.GetWhere()) std::cout << "value? " << *(T*)obj.GetWhere() << std::endl;
127  }
128 
129  TStlObjProxy() : obj() {};
130  TStlObjProxy(TBranchProxyDirector *director, const char *name) : obj(director,name) {};
131  TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name) :
132  obj(director,top,name) {};
133  TStlObjProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
134  obj(director,top,name,data) {};
135  TStlObjProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
136  obj(director,parent, name, top, mid) {};
137  ~TStlObjProxy() {};
138 
139  TVirtualCollectionProxy* GetCollection() {
140  return obj.GetPtr();
141  }
142 
143  Int_t GetEntries() { return obj.GetEntries(); }
144 
145  const value_t& At(UInt_t i) {
146  static const value_t default_val;
147  if (!obj.Read()) return default_val;
148  if (obj.GetWhere()==0) return default_val;
149 
150  value_t *temp = (value_t*)obj.GetStlStart(i);
151  if (temp) return *temp;
152  else return default_val;
153  }
154 
155  const value_t& operator [](Int_t i) { return At(i); }
156  const value_t& operator [](UInt_t i) { return At(i); }
157 
158  };
159 
160 
161  template <class T>
162  class TStlSimpleProxy : TObjProxy<T> {
163  // Intended to compiled non-split collection
164 
165  TVirtualCollectionProxy *fCollection;
166  typedef typename T::value_type value_t;
167  public:
168 
169  TStlSimpleProxy() : TObjProxy<T>(),fCollection(0) {};
170  TStlSimpleProxy(TBranchProxyDirector *director, const char *name) : TObjProxy<T>(director,name),fCollection(0) {};
171  TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name) :
172  TObjProxy<T>(director,top,name),fCollection(0) {};
173  TStlSimpleProxy(TBranchProxyDirector *director, const char *top, const char *name, const char *data) :
174  TObjProxy<T>(director,top,name,data),fCollection(0) {};
175  TStlSimpleProxy(TBranchProxyDirector *director, Detail::TBranchProxy *parent, const char *name, const char* top = 0, const char* mid = 0) :
176  TObjProxy<T>(director,parent, name, top, mid),fCollection(0) {};
177  ~TStlSimpleProxy() { delete fCollection; };
178 
179  TVirtualCollectionProxy* GetCollection() {
180  if (fCollection==0) {
181  TClass *cl = TClass::GetClass<T>();
182  if (cl && cl->GetCollectionProxy()) {
183  fCollection = cl->GetCollectionProxy()->Generate();
184  }
185  }
186  return fCollection;
187  }
188 
189  Int_t GetEntries() {
190  T *temp = TObjProxy<T>::GetPtr();
191  if (temp) {
192  GetCollection();
193  if (!fCollection) return 0;
194  TVirtualCollectionProxy::TPushPop helper( fCollection, temp );
195  return fCollection->Size();
196  }
197  return 0;
198  }
199 
200  const value_t At(UInt_t i) {
201  static value_t default_val;
202  T *temp = TObjProxy<T>::GetPtr();
203  if (temp) {
204  GetCollection();
205  if (!fCollection) return 0;
206  TVirtualCollectionProxy::TPushPop helper( fCollection, temp );
207  return *(value_t*)(fCollection->At(i));
208  }
209  else return default_val;
210  }
211 
212  const value_t operator [](Int_t i) { return At(i); }
213  const value_t operator [](UInt_t i) { return At(i); }
214 
215  T* operator->() { return TObjProxy<T>::GetPtr(); }
216  operator T*() { return TObjProxy<T>::GetPtr(); }
217  // operator T&() { return *GetPtr(); }
218 
219  };
220 
221 } // namespace Internal
222 } // namespace ROOT
223 
224 #endif