1 #ifndef DataFormats_Common_DetSetVectorNew_h
2 #define DataFormats_Common_DetSetVectorNew_h
9 #include <boost/iterator_adaptors.hpp>
10 #include <boost/iterator/transform_iterator.hpp>
11 #include <boost/iterator/counting_iterator.hpp>
12 #include <boost/any.hpp>
17 #if !defined(__ROOTCLING__)
18 #define DSVN_USE_ATOMIC
47 namespace dstvdetails {
82 id=rh.id;
offset=int(rh.offset);
size=rh.size;
return *
this;
92 #ifdef DSVN_USE_ATOMIC
96 return offset.compare_exchange_strong(expected,-2);
110 #ifdef DSVN_USE_ATOMIC
117 bool ready()
const {
return true;}
136 class DetSetVector :
private dstvdetails::DetSetVectorTrans {
153 typedef typename IdContainer::iterator
IdIter;
154 typedef typename std::vector<data_type>::iterator
DataIter;
179 typedef std::pair<const_iterator,const_iterator>
Range;
255 m_v.m_data.push_back(d);
268 friend class ::TestDetSet;
284 #ifdef DSVN_USE_ATOMIC
300 while (!
m_v.m_filling.compare_exchange_weak(expected,
true)) { expected=
false; nanosleep(0,0);}
302 if (
m_v.onDemand() &&
m_v.m_data.capacity()<offset+
m_lv.size()) {
303 m_v.m_filling =
false;
311 m_v.m_filling =
false;
349 friend class ::TestDetSet;
362 class FindForDetSetVector :
public std::binary_function<const edmNew::DetSetVector<T>&, unsigned int, const T*> {
365 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex)
366 #ifdef DSVN_USE_ATOMIC
369 while (!iContainer.m_filling.compare_exchange_weak(expected,
true,std::memory_order_acq_rel)) { expected=
false; nanosleep(0,0);}
370 typename self::result_type
item = &(iContainer.m_data[iIndex]);
371 assert(iContainer.m_filling==
true);
372 iContainer.m_filling =
false;
415 m_ids.reserve(isize);
421 m_ids.shrink_to_fit();
425 void resize(
size_t isize,
size_t dsize) {
439 return DetSet(*
this,item,
false);
445 return DetSet(*
this,item,
false);
456 if (p==
m_ids.end())
return;
458 if ( (*p).isValid() && (*p).size>0 &&
459 m_data.size()==(*p).offset+(*p).size)
460 m_data.resize((*p).offset);
488 return p!=
m_ids.end() && (*p).isValid();
503 return DetSet(*
this,*p,
true);
511 boost::make_transform_iterator(p,
517 std::pair<const_IdIter,const_IdIter>
p =
519 return (p.first!=p.second) ? p.first :
m_ids.end();
524 return boost::make_transform_iterator(
m_ids.begin(),
530 return boost::make_transform_iterator(
m_ids.end(),
536 template<
typename CMP>
539 std::pair<const_IdIter,const_IdIter>
p =
541 return Range(boost::make_transform_iterator(p.first,IterHelp(*
this,
update)),
542 boost::make_transform_iterator(p.second,IterHelp(*
this,
update))
568 return m_ids[cell].id;
586 friend class ::TestDetSet;
602 template<
typename T>
613 const std::vector<det_id_type>& iDets,
618 m_ids.reserve(iDets.size());
620 for(std::vector<det_id_type>::const_iterator itDetId = iDets.begin(), itDetIdEnd = iDets.end();
621 itDetId != itDetIdEnd;
623 assert(sanityCheck < *itDetId &&
"vector of det_id_type was not ordered");
624 sanityCheck = *itDetId;
625 m_ids.push_back(*itDetId);
629 #ifdef DSVN_USE_ATOMIC
638 (*boost::any_cast<std::shared_ptr<Getter> >(&m_getter))->fill(ff);
646 #ifdef DSVN_USE_ATOMIC
651 if (update) icont.update(item);
653 m_data=&icont.data();
662 #include <boost/mpl/assert.hpp>
663 #include <boost/type_traits/is_same.hpp>
668 namespace refhelper {
677 namespace refhelper {
681 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex) {
682 return &(iContainer[iIndex]);
696 template<
class HandleT>
700 typename HandleT::element_type::value_type::const_iterator itIter) {
702 auto index = itIter - &iHandle->data().front();
703 return edm::Ref<
typename HandleT::element_type,
705 (iHandle.id(), &(*itIter),
index);
721 return iElement-&(iContainer->
data().front());
726 #ifdef DSVN_USE_ATOMIC
727 #undef DSVN_USE_ATOMIC
void swap(ora::Record &rh, ora::Record &lh)
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
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
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)
Range equal_range(id_type i, CMP cmp, bool update=false) const
std::vector< data_type > DataContainer
Item & push_back(id_type iid)
const_IdIter findItem(id_type i) const
std::vector< Trans::Item > m_ids
bool any(const std::vector< T > &v, const T &what)
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)
std::pair< const_IdIter, const_DataIter > const_IterPair
Item & operator=(Item &&rh)
DetSetVector(int isubdet=0)
std::pair< const_iterator, const_iterator > Range
TSFastFiller(DetSetVector< T > const &iv, typename DetSetVector< T >::Item const &it)
void pop_back(id_type iid)
#define CMS_CLASS_VERSION(_version_)
friend class TSFastFiller
id_type id(size_t cell) const
DetSetVectorTrans & operator=(const DetSetVectorTrans &)=delete
DetSetVector< T > const & m_v
bool operator<(Item const &rh) const
DetSetVector< T > const * m_v
dstvdetails::DetSetVectorTrans Trans
self::result_type operator()(typename self::first_argument_type iContainer, typename self::second_argument_type iIndex)
Item const & item(size_t cell) const
void checkCapacityExausted() const
Container::value_type value_type
IterHelp(DetSetVector< T > const &iv, bool iup)
Item & addItem(id_type iid, size_type isize)
DetSetVector & operator=(const DetSetVector &)=delete
DetSetVector< T >::data_type value_type
static DetSetVector< T >::Item const & dummy()
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)
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::vector< Item > IdContainer
friend class FindForDetSetVector
dslv::LazyGetter< T > Getter
DetSetVector< T >::id_type key_type
void errorIdExists(det_id_type iid)
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()
Item & operator=(Item const &rh)
DetSet insert(id_type iid, size_type isize)
std::pair< IdIter, DataIter > IterPair
std::atomic< bool > m_filling
IdContainer::const_iterator const_IdIter
data_type operator()(size_t cell, size_t frame) const
self::result_type operator()(typename self::first_argument_type iContainer, typename self::second_argument_type iIndex)
edmNew::DetSet< T > DetSet
volatile std::atomic< bool > shutdown_flag false
FastFiller(DetSetVector< T > &iv, typename DetSetVector< T >::Item &it, bool isaveEmpty=false)
data_type & operator[](size_type i)
edm::refhelper::FindForNewDetSetVector< data_type > RefFinder
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