ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
LNMMultiplierPlugin.cc
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
4#include "LNMAccessorPlugin.h"
7#include "TransferElement.h"
8
9#include <boost/make_shared.hpp>
10
11namespace ChimeraTK::LNMBackend {
12
13 /********************************************************************************************************************/
14
16 const LNMBackendRegisterInfo& info, size_t pluginIndex, const std::map<std::string, std::string>& parameters)
17 : AccessorPlugin(info, pluginIndex) {
18 // extract parameters
19 if(parameters.find("factor") == parameters.end()) {
20 throw ChimeraTK::logic_error("LogicalNameMappingBackend MultiplierPlugin: Missing parameter 'factor'.");
21 }
22 _factor = std::stod(parameters.at("factor"));
23 }
24
25 /********************************************************************************************************************/
26
31
32 /********************************************************************************************************************/
33
34 template<typename UserType>
37
38 MultiplierPluginDecorator(const boost::shared_ptr<ChimeraTK::NDRegisterAccessor<double>>& target, double factor)
39 : ChimeraTK::NDRegisterAccessorDecorator<UserType, double>(target), _factor(factor) {}
40
41 void doPreRead(TransferType type) override { _target->preRead(type); }
42
43 void doPostRead(TransferType type, bool hasNewData) override;
44
45 void doPreWrite(TransferType type, VersionNumber) override;
46
47 void doPostWrite(TransferType type, VersionNumber dataLost) override { _target->postWrite(type, dataLost); }
48
49 double _factor;
50
51 using ChimeraTK::NDRegisterAccessorDecorator<UserType, double>::_target;
52 };
53
54 template<typename UserType>
56 _target->postRead(type, hasNewData);
57 if(!hasNewData) return;
58 for(size_t i = 0; i < _target->getNumberOfChannels(); ++i) {
59 for(size_t k = 0; k < _target->getNumberOfSamples(); ++k) {
60 buffer_2D[i][k] = numericToUserType<UserType>(_target->accessData(i, k) * _factor);
61 }
62 }
63 this->_versionNumber = _target->getVersionNumber();
64 this->_dataValidity = _target->dataValidity();
65 }
66
67 template<typename UserType>
69 for(size_t i = 0; i < _target->getNumberOfChannels(); ++i) {
70 for(size_t k = 0; k < _target->getNumberOfSamples(); ++k) {
71 _target->accessData(i, k) = userTypeToNumeric<double>(buffer_2D[i][k]) * _factor;
72 }
73 }
74 _target->setDataValidity(this->_dataValidity);
75 _target->preWrite(type, versionNumber);
76 }
77
78 /********************************************************************************************************************/
79
80 template<typename UserType, typename TargetType>
81 boost::shared_ptr<NDRegisterAccessor<UserType>> MultiplierPlugin::decorateAccessor(
82 boost::shared_ptr<LogicalNameMappingBackend>&, boost::shared_ptr<NDRegisterAccessor<TargetType>>& target,
83 const UndecoratedParams&) {
84 if constexpr(std::is_same<TargetType, double>::value) {
85 return boost::make_shared<MultiplierPluginDecorator<UserType>>(target, _factor);
86 }
87
88 assert(false);
89
90 return {};
91 }
92} // namespace ChimeraTK::LNMBackend
void remove(AccessMode flag)
Remove the given flag from the set.
Definition AccessMode.cc:56
Class describing the actual payload data format of a register in an abstract manner.
A class to describe which of the supported data types is used.
LNMBackendRegisterInfo _info
RegisterInfo describing the the target register for which this plugin instance should work.
Base class for plugins that modify the behaviour of accessors in the logical name mapping backend.
MultiplierPlugin(const LNMBackendRegisterInfo &info, size_t pluginIndex, const std::map< std::string, std::string > &parameters)
boost::shared_ptr< NDRegisterAccessor< UserType > > decorateAccessor(boost::shared_ptr< LogicalNameMappingBackend > &backend, boost::shared_ptr< NDRegisterAccessor< TargetType > > &target, const UndecoratedParams &accessorParams)
void doRegisterInfoUpdate() override
Implementation of the plugin specific register information update.
RegisterInfo structure for the LogicalNameMappingBackend.
AccessModeFlags supportedFlags
Supported AccessMode flags.
Base class for decorators of the NDRegisterAccessor.
N-dimensional register accessor.
std::vector< std::vector< UserType > > buffer_2D
Buffer of converted data elements.
void postRead(TransferType type, bool updateDataBuffer)
Transfer the data from the device receive buffer into the user buffer, while converting the data into...
Class for generating and holding version numbers without exposing a numeric representation.
Exception thrown when a logic error has occured.
Definition Exception.h:51
@ raw
Raw access: disable any possible conversion from the original hardware data type into the given UserT...
TransferType
Used to indicate the applicable operation on a Transferelement.
void doPreRead(TransferType type) override
Backend specific implementation of preRead().
void doPreWrite(TransferType type, VersionNumber) override
Backend specific implementation of preWrite().
void doPostWrite(TransferType type, VersionNumber dataLost) override
Backend specific implementation of postWrite().
MultiplierPluginDecorator(const boost::shared_ptr< ChimeraTK::NDRegisterAccessor< double > > &target, double factor)
void doPostRead(TransferType type, bool hasNewData) override
Backend specific implementation of postRead().
Helper struct to hold extra parameters needed by some plugins, used in decorateAccessor()