Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-25 04:54:55

0001 /** \class ShallowCloneProducer

0002  *

0003  * Clones a concrete Candidate collection

0004  * to a CandidateCollection (i.e.: OwnVector<Candidate>) filled

0005  * with shallow clones of the original candidate collection

0006  *

0007  * \author: Francesco Fabozzi, INFN

0008  *          modified by Luca Lista, INFN

0009  *

0010  * Template parameters:

0011  * - C : Concrete candidate collection type

0012  *

0013  */
0014 
0015 #include "DataFormats/Candidate/interface/ShallowCloneCandidate.h"
0016 #include "FWCore/Framework/interface/global/EDProducer.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/Utilities/interface/InputTag.h"
0020 
0021 template <typename C>
0022 class ShallowCloneProducer : public edm::global::EDProducer<> {
0023 public:
0024   /// constructor from parameter set

0025   explicit ShallowCloneProducer(const edm::ParameterSet&);
0026   /// destructor

0027   ~ShallowCloneProducer() override;
0028 
0029 private:
0030   /// process an event

0031   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0032   /// labels of the collection to be converted

0033   const edm::EDGetTokenT<C> srcToken_;
0034 };
0035 
0036 template <typename C>
0037 ShallowCloneProducer<C>::ShallowCloneProducer(const edm::ParameterSet& par)
0038     : srcToken_(consumes<C>(par.template getParameter<edm::InputTag>("src"))) {
0039   produces<reco::CandidateCollection>();
0040 }
0041 
0042 template <typename C>
0043 ShallowCloneProducer<C>::~ShallowCloneProducer() {}
0044 
0045 template <typename C>
0046 void ShallowCloneProducer<C>::produce(edm::StreamID, edm::Event& evt, const edm::EventSetup&) const {
0047   std::unique_ptr<reco::CandidateCollection> coll(new reco::CandidateCollection);
0048   edm::Handle<C> masterCollection;
0049   evt.getByToken(srcToken_, masterCollection);
0050   for (size_t i = 0; i < masterCollection->size(); ++i) {
0051     reco::CandidateBaseRef masterClone(edm::Ref<C>(masterCollection, i));
0052     coll->push_back(new reco::ShallowCloneCandidate(masterClone));
0053   }
0054   evt.put(std::move(coll));
0055 }
0056 
0057 #include "DataFormats/EgammaCandidates/interface/Electron.h"
0058 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
0059 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0060 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0061 #include "DataFormats/JetReco/interface/CaloJet.h"
0062 #include "DataFormats/JetReco/interface/GenJet.h"
0063 #include "DataFormats/METReco/interface/CaloMET.h"
0064 #include "DataFormats/METReco/interface/CaloMETCollection.h"
0065 #include "DataFormats/METReco/interface/GenMET.h"
0066 #include "DataFormats/METReco/interface/GenMETCollection.h"
0067 #include "DataFormats/MuonReco/interface/Muon.h"
0068 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0069 
0070 typedef ShallowCloneProducer<reco::GenMETCollection> GenMETShallowCloneProducer;
0071 typedef ShallowCloneProducer<reco::GsfElectronCollection> PixelMatchGsfElectronShallowCloneProducer;
0072 typedef ShallowCloneProducer<reco::MuonCollection> MuonShallowCloneProducer;
0073 typedef ShallowCloneProducer<reco::CaloMETCollection> CaloMETShallowCloneProducer;
0074 typedef ShallowCloneProducer<reco::ElectronCollection> ElectronShallowCloneProducer;
0075 typedef ShallowCloneProducer<reco::GenJetCollection> GenJetShallowCloneProducer;
0076 typedef ShallowCloneProducer<reco::CaloJetCollection> CaloJetShallowCloneProducer;
0077 
0078 #include "FWCore/Framework/interface/MakerMacros.h"
0079 
0080 DEFINE_FWK_MODULE(GenMETShallowCloneProducer);
0081 DEFINE_FWK_MODULE(PixelMatchGsfElectronShallowCloneProducer);
0082 DEFINE_FWK_MODULE(MuonShallowCloneProducer);
0083 DEFINE_FWK_MODULE(CaloMETShallowCloneProducer);
0084 DEFINE_FWK_MODULE(ElectronShallowCloneProducer);
0085 DEFINE_FWK_MODULE(GenJetShallowCloneProducer);
0086 DEFINE_FWK_MODULE(CaloJetShallowCloneProducer);