RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
businessLogic.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_EXAMPLE_DATATASK_OPTIMISER_BUSINESSLOGIC_HPP
14#define RTCTK_EXAMPLE_DATATASK_OPTIMISER_BUSINESSLOGIC_HPP
15
16#include "computation.hpp"
21
22namespace rtctk::exampleDataTask {
23
24using namespace rtctk::componentFramework;
25
27
29public:
31
32 BusinessLogic(const std::string& name, ServiceContainer& services)
33 : m_rtr(services.Get<RuntimeRepoIf>())
34 , m_oldb(services.Get<OldbIf>())
35 , m_dp_slopes("/common/static/wfs_1/slopes")
36 , m_dp_nacts("/common/static/dm_1/acts")
37 , m_dp_im("/" + name + "/" + "dynamic/im")
38 , m_dp_cm("/" + name + "/" + "dynamic/cm")
39 , m_dp_stats_time("/" + name + "/" + "statistics/computation/time")
40 , m_computation() {
41 // create some data points
42 m_oldb.CreateDataPoint<double>(m_dp_stats_time);
43 m_oldb.SetDataPoint<double>(m_dp_stats_time, 0.0);
44 }
45
47 m_computation.SetStaticConfig(m_rtr.GetDataPoint<int32_t>(m_dp_slopes),
48 m_rtr.GetDataPoint<int32_t>(m_dp_nacts));
49
50 m_computation.SetDynamicConfig(m_rtr.GetDataPoint<MatrixBuffer<float>>(m_dp_im));
51 }
52
53 void ActivityUpdating(StopToken st, const JsonPayload& arg) override {
54 m_computation.SetDynamicConfig(m_rtr.GetDataPoint<MatrixBuffer<float>>(m_dp_im));
55 }
56
58 auto result = m_computation.Compute(ParseAlgorithm(arg));
59
60 m_rtr.WriteDataPoint<MatrixBuffer<float>>(m_dp_cm, result.cm);
61 m_oldb.SetDataPoint<double>(m_dp_stats_time, result.stats.elapsed.count());
62 }
63
64private:
65 Computation::Algorithm ParseAlgorithm(const JsonPayload& arg) {
66 const std::string alg_key = "algorithm";
67
68 if (not arg.contains(alg_key)) {
69 std::stringstream err_text;
70 err_text << "No algorithm specified: ";
71 for (auto& [key, value] : arg.items()) {
72 err_text << " " << key << " : " << value;
73 }
75 }
76
77 std::string value = arg[alg_key];
78
79 if (value == "SimpleInversion") {
81 } else if (value == "PythonInversion") {
83 } else {
84 std::stringstream err_text;
85 err_text << "Invalid algorithm specified: ";
86 for (auto& [key, value] : arg.items()) {
87 err_text << " " << key << " : " << value;
88 }
90 }
91 }
92
93 // used services
94 RuntimeRepoIf& m_rtr;
95 OldbIf& m_oldb;
96
97 // datapoints
98 DataPointPath m_dp_slopes;
99 DataPointPath m_dp_nacts;
100 DataPointPath m_dp_im;
101 DataPointPath m_dp_cm;
102 DataPointPath m_dp_stats_time;
103
104 Computation m_computation;
105};
106
107} // namespace rtctk::exampleDataTask
108
109#endif // RTCTK_EXAMPLE_DATATASK_OPTIMISER_BUSINESSLOGIC_HPP
Definition main.cpp:25
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:28
Base interface for all OLDB adapters.
Definition oldbIf.hpp:25
T GetDataPoint(const DataPointPath &path) const
Fetches a datapoint from the repository.
Definition repositoryIf.ipp:1711
void CreateDataPoint(const DataPointPath &path)
Creates a new datapoint in the repository.
Definition repositoryIf.ipp:1696
void SetDataPoint(const DataPointPath &path, const T &value)
Sets a datapoint in the repository.
Definition repositoryIf.ipp:1720
void WriteDataPoint(const DataPointPath &path, const T &buffer)
Writes a datapoint to the repository.
Definition repositoryIf.ipp:1734
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
Base interface for all Runtime Configuration Repository adapters.
Definition runtimeRepoIf.hpp:27
Container class that holds services of any type.
Definition serviceContainer.hpp:39
void ActivityOptimising(StopToken st, const JsonPayload &arg) override
Definition businessLogic.hpp:57
void ActivityInitialising(StopToken st) override
Definition businessLogic.hpp:46
void ActivityUpdating(StopToken st, const JsonPayload &arg) override
Definition businessLogic.hpp:53
BusinessLogic(const std::string &name, ServiceContainer &services)
Definition businessLogic.hpp:32
Algorithm
Definition computation.hpp:37
Definition commandReplier.cpp:22
rad::StopToken StopToken
Definition stopToken.hpp:20
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:25
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Definition businessLogic.cpp:27
Runnable< RtcComponent > LifeCycle
Definition businessLogic.hpp:27
Header file for OldbIf, which defines the API for OldbAdapters.
Lifecycle Extension that makes an RTC Component 'Optimisable'.
Computation class of the example data task.
Lifecycle of a basic 'RtcComponent'.
Header file for RuntimeRepoIf, which defines the API for RuntimeRepoAdapters.
Life cycle extension to make RtcComponent Optimisable.
Definition optimisable.hpp:128
Basic life cycle for RtcComponent.
Definition rtcComponent.hpp:74
Life cycle extension to make RtcComponent Runnable.
Definition runnable.hpp:31