CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SortCollectionSelector.h
Go to the documentation of this file.
1 #ifndef RecoAlgos_SortCollectionSelector_h
2 #define RecoAlgos_SortCollectionSelector_h
3 
20 #include <algorithm>
21 #include <utility>
22 namespace edm { class Event; }
23 
24 template<typename InputCollection, typename Comparator,
25  typename OutputCollection = typename helper::SelectedOutputCollectionTrait<InputCollection>::type,
26  typename StoreContainer = typename helper::StoreContainerTrait<OutputCollection>::type,
29 public:
31 private:
32  typedef const typename InputCollection::value_type * reference;
33  typedef std::pair<reference, size_t> pair;
34  typedef StoreContainer container;
35  typedef typename container::const_iterator const_iterator;
36 
37 public:
40  maxNumber_(cfg.template getParameter<unsigned int>("maxNumber")) { }
41  const_iterator begin() const { return selected_.begin(); }
42  const_iterator end() const { return selected_.end(); }
44  std::vector<pair> v;
45  for(size_t idx = 0; idx < c->size(); ++ idx)
46  v.push_back(std::make_pair(&(*c)[idx], idx));
47  std::sort(v.begin(), v.end(), compare_);
48  selected_.clear();
49  for(size_t i = 0; i < maxNumber_ && i < v.size(); ++i)
50  addRef_(selected_, c, v[i].second);
51  }
52 private:
53  struct PairComparator {
54  PairComparator(const Comparator & cmp) : cmp_(cmp) { }
55  bool operator()(const pair & t1, const pair & t2) const {
56  return cmp_(*t1.first, *t2.first);
57  }
59  };
61  unsigned int maxNumber_;
62  StoreContainer selected_;
63  RefAdder addRef_;
64 };
65 
66 #endif
67 
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
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
Container::value_type value_type
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
const_iterator end() const
std::pair< reference, size_t > pair
def template
Definition: svgfig.py:520