Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-11 23:28:12

0001 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0002 #include "DataFormats/BeamSpot/interface/BeamSpotHost.h"
0003 #include "DataFormats/BeamSpot/interface/BeamSpotPOD.h"
0004 #include "DataFormats/BeamSpot/interface/alpaka/BeamSpotDevice.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0010 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/global/EDProducer.h"
0011 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0012 
0013 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0014 
0015   class BeamSpotDeviceProducer : public global::EDProducer<> {
0016   public:
0017     BeamSpotDeviceProducer(edm::ParameterSet const& config)
0018         : legacyToken_{consumes(config.getParameter<edm::InputTag>("src"))}, deviceToken_{produces()} {
0019       // Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
0020 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0021       producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::BeamSpotDevice>");
0022 #endif
0023     }
0024 
0025     void produce(edm::StreamID, device::Event& event, device::EventSetup const& setup) const override {
0026       reco::BeamSpot const& beamspot = event.get(legacyToken_);
0027 
0028       BeamSpotHost hostProduct{event.queue()};
0029       hostProduct->x = beamspot.x0();
0030       hostProduct->y = beamspot.y0();
0031       hostProduct->z = beamspot.z0();
0032       hostProduct->sigmaZ = beamspot.sigmaZ();
0033       hostProduct->beamWidthX = beamspot.BeamWidthX();
0034       hostProduct->beamWidthY = beamspot.BeamWidthY();
0035       hostProduct->dxdz = beamspot.dxdz();
0036       hostProduct->dydz = beamspot.dydz();
0037       hostProduct->emittanceX = beamspot.emittanceX();
0038       hostProduct->emittanceY = beamspot.emittanceY();
0039       hostProduct->betaStar = beamspot.betaStar();
0040 
0041       if constexpr (std::is_same_v<Device, alpaka::DevCpu>) {
0042         event.emplace(deviceToken_, std::move(hostProduct));
0043       } else {
0044         BeamSpotDevice deviceProduct{event.queue()};
0045         alpaka::memcpy(event.queue(), deviceProduct.buffer(), hostProduct.const_buffer());
0046         event.emplace(deviceToken_, std::move(deviceProduct));
0047       }
0048     }
0049 
0050     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0051       edm::ParameterSetDescription desc;
0052       desc.add("src", edm::InputTag{});
0053       descriptions.addWithDefaultLabel(desc);
0054     }
0055 
0056   private:
0057     const edm::EDGetTokenT<reco::BeamSpot> legacyToken_;
0058     const device::EDPutToken<BeamSpotDevice> deviceToken_;
0059   };
0060 
0061 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0062 
0063 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0064 DEFINE_FWK_ALPAKA_MODULE(BeamSpotDeviceProducer);