Go to the documentation of this file.00001 #ifndef RecoAlgos_ObjectPairCollectionSelector_h
00002 #define RecoAlgos_ObjectPairCollectionSelector_h
00003
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 #include "CommonTools/UtilAlgos/interface/SelectionAdderTrait.h"
00018 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00019 #include <vector>
00020
00021 namespace edm { class Event; }
00022
00023 template<typename InputCollection, typename Selector,
00024 typename StoreContainer = std::vector<const typename InputCollection::value_type *>,
00025 typename RefAdder = typename helper::SelectionAdderTrait<InputCollection, StoreContainer>::type>
00026 class ObjectPairCollectionSelector {
00027 public:
00028 typedef InputCollection collection;
00029
00030 private:
00031 typedef const typename InputCollection::value_type * reference;
00032 typedef StoreContainer container;
00033 typedef typename container::const_iterator const_iterator;
00034
00035 public:
00036 ObjectPairCollectionSelector(const edm::ParameterSet & cfg) :
00037 select_(reco::modules::make<Selector>(cfg)) { }
00038 const_iterator begin() const { return selected_.begin(); }
00039 const_iterator end() const { return selected_.end(); }
00040 void select(const edm::Handle<InputCollection> &c, const edm::Event &, const edm::EventSetup &) {
00041 unsigned int s = c->size();
00042 std::vector<bool> v(s, false);
00043 for(unsigned int i = 0; i < s; ++i)
00044 for(unsigned int j = i + 1; j < s; ++j) {
00045 if(select_((*c)[i], (*c)[j]))
00046 v[i] = v[j] = true;
00047 }
00048 selected_.clear();
00049 for(unsigned int i = 0; i < s; ++i)
00050 if (v[i])
00051 addRef_(selected_, c, i);
00052 }
00053
00054 private:
00055 Selector select_;
00056 StoreContainer selected_;
00057 RefAdder addRef_;
00058 };
00059
00060 #endif