CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefToBaseVector.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefToBaseVector_h
2 #define DataFormats_Common_RefToBaseVector_h
3 
10 #include "boost/shared_ptr.hpp"
11 #include <vector>
12 
13 namespace edm {
14  template<typename T> class RefToBase;
15  template<typename T> class View;
16  template<typename C> class Handle;
17  class EDProductGetter;
18  namespace reftobase {
19  template<typename T> class BaseVectorHolder;
20  class RefVectorHolderBase;
21  }
22 
23  template <class T>
24  class RefToBaseVector {
25  public:
27  typedef T member_type;
30  typedef typename holder_type::const_iterator const_iterator;
31 
34  template<class REFV>
35  explicit RefToBaseVector(REFV const& );
36  template<typename C>
37  explicit RefToBaseVector(Handle<C> const& );
38  template<typename T1>
39  explicit RefToBaseVector(Handle<View<T1> > const& );
40  RefToBaseVector(boost::shared_ptr<reftobase::RefVectorHolderBase> p);
42  void swap(RefToBaseVector& other);
43 
45 
46  //void reserve(size_type n);
47  void clear();
48 
49  value_type at(size_type idx) const;
51  bool isValid() const { return holder_ != 0; }
52  bool isInvalid() const { return holder_ == 0; }
53  bool empty() const;
54  size_type size() const;
55  //size_type capacity() const;
56  ProductID id() const;
57  EDProductGetter const * productGetter() const;
58  const_iterator begin() const;
59  const_iterator end() const;
60 
61  void push_back( const RefToBase<T> & );
62 
63  void fillView(std::vector<void const*>& pointers) const;
64  std::auto_ptr<reftobase::RefVectorHolderBase> vectorHolder() const;
65  const void * product() const;
66 
69  bool isAvailable() const { return holder_->isAvailable(); }
70 
71  //Needed for ROOT storage
73 
74  private:
76  };
77 }
78 
79 #include "DataFormats/Common/interface/RefToBase.h"
85 
86 namespace edm {
87  template <class T>
88  inline
89  void
91  a.swap(b);
92  }
93 
94  template <class T>
95  inline
96  bool
98  RefToBaseVector<T> const& b)
99  {
100  if ( a.isInvalid() && b.isInvalid() ) return true;
101  if ( a.isInvalid() || b.isInvalid() ) return false;
102  return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
103  }
104 
105  //--------------------------------------------------------------------
106  // Implementation of RefToBaseVector<T>
107  //--------------------------------------------------------------------
108 
109  template <class T>
110  inline
112  holder_(0)
113  { }
114 
115  template <class T>
116  template <class REFV>
117  inline
119  holder_(new reftobase::VectorHolder<T,REFV>(iRef))
120  { }
121 
122  template <class T>
123  inline
125  holder_(iOther.holder_ ? iOther.holder_->clone() : 0)
126  { }
127 
128  template <class T>
129  inline
130  RefToBaseVector<T>::RefToBaseVector(boost::shared_ptr<reftobase::RefVectorHolderBase> p) :
131  holder_(new reftobase::IndirectVectorHolder<T>(p)) {
132  }
133 
134  template <class T>
135  inline
138  RefToBaseVector temp(iRHS);
139  this->swap(temp);
140  return *this;
141  }
142 
143  template <class T>
144  inline
145  void
147  std::swap(holder_, other.holder_);
148  }
149 
150  template <class T>
151  inline
153  {
154  delete holder_;
155  }
156 
157  template <class T>
158  inline
161  {
162  if ( holder_ == 0 )
164  "Trying to dereference null RefToBaseVector<T> in method: at(",
165  idx,
166  ")\n");
167  return holder_->at( idx );
168  }
169 
170  template <class T>
171  inline
174  {
175  return at( idx );
176  }
177 
178  template <class T>
179  inline
180  bool
182  {
183  return holder_ ? holder_->empty() : true;
184  }
185 
186  template <class T>
187  inline
190  {
191  return holder_ ? holder_->size() : 0;
192  }
193 
194  template <class T>
195  inline
196  void
198  {
199  if ( holder_ != 0 )
200  holder_->clear();
201  }
202 
203  template <class T>
204  inline
205  ProductID
207  {
208  return holder_ ? holder_->id() : ProductID();
209  }
210 
211  template <class T>
212  inline
213  EDProductGetter const *
215  {
216  return holder_ ? holder_->productGetter() : 0;
217  }
218 
219  template <class T>
220  inline
223  {
224  return holder_ ? holder_->begin() : const_iterator();
225  }
226 
227  template <class T>
228  inline
231  {
232  return holder_ ? holder_->end() : const_iterator();
233  }
234 
235  template <typename T>
236  void
237  RefToBaseVector<T>::fillView(std::vector<void const*>& pointers) const
238  {
239  pointers.reserve(this->size());
240  for (const_iterator i=begin(), e=end(); i!=e; ++i) {
241  RefToBase<T> ref = * i;
242  member_type const * address = ref.isNull() ? 0 : & * ref;
243  pointers.push_back(address);
244  }
245  }
246 
247  // NOTE: the following implementation has unusual signature!
248  template <typename T>
249  inline void fillView(RefToBaseVector<T> const& obj,
250  std::vector<void const*>& pointers) {
251  obj.fillView(pointers);
252  }
253 
254  template <typename T>
256  static bool const value = true;
257  };
258 
259  template <typename T>
261  if ( holder_ == 0 ) {
262  std::auto_ptr<reftobase::BaseVectorHolder<T> > p = r.holder_->makeVectorHolder();
263  holder_ = p.release();
264  }
265  holder_->push_back( r.holder_ );
266  }
267 
268  template <typename T>
269  std::auto_ptr<reftobase::RefVectorHolderBase> RefToBaseVector<T>::vectorHolder() const {
270  return holder_ ? holder_->vectorHolder() : std::auto_ptr<reftobase::RefVectorHolderBase>();
271  }
272 
273  template <typename T>
274  const void * RefToBaseVector<T>::product() const {
275  return holder_ ? holder_->product() : 0;
276  }
277 
278 }
279 
283 
284 namespace edm {
285 
286  template<typename T>
287  template<typename C>
289  holder_(new reftobase::VectorHolder<T, RefVector<C, typename refhelper::ValueTrait<C>::value,
290  typename refhelper::FindTrait<C, T>::value> >(h.id())) {
291  }
292 
293  template<typename T>
294  template<typename T1>
296  holder_(h->refVector().holder_->cloneEmpty()) {
297  }
298 
299 }
300 #endif
virtual void const * product() const =0
virtual ProductID id() const =0
virtual void push_back(BaseHolder< T > const *)=0
int i
Definition: DBlmapReader.cc:9
holder_type::const_iterator const_iterator
virtual const_iterator begin() const =0
value_type operator[](size_type idx) const
void fillView(AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper > const &obj, ProductID const &id, std::vector< void const * > &pointers, helper_vector &helpers)
const_iterator end() const
bool isNull() const
Checks for null.
Definition: RefToBase.h:270
bool isValid() const
virtual size_type size() const =0
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
value_type at(size_type idx) const
RefToBase< T > value_type
virtual EDProductGetter const * productGetter() const =0
bool isInvalid() const
virtual std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder() const =0
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
reftobase::BaseVectorHolder< T > holder_type
bool equal(const T &first, const T &second)
Definition: Equal.h:34
EDProductGetter const * productGetter() const
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
virtual bool isAvailable() const =0
holder_type * holder_
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
std::auto_ptr< reftobase::RefVectorHolderBase > vectorHolder() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
#define end
Definition: vmac.h:37
size_type size() const
virtual std::auto_ptr< RefVectorHolderBase > vectorHolder() const =0
virtual const_iterator end() const =0
void swap(RefToBaseVector &other)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
double b
Definition: hdecay.h:120
RefToBaseVector & operator=(RefToBaseVector const &iRHS)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void fillView(std::vector< void const * > &pointers) const
const_iterator begin() const
#define private
Definition: FWFileEntry.h:17
#define begin
Definition: vmac.h:30
double a
Definition: hdecay.h:121
void push_back(const RefToBase< T > &)
reftobase::BaseHolder< value_type > * holder_
Definition: RefToBase.h:118
virtual bool empty() const =0
virtual base_ref_type const at(size_type idx) const =0
long double T
bool isAvailable() const
tuple size
Write out results.
ProductID id() const
static bool const value
Definition: traits.h:124
holder_type::size_type size_type
list at
Definition: asciidump.py:428
const void * product() const