ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
LNMMathPluginFormulaHelper.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// note this header is internal (i.e. should not be installed as part of DeviceAccess API) and is the only place
6// where exprtk is included.
7// So this header must only be included from .cc files, in order to keep exprtk hidden
8
9#include "LNMAccessorPlugin.h"
10
11#include <boost/make_shared.hpp>
12
13#include <exprtk.hpp>
14
15#include <utility>
16
18
19 class MathPlugin;
20
22 public:
23 MathPluginFormulaHelper(MathPlugin* p, const boost::shared_ptr<LogicalNameMappingBackend>& backend);
24
25 void compileFormula(const std::string& formula,
26 const std::map<std::string, boost::shared_ptr<ChimeraTK::NDRegisterAccessor<double>>>& parameters,
27 size_t nElements);
28
29 template<typename T>
30 void computeResult(std::vector<double>& x, std::vector<T>& resultBuffer);
31
32 // This function updates all parameter accessors and return their worst validity
34
35 // This function updates result in target based on latest values of parameter accessors and lastMainValue
36 void updateResult(ChimeraTK::VersionNumber versionNumber);
37
38 // Checks that all parameters have been written since opening the device.
39 // Returns false as long as at least one parameter is still on the backend's _versionOnOpen.
40 // Only call this function when holding the _writeMutex. It updates the _allParametersWrittenAfterOpen
41 // variable which is protected by that mutex.
43
44 // set the exception backend for all parameter accessors
45 void setExceptionBackend(boost::shared_ptr<DeviceBackend> exceptionBackend);
46
47 // return the LNM backend
48 boost::shared_ptr<LogicalNameMappingBackend> getBackend();
49
50 protected:
51 std::string varName;
52 exprtk::expression<double> expression;
53 exprtk::symbol_table<double> symbols;
54 exprtk::rtl::vecops::package<double> vecOpsPkg;
55 std::unique_ptr<exprtk::vector_view<double>> valueView;
56 std::map<boost::shared_ptr<NDRegisterAccessor<double>>, std::unique_ptr<exprtk::vector_view<double>>> params;
57
58 boost::shared_ptr<LogicalNameMappingBackend> _backend;
59 boost::shared_ptr<NDRegisterAccessor<double>> _target;
60
61 // We assume plugin lives at least as long as MathPluginFormulaHelper
63
64 std::map<std::string, boost::shared_ptr<NDRegisterAccessor<double>>> _accessorMap;
65 };
66
67} // namespace ChimeraTK::LNMBackend
exprtk::rtl::vecops::package< double > vecOpsPkg
boost::shared_ptr< LogicalNameMappingBackend > _backend
boost::shared_ptr< LogicalNameMappingBackend > getBackend()
boost::shared_ptr< NDRegisterAccessor< double > > _target
void setExceptionBackend(boost::shared_ptr< DeviceBackend > exceptionBackend)
void compileFormula(const std::string &formula, const std::map< std::string, boost::shared_ptr< ChimeraTK::NDRegisterAccessor< double > > > &parameters, size_t nElements)
std::map< std::string, boost::shared_ptr< NDRegisterAccessor< double > > > _accessorMap
std::unique_ptr< exprtk::vector_view< double > > valueView
std::map< boost::shared_ptr< NDRegisterAccessor< double > >, std::unique_ptr< exprtk::vector_view< double > > > params
void computeResult(std::vector< double > &x, std::vector< T > &resultBuffer)
void updateResult(ChimeraTK::VersionNumber versionNumber)
Math Plugin: Apply mathematical formula to register's data.
N-dimensional register accessor.
Class for generating and holding version numbers without exposing a numeric representation.
DataValidity
The current state of the data.