ChimeraTK-DeviceAccess  03.18.00
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 
11 namespace 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 
30  }
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 
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
ChimeraTK::AccessMode::raw
@ raw
Raw access: disable any possible conversion from the original hardware data type into the given UserT...
ChimeraTK::LNMBackend::MultiplierPluginDecorator::doPreWrite
void doPreWrite(TransferType type, VersionNumber) override
Definition: LNMMultiplierPlugin.cc:68
ChimeraTK::LNMBackend::AccessorPlugin
Base class for plugins that modify the behaviour of accessors in the logical name mapping backend.
Definition: LNMAccessorPlugin.h:104
ChimeraTK::LNMBackend
Definition: LNMMathPluginFormulaHelper.h:16
TransferElement.h
ChimeraTK::LNMBackend::MultiplierPlugin::doRegisterInfoUpdate
void doRegisterInfoUpdate() override
Implementation of the plugin specific register information update.
Definition: LNMMultiplierPlugin.cc:27
ChimeraTK::AccessModeFlags::remove
void remove(AccessMode flag)
Remove the given flag from the set.
Definition: AccessMode.cc:56
ChimeraTK::LNMBackend::MultiplierPluginDecorator::_factor
double _factor
Definition: LNMMultiplierPlugin.cc:49
ChimeraTK::LNMBackend::MultiplierPluginDecorator::MultiplierPluginDecorator
MultiplierPluginDecorator(const boost::shared_ptr< ChimeraTK::NDRegisterAccessor< double >> &target, double factor)
Definition: LNMMultiplierPlugin.cc:38
NDRegisterAccessorDecorator.h
ChimeraTK::LNMBackend::UndecoratedParams
Helper struct to hold extra parameters needed by some plugins, used in decorateAccessor()
Definition: LNMAccessorPlugin.h:13
ChimeraTK::DataDescriptor
Class describing the actual payload data format of a register in an abstract manner.
Definition: DataDescriptor.h:19
ChimeraTK::LNMBackend::MultiplierPlugin::_factor
double _factor
Definition: LNMAccessorPlugin.h:182
ChimeraTK::LNMBackend::MultiplierPluginDecorator
Definition: LNMMultiplierPlugin.cc:35
ChimeraTK::LNMBackend::MultiplierPluginDecorator::doPostWrite
void doPostWrite(TransferType type, VersionNumber dataLost) override
Definition: LNMMultiplierPlugin.cc:47
ChimeraTK::LNMBackendRegisterInfo
RegisterInfo structure for the LogicalNameMappingBackend.
Definition: LNMBackendRegisterInfo.h:22
ChimeraTK::LNMBackend::MultiplierPlugin::MultiplierPlugin
MultiplierPlugin(const LNMBackendRegisterInfo &info, size_t pluginIndex, const std::map< std::string, std::string > &parameters)
Definition: LNMMultiplierPlugin.cc:15
ChimeraTK::LNMBackend::AccessorPluginBase::_info
LNMBackendRegisterInfo _info
RegisterInfo describing the the target register for which this plugin instance should work.
Definition: LNMAccessorPlugin.h:93
ChimeraTK::LNMBackend::MultiplierPluginDecorator::doPostRead
void doPostRead(TransferType type, bool hasNewData) override
Definition: LNMMultiplierPlugin.cc:55
ChimeraTK::TransferType
TransferType
Used to indicate the applicable operation on a Transferelement.
Definition: TransferElement.h:51
ChimeraTK::DataType
A class to describe which of the supported data types is used.
Definition: SupportedUserTypes.h:599
ChimeraTK::NDRegisterAccessorDecorator
Base class for decorators of the NDRegisterAccessor.
Definition: NDRegisterAccessorDecorator.h:120
ChimeraTK::LNMBackendRegisterInfo::_dataDescriptor
DataDescriptor _dataDescriptor
Definition: LNMBackendRegisterInfo.h:111
ChimeraTK::LNMBackend::MultiplierPluginDecorator::doPreRead
void doPreRead(TransferType type) override
Definition: LNMMultiplierPlugin.cc:41
ChimeraTK::LNMBackendRegisterInfo::supportedFlags
AccessModeFlags supportedFlags
Supported AccessMode flags.
Definition: LNMBackendRegisterInfo.h:106
ChimeraTK::LNMBackend::MultiplierPlugin::decorateAccessor
boost::shared_ptr< NDRegisterAccessor< UserType > > decorateAccessor(boost::shared_ptr< LogicalNameMappingBackend > &backend, boost::shared_ptr< NDRegisterAccessor< TargetType >> &target, const UndecoratedParams &accessorParams)
Definition: LNMMultiplierPlugin.cc:81
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
LNMBackendRegisterInfo.h
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::NDRegisterAccessor
N-dimensional register accessor.
Definition: ForwardDeclarations.h:17
LNMAccessorPlugin.h
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51