Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-25 10:58:28

0001 #include "CUDADataFormats/EcalRecHitSoA/interface/EcalRecHit.h"
0002 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0003 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0004 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Framework/interface/stream/EDProducer.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 
0011 class EcalRecHitConvertGPU2CPUFormat : public edm::stream::EDProducer<> {
0012 public:
0013   explicit EcalRecHitConvertGPU2CPUFormat(edm::ParameterSet const& ps);
0014   ~EcalRecHitConvertGPU2CPUFormat() override;
0015   static void fillDescriptions(edm::ConfigurationDescriptions&);
0016 
0017 private:
0018   using InputProduct = ecal::RecHit<calo::common::VecStoragePolicy<calo::common::CUDAHostAllocatorAlias>>;
0019   void produce(edm::Event&, edm::EventSetup const&) override;
0020 
0021 private:
0022   const edm::EDGetTokenT<InputProduct> recHitsGPUEB_;
0023   const edm::EDGetTokenT<InputProduct> recHitsGPUEE_;
0024 
0025   const std::string recHitsLabelCPUEB_, recHitsLabelCPUEE_;
0026 };
0027 
0028 void EcalRecHitConvertGPU2CPUFormat::fillDescriptions(edm::ConfigurationDescriptions& confDesc) {
0029   edm::ParameterSetDescription desc;
0030 
0031   desc.add<edm::InputTag>("recHitsLabelGPUEB", edm::InputTag("ecalRecHitProducerGPU", "EcalRecHitsGPUEB"));
0032   desc.add<edm::InputTag>("recHitsLabelGPUEE", edm::InputTag("ecalRecHitProducerGPU", "EcalRecHitsGPUEE"));
0033 
0034   desc.add<std::string>("recHitsLabelCPUEB", "EcalRecHitsEB");
0035   desc.add<std::string>("recHitsLabelCPUEE", "EcalRecHitsEE");
0036 
0037   confDesc.addWithDefaultLabel(desc);
0038 }
0039 
0040 EcalRecHitConvertGPU2CPUFormat::EcalRecHitConvertGPU2CPUFormat(const edm::ParameterSet& ps)
0041     : recHitsGPUEB_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsLabelGPUEB"))},
0042       recHitsGPUEE_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsLabelGPUEE"))},
0043       recHitsLabelCPUEB_{ps.getParameter<std::string>("recHitsLabelCPUEB")},
0044       recHitsLabelCPUEE_{ps.getParameter<std::string>("recHitsLabelCPUEE")} {
0045   produces<EBRecHitCollection>(recHitsLabelCPUEB_);
0046   produces<EERecHitCollection>(recHitsLabelCPUEE_);
0047 }
0048 
0049 EcalRecHitConvertGPU2CPUFormat::~EcalRecHitConvertGPU2CPUFormat() {}
0050 
0051 void EcalRecHitConvertGPU2CPUFormat::produce(edm::Event& event, edm::EventSetup const& setup) {
0052   auto const& hRecHitsGPUEB = event.get(recHitsGPUEB_);
0053   auto const& hRecHitsGPUEE = event.get(recHitsGPUEE_);
0054 
0055   auto recHitsCPUEB = std::make_unique<EBRecHitCollection>();
0056   auto recHitsCPUEE = std::make_unique<EERecHitCollection>();
0057   recHitsCPUEB->reserve(hRecHitsGPUEB.energy.size());
0058   recHitsCPUEE->reserve(hRecHitsGPUEE.energy.size());
0059 
0060   for (uint32_t i = 0; i < hRecHitsGPUEB.energy.size(); ++i) {
0061     //
0062     // Save only if energy is >= 0 !
0063     // This is extremely important because the channels that were supposed
0064     // to be excluded get "-1" as energy
0065     //
0066 
0067     if (hRecHitsGPUEB.energy[i] >= 0) {
0068       recHitsCPUEB->emplace_back(DetId{hRecHitsGPUEB.did[i]},
0069                                  hRecHitsGPUEB.energy[i],
0070                                  hRecHitsGPUEB.time[i],
0071                                  hRecHitsGPUEB.extra[i],
0072                                  hRecHitsGPUEB.flagBits[i]);
0073     }
0074   }
0075 
0076   for (uint32_t i = 0; i < hRecHitsGPUEE.energy.size(); ++i) {
0077     //
0078     // Save only if energy is >= 0 !
0079     // This is extremely important because the channels that were supposed
0080     // to be excluded get "-1" as energy
0081     //
0082 
0083     if (hRecHitsGPUEE.energy[i] >= 0) {
0084       recHitsCPUEE->emplace_back(DetId{hRecHitsGPUEE.did[i]},
0085                                  hRecHitsGPUEE.energy[i],
0086                                  hRecHitsGPUEE.time[i],
0087                                  hRecHitsGPUEE.extra[i],
0088                                  hRecHitsGPUEE.flagBits[i]);
0089     }
0090   }
0091 
0092   event.put(std::move(recHitsCPUEB), recHitsLabelCPUEB_);
0093   event.put(std::move(recHitsCPUEE), recHitsLabelCPUEE_);
0094 }
0095 
0096 DEFINE_FWK_MODULE(EcalRecHitConvertGPU2CPUFormat);