CMS 3D CMS Logo

GenericSelectorByValueMap.h
Go to the documentation of this file.
1 #ifndef GenericSelectorByValueMap_h
2 #define GenericSelectorByValueMap_h
3 
16 
17 namespace edm {
18 
19  namespace details {
20 
21  // which type should be used in edm::ParameterSet::getParameter<_> to read a parameter compatible with T ?
22 
23  // most types can use themselves
24  template <typename C>
26  typedef C type;
27  };
28 
29  // "float" is not allowed, as it conflicts with "double"
30  template <>
32  typedef double type;
33  };
34 
35  } // namespace details
36 
37  template <typename T, typename C>
39  public:
41 
42  private:
43  typedef T candidate_type;
44  typedef C selection_type;
46 
47  void produce(edm::Event& event, edm::EventSetup const& setup) override;
48 
51 
53  };
54 
55 } // namespace edm
56 
57 //------------------------------------------------------------------------------
58 
59 #include <vector>
60 #include <memory>
61 
66 
67 //------------------------------------------------------------------------------
68 
69 namespace edm {
70 
71  template <typename T, typename C>
73  : token_electrons(consumes<edm::View<candidate_type>>(config.getParameter<edm::InputTag>("input"))),
74  token_selection(consumes<edm::ValueMap<selection_type>>(config.getParameter<edm::InputTag>("selection"))),
75  m_cut(config.getParameter<cut_type>("cut")) {
76  // register the product
77  produces<edm::RefToBaseVector<candidate_type>>();
78  }
79 
80  //------------------------------------------------------------------------------
81 
82  template <typename T, typename C>
84  auto candidates = std::make_unique<edm::RefToBaseVector<candidate_type>>();
85 
86  // read the collection of GsfElectrons from the Event
88  event.getByToken(token_electrons, h_electrons);
89  edm::View<candidate_type> const& electrons = *h_electrons;
90 
91  // read the selection map from the Event
93  event.getByToken(token_selection, h_selection);
94  edm::ValueMap<selection_type> const& selectionMap = *h_selection;
95 
96  for (unsigned int i = 0; i < electrons.size(); ++i) {
98  if (selectionMap[ptr] > m_cut)
99  candidates->push_back(ptr);
100  }
101 
102  // put the product in the event
103  event.put(std::move(candidates));
104  }
105 
106 } // namespace edm
107 
108 #endif // GenericSelectorByValueMap_h
GenericSelectorByValueMap(edm::ParameterSet const &config)
Definition: config.py:1
Definition: helper.h:56
edm::EDGetTokenT< edm::ValueMap< selection_type > > token_selection
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
details::template CompatibleConfigurationType< selection_type >::type cut_type
HLT enums.
edm::EDGetTokenT< edm::View< candidate_type > > token_electrons
long double T
void produce(edm::Event &event, edm::EventSetup const &setup) override
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1