Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-11 03:12:54

0001 /* \class CandViewRefMerger
0002  *
0003  * Producer of merged references to Candidates
0004  *
0005  * \author: Luca Lista, INFN
0006  *
0007  */
0008 
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "DataFormats/Candidate/interface/Candidate.h"
0011 #include "FWCore/Framework/interface/global/EDProducer.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Framework/interface/Event.h"
0014 #include "FWCore/Utilities/interface/transform.h"
0015 #include "DataFormats/Common/interface/Handle.h"
0016 
0017 class CandViewRefMerger : public edm::global::EDProducer<> {
0018 public:
0019   explicit CandViewRefMerger(const edm::ParameterSet& cfg)
0020       : srcTokens_(
0021             edm::vector_transform(cfg.getParameter<std::vector<edm::InputTag> >("src"),
0022                                   [this](edm::InputTag const& tag) { return consumes<reco::CandidateView>(tag); })) {
0023     produces<std::vector<reco::CandidateBaseRef> >();
0024   }
0025 
0026 private:
0027   void produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const override {
0028     std::unique_ptr<std::vector<reco::CandidateBaseRef> > out(new std::vector<reco::CandidateBaseRef>);
0029     for (std::vector<edm::EDGetTokenT<reco::CandidateView> >::const_iterator i = srcTokens_.begin();
0030          i != srcTokens_.end();
0031          ++i) {
0032       edm::Handle<reco::CandidateView> src;
0033       evt.getByToken(*i, src);
0034       for (size_t j = 0; j < src->size(); ++j)
0035         out->push_back(src->refAt(j));
0036     }
0037     evt.put(std::move(out));
0038   }
0039   std::vector<edm::EDGetTokenT<reco::CandidateView> > srcTokens_;
0040 };
0041 
0042 DEFINE_FWK_MODULE(CandViewRefMerger);