1 #ifndef DataFormats_Common_DetSetVectorNew_h
2 #define DataFormats_Common_DetSetVectorNew_h
8 #include <boost/iterator/transform_iterator.hpp>
48 namespace dstvdetails {
75 assert(rh.m_filling ==
false);
82 assert(rh.m_filling ==
false);
122 return offset.compare_exchange_strong(expected, -2);
134 bool expected =
false;
135 if (!
m_filling.compare_exchange_strong(expected,
true))
154 template <
typename T>
155 class DetSetVector :
private dstvdetails::DetSetVectorTrans {
171 typedef typename IdContainer::iterator
IdIter;
172 typedef typename std::vector<data_type>::iterator
DataIter;
198 typedef std::pair<const_iterator, const_iterator>
Range;
234 m_v.m_filling =
false;
243 if (
m_v.onDemand() &&
m_v.m_data.size() ==
m_v.m_data.capacity())
248 if (
m_v.onDemand() &&
m_v.m_data.size() + s >
m_v.m_data.capacity())
263 m_v.m_dataSize =
m_v.m_data.size();
275 template <
typename... Args>
278 m_v.m_data.emplace_back(
args...);
285 m_v.m_data.push_back(d);
301 friend class ::TestDetSet;
326 m_v.m_filling =
false;
331 bool expected =
false;
332 while (!
m_v.m_filling.compare_exchange_weak(expected,
true)) {
334 nanosleep(
nullptr,
nullptr);
337 if (
m_v.onDemand() &&
full()) {
338 m_v.m_filling =
false;
345 m_v.m_dataSize =
m_v.m_data.size();
347 m_v.m_filling =
false;
352 return m_v.m_data.capacity() < offset +
m_lv.size();
369 template <
typename... Args>
381 friend class ::TestDetSet;
399 bool expected =
false;
400 while (!iContainer.
m_filling.compare_exchange_weak(expected,
true, std::memory_order_acq_rel)) {
402 nanosleep(
nullptr,
nullptr);
445 m_ids.reserve(isize);
451 m_ids.shrink_to_fit();
455 void resize(
size_t isize,
size_t dsize) {
471 return DetSet(*
this, item,
false);
478 return DetSet(*
this, item,
false);
487 if (p ==
m_ids.end())
490 if ((*p).isValid() && (*p).size > 0 &&
m_data.size() == (*p).offset + (*p).size) {
491 m_data.resize((*p).offset);
501 if (p !=
m_ids.end() && !(it < *
p))
513 return p !=
m_ids.end() && (*p).isValid();
526 if (p ==
m_ids.end())
528 return DetSet(*
this, *p,
true);
540 std::pair<const_IdIter, const_IdIter>
p = std::equal_range(
m_ids.begin(),
m_ids.end(),
Item(i));
541 return (p.first != p.second) ? p.first :
m_ids.end();
555 template <
typename CMP>
558 std::pair<const_IdIter, const_IdIter>
p = std::equal_range(
m_ids.begin(),
m_ids.end(),
i, cmp);
560 boost::make_transform_iterator(p.second,
IterHelp(*
this,
update)));
593 friend class ::TestDetSet;
608 template <
typename T>
616 template <
typename T>
618 const std::vector<det_id_type>& iDets,
623 m_ids.reserve(iDets.size());
625 for (std::vector<det_id_type>::const_iterator itDetId = iDets.begin(), itDetIdEnd = iDets.end();
626 itDetId != itDetIdEnd;
628 assert(sanityCheck < *itDetId &&
"vector of det_id_type was not ordered");
629 sanityCheck = *itDetId;
630 m_ids.push_back(*itDetId);
634 template <
typename T>
645 static_cast<Getter*
>(m_getter.get())->
fill(ff);
651 template <
typename T>
657 nanosleep(
nullptr,
nullptr);
658 m_data = &icont.data();
666 #include <type_traits>
671 namespace refhelper {
672 template <
typename T>
680 namespace refhelper {
681 template <
typename T>
688 return &(iContainer[iIndex]);
692 template <
typename T>
702 template <
class HandleT>
705 const HandleT& iHandle,
typename HandleT::element_type::value_type::const_iterator itIter) {
706 static_assert(std::is_same<
typename HandleT::element_type,
708 "Handle and DetSetVector do not have compatible types.");
709 auto index = itIter - &iHandle->data().front();
711 iHandle.id(), &(*itIter),
index);
718 template <
typename T>
725 return iElement - &(iContainer->
data().front());
732 namespace edm::detail {
733 template <
typename T>
739 template <
typename T,
typename Selector>
742 unsigned int& iIndex,
746 for (
auto iter = detset.
begin(),
end = detset.
end(); iter !=
end; ++iter, ++iIndex) {
749 if (detset.
begin() != detset.
end()) {
Item & operator=(Item const &rh) noexcept
bool isValid(id_type i) const
DataContainer const & data() const
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
static unsigned int indexFor(const value_type *iElement, const edmNew::DetSetVector< T > *iContainer)
void swap(DetSetVectorTrans &rh)
void push_back(data_type const &d)
void update(Item const &item) const
const_iterator end(bool update=false) const
static DetSetVector< T >::Item & dummy()
size_type dataSize() const
DetSetVector< T >::id_type id_type
void reserve(size_type s)
result_type operator()(first_argument_type iContainer, second_argument_type iIndex)
Range equal_range(id_type i, CMP cmp, bool update=false) const
std::vector< data_type > DataContainer
std::pair< const_iterator, const_iterator > Range
Item & push_back(id_type iid)
const_IdIter findItem(id_type i) const
std::vector< Trans::Item > m_ids
void fillCollectionForThinning(Item const &item, Selector &selector, unsigned int iIndex, Collection &output, ThinnedAssociation &association)
bool uninitialized() const
IdContainer::iterator IdIter
void checkCapacityExausted(size_type s) const
void set(Container const &icont, typename Container::Item const &item, bool update=true)
void push_back(data_type &&d)
void throwCapacityExausted()
void reserve(size_type s)
edmNew::DetSetVector< T >::FindForDetSetVector value
std::vector< data_type >::const_iterator const_DataIter
void push_back(data_type &&d)
void swap(DetSetVector &rh)
void throw_range(det_id_type iid)
DetSetVector(int isubdet=0)
TSFastFiller(DetSetVector< T > const &iv, typename DetSetVector< T >::Item const &it)
void pop_back(id_type iid)
#define CMS_CLASS_VERSION(_version_)
Item(Item const &rh) noexcept
id_type id(size_t cell) const
DetSetVectorTrans(const DetSetVectorTrans &rh)
DetSetVectorTrans & operator=(const DetSetVectorTrans &)=delete
DetSetVector< T > const & m_v
bool operator<(Item const &rh) const
void swap(Association< C > &lhs, Association< C > &rhs)
DetSetVector< T > const * m_v
dstvdetails::DetSetVectorTrans Trans
Item const & item(size_t cell) const
void checkCapacityExausted() const
IterHelp(DetSetVector< T > const &iv, bool iup)
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Item & addItem(id_type iid, size_type isize)
typename edmNew::DetSetVector< T >::data_type type
DetSetVector & operator=(const DetSetVector &)=delete
DetSetVector< T >::data_type value_type
static DetSetVector< T >::Item const & dummy()
DetSetVectorTrans & operator=(DetSetVectorTrans &&rh)
unsigned int second_argument_type
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
DetSetVector< T >::Item & m_item
bool exists(id_type i) const
void push_back(data_type const &d)
IdContainer const & ids() const
bool initializing() const
data_type const * data(size_t cell) const
FastFiller(DetSetVector< T > &iv, id_type id, bool isaveEmpty=false)
#define CMS_THREAD_GUARD(_var_)
FindSetForNewDetSetVector< T > value
DetSetVector< T >::size_type size_type
Item(id_type i=0, int io=-1, size_type is=0)
DetSetVector< T >::Item const & m_item
void swap(IdContainer &iic, DataContainer &idc)
Functor that operates on <T>
DetSetVector< T >::id_type key_type
static size_t size(const edmNew::DetSetVector< T > *iContainer)
void resize(size_t isize, size_t dsize)
TSFastFiller(DetSetVector< T > &iv, id_type id)
size_type detsetSize(size_t cell) const
std::atomic< int > offset
DetSet insert(id_type iid, data_type const *idata, size_type isize)
std::pair< IdIter, DataIter > IterPair
unsigned int second_argument_type
std::vector< Item > IdContainer
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
dslv::LazyGetter< T > Getter
DetSetVector< T >::id_type key_type
void errorIdExists(det_id_type iid)
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
result_type operator()(first_argument_type iContainer, second_argument_type iIndex)
void reserve(size_t isize, size_t dsize)
data_type & operator[](size_type i)
std::vector< data_type >::iterator DataIter
result_type & operator()(Item const &item) const
const_iterator find(id_type i, bool update=false) const
CapacityExaustedException()
DetSet insert(id_type iid, size_type isize)
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
std::atomic< size_type > m_dataSize
std::atomic< bool > m_filling
void emplace_back(Args &&...args)
IdContainer::const_iterator const_IdIter
void emplace_back(Args &&...args)
data_type operator()(size_t cell, size_t frame) const
edmNew::DetSet< T > DetSet
std::pair< const_IdIter, const_DataIter > const_IterPair
FastFiller(DetSetVector< T > &iv, typename DetSetVector< T >::Item &it, bool isaveEmpty=false)
void fillCollectionForThinning(edmNew::DetSet< T > const &detset, Selector &selector, unsigned int &iIndex, edmNew::DetSetVector< T > &output, edm::ThinnedAssociation &association)
data_type & operator[](size_type i)
edm::refhelper::FindForNewDetSetVector< data_type > RefFinder
DetSetVectorTrans(DetSetVectorTrans &&rh)
std::shared_ptr< void > m_getter
DetSetVector< T >::size_type size_type
DetSetVector< T >::id_type id_type
DetSet operator[](id_type i) const
DetSetVector< T >::data_type value_type
const_iterator begin(bool update=false) const
Item & operator=(Item &&rh) noexcept