File indexing completed on 2023-03-17 10:49:21
0001 #ifndef DataFormats_Common_interface_DeviceProduct_h
0002 #define DataFormats_Common_interface_DeviceProduct_h
0003
0004 #include <cassert>
0005 #include <memory>
0006
0007 namespace edm {
0008 class DeviceProductBase {
0009 public:
0010 DeviceProductBase() = default;
0011 ~DeviceProductBase() = default;
0012
0013
0014 template <typename M>
0015 M const& metadata() const {
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 assert(typeid(M) == *metadataType_);
0026 return *static_cast<M const*>(metadata_.get());
0027 }
0028
0029 protected:
0030 template <typename M>
0031 explicit DeviceProductBase(std::shared_ptr<M> metadata)
0032 : metadata_(std::move(metadata)), metadataType_(&typeid(M)) {}
0033
0034 private:
0035 std::shared_ptr<void const> metadata_;
0036 std::type_info const* metadataType_;
0037 };
0038
0039
0040
0041
0042
0043
0044
0045 template <typename T>
0046 class DeviceProduct : public DeviceProductBase {
0047 public:
0048 DeviceProduct() = default;
0049
0050 template <typename M, typename... Args>
0051 explicit DeviceProduct(std::shared_ptr<M> metadata, Args&&... args)
0052 : DeviceProductBase(std::move(metadata)), data_(std::forward<Args>(args)...) {}
0053
0054 DeviceProduct(const DeviceProduct&) = delete;
0055 DeviceProduct& operator=(const DeviceProduct&) = delete;
0056 DeviceProduct(DeviceProduct&&) = default;
0057 DeviceProduct& operator=(DeviceProduct&&) = default;
0058
0059
0060
0061
0062
0063
0064
0065 template <typename M, typename... Args>
0066 T const& getSynchronized(Args&&... args) const {
0067 auto const& md = metadata<M>();
0068 md.synchronize(std::forward<Args>(args)...);
0069 return data_;
0070 }
0071
0072 private:
0073 T data_;
0074 };
0075 }
0076 #endif