Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-05 03:12:13

0001 #include "DataFormats/L1TCorrelator/interface/TkElectron.h"
0002 #include "DataFormats/L1TCorrelator/interface/TkElectronFwd.h"
0003 #include "DataFormats/L1Trigger/interface/EGamma.h"
0004 #include "DataFormats/L1TCorrelator/interface/TkEm.h"
0005 #include "DataFormats/L1TCorrelator/interface/TkEmFwd.h"
0006 
0007 #include "FWCore/Framework/interface/global/EDProducer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/Utilities/interface/transform.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include <vector>
0015 #include <iostream>
0016 
0017 class L1TEGMultiMerger : public edm::global::EDProducer<> {
0018 public:
0019   explicit L1TEGMultiMerger(const edm::ParameterSet&);
0020   ~L1TEGMultiMerger() override;
0021   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0022 
0023 private:
0024   void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0025 
0026   template <class T>
0027   class InstanceMerger {
0028   public:
0029     InstanceMerger(L1TEGMultiMerger* prod, const edm::ParameterSet& conf)
0030         : instanceLabel_(conf.getParameter<std::string>("instance")) {
0031       for (const auto& producer_tag : conf.getParameter<std::vector<edm::InputTag>>("pfProducers")) {
0032         tokens_.push_back(
0033             prod->consumes<T>(edm::InputTag(producer_tag.label(), producer_tag.instance(), producer_tag.process())));
0034       }
0035       // FIXME: move this outside
0036       prod->produces<T>(instanceLabel_);
0037     }
0038 
0039     void produce(edm::Event& iEvent) const {
0040       edm::Handle<T> handle;
0041       auto out = std::make_unique<T>();
0042       for (const auto& token : tokens_) {
0043         iEvent.getByToken(token, handle);
0044         populate(out, handle);
0045       }
0046       iEvent.put(std::move(out), instanceLabel_);
0047     }
0048 
0049   private:
0050     template <class TT>
0051     void populate(std::unique_ptr<TT>& out, const edm::Handle<TT>& in) const {
0052       out->insert(out->end(), in->begin(), in->end());
0053     }
0054 
0055     void populate(std::unique_ptr<BXVector<l1t::EGamma>>& out, const edm::Handle<BXVector<l1t::EGamma>>& in) const {
0056       for (int bx = in->getFirstBX(); bx <= in->getLastBX(); bx++) {
0057         for (auto egee_itr = in->begin(bx); egee_itr != in->end(bx); egee_itr++) {
0058           out->push_back(bx, *egee_itr);
0059         }
0060       }
0061     }
0062 
0063     std::vector<edm::EDGetTokenT<T>> tokens_;
0064     std::string instanceLabel_;
0065   };
0066 
0067   std::vector<InstanceMerger<l1t::TkElectronCollection>> tkEleMerger;
0068   std::vector<InstanceMerger<l1t::TkEmCollection>> tkEmMerger;
0069   std::vector<InstanceMerger<BXVector<l1t::EGamma>>> tkEGMerger;
0070 };
0071 
0072 L1TEGMultiMerger::L1TEGMultiMerger(const edm::ParameterSet& conf) {
0073   for (const auto& config : conf.getParameter<std::vector<edm::ParameterSet>>("tkEgs")) {
0074     tkEGMerger.push_back(InstanceMerger<BXVector<l1t::EGamma>>(this, config));
0075   }
0076   for (const auto& config : conf.getParameter<std::vector<edm::ParameterSet>>("tkElectrons")) {
0077     tkEleMerger.push_back(InstanceMerger<l1t::TkElectronCollection>(this, config));
0078   }
0079   for (const auto& config : conf.getParameter<std::vector<edm::ParameterSet>>("tkEms")) {
0080     tkEmMerger.push_back(InstanceMerger<l1t::TkEmCollection>(this, config));
0081   }
0082 }
0083 
0084 L1TEGMultiMerger::~L1TEGMultiMerger() {}
0085 
0086 void L1TEGMultiMerger::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup&) const {
0087   for (const auto& egMerger : tkEGMerger)
0088     egMerger.produce(iEvent);
0089   for (const auto& eleMerger : tkEleMerger)
0090     eleMerger.produce(iEvent);
0091   for (const auto& emMerger : tkEmMerger)
0092     emMerger.produce(iEvent);
0093 }
0094 
0095 void L1TEGMultiMerger::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0096   edm::ParameterSetDescription psetDesc;
0097   psetDesc.add<std::string>("instance");
0098   psetDesc.add<std::vector<edm::InputTag>>("pfProducers");
0099   edm::ParameterSetDescription desc;
0100   desc.addVPSet("tkElectrons", psetDesc);
0101   desc.addVPSet("tkEms", psetDesc);
0102   desc.addVPSet("tkEgs", psetDesc);
0103   descriptions.addWithDefaultLabel(desc);
0104 }
0105 
0106 #include "FWCore/Framework/interface/MakerMacros.h"
0107 DEFINE_FWK_MODULE(L1TEGMultiMerger);