ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
VariableDistributor.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
7
8#include <memory>
9
10namespace ChimeraTK::async {
11
12 template<typename SourceType>
14 public:
15 VariableDistributor(boost::shared_ptr<DeviceBackend> backend, boost::shared_ptr<SubDomain<SourceType>> parent,
16 boost::shared_ptr<Domain> asyncDomain);
17
18 template<typename UserType>
19 std::unique_ptr<AsyncVariable> createAsyncVariable(AccessorInstanceDescriptor const& descriptor);
20
21 boost::shared_ptr<SubDomain<SourceType>> _parent;
22 };
23
24 /********************************************************************************************************************/
25
26 template<typename SourceType, typename UserType>
27 class GenericAsyncVariable : public AsyncVariableImpl<UserType> {
28 public:
29 GenericAsyncVariable(SourceType& dataBuffer, VersionNumber& v, unsigned int nChannels, unsigned int nElements)
30 : AsyncVariableImpl<UserType>(nChannels, nElements), _dataBuffer(dataBuffer), _version(v) {}
31
32 // implement fillSendBuffer() in a derived class for template specialisation
33
36 const std::string& getUnit() override { return _emptyString; }
37
40 const std::string& getDescription() override { return _emptyString; }
41
42 protected:
43 std::string _emptyString;
44 SourceType& _dataBuffer;
46 };
47
48 /********************************************************************************************************************/
49
50 // partial template specialisation by inheritance for void
51 template<typename UserType>
52 class VoidAsyncVariable : public GenericAsyncVariable<std::nullptr_t, UserType> {
53 using GenericAsyncVariable<std::nullptr_t, UserType>::GenericAsyncVariable;
54 void fillSendBuffer() final;
55 };
56
57 /********************************************************************************************************************/
58 // Implementations
59 /********************************************************************************************************************/
60 template<typename SourceType>
61 VariableDistributor<SourceType>::VariableDistributor(boost::shared_ptr<DeviceBackend> backend,
62 boost::shared_ptr<SubDomain<SourceType>> parent, boost::shared_ptr<Domain> asyncDomain)
63 : SourceTypedAsyncAccessorManager<SourceType>(backend, asyncDomain), _parent(std::move(parent)) {
65 }
66
67 /********************************************************************************************************************/
68
69 // currently only for void
70 template<>
71 template<typename UserType>
74 // for the full implementation
75 // - extract size from catalogue and instance descriptor
76 return std::make_unique<VoidAsyncVariable<UserType>>(_sourceBuffer, _version, 1, 1);
77 }
78
79 /********************************************************************************************************************/
80 template<typename UserType>
82 // We know that the SourceBuffer contains nullptr. We don't have a conversion formula for that to user type
83 // (especially for string). But we know how to convert ChimeraTK::Void, so we do this instead.
84 this->_sendBuffer.value[0][0] = userTypeToUserType<UserType, ChimeraTK::Void>({});
85 this->_sendBuffer.versionNumber = this->_version;
86 }
87
88} // namespace ChimeraTK::async
#define FILL_VIRTUAL_FUNCTION_TEMPLATE_VTABLE(functionName)
Fill the vtable of a virtual function template defined with DEFINE_VIRTUAL_FUNCTION_TEMPLATE.
Class for generating and holding version numbers without exposing a numeric representation.
GenericAsyncVariable(SourceType &dataBuffer, VersionNumber &v, unsigned int nChannels, unsigned int nElements)
const std::string & getDescription() override
Make template specialisations on the SourceType in case the source data contains a description.
const std::string & getUnit() override
Make template specialisations on the SourceType in case the source data contains a unit.
Send backend-specific asynchronous data to different distributors:
Definition SubDomain.h:33
boost::shared_ptr< SubDomain< SourceType > > _parent
std::unique_ptr< AsyncVariable > createAsyncVariable(AccessorInstanceDescriptor const &descriptor)
VariableDistributor(boost::shared_ptr< DeviceBackend > backend, boost::shared_ptr< SubDomain< SourceType > > parent, boost::shared_ptr< Domain > asyncDomain)
STL namespace.
Helper class to have a complete descriton to create an Accessor.
AsyncVariableImpl contains a weak pointer to an AsyncNDRegisterAccessor<UserType> and a send buffer N...