Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <alpaka/alpaka.hpp>
0002 
0003 #include "DataFormats/TrackSoA/interface/TracksHost.h"
0004 #include "DataFormats/TrackSoA/interface/alpaka/TracksSoACollection.h"
0005 #include "DataFormats/TrackSoA/interface/TracksDevice.h"
0006 #include "DataFormats/TrackingRecHitSoA/interface/alpaka/TrackingRecHitsSoACollection.h"
0007 #include "FWCore/Framework/interface/ConsumesCollector.h"
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/Utilities/interface/ESGetToken.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "FWCore/Utilities/interface/RunningAverage.h"
0015 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDGetToken.h"
0016 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDPutToken.h"
0017 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
0018 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
0019 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/stream/EDProducer.h"
0020 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0021 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0022 #include "RecoTracker/TkMSParametrization/interface/PixelRecoUtilities.h"
0023 #include "RecoLocalTracker/Records/interface/PixelCPEFastParamsRecord.h"
0024 #include "RecoLocalTracker/SiPixelRecHits/interface/alpaka/PixelCPEFastParamsCollection.h"
0025 
0026 #include "CAHitNtupletGenerator.h"
0027 
0028 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0029   template <typename TrackerTraits>
0030   class CAHitNtupletAlpaka : public stream::EDProducer<> {
0031     using HitsConstView = TrackingRecHitSoAConstView<TrackerTraits>;
0032     using HitsOnDevice = TrackingRecHitsSoACollection<TrackerTraits>;
0033     using HitsOnHost = TrackingRecHitHost<TrackerTraits>;
0034 
0035     using TkSoAHost = TracksHost<TrackerTraits>;
0036     using TkSoADevice = TracksSoACollection<TrackerTraits>;
0037 
0038     using Algo = CAHitNtupletGenerator<TrackerTraits>;
0039 
0040   public:
0041     explicit CAHitNtupletAlpaka(const edm::ParameterSet& iConfig);
0042     ~CAHitNtupletAlpaka() override = default;
0043     void produce(device::Event& iEvent, const device::EventSetup& es) override;
0044     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046   private:
0047     const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> tokenField_;
0048     const device::ESGetToken<PixelCPEFastParams<TrackerTraits>, PixelCPEFastParamsRecord> cpeToken_;
0049     const device::EDGetToken<HitsOnDevice> tokenHit_;
0050     const device::EDPutToken<TkSoADevice> tokenTrack_;
0051 
0052     Algo deviceAlgo_;
0053   };
0054 
0055   template <typename TrackerTraits>
0056   CAHitNtupletAlpaka<TrackerTraits>::CAHitNtupletAlpaka(const edm::ParameterSet& iConfig)
0057       : tokenField_(esConsumes()),
0058         cpeToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("CPE")))),
0059         tokenHit_(consumes(iConfig.getParameter<edm::InputTag>("pixelRecHitSrc"))),
0060         tokenTrack_(produces()),
0061         deviceAlgo_(iConfig) {
0062     // Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
0063 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
0064     if constexpr (std::is_same_v<TrackerTraits, pixelTopology::Phase1>) {
0065       producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::pixelTrack::TracksSoACollectionPhase1>");
0066     }
0067 #endif
0068   }
0069 
0070   template <typename TrackerTraits>
0071   void CAHitNtupletAlpaka<TrackerTraits>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0072     edm::ParameterSetDescription desc;
0073 
0074     desc.add<edm::InputTag>("pixelRecHitSrc", edm::InputTag("siPixelRecHitsPreSplittingAlpaka"));
0075 
0076     std::string cpe = "PixelCPEFastParams";
0077     cpe += TrackerTraits::nameModifier;
0078     desc.add<std::string>("CPE", cpe);
0079 
0080     Algo::fillPSetDescription(desc);
0081     descriptions.addWithDefaultLabel(desc);
0082   }
0083 
0084   template <typename TrackerTraits>
0085   void CAHitNtupletAlpaka<TrackerTraits>::produce(device::Event& iEvent, const device::EventSetup& es) {
0086     auto bf = 1. / es.getData(tokenField_).inverseBzAtOriginInGeV();
0087 
0088     auto& fcpe = es.getData(cpeToken_);
0089 
0090     auto const& hits = iEvent.get(tokenHit_);
0091 
0092     iEvent.emplace(tokenTrack_, deviceAlgo_.makeTuplesAsync(hits, fcpe.const_buffer().data(), bf, iEvent.queue()));
0093   }
0094 
0095   using CAHitNtupletAlpakaPhase1 = CAHitNtupletAlpaka<pixelTopology::Phase1>;
0096   using CAHitNtupletAlpakaPhase2 = CAHitNtupletAlpaka<pixelTopology::Phase2>;
0097 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0098 
0099 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/MakerMacros.h"
0100 
0101 DEFINE_FWK_ALPAKA_MODULE(CAHitNtupletAlpakaPhase1);
0102 DEFINE_FWK_ALPAKA_MODULE(CAHitNtupletAlpakaPhase2);