ChimeraTK-DeviceAccess  03.18.00
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 #include <utility>
15 
17 
18  class MathPlugin;
19 
21  public:
22  MathPluginFormulaHelper(MathPlugin* p, const boost::shared_ptr<LogicalNameMappingBackend>& backend);
23 
24  void compileFormula(const std::string& formula,
25  const std::map<std::string, boost::shared_ptr<ChimeraTK::NDRegisterAccessor<double>>>& parameters,
26  size_t nElements);
27 
28  template<typename T>
29  void computeResult(std::vector<double>& x, std::vector<T>& resultBuffer);
30 
31  // This function updates all parameter accessors and return their worst validity
33 
34  // This function updates result in target based on latest values of parameter accessors and lastMainValue
35  void updateResult(ChimeraTK::VersionNumber versionNumber);
36 
37  // Checks that all parameters have been written since opening the device.
38  // Returns false as long as at least one parameter is still on the backend's _versionOnOpen.
39  // Only call this function when holding the _writeMutex. It updates the _allParametersWrittenAfterOpen
40  // variable which is protected by that mutex.
42 
43  // set the exception backend for all parameter accessors
44  void setExceptionBackend(boost::shared_ptr<DeviceBackend> exceptionBackend);
45 
46  // return the LNM backend
47  boost::shared_ptr<LogicalNameMappingBackend> getBackend();
48 
49  protected:
50  std::string varName;
51  exprtk::expression<double> expression;
52  exprtk::symbol_table<double> symbols;
53  exprtk::rtl::vecops::package<double> vecOpsPkg;
54  std::unique_ptr<exprtk::vector_view<double>> valueView;
55  std::map<boost::shared_ptr<NDRegisterAccessor<double>>, std::unique_ptr<exprtk::vector_view<double>>> params;
56 
57  boost::shared_ptr<LogicalNameMappingBackend> _backend;
58  boost::shared_ptr<NDRegisterAccessor<double>> _target;
59 
60  // We assume plugin lives at least as long as MathPluginFormulaHelper
62 
63  std::map<std::string, boost::shared_ptr<NDRegisterAccessor<double>>> _accessorMap;
64  };
65 
66 } // namespace ChimeraTK::LNMBackend
ChimeraTK::LNMBackend::MathPluginFormulaHelper::updateParameters
ChimeraTK::DataValidity updateParameters()
Definition: LNMMathPlugin.cc:132
ChimeraTK::LNMBackend::MathPluginFormulaHelper::checkAllParametersWritten
bool checkAllParametersWritten()
Definition: LNMMathPlugin.cc:193
ChimeraTK::LNMBackend::MathPluginFormulaHelper::computeResult
void computeResult(std::vector< double > &x, std::vector< T > &resultBuffer)
Definition: LNMMathPlugin.cc:525
ChimeraTK::LNMBackend::MathPluginFormulaHelper::_mp
MathPlugin * _mp
Definition: LNMMathPluginFormulaHelper.h:61
ChimeraTK::LNMBackend
Definition: LNMMathPluginFormulaHelper.h:16
ChimeraTK::LNMBackend::MathPlugin
Math Plugin: Apply mathematical formula to register's data.
Definition: LNMMathPlugin.h:17
ChimeraTK::LNMBackend::MathPluginFormulaHelper::MathPluginFormulaHelper
MathPluginFormulaHelper(MathPlugin *p, const boost::shared_ptr< LogicalNameMappingBackend > &backend)
Definition: LNMMathPlugin.cc:443
ChimeraTK::LNMBackend::MathPluginFormulaHelper::symbols
exprtk::symbol_table< double > symbols
Definition: LNMMathPluginFormulaHelper.h:52
ChimeraTK::LNMBackend::MathPluginFormulaHelper::valueView
std::unique_ptr< exprtk::vector_view< double > > valueView
Definition: LNMMathPluginFormulaHelper.h:54
ChimeraTK::LNMBackend::MathPluginFormulaHelper
Definition: LNMMathPluginFormulaHelper.h:20
ChimeraTK::LNMBackend::MathPluginFormulaHelper::getBackend
boost::shared_ptr< LogicalNameMappingBackend > getBackend()
Definition: LNMMathPlugin.cc:292
ChimeraTK::LNMBackend::MathPluginFormulaHelper::varName
std::string varName
Definition: LNMMathPluginFormulaHelper.h:50
ChimeraTK::LNMBackend::MathPluginFormulaHelper::updateResult
void updateResult(ChimeraTK::VersionNumber versionNumber)
Definition: LNMMathPlugin.cc:146
ChimeraTK::LNMBackend::MathPluginFormulaHelper::vecOpsPkg
exprtk::rtl::vecops::package< double > vecOpsPkg
Definition: LNMMathPluginFormulaHelper.h:53
ChimeraTK::DataValidity
DataValidity
The current state of the data.
Definition: TransferElement.h:41
ChimeraTK::LNMBackend::MathPluginFormulaHelper::expression
exprtk::expression< double > expression
Definition: LNMMathPluginFormulaHelper.h:51
ChimeraTK::LNMBackend::MathPluginFormulaHelper::compileFormula
void compileFormula(const std::string &formula, const std::map< std::string, boost::shared_ptr< ChimeraTK::NDRegisterAccessor< double >>> &parameters, size_t nElements)
Definition: LNMMathPlugin.cc:474
ChimeraTK::LNMBackend::MathPluginFormulaHelper::_target
boost::shared_ptr< NDRegisterAccessor< double > > _target
Definition: LNMMathPluginFormulaHelper.h:58
ChimeraTK::LNMBackend::MathPluginFormulaHelper::setExceptionBackend
void setExceptionBackend(boost::shared_ptr< DeviceBackend > exceptionBackend)
Definition: LNMMathPlugin.cc:419
ChimeraTK::LNMBackend::MathPluginFormulaHelper::_accessorMap
std::map< std::string, boost::shared_ptr< NDRegisterAccessor< double > > > _accessorMap
Definition: LNMMathPluginFormulaHelper.h:63
ChimeraTK::LNMBackend::MathPluginFormulaHelper::params
std::map< boost::shared_ptr< NDRegisterAccessor< double > >, std::unique_ptr< exprtk::vector_view< double > > > params
Definition: LNMMathPluginFormulaHelper.h:55
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::LNMBackend::MathPluginFormulaHelper::_backend
boost::shared_ptr< LogicalNameMappingBackend > _backend
Definition: LNMMathPluginFormulaHelper.h:57
ChimeraTK::NDRegisterAccessor
N-dimensional register accessor.
Definition: ForwardDeclarations.h:17
LNMAccessorPlugin.h