1 #ifndef DataFormats_Common_DetSetVector_h
2 #define DataFormats_Common_DetSetVector_h
42 #include "boost/concept_check.hpp"
43 #include "boost/mpl/if.hpp"
71 "DetSetVector::operator[] called with index not in collection;\nindex value: ", i);
87 public boost::mpl::if_c<boost::is_base_of<edm::DoNotSortUponInsertion, T>::value,
88 edm::DoNotSortUponInsertion,
103 typedef typename collection_type::iterator
iterator;
184 std::vector<void const*>& pointers,
211 if (!alreadySorted)
_sort();
218 _sets.swap(other._sets);
219 bool tmp = _alreadySorted; _alreadySorted = other._alreadySorted; other._alreadySorted =
tmp;
227 DetSetVector<T>
temp(other);
236 _alreadySorted =
false;
238 _sets.insert(std::lower_bound(_sets.begin(),
257 std::pair<iterator,iterator>
p =
258 std::equal_range(_sets.begin(), _sets.end(), id);
262 if (p.first != p.second)
return *p.first;
266 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
267 return *(_sets.emplace(p.first,
id));
269 return *(_sets.insert(p.first,
detset(
id)));
277 return _sets.empty();
291 _alreadySorted =
false;
292 std::pair<iterator,iterator>
p =
293 std::equal_range(_sets.begin(), _sets.end(), id);
294 if (p.first == p.second)
return _sets.end();
311 std::pair<const_iterator,const_iterator>
p =
312 std::equal_range(_sets.begin(), _sets.end(), id);
313 if (p.first == p.second)
return _sets.end();
324 _alreadySorted =
false;
347 _alreadySorted =
false;
348 return _sets.begin();
355 return _sets.begin();
362 _alreadySorted =
false;
380 std::back_inserter(result),
388 _sets.shrink_to_fit();
389 if (_alreadySorted)
return;
390 typename collection_type::iterator
i = _sets.begin();
391 typename collection_type::iterator
e = _sets.end();
393 for (; i !=
e; ++
i) {
394 i->data.shrink_to_fit();
396 std::sort(i->data.begin(), i->data.end());
404 std::sort(_sets.begin(), _sets.end());
409 std::vector<void const*>& pointers,
424 std::vector<void const*>& pointers,
427 obj.fillView(
id, pointers, helpers);
452 namespace refhelper {
454 class FindForDetSetVector :
public std::binary_function<const DetSetVector<T>&, std::pair<det_id_type, typename DetSet<T>::collection_type::size_type>, const T*> {
457 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex) {
458 return &(*(iContainer.find(iIndex.first)->data.begin()+iIndex.second));
470 template<
class HandleT>
475 typename HandleT::element_type::value_type::const_iterator itIter) {
476 typedef typename HandleT::element_type Vec;
478 typename Vec::const_iterator itFound = iHandle->find(iDetID);
479 if(itFound == iHandle->end()) {
481 "an edm::Ref to an edm::DetSetVector was given a DetId, ", iDetID,
", that is not in the DetSetVector");
483 index += (itIter- itFound->data.begin());
484 if(index >= itFound->data.size()) {
486 "an edm::Ref to a edm::DetSetVector is being made with an interator that is not part of the edm::DetSet itself");
488 return Ref<
typename HandleT::element_type,
490 (iHandle,std::make_pair(iDetID,index));
493 template<
class HandleT>
495 Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>
498 typename HandleT::element_type::value_type::iterator itIter) {
499 typedef typename HandleT::element_type Vec;
500 typename Vec::detset::const_iterator itIter2 = itIter;
501 return makeRefTo(iHandle,iDetID,itIter2);
void _throw_range(det_id_type i)
detset const & const_reference
iterator find(det_id_type id)
DetSetVector & operator=(DetSetVector const &other)
void reallyFillView(COLLECTION const &coll, ProductID const &id, std::vector< void const * > &ptrs, FillViewHelperVector &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)
static std::string const input
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
Container::value_type value_type
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)
void fillView(AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper > const &obj, ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers)
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)
void fillView(ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers) const
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
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector