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 
52  cut_type m_cut;
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 {
77  // register the product
78  produces<edm::RefToBaseVector<candidate_type> >();
79 }
80 
81 //------------------------------------------------------------------------------
82 
83 template <typename T, typename C>
85 {
86  auto candidates = std::make_unique<edm::RefToBaseVector<candidate_type>>();
87 
88  // read the collection of GsfElectrons from the Event
90  event.getByToken(token_electrons, h_electrons);
91  edm::View<candidate_type> const & electrons = * h_electrons;
92 
93  // read the selection map from the Event
95  event.getByToken(token_selection, h_selection);
96  edm::ValueMap<selection_type> const & selectionMap = * h_selection;
97 
98  for (unsigned int i = 0; i < electrons.size(); ++i) {
99  edm::RefToBase<candidate_type> ptr = electrons.refAt(i);
100  if (selectionMap[ptr] > m_cut)
101  candidates->push_back(ptr);
102  }
103 
104  // put the product in the event
105  event.put(std::move(candidates));
106 }
107 
108 } // namespace edm;
109 
110 #endif // GenericSelectorByValueMap_h
GenericSelectorByValueMap(edm::ParameterSet const &config)
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
size_type size() const
Definition: config.py:1
RefToBase< value_type > refAt(size_type i) const
edm::EDGetTokenT< edm::ValueMap< selection_type > > token_selection
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
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:510
Definition: event.py:1