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>
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  RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p);
40  void swap(RefToBaseVector& other);
41 
43 
44  //void reserve(size_type n);
45  void clear();
46 
47  value_type at(size_type idx) const;
49  bool isValid() const { return holder_ != 0; }
50  bool isInvalid() const { return holder_ == 0; }
51  bool empty() const;
52  size_type size() const;
53  //size_type capacity() const;
54  ProductID id() const;
55  EDProductGetter const * productGetter() const;
56  const_iterator begin() const;
57  const_iterator end() const;
58 
59  void push_back( const RefToBase<T> & );
60 
61  void fillView(std::vector<void const*>& pointers) const;
62  std::auto_ptr<reftobase::RefVectorHolderBase> vectorHolder() const;
63  const void * product() const;
64 
67  bool isAvailable() const { return holder_->isAvailable(); }
68 
69  //Needed for ROOT storage
71 
72  private:
74  };
75 }
76 
77 #include "DataFormats/Common/interface/RefToBase.h"
83 
84 namespace edm {
85  template <class T>
86  inline
87  void
89  a.swap(b);
90  }
91 
92  template <class T>
93  inline
94  bool
96  RefToBaseVector<T> const& b)
97  {
98  if ( a.isInvalid() && b.isInvalid() ) return true;
99  if ( a.isInvalid() || b.isInvalid() ) return false;
100  return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
101  }
102 
103  //--------------------------------------------------------------------
104  // Implementation of RefToBaseVector<T>
105  //--------------------------------------------------------------------
106 
107  template <class T>
108  inline
110  holder_(0)
111  { }
112 
113  template <class T>
114  template <class REFV>
115  inline
117  holder_(new reftobase::VectorHolder<T,REFV>(iRef))
118  { }
119 
120  template <class T>
121  inline
123  holder_(iOther.holder_ ? iOther.holder_->clone() : 0)
124  { }
125 
126  template <class T>
127  inline
128  RefToBaseVector<T>::RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p) :
129  holder_(new reftobase::IndirectVectorHolder<T>(p)) {
130  }
131 
132  template <class T>
133  inline
136  RefToBaseVector temp(iRHS);
137  this->swap(temp);
138  return *this;
139  }
140 
141  template <class T>
142  inline
143  void
145  std::swap(holder_, other.holder_);
146  }
147 
148  template <class T>
149  inline
151  {
152  delete holder_;
153  }
154 
155  template <class T>
156  inline
159  {
160  if ( holder_ == 0 )
162  "Trying to dereference null RefToBaseVector<T> in method: at(",
163  idx,
164  ")\n");
165  return holder_->at( idx );
166  }
167 
168  template <class T>
169  inline
172  {
173  return at( idx );
174  }
175 
176  template <class T>
177  inline
178  bool
180  {
181  return holder_ ? holder_->empty() : true;
182  }
183 
184  template <class T>
185  inline
188  {
189  return holder_ ? holder_->size() : 0;
190  }
191 
192  template <class T>
193  inline
194  void
196  {
197  if ( holder_ != 0 )
198  holder_->clear();
199  }
200 
201  template <class T>
202  inline
203  ProductID
205  {
206  return holder_ ? holder_->id() : ProductID();
207  }
208 
209  template <class T>
210  inline
211  EDProductGetter const *
213  {
214  return holder_ ? holder_->productGetter() : 0;
215  }
216 
217  template <class T>
218  inline
221  {
222  return holder_ ? holder_->begin() : const_iterator();
223  }
224 
225  template <class T>
226  inline
229  {
230  return holder_ ? holder_->end() : const_iterator();
231  }
232 
233  template <typename T>
234  void
235  RefToBaseVector<T>::fillView(std::vector<void const*>& pointers) const
236  {
237  pointers.reserve(this->size());
238  for (const_iterator i=begin(), e=end(); i!=e; ++i) {
239  RefToBase<T> ref = * i;
240  member_type const * address = ref.isNull() ? 0 : & * ref;
241  pointers.push_back(address);
242  }
243  }
244 
245  // NOTE: the following implementation has unusual signature!
246  template <typename T>
247  inline void fillView(RefToBaseVector<T> const& obj,
248  std::vector<void const*>& pointers) {
249  obj.fillView(pointers);
250  }
251 
252  template <typename T>
254  static bool const value = true;
255  };
256 
257  template <typename T>
259  if ( holder_ == 0 ) {
260  std::auto_ptr<reftobase::BaseVectorHolder<T> > p = r.holder_->makeVectorHolder();
261  holder_ = p.release();
262  }
263  holder_->push_back( r.holder_ );
264  }
265 
266  template <typename T>
267  std::auto_ptr<reftobase::RefVectorHolderBase> RefToBaseVector<T>::vectorHolder() const {
268  return holder_ ? holder_->vectorHolder() : std::auto_ptr<reftobase::RefVectorHolderBase>();
269  }
270 
271  template <typename T>
272  const void * RefToBaseVector<T>::product() const {
273  return holder_ ? holder_->product() : 0;
274  }
275 
276 }
277 
280 
281 namespace edm {
282 
283  template<typename T>
284  template<typename C>
286  holder_(new reftobase::VectorHolder<T, RefVector<C, typename refhelper::ValueTrait<C>::value,
287  typename refhelper::FindTrait<C, T>::value> >(h.id())) {
288  }
289 
290 }
291 #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:118
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:270
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