12#ifndef RTCTK_GEN_RTR_WRITER_
13#define RTCTK_GEN_RTR_WRITER_
19#include <boost/accumulators/accumulators.hpp>
20#include <boost/accumulators/statistics/count.hpp>
21#include <boost/accumulators/statistics/max.hpp>
22#include <boost/accumulators/statistics/mean.hpp>
23#include <boost/accumulators/statistics/min.hpp>
24#include <boost/accumulators/statistics/stats.hpp>
25#include <boost/accumulators/statistics/variance.hpp>
30using namespace std::chrono;
31namespace ba = boost::accumulators;
40 std::shared_ptr<rtctk_cfw::RuntimeRepoIf>
m_rtr;
54 ba::stats<ba::tag::mean, ba::tag::variance, ba::tag::min, ba::tag::max, ba::tag::count>>
60 const std::string& server_alias =
"")
78 std::chrono::microseconds period,
79 uint32_t iterations) = 0;
121 std::unique_ptr<rtctk_cfw::MatrixBuffer<T>> m_value;
126 void WriteDataPoint() {
127 uint16_t error_counter = 0;
130 "[%s] Going to write value of size: %ld x %ld (%d bytes) %d times.",
139 "[%s] Going to write value of size: %ld x %ld (%d bytes) until Ctrl-C.",
148 uint32_t iteration_counter = 0;
152 if (iteration_counter % 100 == 0) {
154 "[%s] Going to write DP. Iteration: %d.",
158 auto timestamp = high_resolution_clock::now();
160 auto t1 = std::chrono::steady_clock::now();
165 auto t2 = std::chrono::steady_clock::now();
167 std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
170 if (iteration_counter % 100 == 0) {
171 auto timestamp_nanos =
172 duration_cast<nanoseconds>(timestamp.time_since_epoch()).count();
173 double timestamp_s =
static_cast<double>(timestamp_nanos) / 1e9;
176 "[%s]\tWrote to DP at time (epoch): %f. Iteration: %d.\tWrite "
177 "time [us]: min: %u max: %u mean: %.2f variance: %.2f",
188 }
catch (
const std::exception& ex) {
190 "[%s ] Iteration: %d exception caught: %s!",
194 if (error_counter++ > 5) {
197 "[%s] More than 5 consecutive exception caught. Writing to RTR stoped!",
203 "[%s ] Iteration: %d unknown exception caught!",
206 if (error_counter++ > 5) {
209 "[%s] More than 5 consecutive exception caught. Writing to RTR stoped!",
219 "[%s] %u / %u values have been written. DONE!",
225 "time [us]: min: %u max: %u med: %.2f variance: %.2f",
236 const std::string& server_alias =
"")
257 std::chrono::microseconds period,
258 uint32_t iterations) {
261 m_value = std::make_unique<rtctk_cfw::MatrixBuffer<T>>();
262 m_value->resize(dim_x, dim_y);
264 "[%s] Created matrix of size: %ld x %ld",
268 m_payload_bytes = m_value->GetNrows() * m_value->GetNcols() *
sizeof(T);
273 "[%s] DP does not exist going to create one (server alias=%s).",
280 }
catch (
const std::exception& ex) {
286 "[%s] Going to delete DP after an error.",
290 CII_THROW_WITH_NESTED(
293 "[" +
m_dp.
ToString() +
"] Problem creating DP and setting inital value");
300 m_thread = std::thread(&GenRtrWriter::WriteDataPoint,
this);
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
const std::string & ToString() const noexcept
Get string representing the DataPointPath.
Definition dataPointPath.hpp:428
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:28
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
Logging Support Library based on log4cplus.
Declaration of the MatrixSpan template class used in APIs.
Definition commandReplier.cpp:22
Header file for RuntimeRepoIf, which defines the API for RuntimeRepoAdapters.