Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/AlpakaInterface/interface/config.h"
0008 
0009 namespace ALPAKA_ACCELERATOR_NAMESPACE::device {
0010   /**
0011    * The device::EventSetup mimics edm::EventSetup, and provides access
0012    * to ESProducts in the host memory space, and in the device memory
0013    * space defined by the backend (i.e. ALPAKA_ACCELERATOR_NAMESPACE).
0014    *
0015    * Access to device memory space products is synchronized properly.
0016    *
0017    * Note that not full interface of edm::EventSetup is replicated
0018    * here. If something important is missing, that can be added.
0019    */
0020   class EventSetup {
0021   public:
0022     EventSetup(edm::EventSetup const& iSetup, Device const& dev) : setup_(iSetup), device_(dev) {}
0023 
0024     // getData()
0025 
0026     template <typename T, typename R>
0027     T const& getData(edm::ESGetToken<T, R> const& iToken) const {
0028       return setup_.getData(iToken);
0029     }
0030 
0031     template <typename T, typename R>
0032     T const& getData(device::ESGetToken<T, R> const& iToken) const {
0033       auto const& product = setup_.getData(iToken.underlyingToken());
0034       return product.get(device_);
0035     }
0036 
0037     // getHandle()
0038 
0039     template <typename T, typename R>
0040     edm::ESHandle<T> getHandle(edm::ESGetToken<T, R> const& iToken) const {
0041       return setup_.getHandle(iToken);
0042     }
0043 
0044     template <typename T, typename R>
0045     edm::ESHandle<T> getHandle(device::ESGetToken<T, R> const& iToken) const {
0046       auto handle = setup_.getHandle(iToken.underlyingToken());
0047       if (not handle) {
0048         return edm::ESHandle<T>(handle.whyFailedFactory());
0049       }
0050       return edm::ESHandle<T>(&handle->get(device_), handle.description());
0051     }
0052 
0053     // getTransientHandle() is intentionally omitted for now. It makes
0054     // little sense for event transitions, and for now
0055     // device::EventSetup is available only for those. If
0056     // device::EventSetup ever gets added for run or lumi transitions,
0057     // getTransientHandle() will be straightforward to add
0058 
0059   private:
0060     edm::EventSetup const& setup_;
0061     // Taking a copy because alpaka::getDev() returns a temporary. To
0062     // be removed after a proper treatment of multiple devices per
0063     // backend is implemented in Eventsetup
0064     Device const device_;
0065   };
0066 }  // namespace ALPAKA_ACCELERATOR_NAMESPACE::device
0067 
0068 #endif