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 <memory>
11 #include <vector>
13 
14 namespace edm {
15  template<typename T> class RefToBase;
16  template<typename T> class View;
17  template<typename C> class Handle;
18  class EDProductGetter;
19  namespace reftobase {
20  template<typename T> class BaseVectorHolder;
21  class RefVectorHolderBase;
22  }
23 
24  template <class T>
25  class RefToBaseVector {
26  public:
28  typedef T member_type;
31  typedef typename holder_type::const_iterator const_iterator;
32 
35  template<class REFV>
36  explicit RefToBaseVector(REFV const& );
37  template<typename C>
38  explicit RefToBaseVector(Handle<C> const& );
39  RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p);
41  void swap(RefToBaseVector& other);
42 
44 
45  //void reserve(size_type n);
46  void clear();
47 
48  value_type at(size_type idx) const;
50  bool isValid() const { return holder_ != 0; }
51  bool isInvalid() const { return holder_ == 0; }
52  bool empty() const;
53  size_type size() const;
54  //size_type capacity() const;
55  ProductID id() const;
56  EDProductGetter const * productGetter() const;
57  const_iterator begin() const;
58  const_iterator end() const;
59 
60  void push_back( const RefToBase<T> & );
61 
62  void fillView(std::vector<void const*>& pointers) const;
63  std::auto_ptr<reftobase::RefVectorHolderBase> vectorHolder() const;
64  const void * product() const;
65 
68  bool isAvailable() const { return holder_->isAvailable(); }
69 
70  //Needed for ROOT storage
72 
73  private:
75  };
76 }
77 
78 #include "DataFormats/Common/interface/RefToBase.h"
84 
85 namespace edm {
86  template <class T>
87  inline
88  void
90  a.swap(b);
91  }
92 
93  template <class T>
94  inline
95  bool
97  RefToBaseVector<T> const& b)
98  {
99  if ( a.isInvalid() && b.isInvalid() ) return true;
100  if ( a.isInvalid() || b.isInvalid() ) return false;
101  return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
102  }
103 
104  //--------------------------------------------------------------------
105  // Implementation of RefToBaseVector<T>
106  //--------------------------------------------------------------------
107 
108  template <class T>
109  inline
111  holder_(0)
112  { }
113 
114  template <class T>
115  template <class REFV>
116  inline
118  holder_(new reftobase::VectorHolder<T,REFV>(iRef))
119  { }
120 
121  template <class T>
122  inline
124  holder_(iOther.holder_ ? iOther.holder_->clone() : 0)
125  { }
126 
127  template <class T>
128  inline
129  RefToBaseVector<T>::RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p) :
130  holder_(new reftobase::IndirectVectorHolder<T>(p)) {
131  }
132 
133  template <class T>
134  inline
137  RefToBaseVector temp(iRHS);
138  this->swap(temp);
139  return *this;
140  }
141 
142  template <class T>
143  inline
144  void
146  std::swap(holder_, other.holder_);
147  }
148 
149  template <class T>
150  inline
152  {
153  delete holder_;
154  }
155 
156  template <class T>
157  inline
160  {
161  if ( holder_ == 0 )
163  "Trying to dereference null RefToBaseVector<T> in method: at(",
164  idx,
165  ")\n");
166  return holder_->at( idx );
167  }
168 
169  template <class T>
170  inline
173  {
174  return at( idx );
175  }
176 
177  template <class T>
178  inline
179  bool
181  {
182  return holder_ ? holder_->empty() : true;
183  }
184 
185  template <class T>
186  inline
189  {
190  return holder_ ? holder_->size() : 0;
191  }
192 
193  template <class T>
194  inline
195  void
197  {
198  if ( holder_ != 0 )
199  holder_->clear();
200  }
201 
202  template <class T>
203  inline
204  ProductID
206  {
207  return holder_ ? holder_->id() : ProductID();
208  }
209 
210  template <class T>
211  inline
212  EDProductGetter const *
214  {
215  return holder_ ? holder_->productGetter() : 0;
216  }
217 
218  template <class T>
219  inline
222  {
223  return holder_ ? holder_->begin() : const_iterator();
224  }
225 
226  template <class T>
227  inline
230  {
231  return holder_ ? holder_->end() : const_iterator();
232  }
233 
234  template <typename T>
235  void
236  RefToBaseVector<T>::fillView(std::vector<void const*>& pointers) const
237  {
238  pointers.reserve(this->size());
239  for (const_iterator i=begin(), e=end(); i!=e; ++i) {
240  RefToBase<T> ref = * i;
241  member_type const * address = ref.isNull() ? 0 : & * ref;
242  pointers.push_back(address);
243  }
244  }
245 
246  // NOTE: the following implementation has unusual signature!
247  template <typename T>
248  inline void fillView(RefToBaseVector<T> const& obj,
249  std::vector<void const*>& pointers) {
250  obj.fillView(pointers);
251  }
252 
253  template <typename T>
255  static bool const value = true;
256  };
257 
258  template <typename T>
260  if ( holder_ == 0 ) {
261  std::auto_ptr<reftobase::BaseVectorHolder<T> > p = r.holder_->makeVectorHolder();
262  holder_ = p.release();
263  }
264  holder_->push_back( r.holder_ );
265  }
266 
267  template <typename T>
268  std::auto_ptr<reftobase::RefVectorHolderBase> RefToBaseVector<T>::vectorHolder() const {
269  return holder_ ? holder_->vectorHolder() : std::auto_ptr<reftobase::RefVectorHolderBase>();
270  }
271 
272  template <typename T>
273  const void * RefToBaseVector<T>::product() const {
274  return holder_ ? holder_->product() : 0;
275  }
276 
277 }
278 
281 
282 namespace edm {
283 
284  template<typename T>
285  template<typename C>
287  holder_(new reftobase::VectorHolder<T, RefVector<C, typename refhelper::ValueTrait<C>::value,
288  typename refhelper::FindTrait<C, T>::value> >(h.id())) {
289  }
290 
291 }
292 #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 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_
reftobase::BaseHolder< value_type > * holder_
Definition: RefToBase.h:119
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...
bool isNull() const
Checks for null.
Definition: RefToBase.h:271
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 > &)
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