CMS 3D CMS Logo

SortCollectionSelector.h
Go to the documentation of this file.
1 #ifndef RecoAlgos_SortCollectionSelector_h
2 #define RecoAlgos_SortCollectionSelector_h
3 
21 #include <algorithm>
22 #include <utility>
23 
24 namespace edm {
25  class Event;
26  class EventSetup;
27 }
28 
29 template<typename InputCollection, typename Comparator,
30  typename OutputCollection = typename helper::SelectedOutputCollectionTrait<InputCollection>::type,
31  typename StoreContainer = typename helper::StoreContainerTrait<OutputCollection>::type,
34 public:
36 private:
37  typedef const typename InputCollection::value_type * reference;
38  typedef std::pair<reference, size_t> pair;
39  typedef StoreContainer container;
40  typedef typename container::const_iterator const_iterator;
41 
42 public:
44  compare_(Comparator()),
45  maxNumber_(cfg.template getParameter<unsigned int>("maxNumber")) { }
46  const_iterator begin() const { return selected_.begin(); }
47  const_iterator end() const { return selected_.end(); }
49  std::vector<pair> v;
50  for(size_t idx = 0; idx < c->size(); ++ idx)
51  v.push_back(std::make_pair(&(*c)[idx], idx));
52  std::sort(v.begin(), v.end(), compare_);
53  selected_.clear();
54  for(size_t i = 0; i < maxNumber_ && i < v.size(); ++i)
55  addRef_(selected_, c, v[i].second);
56  }
57 private:
58  struct PairComparator {
59  PairComparator(const Comparator & cmp) : cmp_(cmp) { }
60  bool operator()(const pair & t1, const pair & t2) const {
61  return cmp_(*t1.first, *t2.first);
62  }
64  };
66  unsigned int maxNumber_;
67  StoreContainer selected_;
68  RefAdder addRef_;
69 };
70 
71 #endif
72 
const InputCollection::value_type * reference
std::vector< const typename OutputCollection::value_type * > type
container::const_iterator const_iterator
SortCollectionSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
void select(const edm::Handle< InputCollection > &c, const edm::Event &, const edm::EventSetup &)
U second(std::pair< T, U > const &p)
const_iterator begin() const
bool operator()(const pair &t1, const pair &t2) const
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
const_iterator end() const
HLT enums.
std::pair< reference, size_t > pair