1 #ifndef DataFormats_Common_DetSetLazyVector_h
2 #define DataFormats_Common_DetSetLazyVector_h
31 #include "boost/concept_check.hpp"
32 #include "boost/iterator/transform_iterator.hpp"
57 "DetSetLazyVector::operator[] called with index not in collection;\nindex value: ", i);
69 struct LazyAdapter :
public std::unary_function<const DetSet<T>&, const DetSet<T>&> {
90 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex)
const {
91 return &(*(iContainer.find(iIndex)));
97 class DetSetLazyVector
111 typedef boost::transform_iterator< dslv::LazyAdapter<T>,
typename collection_type::const_iterator >
const_iterator;
126 sets_.reserve(iDets.size());
128 for(std::vector<det_id_type>::const_iterator itDetId = iDets.begin(), itDetIdEnd = iDets.end();
129 itDetId != itDetIdEnd;
131 assert(sanityCheck <= *itDetId &&
"vector of det_id_type was not ordered");
132 sanityCheck = *itDetId;
172 std::shared_ptr<dslv::LazyGetter<T> >
getter_;
180 sets_.swap(other.sets_);
189 return sets_.empty();
207 return boost::make_transform_iterator(sets_.end(),adapter);
211 std::pair<typename collection_type::const_iterator,typename collection_type::const_iterator>
p =
212 std::equal_range(sets_.begin(), sets_.end(), id);
213 if (p.first == p.second) {
215 return boost::make_transform_iterator(sets_.end(),adapter);
221 return boost::make_transform_iterator(p.first,adapter);
242 return boost::make_transform_iterator(sets_.begin(),adapter);
251 return boost::make_transform_iterator(sets_.end(),adapter);
265 namespace refhelper {
267 struct FindForDetSetLazyVector :
public std::binary_function<const DetSetLazyVector<T>&, std::pair<det_id_type, typename DetSet<T>::collection_type::size_type>, const T*> {
269 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex) {
270 return &(*(iContainer.find(iIndex.first)->data.begin()+iIndex.second));
282 template<
class HandleT>
286 typename HandleT::element_type::value_type::const_iterator itIter) {
287 typedef typename HandleT::element_type Vec;
289 typename Vec::const_iterator itFound = iHandle->find(iDetID);
290 index += (itIter- itFound->data.begin());
294 template<
class HandleT>
295 Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>
298 typename HandleT::element_type::value_type::iterator itIter) {
299 typedef typename HandleT::element_type Vec;
300 typename Vec::detset::const_iterator itIter2 = itIter;
BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept)
self::result_type operator()(typename self::first_argument_type iContainer, typename self::second_argument_type iIndex)
collection_type::size_type size_type
DetSetLazyVector(std::shared_ptr< dslv::LazyGetter< T > > iGetter, const std::vector< det_id_type > &iDets)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void _throw_range(det_id_type i)
std::shared_ptr< LazyGetter< T > > getter_
void swap(Association< C > &lhs, Association< C > &rhs)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
const_reference operator[](det_id_type i) const
size_type size() const
Return the number of contained DetSets.
void swap(DetSetLazyVector &other)
const_iterator begin() const
Return an iterator to the first DetSet.
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::shared_ptr< dslv::LazyGetter< T > > getter_
self::result_type operator()(typename self::first_argument_type iContainer, typename self::second_argument_type iIndex) const
const_iterator find(det_id_type id) const
virtual void fill(DetSet< T > &)=0
detset const & const_reference
Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefToDetSetLazyVector(const HandleT &iHandle, det_id_type iDetID, typename HandleT::element_type::value_type::const_iterator itIter)
LazyAdapter(std::shared_ptr< LazyGetter< T > > iGetter)
std::vector< value_type > collection_type
bool empty() const
Return true if we contain no DetSets.
const DetSet< T > & operator()(const DetSet< T > &iUpdate) const
const_iterator end() const
Return the off-the-end iterator.
FindForDetSetLazyVector< T > value
boost::transform_iterator< dslv::LazyAdapter< T >, typename collection_type::const_iterator > const_iterator