Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-15 01:07:31

0001 #ifndef DataFormats_Portable_interface_Product_h
0002 #define DataFormats_Portable_interface_Product_h
0003 
0004 #include <memory>
0005 #include <utility>
0006 
0007 #include "DataFormats/Portable/interface/ProductBase.h"
0008 #include "HeterogeneousCore/AlpakaInterface/interface/ScopedContextFwd.h"
0009 #include "HeterogeneousCore/AlpakaInterface/interface/config.h"
0010 #include "HeterogeneousCore/AlpakaInterface/interface/traits.h"
0011 
0012 namespace edm {
0013   template <typename T>
0014   class Wrapper;
0015 }
0016 
0017 namespace cms::alpakatools {
0018 
0019   /**
0020      * The purpose of this class is to wrap alpaka-based data products for
0021      * the edm::Event in a way which forces correct use of various utilities.
0022      *
0023      * The default constructor is needed only for the ROOT dictionary generation.
0024      *
0025      * The non-default construction has to be done with ScopedContext
0026      * (in order to properly register the alpaka event).
0027      *
0028      * The alpaka event is in practice needed only for inter-queue
0029      * synchronization, but someone with long-enough lifetime has to own
0030      * it. Here is a somewhat natural place. If the overhead is too much, we
0031      * can use them only where synchronization between queues is needed.
0032      */
0033   template <typename TQueue, typename T, typename = std::enable_if_t<cms::alpakatools::is_queue_v<TQueue>>>
0034   class Product : public ProductBase<TQueue> {
0035   public:
0036     using Queue = TQueue;
0037     using Event = alpaka::Event<Queue>;
0038 
0039     Product() = default;  // Needed only for ROOT dictionary generation
0040 
0041     Product(const Product&) = delete;
0042     Product& operator=(const Product&) = delete;
0043     Product(Product&&) = default;
0044     Product& operator=(Product&&) = default;
0045 
0046   private:
0047     friend class impl::ScopedContextGetterBase<Queue>;
0048     friend class ScopedContextProduce<Queue>;
0049     friend class edm::Wrapper<Product<Queue, T>>;
0050 
0051     explicit Product(std::shared_ptr<Queue> queue, std::shared_ptr<Event> event, T data)
0052         : ProductBase<Queue>(std::move(queue), std::move(event)), data_(std::move(data)) {}
0053 
0054     template <typename... Args>
0055     explicit Product(std::shared_ptr<Queue> queue, std::shared_ptr<Event> event, Args&&... args)
0056         : ProductBase<Queue>(std::move(queue), std::move(event)), data_(std::forward<Args>(args)...) {}
0057 
0058     T data_;  //!
0059   };
0060 
0061 }  // namespace cms::alpakatools
0062 
0063 #endif  // DataFormats_Portable_interface_Product_h