1 #ifndef DataFormats_Common_AssociationVector_h
2 #define DataFormats_Common_AssociationVector_h
25 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
27 #include <type_traits>
30 #include "boost/static_assert.hpp"
33 template<
class T>
class Ptr;
47 template<
typename REFPROD>
61 template<
typename KeyRefProd,
typename CVal,
63 typename SizeType =
unsigned int,
71 typedef typename KeyRefProd::product_type
CKey;
74 typedef typename std::pair<KeyRef, typename CVal::value_type>
value_type;
85 typename CVal::const_reference
operator[](KeyRef
const&
k)
const;
96 void swap(
self& other);
102 std::vector<void const*>& pointers,
117 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
127 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
128 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
132 return *(transientVector_.load(std::memory_order_acquire)); }
135 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
137 data_(), ref_(), transientVector_(
nullptr) { }
139 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
142 data_(coll == 0 ? ref->
size() : coll->
size()), ref_(ref),
145 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
146 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
149 data_(o.data_), ref_(o.ref_), transientVector_() {
157 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
158 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
160 delete transientVector_.load(std::memory_order_acquire);
164 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
167 return transientVector()[
n ];
170 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
171 inline typename CVal::const_reference
175 return data_[ keyRef.key() ];
178 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
179 template<
typename K>
180 inline typename CVal::const_reference
182 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
186 return data_[ k.
key() ];
189 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
190 template<
typename K>
191 typename CVal::const_reference
193 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
197 return data_[ k.
key() ];
201 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
202 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
206 auto t = transientVector_.exchange(
nullptr,std::memory_order_acq_rel);
209 return data_[ keyRef.key() ];
213 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
214 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
222 auto t =transientVector_.exchange(
nullptr, std::memory_order_acq_rel);
227 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
231 auto t = transientVector_.load(std::memory_order_acquire);
232 (*t)[
i ].first = ref;
233 (*t)[
i ].second = data_[
i ];
237 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
243 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
245 return data_.empty();
248 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
249 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
252 auto t = transientVector_.load(std::memory_order_acquire);
257 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
259 data_.swap(other.data_);
260 other.transientVector_.store(transientVector_.exchange(other.transientVector_.load(std::memory_order_acquire),std::memory_order_acq_rel),std::memory_order_release);
261 ref_.swap(other.ref_);
264 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
266 if (
nullptr == transientVector_.load(std::memory_order_acquire)) {
269 (*newT)[
i ] = std::make_pair(KeyRef(ref_,
i), data_[
i ]);
272 if(transientVector_.compare_exchange_strong(expected, newT.get()) ) {
279 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
281 std::vector<void const*>& pointers,
292 template<
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
302 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
307 std::vector<void const*>& pointers,
309 obj.
fillView(
id, pointers, helpers);
312 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
void checkForWrongProduct(ProductID const &keyID, ProductID const &refID)
void fillView(ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers) const
transient_vector_type::const_iterator const_iterator
void reallyFillView(COLLECTION const &coll, ProductID const &id, std::vector< void const * > &ptrs, FillViewHelperVector &helpers)
Ref< typename RefProd< C >::product_type > ref_type
self & operator=(self const &)
const_iterator end() const
std::vector< value_type > transient_vector_type
#define CMS_CLASS_VERSION(_version_)
void swap(Association< C > &lhs, Association< C > &rhs)
AssociationIdenticalKeyReference type
value_type const & const_reference
const_reference operator[](size_type n) const
std::pair< KeyRef, typename CVal::value_type > value_type
BOOST_STATIC_ASSERT((boost::is_convertible< SizeType, typename CVal::size_type >::value))
void fillView(AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper > const &obj, ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers)
CVal::value_type const value(size_type i) const
KeyRefProd::product_type CKey
Container::transient_vector_type transient_vector_type
Container::value_type value_type
KeyRef key(size_type i) const
KeyRef::value_type key_type
ProductID id() const
Accessor for product ID.
std::atomic< transient_vector_type * > transientVector_
KeyRefProd const & keyProduct() const
transient_vector_type const & transientVector() const
void setValue(size_type i, typename CVal::value_type const &val)
const_iterator begin() const
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
tuple size
Write out results.
T get(const Candidate &c)