CMS 3D CMS Logo

HLTMultiplicityValueProducer.h
Go to the documentation of this file.
1 #ifndef HLTrigger_JetMET_plugins_HLTMultiplicityValueProducer_h
2 #define HLTrigger_JetMET_plugins_HLTMultiplicityValueProducer_h
3 
4 #include <string>
5 #include <memory>
6 
15 
16 template <class INP_TYPE, class OUT_TYPE>
18 public:
21 
23 
24 protected:
25  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
26 
29  OUT_TYPE const defaultValue_;
30 };
31 
32 template <class INP_TYPE, class OUT_TYPE>
34  : src_token_(consumes<edm::View<INP_TYPE>>(iConfig.getParameter<edm::InputTag>("src"))),
35  strObjSelector_(StringCutObjectSelector<INP_TYPE, true>(iConfig.getParameter<std::string>("cut"))),
36  defaultValue_(iConfig.getParameter<OUT_TYPE>("defaultValue")) {
37  produces<OUT_TYPE>();
38 }
39 
40 template <class INP_TYPE, class OUT_TYPE>
43  edm::EventSetup const& iSetup) const {
44  auto const& objHandle(iEvent.getHandle(src_token_));
45 
46  if (objHandle.isValid()) {
47  LogDebug("Input") << "size of input collection: " << objHandle->size();
48 
49  OUT_TYPE objMult(0);
50  for (auto const& obj : *objHandle) {
51  if (strObjSelector_(obj)) {
52  ++objMult;
53  }
54  }
55 
56  LogDebug("Output") << "size of selected input objects: " << objMult;
57 
58  iEvent.put(std::make_unique<OUT_TYPE>(objMult));
59  } else {
60  iEvent.put(std::make_unique<OUT_TYPE>(defaultValue_));
61  }
62 }
63 
64 template <class INP_TYPE, class OUT_TYPE>
67  desc.add<edm::InputTag>("src", edm::InputTag(""))->setComment("input collection");
68  desc.add<std::string>("cut", "")->setComment("string for StringCutObjectSelector");
69  desc.add<OUT_TYPE>("defaultValue", 0)->setComment("default output value (used when input collection is unavailable)");
70  descriptions.addWithDefaultLabel(desc);
71 }
72 
73 #endif // HLTrigger_JetMET_plugins_HLTMultiplicityValueProducer_h
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
StringCutObjectSelector< INP_TYPE, true > const strObjSelector_
HLT enums.
HLTMultiplicityValueProducer(edm::ParameterSet const &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
edm::EDGetTokenT< edm::View< INP_TYPE > > const src_token_
#define LogDebug(id)