CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CommonTools/CandAlgos/interface/ShallowCloneProducer.h

Go to the documentation of this file.
00001 #ifndef CandAlgos_ShallowCloneProducer_h
00002 #define CandAlgos_ShallowCloneProducer_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/ShallowCloneCandidate.h"
00021 
00022 template<typename C>
00023 class ShallowCloneProducer : public edm::EDProducer {
00024 public:
00026   explicit ShallowCloneProducer( const edm::ParameterSet& );
00028   ~ShallowCloneProducer();
00029 
00030 private:
00032   virtual void produce( edm::Event&, const edm::EventSetup& );
00034   edm::InputTag src_;
00035 };
00036 
00037 template<typename C>
00038 ShallowCloneProducer<C>::ShallowCloneProducer( const edm::ParameterSet& par ) : 
00039   src_( par.template getParameter<edm::InputTag>( "src" ) ) {
00040   produces<reco::CandidateCollection>();
00041 }
00042 
00043 template<typename C>
00044 ShallowCloneProducer<C>::~ShallowCloneProducer() {
00045 }
00046 
00047 template<typename C>
00048 void ShallowCloneProducer<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( new reco::ShallowCloneCandidate( masterClone ) );
00055   }
00056   evt.put( coll );
00057 }
00058 
00059 #endif