RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
businessLogic.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_EXAMPLE_DATATASK_OPTIMISER_BUSINESSLOGIC_HPP
13#define RTCTK_EXAMPLE_DATATASK_OPTIMISER_BUSINESSLOGIC_HPP
14
15#include "computation.hpp"
20
21namespace rtctk::exampleDataTask {
22
23using namespace rtctk::componentFramework;
24
26
27class BusinessLogic : public LifeCycle::BizLogicIf {
28public:
30
31 BusinessLogic(const std::string& name, ServiceContainer& services)
32 : m_rtr(services.Get<RuntimeRepoIf>())
33 , m_oldb(services.Get<OldbIf>())
34 , m_dp_slopes("/common/static/wfs_1/slopes")
35 , m_dp_nacts("/common/static/dm_1/acts")
36 , m_dp_im("/" + name + "/" + "dynamic/im")
37 , m_dp_cm("/" + name + "/" + "dynamic/cm")
38 , m_dp_stats_time("/" + name + "/" + "statistics/computation/time")
39 , m_computation() {
40 // create some data points
41 m_oldb.CreateDataPoint<double>(m_dp_stats_time);
42 m_oldb.SetDataPoint<double>(m_dp_stats_time, 0.0);
43 }
44
45 void ActivityInitialising(StopToken st) override {
46 m_computation.SetStaticConfig(m_rtr.GetDataPoint<int32_t>(m_dp_slopes),
47 m_rtr.GetDataPoint<int32_t>(m_dp_nacts));
48
49 m_computation.SetDynamicConfig(m_rtr.GetDataPoint<MatrixBuffer<float>>(m_dp_im));
50 }
51
52 void ActivityUpdating(StopToken st, const JsonPayload& arg) override {
53 m_computation.SetDynamicConfig(m_rtr.GetDataPoint<MatrixBuffer<float>>(m_dp_im));
54 }
55
56 void ActivityOptimising(StopToken st, const JsonPayload& arg) override {
57 auto result = m_computation.Compute(ParseAlgorithm(arg));
58
59 m_rtr.WriteDataPoint<MatrixBuffer<float>>(m_dp_cm, result.cm);
60 m_oldb.SetDataPoint<double>(m_dp_stats_time, result.stats.elapsed.count());
61 }
62
63private:
64 Computation::Algorithm ParseAlgorithm(const JsonPayload& arg) {
65 const std::string alg_key = "algorithm";
66
67 if (not arg.contains(alg_key)) {
68 std::stringstream err_text;
69 err_text << "No algorithm specified: ";
70 for (auto& [key, value] : arg.items()) {
71 err_text << " " << key << " : " << value;
72 }
73 CII_THROW(RtctkException, err_text.str());
74 }
75
76 std::string value = arg[alg_key];
77
78 if (value == "SimpleInversion") {
80 } else if (value == "PythonInversion") {
82 } else {
83 std::stringstream err_text;
84 err_text << "Invalid algorithm specified: ";
85 for (auto& [key, value] : arg.items()) {
86 err_text << " " << key << " : " << value;
87 }
88 CII_THROW(RtctkException, err_text.str());
89 }
90 }
91
92 // used services
93 RuntimeRepoIf& m_rtr;
94 OldbIf& m_oldb;
95
96 // datapoints
97 DataPointPath m_dp_slopes;
98 DataPointPath m_dp_nacts;
99 DataPointPath m_dp_im;
100 DataPointPath m_dp_cm;
101 DataPointPath m_dp_stats_time;
102
103 Computation m_computation;
104};
105
106} // namespace rtctk::exampleDataTask
107
108#endif // RTCTK_EXAMPLE_DATATASK_OPTIMISER_BUSINESSLOGIC_HPP
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:220
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:27
Base interface for all OLDB adapters.
Definition oldbIf.hpp:24
Base interface for all Runtime Configuration Repository adapters.
Definition runtimeRepoIf.hpp:26
Container class that holds services of any type.
Definition serviceContainer.hpp:38
Definition businessLogic.hpp:28
void ActivityOptimising(StopToken st, const JsonPayload &arg) override
Definition businessLogic.hpp:56
void ActivityInitialising(StopToken st) override
Definition businessLogic.hpp:45
LifeCycle ComponentType
Definition businessLogic.hpp:30
void ActivityUpdating(StopToken st, const JsonPayload &arg) override
Definition businessLogic.hpp:52
BusinessLogic(const std::string &name, ServiceContainer &services)
Definition businessLogic.hpp:31
Algorithm
Definition computation.hpp:36
@ SimpleInversion
Definition computation.hpp:36
@ PythonInversion
Definition computation.hpp:36
rad::StopToken StopToken
Definition stopToken.hpp:19
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:24
Definition businessLogic.cpp:26
Runnable< RtcComponent > LifeCycle
Definition businessLogic.hpp:26
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:127