1 #ifndef DataFormats_Common_AssociationVector_h
2 #define DataFormats_Common_AssociationVector_h
26 #include <type_traits>
47 template <
typename REFPROD>
61 template <
typename KeyRefProd,
69 "Can not convert container size_type to unsigned int.");
74 typedef typename KeyRefProd::product_type
CKey;
77 typedef typename std::pair<KeyRef, typename CVal::value_type>
value_type;
88 typename CVal::const_reference
operator[](KeyRef
const&
k)
const;
124 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
129 return *(transientVector_.load(std::memory_order_acquire));
132 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
134 : data_(), ref_(), transientVector_(nullptr) {}
136 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
138 KeyRefProd
const& ref,
CKey const* coll)
139 : data_(coll == nullptr ? ref->
size() : coll->
size()),
143 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
146 : data_(
o.data_), ref_(
o.ref_), transientVector_() {
147 auto t =
o.transientVector_.load(std::memory_order_acquire);
153 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
155 delete transientVector_.load(std::memory_order_acquire);
158 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
161 return transientVector()[
n];
164 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
165 inline typename CVal::const_reference
169 return data_[keyRef.key()];
172 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
173 template <
typename K>
174 inline typename CVal::const_reference
177 "edm::Ptr's key type is not a base class of AssociationVector's item type");
179 return data_[
k.key()];
182 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
183 template <
typename K>
187 "edm::RefToBase's key type is not a base class of AssociationVector's item type");
189 return data_[
k.key()];
192 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
196 auto t = transientVector_.exchange(
nullptr, std::memory_order_acq_rel);
199 return data_[keyRef.key()];
202 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
210 auto t = transientVector_.exchange(
nullptr, std::memory_order_acq_rel);
215 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
220 auto t = transientVector_.load(std::memory_order_acquire);
222 (*t)[
i].second = data_[
i];
225 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
231 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
233 return data_.empty();
236 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
239 auto t = transientVector_.load(std::memory_order_acquire);
245 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
247 data_.swap(
other.data_);
248 other.transientVector_.store(
249 transientVector_.exchange(
other.transientVector_.load(std::memory_order_acquire), std::memory_order_acq_rel),
250 std::memory_order_release);
251 ref_.swap(
other.ref_);
254 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
256 if (
nullptr == transientVector_.load(std::memory_order_acquire)) {
259 (*newT)[
i] = std::make_pair(KeyRef(ref_,
i), data_[
i]);
262 if (transientVector_.compare_exchange_strong(expected, newT.get())) {
268 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
279 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
289 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>
292 std::vector<void const*>& pointers,
297 template <
typename KeyRefProd,
typename CVal,
typename KeyRef,
typename SizeType,
typename KeyReferenceHelper>