CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CommonTools/CandAlgos/plugins/CandReducer.cc

Go to the documentation of this file.
00001 
00019 #include "FWCore/Framework/interface/EDProducer.h"
00020 #include "FWCore/Utilities/interface/InputTag.h"
00021 
00022 class CandReducer : public edm::EDProducer {
00023 public:
00025   explicit CandReducer( const edm::ParameterSet& );
00027   ~CandReducer();
00028 private:
00030   void produce( edm::Event& evt, const edm::EventSetup& );
00032   edm::InputTag src_;
00033 };
00034 
00035 #include "FWCore/Framework/interface/Event.h"
00036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00037 #include "DataFormats/Candidate/interface/Candidate.h"
00038 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00039 #include "FWCore/Utilities/interface/EDMException.h"
00040 
00041 using namespace reco;
00042 using namespace edm;
00043 
00044 CandReducer::CandReducer( const edm::ParameterSet& cfg ) :
00045   src_( cfg.getParameter<edm::InputTag>("src") ) {
00046   produces<CandidateCollection>();
00047 }
00048 
00049 CandReducer::~CandReducer() {
00050 }
00051 
00052 void CandReducer::produce( Event& evt, const EventSetup& ) {
00053   Handle<reco::CandidateView> cands;
00054   evt.getByLabel( src_, cands );
00055   std::auto_ptr<CandidateCollection> comp( new CandidateCollection );
00056   for( reco::CandidateView::const_iterator c = cands->begin(); c != cands->end(); ++c ) {
00057     std::auto_ptr<Candidate> cand( new LeafCandidate( * c ) );
00058     comp->push_back( cand.release() );
00059   }
00060   evt.put( comp );
00061 }
00062 
00063 #include "FWCore/Framework/interface/MakerMacros.h"
00064 
00065 DEFINE_FWK_MODULE( CandReducer );