CMS 3D CMS Logo

RefToBaseVector.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefToBaseVector_h
2 #define DataFormats_Common_RefToBaseVector_h
3 
11 #include <algorithm>
12 #include <memory>
13 #include <utility>
14 #include <vector>
15 
16 namespace edm {
17  template <typename T>
18  class RefToBase;
19  template <typename T>
20  class View;
21  template <typename C>
22  class Handle;
23  class EDProductGetter;
24  namespace reftobase {
25  template <typename T>
26  class BaseVectorHolder;
27  class RefVectorHolderBase;
28  } // namespace reftobase
29 
30  template <class T>
31  class RefToBaseVector {
32  public:
34  typedef T member_type;
38 
41  template <class REFV>
42  explicit RefToBaseVector(REFV const&);
43  template <typename C>
44  explicit RefToBaseVector(Handle<C> const&);
45  RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p);
47  void swap(RefToBaseVector& other);
48 
50 
51  //void reserve(size_type n);
52  void clear();
53 
54  value_type at(size_type idx) const;
56  bool isValid() const { return holder_ != nullptr; }
57  bool isInvalid() const { return holder_ == nullptr; }
58  bool empty() const;
59  size_type size() const;
60  //size_type capacity() const;
61  ProductID id() const;
62  EDProductGetter const* productGetter() const;
63  const_iterator begin() const;
64  const_iterator end() const;
65 
66  void push_back(const RefToBase<T>&);
67 
68  void fillView(std::vector<void const*>& pointers, FillViewHelperVector& helpers) const;
69  std::unique_ptr<reftobase::RefVectorHolderBase> vectorHolder() const;
70 
73  bool isAvailable() const { return holder_->isAvailable(); }
74 
75  //Needed for ROOT storage
77 
78  private:
80  };
81 } // namespace edm
82 
83 #include "DataFormats/Common/interface/RefToBase.h"
89 
90 namespace edm {
91  template <class T>
93  a.swap(b);
94  }
95 
96  template <class T>
97  inline bool operator==(RefToBaseVector<T> const& a, RefToBaseVector<T> const& b) {
98  if (a.isInvalid() && b.isInvalid())
99  return true;
100  if (a.isInvalid() || b.isInvalid())
101  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>
111 
112  template <class T>
113  template <class REFV>
114  inline RefToBaseVector<T>::RefToBaseVector(const REFV& iRef) : holder_(new reftobase::VectorHolder<T, REFV>(iRef)) {}
115 
116  template <class T>
118  : holder_(iOther.holder_ ? iOther.holder_->clone() : nullptr) {}
119 
120  template <class T>
121  inline RefToBaseVector<T>::RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p)
122  : holder_(new reftobase::IndirectVectorHolder<T>(p)) {}
123 
124  template <class T>
126  RefToBaseVector temp(iRHS);
127  this->swap(temp);
128  return *this;
129  }
130 
131  template <class T>
133  std::swap(holder_, other.holder_);
134  }
135 
136  template <class T>
138  delete holder_;
139  }
140 
141  template <class T>
143  if (holder_ == nullptr)
144  Exception::throwThis(
145  errors::InvalidReference, "Trying to dereference null RefToBaseVector<T> in method: at(", idx, ")\n");
146  return holder_->at(idx);
147  }
148 
149  template <class T>
151  return at(idx);
152  }
153 
154  template <class T>
155  inline bool RefToBaseVector<T>::empty() const {
156  return holder_ ? holder_->empty() : true;
157  }
158 
159  template <class T>
161  return holder_ ? holder_->size() : 0;
162  }
163 
164  template <class T>
166  if (holder_ != nullptr)
167  holder_->clear();
168  }
169 
170  template <class T>
172  return holder_ ? holder_->id() : ProductID();
173  }
174 
175  template <class T>
177  return holder_ ? holder_->productGetter() : nullptr;
178  }
179 
180  template <class T>
182  return holder_ ? holder_->begin() : const_iterator();
183  }
184 
185  template <class T>
187  return holder_ ? holder_->end() : const_iterator();
188  }
189 
190  template <typename T>
191  void RefToBaseVector<T>::fillView(std::vector<void const*>& pointers, FillViewHelperVector& helpers) const {
192  pointers.reserve(this->size());
193  helpers.reserve(this->size());
194  for (const_iterator i = begin(), e = end(); i != e; ++i) {
195  RefToBase<T> ref = *i;
196  member_type const* address = ref.isNull() ? nullptr : &*ref;
197  pointers.push_back(address);
198  helpers.push_back(FillViewHelperVector::value_type(ref.id(), ref.key()));
199  }
200  }
201 
202  // NOTE: the following implementation has unusual signature!
203  template <typename T>
204  inline void fillView(RefToBaseVector<T> const& obj,
205  ProductID const&,
206  std::vector<void const*>& pointers,
208  obj.fillView(pointers, helpers);
209  }
210 
211  template <typename T>
213  static bool const value = true;
214  };
215 
216  template <typename T>
218  if (holder_ == nullptr) {
219  std::unique_ptr<reftobase::BaseVectorHolder<T> > p = r.holder_->makeVectorHolder();
220  holder_ = p.release();
221  }
222  holder_->push_back(r.holder_);
223  }
224 
225  template <typename T>
226  std::unique_ptr<reftobase::RefVectorHolderBase> RefToBaseVector<T>::vectorHolder() const {
227  return holder_ ? holder_->vectorHolder() : std::unique_ptr<reftobase::RefVectorHolderBase>();
228  }
229 } // namespace edm
230 
233 
234 namespace edm {
235 
236  template <typename T>
237  template <typename C>
239  : holder_(new reftobase::VectorHolder<
240  T,
241  RefVector<C, typename refhelper::ValueTrait<C>::value, typename refhelper::FindTrait<C, T>::value> >(
242  h.id())) {}
243 
244 } // namespace edm
245 #endif
size
Write out results.
constexpr bool operator==(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
virtual ProductID id() const =0
virtual void push_back(BaseHolder< T > const *)=0
value_type at(size_type idx) const
holder_type::const_iterator const_iterator
Basic3DVector & operator=(const Basic3DVector &)=default
Assignment operator.
virtual const_iterator begin() const =0
bool isInvalid() const
virtual size_type size() const =0
#define CMS_CLASS_VERSION(_version_)
size_type size() const
bool isAvailable() const
RefToBase< T > value_type
virtual EDProductGetter const * productGetter() const =0
reftobase::BaseVectorHolder< T > holder_type
bool equal(const T &first, const T &second)
Definition: Equal.h:32
ProductID id() const
Definition: RefToBase.h:221
virtual bool isAvailable() const =0
void swap(RefToBaseVector< T > &a, RefToBaseVector< T > &b)
holder_type * holder_
const_iterator begin() const
std::unique_ptr< reftobase::RefVectorHolderBase > vectorHolder() const
void fillView(RefToBaseVector< T > const &obj, ProductID const &, std::vector< void const *> &pointers, FillViewHelperVector &helpers)
const_iterator end() const
Definition: value.py:1
bool isNull() const
Checks for null.
Definition: RefToBase.h:284
virtual const_iterator end() const =0
void swap(RefToBaseVector &other)
size_t key() const
Definition: RefToBase.h:226
EDProductGetter const * productGetter() const
double b
Definition: hdecay.h:120
RefToBaseVector & operator=(RefToBaseVector const &iRHS)
value_type operator[](size_type idx) const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
HLT enums.
double a
Definition: hdecay.h:121
void push_back(const RefToBase< T > &)
ProductID id() const
virtual std::unique_ptr< RefVectorHolderBase > vectorHolder() const =0
void fillView(std::vector< void const *> &pointers, FillViewHelperVector &helpers) const
EDProductGetter const * productGetter(std::atomic< void const *> const &iCache)
void clear(EGIsoObj &c)
Definition: egamma.h:82
virtual bool empty() const =0
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T operator[](int i) const
virtual base_ref_type const at(size_type idx) const =0
long double T
holder_type::size_type size_type
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector