CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/CommonTools/CandAlgos/interface/CloneProducer.h

Go to the documentation of this file.
00001 #ifndef CandAlgos_CloneProducer_h
00002 #define CandAlgos_CloneProducer_h
00003 
00016 #include "FWCore/Framework/interface/EDProducer.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/Utilities/interface/InputTag.h"
00020 #include "DataFormats/Candidate/interface/Candidate.h"
00021 
00022 template<typename C>
00023 class CloneProducer : public edm::EDProducer {
00024 public:
00026   explicit CloneProducer( const edm::ParameterSet& );
00028   ~CloneProducer();
00029 
00030 private:
00032   virtual void produce( edm::Event&, const edm::EventSetup& );
00034   edm::InputTag src_;
00035 };
00036 
00037 template<typename C>
00038 CloneProducer<C>::CloneProducer( const edm::ParameterSet& par ) : 
00039   src_( par.template getParameter<edm::InputTag>( "src" ) ) {
00040   produces<reco::CandidateCollection>();
00041 }
00042 
00043 template<typename C>
00044 CloneProducer<C>::~CloneProducer() {
00045 }
00046 
00047 template<typename C>
00048 void CloneProducer<C>::produce( edm::Event& evt, const edm::EventSetup& ) {
00049   std::auto_ptr<reco::CandidateCollection> coll( new reco::CandidateCollection );
00050   edm::Handle<C> masterCollection;
00051   evt.getByLabel( src_, masterCollection );
00052   for( size_t i = 0; i < masterCollection->size(); ++i ) {
00053     reco::CandidateBaseRef masterClone( edm::Ref<C>( masterCollection, i ) );
00054     coll->push_back( masterClone->clone() );
00055   }
00056   evt.put( coll );
00057 }
00058 
00059 #endif