Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-06 09:40:14

0001 #include "DataFormats/Common/interface/View.h"
0002 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0003 #include "DataFormats/PatCandidates/interface/Electron.h"
0004 #include "DataFormats/PatCandidates/interface/Jet.h"
0005 #include "DataFormats/PatCandidates/interface/Muon.h"
0006 #include "DataFormats/PatCandidates/interface/Photon.h"
0007 #include "DataFormats/PatCandidates/interface/Tau.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/stream/EDProducer.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/Utilities/interface/InputTag.h"
0012 #include "PhysicsTools/PatAlgos/interface/ObjectModifier.h"
0013 
0014 #include <memory>
0015 
0016 namespace pat {
0017 
0018   template <class T>
0019   class ModifiedObjectProducer : public edm::stream::EDProducer<> {
0020   public:
0021     typedef std::vector<T> Collection;
0022     typedef pat::ObjectModifier<T> Modifier;
0023 
0024     ModifiedObjectProducer(const edm::ParameterSet& conf) {
0025       //set our input source
0026       src_ = consumes<edm::View<T> >(conf.getParameter<edm::InputTag>("src"));
0027       //setup modifier
0028       const edm::ParameterSet& mod_config = conf.getParameter<edm::ParameterSet>("modifierConfig");
0029       modifier_ = std::make_unique<Modifier>(mod_config, consumesCollector());
0030       //declare products
0031       produces<Collection>();
0032     }
0033     ~ModifiedObjectProducer() override {}
0034 
0035     void produce(edm::Event& evt, const edm::EventSetup& evs) final {
0036       modifier_->setEventContent(evs);
0037 
0038       auto output = std::make_unique<Collection>();
0039 
0040       auto input = evt.getHandle(src_);
0041       output->reserve(input->size());
0042 
0043       modifier_->setEvent(evt);
0044 
0045       for (auto const& itr : *input) {
0046         output->push_back(itr);
0047         T& obj = output->back();
0048         modifier_->modify(obj);
0049       }
0050 
0051       evt.put(std::move(output));
0052     }
0053 
0054   private:
0055     edm::EDGetTokenT<edm::View<T> > src_;
0056     std::unique_ptr<Modifier> modifier_;
0057   };
0058 }  // namespace pat
0059 
0060 typedef pat::ModifiedObjectProducer<reco::GsfElectron> ModifiedGsfElectronProducer;
0061 typedef pat::ModifiedObjectProducer<pat::Electron> ModifiedElectronProducer;
0062 typedef pat::ModifiedObjectProducer<pat::Photon> ModifiedPhotonProducer;
0063 typedef pat::ModifiedObjectProducer<pat::Muon> ModifiedMuonProducer;
0064 typedef pat::ModifiedObjectProducer<pat::Tau> ModifiedTauProducer;
0065 typedef pat::ModifiedObjectProducer<pat::Jet> ModifiedJetProducer;
0066 
0067 #include "FWCore/Framework/interface/MakerMacros.h"
0068 DEFINE_FWK_MODULE(ModifiedGsfElectronProducer);
0069 DEFINE_FWK_MODULE(ModifiedElectronProducer);
0070 DEFINE_FWK_MODULE(ModifiedPhotonProducer);
0071 DEFINE_FWK_MODULE(ModifiedMuonProducer);
0072 DEFINE_FWK_MODULE(ModifiedTauProducer);
0073 DEFINE_FWK_MODULE(ModifiedJetProducer);