Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:50:22

0001 #ifndef HeterogeneousCore_AlpakaCore_interface_alpaka_EventSetup_h
0002 #define HeterogeneousCore_AlpakaCore_interface_alpaka_EventSetup_h
0003 
0004 #include "FWCore/Framework/interface/EventSetup.h"
0005 #include "FWCore/Utilities/interface/ESGetToken.h"
0006 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESGetToken.h"
0007 #include "HeterogeneousCore/AlpakaCore/interface/alpaka/ESDeviceProductType.h"
0008 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0009 
0010 namespace ALPAKA_ACCELERATOR_NAMESPACE::device {
0011   /**
0012    * The device::EventSetup mimics edm::EventSetup, and provides access
0013    * to ESProducts in the host memory space, and in the device memory
0014    * space defined by the backend (i.e. ALPAKA_ACCELERATOR_NAMESPACE).
0015    *
0016    * Access to device memory space products is synchronized properly.
0017    *
0018    * Note that not full interface of edm::EventSetup is replicated
0019    * here. If something important is missing, that can be added.
0020    */
0021   class EventSetup {
0022   public:
0023     EventSetup(edm::EventSetup const& iSetup, Device const& dev) : setup_(iSetup), device_(dev) {}
0024 
0025     // To be able to interact with non-Alpaka helper code that needs
0026     // to access edm::EventSetup
0027     operator edm::EventSetup const&() const { return setup_; }
0028 
0029     // getData()
0030 
0031     template <typename T, typename R>
0032     T const& getData(edm::ESGetToken<T, R> const& iToken) const {
0033       return setup_.getData(iToken);
0034     }
0035 
0036     template <typename T, typename R>
0037     T const& getData(device::ESGetToken<T, R> const& iToken) const {
0038       auto const& product = setup_.getData(iToken.underlyingToken());
0039       if constexpr (detail::useESProductDirectly<T>) {
0040         return product;
0041       } else {
0042         return product.get(device_);
0043       }
0044     }
0045 
0046     // getHandle()
0047 
0048     template <typename T, typename R>
0049     edm::ESHandle<T> getHandle(edm::ESGetToken<T, R> const& iToken) const {
0050       return setup_.getHandle(iToken);
0051     }
0052 
0053     template <typename T, typename R>
0054     edm::ESHandle<T> getHandle(device::ESGetToken<T, R> const& iToken) const {
0055       auto handle = setup_.getHandle(iToken.underlyingToken());
0056       if constexpr (detail::useESProductDirectly<T>) {
0057         return handle;
0058       } else {
0059         if (not handle) {
0060           return edm::ESHandle<T>(handle.whyFailedFactory());
0061         }
0062         return edm::ESHandle<T>(&handle->get(device_), handle.description());
0063       }
0064     }
0065 
0066     // getTransientHandle() is intentionally omitted for now. It makes
0067     // little sense for event transitions, and for now
0068     // device::EventSetup is available only for those. If
0069     // device::EventSetup ever gets added for run or lumi transitions,
0070     // getTransientHandle() will be straightforward to add
0071 
0072   private:
0073     edm::EventSetup const& setup_;
0074     // Taking a copy because alpaka::getDev() returns a temporary. To
0075     // be removed after a proper treatment of multiple devices per
0076     // backend is implemented in Eventsetup
0077     Device const device_;
0078   };
0079 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE::device
0080 
0081 #endif