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>
29namespace rtctk_cfw = rtctk::componentFramework;
30using namespace std::chrono;
31namespace ba = boost::accumulators;
40 std::shared_ptr<rtctk_cfw::RuntimeRepoIf>
m_rtr;
41 rtctk_cfw::DataPointPath
m_dp;
53 ba::stats<ba::tag::mean, ba::tag::variance, ba::tag::min, ba::tag::max, ba::tag::count>>
58 const rtctk_cfw::DataPointPath& dp)
73 std::chrono::microseconds period,
74 uint32_t iterations) = 0;
84 LOG4CPLUS_INFO_FMT(
m_logger,
"[%s] Finalize",
m_dp.ToString().c_str());
93 LOG4CPLUS_DEBUG_FMT(
m_logger,
"[%s] Going to delete DP.",
m_dp.ToString().c_str());
116 std::unique_ptr<rtctk_cfw::MatrixBuffer<T>> m_value;
121 void WriteDataPoint() {
122 uint16_t error_counter = 0;
125 "[%s] Going to write value of size: %ld x %ld (%d bytes) %d times.",
126 m_dp.ToString().c_str(),
134 "[%s] Going to write value of size: %ld x %ld (%d bytes) until Ctrl-C.",
135 m_dp.ToString().c_str(),
143 uint32_t iteration_counter = 0;
147 if (iteration_counter % 100 == 0) {
149 "[%s] Going to write DP. Iteration: %d.",
150 m_dp.ToString().c_str(),
153 auto timestamp = high_resolution_clock::now();
155 auto t1 = std::chrono::steady_clock::now();
160 auto t2 = std::chrono::steady_clock::now();
162 std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
165 if (iteration_counter % 100 == 0) {
166 auto timestamp_nanos =
167 duration_cast<nanoseconds>(timestamp.time_since_epoch()).count();
168 double timestamp_s =
static_cast<double>(timestamp_nanos) / 1e9;
171 "[%s]\tWrote to DP at time (epoch): %f. Iteration: %d.\tWrite "
172 "time [us]: min: %u max: %u mean: %.2f variance: %.2f",
173 m_dp.ToString().c_str(),
183 }
catch (
const std::exception& ex) {
185 "[%s ] Iteration: %d exception caught: %s!",
186 m_dp.ToString().c_str(),
189 if (error_counter++ > 5) {
192 "[%s] More than 5 consecutive exception caught. Writing to RTR stoped!",
193 m_dp.ToString().c_str());
198 "[%s ] Iteration: %d unknown exception caught!",
199 m_dp.ToString().c_str(),
201 if (error_counter++ > 5) {
204 "[%s] More than 5 consecutive exception caught. Writing to RTR stoped!",
205 m_dp.ToString().c_str());
214 "[%s] %u / %u values have been written. DONE!",
215 m_dp.ToString().c_str(),
220 "time [us]: min: %u max: %u med: %.2f variance: %.2f",
221 m_dp.ToString().c_str(),
230 const rtctk_cfw::DataPointPath& dp)
251 std::chrono::microseconds period,
252 uint32_t iterations) {
255 m_value = std::make_unique<rtctk_cfw::MatrixBuffer<T>>();
256 m_value->resize(dim_x, dim_y);
258 "[%s] Created matrix of size: %ld x %ld",
259 m_dp.ToString().c_str(),
262 m_payload_bytes = m_value->GetNrows() * m_value->GetNcols() *
sizeof(T);
267 "[%s] DP does not exist going to create one.",
268 m_dp.ToString().c_str());
269 m_rtr->CreateDataPoint<rtctk_cfw::MatrixBuffer<T>>(
m_dp, *m_value);
271 }
catch (
const std::exception& ex) {
277 "[%s] Going to delete DP after an error.",
278 m_dp.ToString().c_str());
281 CII_THROW_WITH_NESTED(
282 rtctk_cfw::RtctkException,
284 "[" +
m_dp.ToString() +
"] Problem creating DP and setting inital value");
287 LOG4CPLUS_DEBUG_FMT(
m_logger,
"[%s] DP exists.",
m_dp.ToString().c_str());
291 m_thread = std::thread(&GenRtrWriter::WriteDataPoint,
this);
log4cplus::Logger & GetLogger(const std::string &name="app")
Get handle to a specific logger.
Definition logger.cpp:192
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.