Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-24 00:02:22

0001 #ifndef HeterogeneousCore_AlpakaCore_interface_alpaka_stream_SynchronizingEDProducer_h
0002 #define HeterogeneousCore_AlpakaCore_interface_alpaka_stream_SynchronizingEDProducer_h
0003 
0004 #include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
0005 #include "FWCore/Framework/interface/stream/EDProducer.h"
0006 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDMetadataAcquireSentry.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EDMetadataSentry.h"
0008 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/Event.h"
0009 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/EventSetup.h"
0010 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ProducerBase.h"
0011 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0012 
0013 namespace ALPAKA_ACCELERATOR_NAMESPACE {
0014   namespace stream {
0015     template <typename... Args>
0016     class SynchronizingEDProducer : public ProducerBase<edm::stream::EDProducer, edm::ExternalWork, Args...> {
0017       static_assert(
0018           not edm::CheckAbility<edm::module::Abilities::kExternalWork, Args...>::kHasIt,
0019           "ExternalWork ability is redundant with ALPAKA_ACCELERATOR_NAMESPACE::stream::SynchronizingEDProducer."
0020           "Please remove it.");
0021 
0022     public:
0023       void acquire(edm::Event const& iEvent,
0024                    edm::EventSetup const& iSetup,
0025                    edm::WaitingTaskWithArenaHolder holder) final {
0026         detail::EDMetadataAcquireSentry sentry(iEvent.streamID(), std::move(holder));
0027         device::Event const ev(iEvent, sentry.metadata());
0028         device::EventSetup const es(iSetup, ev.device());
0029         acquire(ev, es);
0030         metadata_ = sentry.finish();
0031       }
0032 
0033       void produce(edm::Event& iEvent, edm::EventSetup const& iSetup) final {
0034         detail::EDMetadataSentry sentry(std::move(metadata_));
0035         device::Event ev(iEvent, sentry.metadata());
0036         device::EventSetup const es(iSetup, ev.device());
0037         produce(ev, es);
0038         sentry.finish();
0039       }
0040 
0041       virtual void acquire(device::Event const& iEvent, device::EventSetup const& iSetup) = 0;
0042 
0043       virtual void produce(device::Event& iEvent, device::EventSetup const& iSetup) = 0;
0044 
0045     private:
0046       std::shared_ptr<EDMetadata> metadata_;
0047     };
0048   }  // namespace stream
0049 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE
0050 
0051 #endif