Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-14 02:53:21

0001 #include <alpaka/alpaka.hpp>
0002 
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "CondFormats/DataRecord/interface/EcalMappingElectronicsRcd.h"
0006 #include "CondFormats/EcalObjects/interface/EcalMappingElectronics.h"
0007 #include "CondFormats/EcalObjects/interface/alpaka/EcalElectronicsMappingDevice.h"
0008 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0009 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0010 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESProducer.h"
0011 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ModuleFactory.h"
0012 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0013 #include "HeterogeneousCore/AlpakaInterface/interface/host.h"
0014 #include "HeterogeneousCore/AlpakaInterface/interface/memory.h"
0015 
0016 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0017   class EcalElectronicsMappingHostESProducer : public ESProducer {
0018   public:
0019     EcalElectronicsMappingHostESProducer(edm::ParameterSet const& iConfig) : ESProducer(iConfig) {
0020       auto cc = setWhatProduced(this);
0021       token_ = cc.consumes();
0022     }
0023 
0024     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0025       edm::ParameterSetDescription desc;
0026       descriptions.addWithDefaultLabel(desc);
0027     }
0028 
0029     std::unique_ptr<EcalElectronicsMappingHost> produce(EcalMappingElectronicsRcd const& iRecord) {
0030       auto const& mapping = iRecord.get(token_);
0031 
0032       // TODO: 0x3FFFFF * 4B ~= 16MB
0033       // tmp solution for linear mapping of eid -> did
0034       int const size = 0x3FFFFF;
0035       auto product = std::make_unique<EcalElectronicsMappingHost>(size, cms::alpakatools::host());
0036 
0037       // fill the whole collection with null detids
0038       alpaka::QueueCpuBlocking queue{cms::alpakatools::host()};
0039       alpaka::memset(queue, product->buffer(), 0x00);
0040 
0041       // fill in eb
0042       auto const& barrelValues = mapping.barrelItems();
0043       for (unsigned int i = 0; i < barrelValues.size(); ++i) {
0044         EcalElectronicsId eid{barrelValues[i].electronicsid};
0045         EBDetId did{EBDetId::unhashIndex(i)};
0046         product->view()[eid.linearIndex()].rawid() = did.rawId();
0047       }
0048 
0049       // fill in ee
0050       auto const& endcapValues = mapping.endcapItems();
0051       for (unsigned int i = 0; i < endcapValues.size(); ++i) {
0052         EcalElectronicsId eid{endcapValues[i].electronicsid};
0053         EEDetId did{EEDetId::unhashIndex(i)};
0054         product->view()[eid.linearIndex()].rawid() = did.rawId();
0055       }
0056       return product;
0057     }
0058 
0059   private:
0060     edm::ESGetToken<EcalMappingElectronics, EcalMappingElectronicsRcd> token_;
0061   };
0062 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0063 
0064 DEFINE_FWK_EVENTSETUP_ALPAKA_MODULE(EcalElectronicsMappingHostESProducer);