File indexing completed on 2023-03-17 11:18:44
0001 #include "CUDADataFormats/EcalRecHitSoA/interface/EcalUncalibratedRecHit.h"
0002 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0003 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0004 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.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 #include "FWCore/ParameterSet/interface/EmptyGroupDescription.h"
0011
0012 class EcalUncalibRecHitConvertGPU2CPUFormat : public edm::stream::EDProducer<> {
0013 public:
0014 explicit EcalUncalibRecHitConvertGPU2CPUFormat(edm::ParameterSet const& ps);
0015 ~EcalUncalibRecHitConvertGPU2CPUFormat() override;
0016 static void fillDescriptions(edm::ConfigurationDescriptions&);
0017
0018 private:
0019 using InputProduct = ecal::UncalibratedRecHit<calo::common::VecStoragePolicy<calo::common::CUDAHostAllocatorAlias>>;
0020 void produce(edm::Event&, edm::EventSetup const&) override;
0021
0022 private:
0023 const bool isPhase2_;
0024 const edm::EDGetTokenT<InputProduct> recHitsGPUEB_;
0025 const edm::EDGetTokenT<InputProduct> recHitsGPUEE_;
0026
0027 const std::string recHitsLabelCPUEB_;
0028 const std::string recHitsLabelCPUEE_;
0029 };
0030
0031 void EcalUncalibRecHitConvertGPU2CPUFormat::fillDescriptions(edm::ConfigurationDescriptions& confDesc) {
0032 edm::ParameterSetDescription desc;
0033
0034 desc.add<edm::InputTag>("recHitsLabelGPUEB", edm::InputTag("ecalUncalibRecHitProducerGPU", "EcalUncalibRecHitsEB"));
0035 desc.add<std::string>("recHitsLabelCPUEB", "EcalUncalibRecHitsEB");
0036 desc.ifValue(
0037 edm::ParameterDescription<bool>("isPhase2", false, true),
0038 false >>
0039 (edm::ParameterDescription<edm::InputTag>(
0040 "recHitsLabelGPUEE", edm::InputTag("ecalUncalibRecHitProducerGPU", "EcalUncalibRecHitsEE"), true) and
0041 edm::ParameterDescription<std::string>("recHitsLabelCPUEE", "EcalUncalibRecHitsEE", true)) or
0042 true >> edm::EmptyGroupDescription());
0043 confDesc.add("ecalUncalibRecHitConvertGPU2CPUFormat", desc);
0044 }
0045
0046 EcalUncalibRecHitConvertGPU2CPUFormat::EcalUncalibRecHitConvertGPU2CPUFormat(const edm::ParameterSet& ps)
0047 : isPhase2_{ps.getParameter<bool>("isPhase2")},
0048 recHitsGPUEB_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsLabelGPUEB"))},
0049 recHitsGPUEE_{isPhase2_ ? edm::EDGetTokenT<InputProduct>{}
0050 : consumes<InputProduct>(ps.getParameter<edm::InputTag>("recHitsLabelGPUEE"))},
0051 recHitsLabelCPUEB_{ps.getParameter<std::string>("recHitsLabelCPUEB")},
0052 recHitsLabelCPUEE_{isPhase2_ ? std::string{""} : ps.getParameter<std::string>("recHitsLabelCPUEE")} {
0053 produces<EBUncalibratedRecHitCollection>(recHitsLabelCPUEB_);
0054 if (!isPhase2_)
0055 produces<EEUncalibratedRecHitCollection>(recHitsLabelCPUEE_);
0056 }
0057
0058 EcalUncalibRecHitConvertGPU2CPUFormat::~EcalUncalibRecHitConvertGPU2CPUFormat() {}
0059
0060 void EcalUncalibRecHitConvertGPU2CPUFormat::produce(edm::Event& event, edm::EventSetup const& setup) {
0061 auto const& recHitsGPUEB = event.get(recHitsGPUEB_);
0062 auto recHitsCPUEB = std::make_unique<EBUncalibratedRecHitCollection>();
0063 recHitsCPUEB->reserve(recHitsGPUEB.amplitude.size());
0064
0065 for (uint32_t i = 0; i < recHitsGPUEB.amplitude.size(); ++i) {
0066 recHitsCPUEB->emplace_back(DetId{recHitsGPUEB.did[i]},
0067 recHitsGPUEB.amplitude[i],
0068 recHitsGPUEB.pedestal[i],
0069 recHitsGPUEB.jitter[i],
0070 recHitsGPUEB.chi2[i],
0071 recHitsGPUEB.flags[i]);
0072 if (isPhase2_)
0073 (*recHitsCPUEB)[i].setAmplitudeError(recHitsGPUEB.amplitudeError[i]);
0074 (*recHitsCPUEB)[i].setJitterError(recHitsGPUEB.jitterError[i]);
0075 auto const offset = i * EcalDataFrame::MAXSAMPLES;
0076 for (uint32_t sample = 0; sample < EcalDataFrame::MAXSAMPLES; ++sample)
0077 (*recHitsCPUEB)[i].setOutOfTimeAmplitude(sample, recHitsGPUEB.amplitudesAll[offset + sample]);
0078 }
0079 if (!isPhase2_) {
0080 auto const& recHitsGPUEE = event.get(recHitsGPUEE_);
0081 auto recHitsCPUEE = std::make_unique<EEUncalibratedRecHitCollection>();
0082 recHitsCPUEE->reserve(recHitsGPUEE.amplitude.size());
0083 for (uint32_t i = 0; i < recHitsGPUEE.amplitude.size(); ++i) {
0084 recHitsCPUEE->emplace_back(DetId{recHitsGPUEE.did[i]},
0085 recHitsGPUEE.amplitude[i],
0086 recHitsGPUEE.pedestal[i],
0087 recHitsGPUEE.jitter[i],
0088 recHitsGPUEE.chi2[i],
0089 recHitsGPUEE.flags[i]);
0090 (*recHitsCPUEE)[i].setJitterError(recHitsGPUEE.jitterError[i]);
0091 auto const offset = i * EcalDataFrame::MAXSAMPLES;
0092 for (uint32_t sample = 0; sample < EcalDataFrame::MAXSAMPLES; ++sample) {
0093 (*recHitsCPUEE)[i].setOutOfTimeAmplitude(sample, recHitsGPUEE.amplitudesAll[offset + sample]);
0094 }
0095 }
0096 event.put(std::move(recHitsCPUEE), recHitsLabelCPUEE_);
0097 }
0098 event.put(std::move(recHitsCPUEB), recHitsLabelCPUEB_);
0099 }
0100
0101 DEFINE_FWK_MODULE(EcalUncalibRecHitConvertGPU2CPUFormat);