Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-02 02:36:45

0001 #include "CUDADataFormats/EcalRecHitSoA/interface/EcalRecHit.h"
0002 #include "CUDADataFormats/EcalRecHitSoA/interface/EcalUncalibratedRecHit.h"
0003 #include "CUDADataFormats/EcalRecHitSoA/interface/RecoTypes.h"
0004 #include "CommonTools/Utils/interface/StringToEnumValue.h"
0005 #include "CondFormats/DataRecord/interface/EcalADCToGeVConstantRcd.h"
0006 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
0007 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
0008 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRcd.h"
0009 #include "CondFormats/DataRecord/interface/EcalLaserAPDPNRatiosRefRcd.h"
0010 #include "CondFormats/DataRecord/interface/EcalLaserAlphasRcd.h"
0011 #include "CondFormats/DataRecord/interface/EcalLinearCorrectionsRcd.h"
0012 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstantsGPU.h"
0013 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatiosGPU.h"
0014 #include "CondFormats/EcalObjects/interface/EcalLaserAPDPNRatiosRefGPU.h"
0015 #include "CondFormats/EcalObjects/interface/EcalLaserAlphasGPU.h"
0016 #include "CondFormats/EcalObjects/interface/EcalLinearCorrectionsGPU.h"
0017 #include "CondFormats/EcalObjects/interface/EcalRecHitParametersGPU.h"
0018 #include "CondFormats/EcalObjects/interface/EcalRechitADCToGeVConstantGPU.h"
0019 #include "CondFormats/EcalObjects/interface/EcalRechitChannelStatusGPU.h"
0020 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/EventSetup.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ServiceRegistry/interface/Service.h"
0027 #include "FWCore/Utilities/interface/ESGetToken.h"
0028 #include "HeterogeneousCore/CUDACore/interface/JobConfigurationGPURecord.h"
0029 #include "HeterogeneousCore/CUDACore/interface/ScopedContext.h"
0030 #include "HeterogeneousCore/CUDAServices/interface/CUDAService.h"
0031 #include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
0032 
0033 #include "EcalRecHitBuilderKernels.h"
0034 
0035 class EcalRecHitProducerGPU : public edm::stream::EDProducer<edm::ExternalWork> {
0036 public:
0037   explicit EcalRecHitProducerGPU(edm::ParameterSet const& ps);
0038   ~EcalRecHitProducerGPU() override;
0039   static void fillDescriptions(edm::ConfigurationDescriptions&);
0040 
0041 private:
0042   void acquire(edm::Event const&, edm::EventSetup const&, edm::WaitingTaskWithArenaHolder) override;
0043   void produce(edm::Event&, edm::EventSetup const&) override;
0044 
0045 private:
0046   // data
0047   uint32_t neb_, nee_;  // extremely important, in particular neb_
0048 
0049   // gpu input
0050   using InputProduct = cms::cuda::Product<ecal::UncalibratedRecHit<calo::common::DevStoragePolicy>>;
0051   edm::EDGetTokenT<InputProduct> uncalibRecHitsInEBToken_;
0052   edm::EDGetTokenT<InputProduct> uncalibRecHitsInEEToken_;
0053 
0054   // event data
0055   ecal::rechit::EventOutputDataGPU eventOutputDataGPU_;
0056 
0057   cms::cuda::ContextState cudaState_;
0058 
0059   // gpu output
0060   using OutputProduct = cms::cuda::Product<ecal::RecHit<calo::common::DevStoragePolicy>>;
0061   edm::EDPutTokenT<OutputProduct> recHitsTokenEB_, recHitsTokenEE_;
0062 
0063   // configuration parameters
0064   ecal::rechit::ConfigurationParameters configParameters_;
0065 
0066   // conditions tokens
0067   edm::ESGetToken<EcalRechitADCToGeVConstantGPU, EcalADCToGeVConstantRcd> tokenADCToGeVConstant_;
0068   edm::ESGetToken<EcalIntercalibConstantsGPU, EcalIntercalibConstantsRcd> tokenIntercalibConstants_;
0069   edm::ESGetToken<EcalRechitChannelStatusGPU, EcalChannelStatusRcd> tokenChannelStatus_;
0070   edm::ESGetToken<EcalLaserAPDPNRatiosGPU, EcalLaserAPDPNRatiosRcd> tokenLaserAPDPNRatios_;
0071   edm::ESGetToken<EcalLaserAPDPNRatiosRefGPU, EcalLaserAPDPNRatiosRefRcd> tokenLaserAPDPNRatiosRef_;
0072   edm::ESGetToken<EcalLaserAlphasGPU, EcalLaserAlphasRcd> tokenLaserAlphas_;
0073   edm::ESGetToken<EcalLinearCorrectionsGPU, EcalLinearCorrectionsRcd> tokenLinearCorrections_;
0074   edm::ESGetToken<EcalRecHitParametersGPU, JobConfigurationGPURecord> tokenRecHitParameters_;
0075 
0076   // conditions handles
0077   edm::ESHandle<EcalIntercalibConstantsGPU> IntercalibConstantsHandle_;
0078   edm::ESHandle<EcalRecHitParametersGPU> recHitParametersHandle_;
0079 
0080   // Associate reco flagbit (outer vector) to many db status flags (inner vector)
0081   std::vector<int>
0082       expanded_v_DB_reco_flags_;  // Transform a map in a vector      // FIXME AM: int or uint32 to be checked
0083   std::vector<uint32_t> expanded_Sizes_v_DB_reco_flags_;    // Saving the size for each piece
0084   std::vector<uint32_t> expanded_flagbit_v_DB_reco_flags_;  // And the "key" for each key
0085 
0086   uint32_t flagmask_;  // do not propagate channels with these flags on
0087 };
0088 
0089 void EcalRecHitProducerGPU::fillDescriptions(edm::ConfigurationDescriptions& confDesc) {
0090   edm::ParameterSetDescription desc;
0091 
0092   desc.add<edm::InputTag>("uncalibrecHitsInLabelEB",
0093                           edm::InputTag("ecalUncalibRecHitProducerGPU", "EcalUncalibRecHitsEB"));
0094   desc.add<edm::InputTag>("uncalibrecHitsInLabelEE",
0095                           edm::InputTag("ecalUncalibRecHitProducerGPU", "EcalUncalibRecHitsEE"));
0096 
0097   desc.add<std::string>("recHitsLabelEB", "EcalRecHitsGPUEB");
0098   desc.add<std::string>("recHitsLabelEE", "EcalRecHitsGPUEE");
0099 
0100   desc.add<bool>("killDeadChannels", true);
0101 
0102   desc.add<double>("EBLaserMIN", 0.01);
0103   desc.add<double>("EELaserMIN", 0.01);
0104   desc.add<double>("EBLaserMAX", 30.0);
0105   desc.add<double>("EELaserMAX", 30.0);
0106 
0107   desc.add<uint32_t>("maxNumberHitsEB", 61200);
0108   desc.add<uint32_t>("maxNumberHitsEE", 14648);
0109 }
0110 
0111 EcalRecHitProducerGPU::EcalRecHitProducerGPU(const edm::ParameterSet& ps) {
0112   //---- input
0113   uncalibRecHitsInEBToken_ = consumes<InputProduct>(ps.getParameter<edm::InputTag>("uncalibrecHitsInLabelEB"));
0114   uncalibRecHitsInEEToken_ = consumes<InputProduct>(ps.getParameter<edm::InputTag>("uncalibrecHitsInLabelEE"));
0115 
0116   //---- output
0117   recHitsTokenEB_ = produces<OutputProduct>(ps.getParameter<std::string>("recHitsLabelEB"));
0118   recHitsTokenEE_ = produces<OutputProduct>(ps.getParameter<std::string>("recHitsLabelEE"));
0119 
0120   bool killDeadChannels = ps.getParameter<bool>("killDeadChannels");
0121   configParameters_.killDeadChannels = killDeadChannels;
0122 
0123   configParameters_.EBLaserMIN = ps.getParameter<double>("EBLaserMIN");
0124   configParameters_.EELaserMIN = ps.getParameter<double>("EELaserMIN");
0125   configParameters_.EBLaserMAX = ps.getParameter<double>("EBLaserMAX");
0126   configParameters_.EELaserMAX = ps.getParameter<double>("EELaserMAX");
0127 
0128   // max number of digis to allocate for
0129   configParameters_.maxNumberHitsEB = ps.getParameter<uint32_t>("maxNumberHitsEB");
0130   configParameters_.maxNumberHitsEE = ps.getParameter<uint32_t>("maxNumberHitsEE");
0131 
0132   flagmask_ = 0;
0133   flagmask_ |= 0x1 << EcalRecHit::kNeighboursRecovered;
0134   flagmask_ |= 0x1 << EcalRecHit::kTowerRecovered;
0135   flagmask_ |= 0x1 << EcalRecHit::kDead;
0136   flagmask_ |= 0x1 << EcalRecHit::kKilled;
0137   flagmask_ |= 0x1 << EcalRecHit::kTPSaturated;
0138   flagmask_ |= 0x1 << EcalRecHit::kL1SpikeFlag;
0139 
0140   configParameters_.flagmask = flagmask_;
0141 
0142   // for recovery and killing
0143 
0144   configParameters_.recoverEBIsolatedChannels = ps.getParameter<bool>("recoverEBIsolatedChannels");
0145   configParameters_.recoverEEIsolatedChannels = ps.getParameter<bool>("recoverEEIsolatedChannels");
0146   configParameters_.recoverEBVFE = ps.getParameter<bool>("recoverEBVFE");
0147   configParameters_.recoverEEVFE = ps.getParameter<bool>("recoverEEVFE");
0148   configParameters_.recoverEBFE = ps.getParameter<bool>("recoverEBFE");
0149   configParameters_.recoverEEFE = ps.getParameter<bool>("recoverEEFE");
0150 
0151   // conditions tokens
0152   tokenADCToGeVConstant_ = esConsumes<EcalRechitADCToGeVConstantGPU, EcalADCToGeVConstantRcd>();
0153   tokenIntercalibConstants_ = esConsumes<EcalIntercalibConstantsGPU, EcalIntercalibConstantsRcd>();
0154   tokenChannelStatus_ = esConsumes<EcalRechitChannelStatusGPU, EcalChannelStatusRcd>();
0155   tokenLaserAPDPNRatios_ = esConsumes<EcalLaserAPDPNRatiosGPU, EcalLaserAPDPNRatiosRcd>();
0156   tokenLaserAPDPNRatiosRef_ = esConsumes<EcalLaserAPDPNRatiosRefGPU, EcalLaserAPDPNRatiosRefRcd>();
0157   tokenLaserAlphas_ = esConsumes<EcalLaserAlphasGPU, EcalLaserAlphasRcd>();
0158   tokenLinearCorrections_ = esConsumes<EcalLinearCorrectionsGPU, EcalLinearCorrectionsRcd>();
0159   tokenRecHitParameters_ = esConsumes<EcalRecHitParametersGPU, JobConfigurationGPURecord>();
0160 }
0161 
0162 EcalRecHitProducerGPU::~EcalRecHitProducerGPU() {}
0163 
0164 void EcalRecHitProducerGPU::acquire(edm::Event const& event,
0165                                     edm::EventSetup const& setup,
0166                                     edm::WaitingTaskWithArenaHolder holder) {
0167   // cuda products
0168   auto const& ebUncalibRecHitsProduct = event.get(uncalibRecHitsInEBToken_);
0169   auto const& eeUncalibRecHitsProduct = event.get(uncalibRecHitsInEEToken_);
0170   // raii
0171   cms::cuda::ScopedContextAcquire ctx{ebUncalibRecHitsProduct, std::move(holder), cudaState_};
0172   // get actual object
0173   auto const& ebUncalibRecHits = ctx.get(ebUncalibRecHitsProduct);
0174   auto const& eeUncalibRecHits = ctx.get(eeUncalibRecHitsProduct);
0175 
0176   ecal::rechit::EventInputDataGPU inputDataGPU{ebUncalibRecHits, eeUncalibRecHits};
0177 
0178   neb_ = ebUncalibRecHits.size;
0179   nee_ = eeUncalibRecHits.size;
0180 
0181   // stop here if there are no uncalibRecHits
0182   if (neb_ + nee_ == 0)
0183     return;
0184 
0185   if ((neb_ > configParameters_.maxNumberHitsEB) || (nee_ > configParameters_.maxNumberHitsEE)) {
0186     edm::LogError("EcalRecHitProducerGPU")
0187         << "max number of channels exceeded. See options 'maxNumberHitsEB and maxNumberHitsEE' ";
0188   }
0189 
0190   int nchannelsEB = ebUncalibRecHits.size;  // --> offsetForInput, first EB and then EE
0191 
0192   // conditions
0193   // - laser correction
0194   // - IC
0195   // - adt2gev
0196 
0197   //
0198   IntercalibConstantsHandle_ = setup.getHandle(tokenIntercalibConstants_);
0199   recHitParametersHandle_ = setup.getHandle(tokenRecHitParameters_);
0200 
0201   auto const& ADCToGeVConstantProduct = setup.getData(tokenADCToGeVConstant_).getProduct(ctx.stream());
0202   auto const& IntercalibConstantsProduct = IntercalibConstantsHandle_->getProduct(ctx.stream());
0203   auto const& ChannelStatusProduct = setup.getData(tokenChannelStatus_).getProduct(ctx.stream());
0204 
0205   auto const& LaserAPDPNRatiosProduct = setup.getData(tokenLaserAPDPNRatios_).getProduct(ctx.stream());
0206   auto const& LaserAPDPNRatiosRefProduct = setup.getData(tokenLaserAPDPNRatiosRef_).getProduct(ctx.stream());
0207   auto const& LaserAlphasProduct = setup.getData(tokenLaserAlphas_).getProduct(ctx.stream());
0208   auto const& LinearCorrectionsProduct = setup.getData(tokenLinearCorrections_).getProduct(ctx.stream());
0209   auto const& recHitParametersProduct = recHitParametersHandle_->getProduct(ctx.stream());
0210 
0211   // set config ptrs : this is done to avoid changing things downstream
0212   configParameters_.ChannelStatusToBeExcluded = recHitParametersProduct.channelStatusToBeExcluded.get();
0213   configParameters_.ChannelStatusToBeExcludedSize = std::get<0>(recHitParametersHandle_->getValues()).get().size();
0214   configParameters_.expanded_v_DB_reco_flags = recHitParametersProduct.expanded_v_DB_reco_flags.get();
0215   configParameters_.expanded_Sizes_v_DB_reco_flags = recHitParametersProduct.expanded_Sizes_v_DB_reco_flags.get();
0216   configParameters_.expanded_flagbit_v_DB_reco_flags = recHitParametersProduct.expanded_flagbit_v_DB_reco_flags.get();
0217   configParameters_.expanded_v_DB_reco_flagsSize = std::get<3>(recHitParametersHandle_->getValues()).get().size();
0218 
0219   // bundle up conditions
0220   ecal::rechit::ConditionsProducts conditions{ADCToGeVConstantProduct,
0221                                               IntercalibConstantsProduct,
0222                                               ChannelStatusProduct,
0223                                               LaserAPDPNRatiosProduct,
0224                                               LaserAPDPNRatiosRefProduct,
0225                                               LaserAlphasProduct,
0226                                               LinearCorrectionsProduct,
0227                                               IntercalibConstantsHandle_->getOffset()};
0228 
0229   // dev mem
0230   eventOutputDataGPU_.allocate(configParameters_, ctx.stream());
0231 
0232   //
0233   // schedule algorithms
0234   //
0235 
0236   edm::TimeValue_t event_time = event.time().value();
0237 
0238   ecal::rechit::create_ecal_rehit(
0239       inputDataGPU, eventOutputDataGPU_, conditions, configParameters_, nchannelsEB, event_time, ctx.stream());
0240 
0241   cudaCheck(cudaGetLastError());
0242 }
0243 
0244 void EcalRecHitProducerGPU::produce(edm::Event& event, edm::EventSetup const& setup) {
0245   cms::cuda::ScopedContextProduce ctx{cudaState_};
0246 
0247   eventOutputDataGPU_.recHitsEB.size = neb_;
0248   eventOutputDataGPU_.recHitsEE.size = nee_;
0249 
0250   // put into the event
0251   ctx.emplace(event, recHitsTokenEB_, std::move(eventOutputDataGPU_.recHitsEB));
0252   ctx.emplace(event, recHitsTokenEE_, std::move(eventOutputDataGPU_.recHitsEE));
0253 }
0254 
0255 DEFINE_FWK_MODULE(EcalRecHitProducerGPU);