File indexing completed on 2024-04-06 12:25:43
0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005
0006 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0007 #include "HeterogeneousCore/CUDAUtilities/interface/HostAllocator.h"
0008
0009 #include "DataFormats/EcalDigi/interface/EcalDataFrame_Ph2.h"
0010
0011 #include "EcalUncalibRecHitPhase2WeightsAlgoGPU.h"
0012 #include "DeclsForKernelsPhase2.h"
0013
0014 class EcalUncalibRecHitPhase2WeightsProducerGPU : public edm::stream::EDProducer<> {
0015 public:
0016 explicit EcalUncalibRecHitPhase2WeightsProducerGPU(edm::ParameterSet const &ps);
0017 ~EcalUncalibRecHitPhase2WeightsProducerGPU() override = default;
0018 static void fillDescriptions(edm::ConfigurationDescriptions &);
0019
0020 private:
0021 void produce(edm::Event &, edm::EventSetup const &) override;
0022
0023 private:
0024 const std::vector<double, cms::cuda::HostAllocator<double>> weights_;
0025
0026 using InputProduct = cms::cuda::Product<ecal::DigisCollection<calo::common::DevStoragePolicy>>;
0027 const edm::EDGetTokenT<InputProduct> digisToken_;
0028 using OutputProduct = cms::cuda::Product<ecal::UncalibratedRecHit<calo::common::DevStoragePolicy>>;
0029 const edm::EDPutTokenT<OutputProduct> recHitsToken_;
0030
0031
0032 ecal::weights::EventOutputDataGPU eventOutputDataGPU_;
0033 };
0034
0035
0036 EcalUncalibRecHitPhase2WeightsProducerGPU::EcalUncalibRecHitPhase2WeightsProducerGPU(const edm::ParameterSet &ps)
0037 :
0038 weights_([tmp = ps.getParameter<std::vector<double>>("weights")] {
0039 return std::vector<double, cms::cuda::HostAllocator<double>>(tmp.begin(), tmp.end());
0040 }()),
0041 digisToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisLabelEB"))},
0042 recHitsToken_{produces<OutputProduct>(ps.getParameter<std::string>("recHitsLabelEB"))} {}
0043
0044 void EcalUncalibRecHitPhase2WeightsProducerGPU::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0045 edm::ParameterSetDescription desc;
0046
0047 desc.add<std::string>("recHitsLabelEB", "EcalUncalibRecHitsEB");
0048
0049 desc.add<std::vector<double>>("weights",
0050 {-0.121016,
0051 -0.119899,
0052 -0.120923,
0053 -0.0848959,
0054 0.261041,
0055 0.509881,
0056 0.373591,
0057 0.134899,
0058 -0.0233605,
0059 -0.0913195,
0060 -0.112452,
0061 -0.118596,
0062 -0.121737,
0063 -0.121737,
0064 -0.121737,
0065 -0.121737});
0066
0067 desc.add<edm::InputTag>("digisLabelEB", edm::InputTag("simEcalUnsuppressedDigis", ""));
0068
0069 descriptions.addWithDefaultLabel(desc);
0070 }
0071
0072 void EcalUncalibRecHitPhase2WeightsProducerGPU::produce(edm::Event &event, const edm::EventSetup &setup) {
0073
0074 auto const &digisProduct = event.get(digisToken_);
0075
0076 cms::cuda::ScopedContextProduce ctx{digisProduct};
0077
0078
0079 auto const &digis = ctx.get(digisProduct);
0080
0081 const uint32_t size = digis.size;
0082
0083
0084 if (size > 0) {
0085 auto weights_d = cms::cuda::make_device_unique<double[]>(EcalDataFrame_Ph2::MAXSAMPLES, ctx.stream());
0086
0087 cudaCheck(cudaMemcpyAsync(weights_d.get(),
0088 weights_.data(),
0089 EcalDataFrame_Ph2::MAXSAMPLES * sizeof(double),
0090 cudaMemcpyHostToDevice,
0091 ctx.stream()));
0092
0093
0094 eventOutputDataGPU_.allocate(size, ctx.stream());
0095
0096 ecal::weights::phase2Weights(digis, eventOutputDataGPU_, weights_d, ctx.stream());
0097 }
0098
0099
0100 eventOutputDataGPU_.recHits.size = size;
0101
0102
0103 ctx.emplace(event, recHitsToken_, std::move(eventOutputDataGPU_.recHits));
0104 }
0105
0106 DEFINE_FWK_MODULE(EcalUncalibRecHitPhase2WeightsProducerGPU);