Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-18 02:29:45

0001 /** \class cand::modules::CandReducer

0002  *

0003  * Given a collectin of candidates, produced a

0004  * collection of LeafCandidas identical to the

0005  * source collection, but removing all daughters

0006  * and all components.

0007  *

0008  * This is ment to produce a "light" collection

0009  * of candiadates just containing kimenatics

0010  * information for very fast analysis purpose

0011  *

0012  * \author Luca Lista, INFN

0013  *

0014  * \version $Revision: 1.3 $

0015  *

0016  * $Id: CandReducer.cc,v 1.3 2009/09/27 22:26:55 hegner Exp $

0017  *

0018  */
0019 #include "FWCore/Framework/interface/global/EDProducer.h"
0020 #include "FWCore/Utilities/interface/InputTag.h"
0021 #include "DataFormats/Candidate/interface/Candidate.h"
0022 
0023 class CandReducer : public edm::global::EDProducer<> {
0024 public:
0025   /// constructor from parameter set

0026   explicit CandReducer(const edm::ParameterSet&);
0027   /// destructor

0028   ~CandReducer() override = default;
0029 
0030 private:
0031   /// process one evevnt

0032   void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override;
0033   /// label of source candidate collection

0034   const edm::EDGetTokenT<reco::CandidateView> srcToken_;
0035 };
0036 
0037 #include "FWCore/Framework/interface/Event.h"
0038 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0039 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0040 #include "FWCore/Utilities/interface/EDMException.h"
0041 
0042 using namespace reco;
0043 using namespace edm;
0044 
0045 CandReducer::CandReducer(const edm::ParameterSet& cfg)
0046     : srcToken_(consumes<reco::CandidateView>(cfg.getParameter<edm::InputTag>("src"))) {
0047   produces<CandidateCollection>();
0048 }
0049 
0050 void CandReducer::produce(edm::StreamID, edm::Event& evt, edm::EventSetup const&) const {
0051   const Handle<reco::CandidateView> cands = evt.getHandle(srcToken_);
0052   std::unique_ptr<CandidateCollection> comp(new CandidateCollection);
0053   for (reco::CandidateView::const_iterator c = cands->begin(); c != cands->end(); ++c) {
0054     std::unique_ptr<Candidate> cand(new LeafCandidate(*c));
0055     comp->push_back(cand.release());
0056   }
0057   evt.put(std::move(comp));
0058 }
0059 
0060 #include "FWCore/Framework/interface/MakerMacros.h"
0061 DEFINE_FWK_MODULE(CandReducer);