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 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
46 #include "boost/bind.hpp"
75 "DetSetVector::operator[] called with index not in collection;\nindex value: ", i);
91 public boost::mpl::if_c<boost::is_base_of<edm::DoNotSortUponInsertion, T>::value,
92 edm::DoNotSortUponInsertion,
107 typedef typename collection_type::iterator
iterator;
188 std::vector<void const*>& pointers,
215 if (!alreadySorted)
_sort();
222 _sets.swap(other._sets);
223 bool tmp = _alreadySorted; _alreadySorted = other._alreadySorted; other._alreadySorted =
tmp;
240 _alreadySorted =
false;
242 _sets.insert(std::lower_bound(_sets.begin(),
261 std::pair<iterator,iterator>
p =
262 std::equal_range(_sets.begin(), _sets.end(), id);
266 if (p.first != p.second)
return *p.first;
270 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
271 return *(_sets.emplace(p.first,
id));
273 return *(_sets.insert(p.first,
detset(
id)));
281 return _sets.empty();
295 _alreadySorted =
false;
296 std::pair<iterator,iterator>
p =
297 std::equal_range(_sets.begin(), _sets.end(), id);
298 if (p.first == p.second)
return _sets.end();
315 std::pair<const_iterator,const_iterator>
p =
316 std::equal_range(_sets.begin(), _sets.end(), id);
317 if (p.first == p.second)
return _sets.end();
328 _alreadySorted =
false;
351 _alreadySorted =
false;
352 return _sets.begin();
359 return _sets.begin();
366 _alreadySorted =
false;
384 std::back_inserter(result),
385 #
if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
397 _sets.shrink_to_fit();
399 if (_alreadySorted)
return;
400 typename collection_type::iterator
i = _sets.begin();
401 typename collection_type::iterator
e = _sets.end();
403 for (; i !=
e; ++
i) {
405 i->data.shrink_to_fit();
408 std::sort(i->data.begin(), i->data.end());
421 std::vector<void const*>& pointers,
436 std::vector<void const*>& pointers,
439 obj.fillView(
id, pointers, helpers);
464 namespace refhelper {
466 class FindForDetSetVector :
public std::binary_function<const DetSetVector<T>&, std::pair<det_id_type, typename DetSet<T>::collection_type::size_type>, const T*> {
469 typename self::result_type
operator()(
typename self::first_argument_type iContainer,
typename self::second_argument_type iIndex) {
470 return &(*(iContainer.find(iIndex.first)->data.begin()+iIndex.second));
482 template<
class HandleT>
486 typename HandleT::element_type::value_type::const_iterator itIter) {
487 typedef typename HandleT::element_type Vec;
489 typename Vec::const_iterator itFound = iHandle->find(iDetID);
490 if(itFound == iHandle->end()) {
492 "an edm::Ref to an edm::DetSetVector was given a DetId, ", iDetID,
", that is not in the DetSetVector");
494 index += (itIter- itFound->data.begin());
495 if(index >= itFound->data.size()) {
497 "an edm::Ref to a edm::DetSetVector is being made with an interator that is not part of the edm::DetSet itself");
499 return Ref<
typename HandleT::element_type,
501 (iHandle,std::make_pair(iDetID,index));
504 template<
class HandleT>
505 Ref<typename HandleT::element_type, typename HandleT::element_type::value_type::value_type>
508 typename HandleT::element_type::value_type::iterator itIter) {
509 typedef typename HandleT::element_type Vec;
510 typename Vec::detset::const_iterator itIter2 = itIter;
511 return makeRefTo(iHandle,iDetID,itIter2);
void _throw_range(det_id_type i)
detset const & const_reference
iterator find(det_id_type id)
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
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)
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)
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
DetSetVector & operator=(DetSetVector const &other)