CMS 3D CMS Logo

HLTMultiplicityValueProducerFromNestedCollection.h
Go to the documentation of this file.
1 #ifndef HLTrigger_JetMET_plugins_HLTMultiplicityValueProducerFromNestedCollection_h
2 #define HLTrigger_JetMET_plugins_HLTMultiplicityValueProducerFromNestedCollection_h
3 
4 #include <memory>
5 
13 
14 template <class INP_TYPE, class OUT_TYPE>
16 public:
19 
21 
22 protected:
23  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
24 
26  OUT_TYPE const defaultValue_;
27 };
28 
29 template <class INP_TYPE, class OUT_TYPE>
31  edm::ParameterSet const& iConfig)
32  : src_token_(consumes<INP_TYPE>(iConfig.getParameter<edm::InputTag>("src"))),
33  defaultValue_(iConfig.getParameter<OUT_TYPE>("defaultValue")) {
34  produces<OUT_TYPE>();
35 }
36 
37 template <class INP_TYPE, class OUT_TYPE>
39  edm::StreamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const {
40  auto const& objHandle(iEvent.getHandle(src_token_));
41 
42  if (objHandle.isValid()) {
43  LogDebug("Input") << "size of input collection: " << objHandle->size();
44 
45  OUT_TYPE objMult(0);
46  for (auto const& obj : *objHandle) {
47  objMult += obj.size();
48  }
49 
50  LogDebug("Output") << "size of output objects: " << objMult;
51 
52  iEvent.put(std::make_unique<OUT_TYPE>(objMult));
53  } else {
54  iEvent.put(std::make_unique<OUT_TYPE>(defaultValue_));
55  }
56 }
57 
58 template <class INP_TYPE, class OUT_TYPE>
60  edm::ConfigurationDescriptions& descriptions) {
62  desc.add<edm::InputTag>("src", edm::InputTag(""))->setComment("input collection");
63  desc.add<OUT_TYPE>("defaultValue", 0)->setComment("default output value (used when input collection is unavailable)");
64  descriptions.addWithDefaultLabel(desc);
65 }
66 
67 #endif // HLTrigger_JetMET_plugins_HLTMultiplicityValueProducerFromNestedCollection_h
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
int iEvent
Definition: GenABIO.cc:224
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
HLT enums.
#define LogDebug(id)