1 #ifndef DataFormats_Common_DetSetVector_h
2 #define DataFormats_Common_DetSetVector_h
42 #include "boost/concept_check.hpp"
43 #include "boost/mpl/if.hpp"
44 #include "boost/bind.hpp"
73 "DetSetVector::operator[] called with index not in collection;\nindex value: ", i);
89 public boost::mpl::if_c<boost::is_base_of<edm::DoNotSortUponInsertion, T>::value,
90 edm::DoNotSortUponInsertion,
105 typedef typename collection_type::iterator
iterator;
183 std::vector<void const*>& pointers,
210 if (!alreadySorted)
_sort();
217 _sets.swap(other._sets);
218 bool tmp = _alreadySorted; _alreadySorted = other._alreadySorted; other._alreadySorted =
tmp;
235 _alreadySorted =
false;
237 _sets.insert(std::lower_bound(_sets.begin(),
256 std::pair<iterator,iterator>
p =
257 std::equal_range(_sets.begin(), _sets.end(), id);
261 if (p.first != p.second)
return *p.first;
265 return *(_sets.insert(p.first,
detset(
id)));
272 return _sets.empty();
286 _alreadySorted =
false;
287 std::pair<iterator,iterator>
p =
288 std::equal_range(_sets.begin(), _sets.end(), id);
289 if (p.first == p.second)
return _sets.end();
296 assert(std::distance(p.first, p.second) == 1);
306 std::pair<const_iterator,const_iterator>
p =
307 std::equal_range(_sets.begin(), _sets.end(), id);
308 if (p.first == p.second)
return _sets.end();
311 assert(std::distance(p.first, p.second) == 1);
319 _alreadySorted =
false;
342 _alreadySorted =
false;
343 return _sets.begin();
350 return _sets.begin();
357 _alreadySorted =
false;
375 std::back_inserter(result),
383 if (_alreadySorted)
return;
384 typename collection_type::iterator
i = _sets.begin();
385 typename collection_type::iterator
e = _sets.end();
387 for (; i !=
e; ++
i) {
389 std::sort(i->data.begin(), i->data.end());
402 std::vector<void const*>& pointers,
417 std::vector<void const*>& pointers,
420 obj.fillView(
id, pointers, helpers);
445 namespace refhelper {
447 class FindForDetSetVector :
public std::binary_function<const DetSetVector<T>&, std::pair<det_id_type, typename DetSet<T>::collection_type::size_type>, const T*> {
450 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex) {
451 return &(*(iContainer.find(iIndex.first)->data.begin()+iIndex.second));
463 template<
class HandleT>
467 typename HandleT::element_type::value_type::const_iterator itIter) {
468 typedef typename HandleT::element_type Vec;
470 typename Vec::const_iterator itFound = iHandle->find(iDetID);
471 if(itFound == iHandle->end()) {
473 "an edm::Ref to an edm::DetSetVector was given a DetId, ", iDetID,
", that is not in the DetSetVector");
475 index += (itIter- itFound->data.begin());
476 if(index >= itFound->data.size()) {
478 "an edm::Ref to a edm::DetSetVector is being made with an interator that is not part of the edm::DetSet itself");
480 return Ref<
typename HandleT::element_type,
482 (iHandle,std::make_pair(iDetID,index));
485 template<
class HandleT>
486 Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>
489 typename HandleT::element_type::value_type::iterator itIter) {
490 typedef typename HandleT::element_type Vec;
491 typename Vec::detset::const_iterator itIter2 = itIter;
492 return makeRefTo(iHandle,iDetID,itIter2);
void _throw_range(det_id_type i)
detset const & const_reference
iterator find(det_id_type id)
void fillView(AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper > const &obj, ProductID const &id, std::vector< void const * > &pointers, helper_vector &helpers)
void reallyFillView(COLLECTION const &coll, ProductID const &id, std::vector< void const * > &ptrs, helper_vector &helpers)
#define CMS_CLASS_VERSION(_version_)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefToDetSetVector(const HandleT &iHandle, det_id_type iDetID, typename HandleT::element_type::value_type::iterator itIter)
void swap(DetSetVector &other)
void swap(Association< C > &lhs, Association< C > &rhs)
reference find_or_insert(det_id_type id)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
FindForDetSetVector< T > value
Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, det_id_type iDetID, typename HandleT::element_type::value_type::const_iterator itIter)
Container::value_type value_type
std::vector< detset > collection_type
collection_type::iterator iterator
iterator end()
Return the off-the-end iterator.
size_type size() const
Return the number of contained DetSets.
DetSetVector()
Create an empty DetSetVector.
edm::BoolCache _alreadySorted
bool empty() const
Return true if we contain no DetSets.
void getIds(std::vector< det_id_type > &result) const
void _sort()
Sort the DetSet in order of increasing DetId.
BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept)
std::vector< std::vector< double > > tmp
void insert(detset const &s)
Insert the given DetSet.
reference operator[](det_id_type i)
collection_type::size_type size_type
iterator begin()
Return an iterator to the first DetSet.
self::result_type operator()(typename self::first_argument_type iContainer, typename self::second_argument_type iIndex)
collection_type::const_iterator const_iterator
void fillView(ProductID const &id, std::vector< void const * > &pointers, helper_vector &helpers) const
DetSetVector & operator=(DetSetVector const &other)