|
|
Go to the documentation of this file. 1 #ifndef DataFormats_Common_DetSetVectorNew_h
2 #define DataFormats_Common_DetSetVectorNew_h
8 #include <boost/iterator/transform_iterator.hpp>
9 #include <boost/any.hpp>
13 #if !defined(__ROOTCLING__)
14 #define DSVN_USE_ATOMIC
54 namespace dstvdetails {
74 #ifdef DSVN_USE_ATOMIC
85 assert(rh.m_filling ==
false);
87 #ifdef DSVN_USE_ATOMIC
96 assert(rh.m_filling ==
false);
98 #ifdef DSVN_USE_ATOMIC
107 #ifdef DSVN_USE_ATOMIC
119 #ifdef DSVN_USE_ATOMIC
145 #ifdef DSVN_USE_ATOMIC
149 return offset.compare_exchange_strong(expected, -2);
163 #ifdef DSVN_USE_ATOMIC
165 bool expected =
false;
166 if (!
m_filling.compare_exchange_strong(expected,
true))
171 bool ready()
const {
return true; }
188 template <
typename T>
189 class DetSetVector :
private dstvdetails::DetSetVectorTrans {
205 typedef typename IdContainer::iterator
IdIter;
206 typedef typename std::vector<data_type>::iterator
DataIter;
232 typedef std::pair<const_iterator, const_iterator>
Range;
267 m_v.m_filling =
false;
276 if (
m_v.onDemand() &&
m_v.m_data.size() ==
m_v.m_data.capacity())
281 if (
m_v.onDemand() &&
m_v.m_data.size() +
s >
m_v.m_data.capacity())
296 m_v.m_dataSize =
m_v.m_data.size();
310 m_v.m_data.push_back(
d);
325 friend class ::TestDetSet;
341 #ifdef DSVN_USE_ATOMIC
351 m_v.m_filling =
false;
356 bool expected =
false;
357 while (!
m_v.m_filling.compare_exchange_weak(expected,
true)) {
359 nanosleep(
nullptr,
nullptr);
362 if (
m_v.onDemand() &&
full()) {
363 m_v.m_filling =
false;
370 m_v.m_dataSize =
m_v.m_data.size();
372 m_v.m_filling =
false;
403 friend class ::TestDetSet;
421 #ifdef DSVN_USE_ATOMIC
423 bool expected =
false;
424 while (!iContainer.
m_filling.compare_exchange_weak(expected,
true, std::memory_order_acq_rel)) {
426 nanosleep(
nullptr,
nullptr);
472 m_ids.reserve(isize);
478 m_ids.shrink_to_fit();
482 void resize(
size_t isize,
size_t dsize) {
517 if ((*p).isValid() && (*p).size > 0 &&
m_data.size() == (*p).offset + (*p).size) {
518 m_data.resize((*p).offset);
528 if (
p !=
m_ids.end() && !(it < *
p))
540 return p !=
m_ids.end() && (*p).isValid();
555 return DetSet(*
this, *
p,
true);
567 std::pair<const_IdIter, const_IdIter>
p = std::equal_range(
m_ids.begin(),
m_ids.end(),
Item(
i));
568 return (
p.first !=
p.second) ?
p.first :
m_ids.end();
582 template <
typename CMP>
585 std::pair<const_IdIter, const_IdIter>
p = std::equal_range(
m_ids.begin(),
m_ids.end(),
i,
cmp);
620 friend class ::TestDetSet;
635 template <
typename T>
643 template <
typename T>
645 const std::vector<det_id_type>& iDets,
650 m_ids.reserve(iDets.size());
652 for (std::vector<det_id_type>::const_iterator itDetId = iDets.begin(), itDetIdEnd = iDets.end();
653 itDetId != itDetIdEnd;
655 assert(sanityCheck < *itDetId &&
"vector of det_id_type was not ordered");
656 sanityCheck = *itDetId;
657 m_ids.push_back(*itDetId);
661 #ifdef DSVN_USE_ATOMIC
662 template <
typename T>
665 if (m_getter.empty()) {
669 if (
item.initialize()) {
673 (*boost::any_cast<std::shared_ptr<Getter> >(&m_getter))->fill(
ff);
680 #ifdef DSVN_USE_ATOMIC
681 template <
typename T>
686 while (
item.initializing())
687 nanosleep(
nullptr,
nullptr);
688 m_data = &icont.data();
690 m_offset =
item.offset;
697 #include <type_traits>
702 namespace refhelper {
703 template <
typename T>
711 namespace refhelper {
712 template <
typename T>
719 return &(iContainer[iIndex]);
723 template <
typename T>
733 template <
class HandleT>
736 const HandleT& iHandle,
typename HandleT::element_type::value_type::const_iterator itIter) {
737 static_assert(std::is_same<
typename HandleT::element_type,
739 "Handle and DetSetVector do not have compatible types.");
740 auto index = itIter - &iHandle->data().front();
742 iHandle.id(), &(*itIter),
index);
749 template <
typename T>
756 return iElement - &(iContainer->
data().front());
761 #ifdef DSVN_USE_ATOMIC
762 #undef DSVN_USE_ATOMIC
void swap(IdContainer &iic, DataContainer &idc)
void errorIdExists(det_id_type iid)
bool initializing() const
void resize(size_t isize, size_t dsize)
DetSetVector< T >::id_type key_type
void push_back(data_type const &d)
result_type operator()(first_argument_type iContainer, second_argument_type iIndex)
bool exists(id_type i) const
id_type id(size_t cell) const
DetSetVector< T >::Item const & m_item
FastFiller(DetSetVector< T > &iv, typename DetSetVector< T >::Item &it, bool isaveEmpty=false)
DetSetVector< T >::size_type size_type
DetSet insert(id_type iid, data_type const *idata, size_type isize)
DetSetVector< T >::size_type size_type
std::pair< IdIter, DataIter > IterPair
void reserve(size_t isize, size_t dsize)
void swap(Association< C > &lhs, Association< C > &rhs)
std::vector< Item > IdContainer
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)
void update(Item const &item) const
std::vector< data_type >::iterator DataIter
DetSetVectorTrans(const DetSetVectorTrans &rh)
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
dslv::LazyGetter< T > Getter
static unsigned int indexFor(const value_type *iElement, const edmNew::DetSetVector< T > *iContainer)
const_iterator begin(bool update=false) const
DetSet insert(id_type iid, size_type isize)
DetSetVector< T >::id_type id_type
void throwCapacityExausted()
data_type & operator[](size_type i)
void push_back(data_type const &d)
Item const & item(size_t cell) const
TSFastFiller(DetSetVector< T > &iv, id_type id)
static DetSetVector< T >::Item & dummy()
IterHelp(DetSetVector< T > const &iv, bool iup)
void swap(DetSetVectorTrans &rh)
DetSetVector< T >::data_type value_type
IdContainer const & ids() const
DetSetVector< T > const * m_v
IdContainer::const_iterator const_IdIter
bool any(const std::vector< T > &v, const T &what)
edmNew::DetSet< T > DetSet
Item & operator=(Item &&rh) noexcept
void push_back(data_type &&d)
const_iterator find(id_type i, bool update=false) const
void checkCapacityExausted() const
FindSetForNewDetSetVector< T > value
edm::refhelper::FindForNewDetSetVector< data_type > RefFinder
std::atomic< int > offset
DetSetVector< T >::id_type key_type
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
result_type operator()(first_argument_type iContainer, second_argument_type iIndex)
DetSetVectorTrans & operator=(DetSetVectorTrans &&rh)
std::pair< const_IdIter, const_DataIter > const_IterPair
DetSetVector< T >::data_type value_type
static size_t size(const edmNew::DetSetVector< T > *iContainer)
#define CMS_CLASS_VERSION(_version_)
void throw_range(det_id_type iid)
unsigned int second_argument_type
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Item & operator=(Item const &rh) noexcept
size_type dataSize() const
unsigned int second_argument_type
data_type operator()(size_t cell, size_t frame) const
Range equal_range(id_type i, CMP cmp, bool update=false) const
bool operator<(Item const &rh) const
edmNew::DetSetVector< T >::FindForDetSetVector value
void reserve(size_type s)
void checkCapacityExausted(size_type s) const
Item & push_back(id_type iid)
CapacityExaustedException()
DetSetVector< T >::id_type id_type
DetSetVector< T >::Item & m_item
DetSetVectorTrans & operator=(const DetSetVectorTrans &)=delete
std::vector< data_type > DataContainer
std::pair< const_iterator, const_iterator > Range
void swap(DetSetVector &rh)
std::vector< data_type >::const_iterator const_DataIter
DetSetVectorTrans(DetSetVectorTrans &&rh)
std::vector< Trans::Item > m_ids
void push_back(data_type &&d)
std::atomic< bool > m_filling
DetSetVector(int isubdet=0)
IdContainer::iterator IdIter
FastFiller(DetSetVector< T > &iv, id_type id, bool isaveEmpty=false)
void set(Container const &icont, typename Container::Item const &item, bool update=true)
bool uninitialized() const
void pop_back(id_type iid)
DetSetVector< T > const & m_v
data_type & operator[](size_type i)
data_type const * data(size_t cell) const
const_IdIter findItem(id_type i) const
Item(Item const &rh) noexcept
const_iterator end(bool update=false) const
TSFastFiller(DetSetVector< T > const &iv, typename DetSetVector< T >::Item const &it)
static DetSetVector< T >::Item const & dummy()
DetSet operator[](id_type i) const
void reserve(size_type s)
Item & addItem(id_type iid, size_type isize)
size_type detsetSize(size_t cell) const
dstvdetails::DetSetVectorTrans Trans
bool isValid(id_type i) const
#define CMS_THREAD_GUARD(_var_)
DataContainer const & data() const
Item(id_type i=0, int io=-1, size_type is=0)
result_type & operator()(Item const &item) const
std::atomic< size_type > m_dataSize
DetSetVector & operator=(const DetSetVector &)=delete
Namespace of DDCMS conversion namespace.