CMS 3D CMS Logo

JetCollectionReducer.cc
Go to the documentation of this file.
6 
12 
13 template <typename T>
15 public:
16  explicit JetCollectionReducerT(const edm::ParameterSet& iConfig);
17  ~JetCollectionReducerT() override {}
18 
19  void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
20 
21 private:
24  std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>> collections_;
25 };
26 
27 template <typename T>
29  : jetColToken_(consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("jetCollection"))),
30  writeEmptyCollection_(iConfig.getParameter<bool>("writeEmptyCollection")) {
31  std::vector<edm::InputTag> filtersDecTags = iConfig.getParameter<std::vector<edm::InputTag>>("triggeringCollections");
32  for (std::vector<edm::InputTag>::const_iterator inputTag = filtersDecTags.begin(); inputTag != filtersDecTags.end();
33  ++inputTag) {
35  }
36 
37  produces<std::vector<T>>();
38 }
39 
40 // ------------ method called to produce the data ------------
41 template <typename T>
43  std::unique_ptr<std::vector<T>> outJets(new std::vector<T>());
44 
45  bool filterDecision = false;
47  for (std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>::const_iterator filter = collections_.begin();
48  filter != collections_.end();
49  filter++) {
50  iEvent.getByToken(*filter, tmpCol);
51  if (!tmpCol->empty()) {
52  filterDecision = true;
53  break;
54  }
55  }
56 
57  if (!filterDecision) {
58  if (writeEmptyCollection_)
59  iEvent.put(std::move(outJets));
60  return;
61  }
62 
63  edm::Handle<std::vector<T>> jetColHandle;
64  iEvent.getByToken(jetColToken_, jetColHandle);
65 
66  //MM: probably a better way to do it...
67  for (size_t ij = 0; ij < jetColHandle->size(); ij++) {
68  outJets->push_back((*jetColHandle)[ij]);
69  }
70 
71  iEvent.put(std::move(outJets));
72 }
73 
74 //define this as a plug-in
void produce(edm::StreamID id, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
JetCollectionReducerT(const edm::ParameterSet &iConfig)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int iEvent
Definition: GenABIO.cc:224
JetCollectionReducerT< reco::PFJet > PFJetCollectionReducer
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > collections_
edm::EDGetTokenT< std::vector< T > > jetColToken_
JetCollectionReducerT< pat::Jet > PATJetCollectionReducer
HLT enums.
long double T
def move(src, dest)
Definition: eostools.py:511