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"
58 "DetSetLazyVector::operator[] called with index not in collection;\nindex value: ", i);
70 struct LazyAdapter :
public std::unary_function<const DetSet<T>&, const DetSet<T>&> {
91 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex)
const {
92 return &(*(iContainer.find(iIndex)));
98 class DetSetLazyVector
112 typedef boost::transform_iterator< dslv::LazyAdapter<T>,
typename collection_type::const_iterator >
const_iterator;
127 sets_.reserve(iDets.size());
129 for(std::vector<det_id_type>::const_iterator itDetId = iDets.begin(), itDetIdEnd = iDets.end();
130 itDetId != itDetIdEnd;
132 assert(sanityCheck <= *itDetId &&
"vector of det_id_type was not ordered");
133 sanityCheck = *itDetId;
173 std::shared_ptr<dslv::LazyGetter<T> >
getter_;
181 sets_.swap(other.sets_);
190 return sets_.empty();
208 return boost::make_transform_iterator(sets_.end(),adapter);
212 std::pair<typename collection_type::const_iterator,typename collection_type::const_iterator>
p =
213 std::equal_range(sets_.begin(), sets_.end(), id);
214 if (p.first == p.second) {
216 return boost::make_transform_iterator(sets_.end(),adapter);
220 assert(std::distance(p.first, p.second) == 1);
222 return boost::make_transform_iterator(p.first,adapter);
243 return boost::make_transform_iterator(sets_.begin(),adapter);
252 return boost::make_transform_iterator(sets_.end(),adapter);
266 namespace refhelper {
268 struct FindForDetSetLazyVector :
public std::binary_function<const DetSetLazyVector<T>&, std::pair<det_id_type, typename DetSet<T>::collection_type::size_type>, const T*> {
270 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex) {
271 return &(*(iContainer.find(iIndex.first)->data.begin()+iIndex.second));
283 template<
class HandleT>
287 typename HandleT::element_type::value_type::const_iterator itIter) {
288 typedef typename HandleT::element_type Vec;
290 typename Vec::const_iterator itFound = iHandle->find(iDetID);
291 index += (itIter- itFound->data.begin());
295 template<
class HandleT>
296 Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>
299 typename HandleT::element_type::value_type::iterator itIter) {
300 typedef typename HandleT::element_type Vec;
301 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