ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
LNMMathPlugin.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
5#include "LNMAccessorPlugin.h"
6
7#include <boost/make_shared.hpp>
8
9#include <utility>
10
11namespace ChimeraTK::LNMBackend {
12
13 // forward declaration needed for MathPlugin
14 class MathPluginFormulaHelper;
15
17 class MathPlugin : public AccessorPlugin<MathPlugin> {
18 public:
19 MathPlugin(const LNMBackendRegisterInfo& info, size_t pluginIndex, std::map<std::string, std::string> parameters);
20
21 void doRegisterInfoUpdate() override;
23
24 template<typename UserType, typename TargetType>
25 boost::shared_ptr<NDRegisterAccessor<UserType>> decorateAccessor(
26 boost::shared_ptr<LogicalNameMappingBackend>& backend,
27 boost::shared_ptr<NDRegisterAccessor<TargetType>>& target, const UndecoratedParams& accessorParams);
28
29 void openHook(const boost::shared_ptr<LogicalNameMappingBackend>& backend) override;
30 void postParsingHook(const boost::shared_ptr<const LogicalNameMappingBackend>& backend) override;
31 void closeHook() override;
32 void exceptionHook() override;
33
36 boost::shared_ptr<MathPluginFormulaHelper> getFormulaHelper(boost::shared_ptr<LogicalNameMappingBackend> backend);
38
39 bool _isWrite{false};
40
41 std::map<std::string, std::string> _parameters;
42 std::string _formula; // extracted from _parameters
43 bool _enablePushParameters{false}; // extracted from _parameters
44 bool _hasPushParameter{false}; // only relevant if _isWrite
45
46 // only used if _hasPushParameter == true
47 // The _writeMutex has two functions:
48 // - It protects resources which are shared by main accesor and parameter accessors
49 // - It is held while an accessor is doing the preWrite/writeTransfer/postWrite sequence.
50 // If the other thread would be able to do a transfer bwetween the preWrite and the actual transfer this
51 // would lead to wrong results (although formally the code is thread safe)
52 // Use a recursive mutex because it is allowed to call preWrite() multiple times before executing
53 // the writeTransfer, and the mutex is accquired in preWrite() and release in only in postWrite().
54 std::recursive_mutex _writeMutex;
57 std::vector<double> _lastMainValue;
59 static thread_local int64_t _writeLockCounter;
60
61 bool _creatingFormulaHelper{false}; // a flag to prevent recursion
62
63 private:
64 // store weak pointer because plugin lifetime should not extend MathPluginFormulaHelper lifetime
65 boost::weak_ptr<MathPluginFormulaHelper> _h;
66 };
67
68} // namespace ChimeraTK::LNMBackend
A class to describe which of the supported data types is used.
@ float64
Double precision float.
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.
Math Plugin: Apply mathematical formula to register's data.
DataType getTargetDataType(DataType) const override
Return the data type for which the target accessor shall be obtained.
ChimeraTK::DataValidity _lastMainValidity
void exceptionHook() override
Hook called when an exception is reported to the the backend via setException(), after the backend ha...
boost::shared_ptr< NDRegisterAccessor< UserType > > decorateAccessor(boost::shared_ptr< LogicalNameMappingBackend > &backend, boost::shared_ptr< NDRegisterAccessor< TargetType > > &target, const UndecoratedParams &accessorParams)
void openHook(const boost::shared_ptr< LogicalNameMappingBackend > &backend) override
Hook called when the backend is opened, at the end of the open() function after all backend work has ...
static thread_local int64_t _writeLockCounter
LNMBackendRegisterInfo * info()
std::map< std::string, std::string > _parameters
void closeHook() override
Hook called when the backend is closed, at the beginning of the close() function when the device is s...
std::recursive_mutex _writeMutex
boost::shared_ptr< MathPluginFormulaHelper > getFormulaHelper(boost::shared_ptr< LogicalNameMappingBackend > backend)
if not yet existing, creates the instance and returns it if already existing, backend ptr may be empt...
void postParsingHook(const boost::shared_ptr< const LogicalNameMappingBackend > &backend) override
Hook called after the parsing of logical name map.
void doRegisterInfoUpdate() override
Implementation of the plugin specific register information update.
std::vector< double > _lastMainValue
RegisterInfo structure for the LogicalNameMappingBackend.
N-dimensional register accessor.
DataValidity
The current state of the data.
Helper struct to hold extra parameters needed by some plugins, used in decorateAccessor()