RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT > Class Template Referenceabstract

Template Class for doing an arithmetic mean. More...

#include "rdm_time_series_mean.h"

Inheritance diagram for RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >:
Inheritance graph

Public Member Functions

uint8_t * serialize (uint8_t *buffer)
uint8_t * unserialize (uint8_t *buffer)
RDM_RETCODE init (RDM_DB p_db)
Initialize this object. More...
void reset (void)
Reset this object. More...
RDM_RETCODE flush_value (uint32_t threshold=1, RDM::DB::TRANSACTIONAL_T transactional=RDM::DB::NOT_TRANSACTIONAL)
Flush this object. More...
RDM_RETCODE flush_range (uint32_t threshold=1, RDM::DB::TRANSACTIONAL_T transactional=RDM::DB::NOT_TRANSACTIONAL)
Flush this object. More...
template<class SOURCE_VALUE_T >
RDM_RETCODE put_value (SOURCE_VALUE_T *source_value, RDM::DB::TRANSACTIONAL_T transactional=RDM::DB::NOT_TRANSACTIONAL)
Template method for receiving a data values. More...
template<class SOURCE_AGGREGATE_T >
RDM_RETCODE put_range (SOURCE_AGGREGATE_T *source_range, RDM::DB::TRANSACTIONAL_T transactional=RDM::DB::NOT_TRANSACTIONAL)
Template method for receiving ranges. More...

Static Public Member Functions

constexpr static int get_serialize_size (void)
Get the size of a buffer for serialization to hold its state. More...

Friends

template<class ANY_NEXT >
class RDM::DB::transaction
template<class ANY_NEXT_1 , class ANY_NEXT_2 >
class split
template<uint32_t ANY_N, class ANY_RANGE_T , class ANY_NEXT >
class collect
template<uint32_t ANY_N, class ANY_RANGE_T , class ANY_INDATA_T , class ANY_NEXT >
class fft
template<uint32_t ANY_N, class ANY_AGGREGATE_T , class ANY_AGG_ELEMENT_T , class ANY_NEXT >
class mean
template<class ANY_RATIO , class ANY_NEXT >
class scale
template<uint32_t ANY_N, class ANY_STATS_T , class ANY_NEXT >
class stats
template<uint32_t ANY_N, class ANY_NEXT >
class downsample
template<class ANY_NEXT >
class custom

Detailed Description

template<uint32_t N, class AGGREGATE_T, class AGG_ELEMENT_T, class NEXT>
class RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >

Template Class for doing an arithmetic mean.

Template class for taking the arithmetic means of data values or ranges. What is received will be collected and used for taking arithmetic means. The result of those arithmetic means will be forwarded to the next class in the chain.

This class is incomplete as it does not have the code for doing the actual FFT computation. Use one of the following derived classes:

Template Parameters
N The number of receved RANGE calculations for each arithmetic mean.
AGGREGATE_T The aggregate range or stats class for which objects will be passed to the next class.
AGG_ELEMENT_T The type for the elements that must be aggregated to compute the mean.
NEXT The class in the chain to receive arithmetic means.

Member Function Documentation

flush_range()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
RDM_RETCODE RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::flush_range ( uint32_t threshold = 1,
RDM::DB::TRANSACTIONAL_T transactional = RDM::DB::NOT_TRANSACTIONAL
)
inline

Flush this object.

Call this method to flush what has been collected so far. A threshold can also be provided. All the data collected for those ranges will be kept as is. The same is the case where the threshold has not been reached.

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
threshold [IN] Only flush objects where at least this many elements have been collected
transactional [IN] Is the flush required to be transactional
353 {
354RDM_RETCODE rc = sOKAY;
355
356if (n >= threshold && n > 0)
357 {
358 AGGREGATE_T scaled_aggregate = aggregate;
359
360for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
361 {
362 agg_scale (n, scaled_aggregate.value_range[i]);
363 }
364
365RDM_TRANS trans{};
366
367if (transactional == RDM::DB::TRANSACTIONAL)
368 {
369 rc = rdm_dbStartUpdate (db, NULL, 0, NULL, 0, &trans);
370 }
371
372if (rc == sOKAY)
373 {
374 rc = next.put_range (&scaled_aggregate, RDM::DB::NOT_TRANSACTIONAL);
375if (rc == sOKAY)
376 {
377 n_just_before_last_flush = n;
378 rc = next.flush_range (threshold, RDM::DB::NOT_TRANSACTIONAL);
379if (rc == sOKAY)
380 {
381 n = 0;
382 }
383else
384 {
385 next.unput ();
386 }
387 }
388if (transactional == RDM::DB::TRANSACTIONAL)
389 {
390if (rc == sOKAY)
391 {
392 rc = rdm_transEnd (trans);
393 }
394else
395 {
397 }
398 }
399 }
400 }
401else
402 {
403if (n == 0)
404 {
405 n_just_before_last_flush = 0;
406 }
407 rc = next.flush_range (threshold, transactional);
408 }
409
410return rc;
411 }

References RDM::DB::NOT_TRANSACTIONAL, rdm_dbStartUpdate(), RDM_LEN, rdm_transEnd(), rdm_transEndRollback(), sOKAY, and RDM::DB::TRANSACTIONAL.

Here is the call graph for this function:

flush_value()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
RDM_RETCODE RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::flush_value ( uint32_t threshold = 1,
RDM::DB::TRANSACTIONAL_T transactional = RDM::DB::NOT_TRANSACTIONAL
)
inline

Flush this object.

Call this method to flush what has been collected so far. A threshold can also be provided. All the data collected for those values will be kept as is. The same is the case where the threshold has not been reached.

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
threshold [IN] Only flush objects where at least this many elements have been collected
transactional [IN] Is the flush required to be transactional
268 {
269RDM_RETCODE rc = sOKAY;
270
271if (n >= threshold && n > 0)
272 {
273 AGGREGATE_T scaled_aggregate = aggregate;
274
275 agg_scale (n, scaled_aggregate.value_range[0]);
276
277RDM_TRANS trans{};
278
279if (transactional == RDM::DB::TRANSACTIONAL)
280 {
281 rc = rdm_dbStartUpdate (db, NULL, 0, NULL, 0, &trans);
282 }
283
284if (rc == sOKAY)
285 {
286 rc = next.put_range (&scaled_aggregate, RDM::DB::NOT_TRANSACTIONAL);
287if (rc == sOKAY)
288 {
289 n_just_before_last_flush = n;
290 rc = next.flush_range (threshold, RDM::DB::NOT_TRANSACTIONAL);
291if (rc == sOKAY)
292 {
293 n = 0;
294 }
295else
296 {
297 next.unput ();
298 }
299 }
300if (transactional == RDM::DB::TRANSACTIONAL)
301 {
302if (rc == sOKAY)
303 {
304 rc = rdm_transEnd (trans);
305 }
306else
307 {
309 }
310 }
311 }
312 }
313else
314 {
315if (n == 0)
316 {
317 n_just_before_last_flush = 0;
318 }
319 rc = next.flush_range (threshold, transactional);
320 }
321
322return rc;
323 }

References RDM::DB::NOT_TRANSACTIONAL, rdm_dbStartUpdate(), rdm_transEnd(), rdm_transEndRollback(), sOKAY, and RDM::DB::TRANSACTIONAL.

Here is the call graph for this function:

get_serialize_size()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
constexpr static int RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::get_serialize_size ( void )
inlinestaticconstexpr

Get the size of a buffer for serialization to hold its state.

Get the size needed for a buffer to hold the state of this object.

162 {
163return sizeof(prev_aggregate) + sizeof(aggregate) + sizeof(n) + sizeof(n_just_before_last_put) + sizeof(n_just_before_last_flush) + NEXT::get_serialize_size ();
164 }

init()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
RDM_RETCODE RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::init ( RDM_DB p_db )
inline

Initialize this object.

Call this method before sending it any ranges or statistics.

Return values
sOKAY Normal, successful return.
eINVARG Invalid argument.
eDBNOTOPEN Database not open.
eCURSORDB Cursor is associated with a different database.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
Parameters
p_db [IN] Use this database for chained classes that need to insert rows
221 {
222RDM_RETCODE rc = next.init (p_db);
223 n = 0;
224
225return rc;
226 }

put_range()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<class SOURCE_AGGREGATE_T >
RDM_RETCODE RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::put_range ( SOURCE_AGGREGATE_T * source_range,
RDM::DB::TRANSACTIONAL_T transactional = RDM::DB::NOT_TRANSACTIONAL
)
inline

Template method for receiving ranges.

Receive one range and process it accordingly.

The type for the value provided is required to have columns for 'time_stamp_first', 'time_stamp_last', and 'value_range' with appropriate types. The column 'value_range' must be an array that is able to hold a static number of elements. Such a type can be generated using rdm-compile with a schema including a table similar to this:

CREATE TABLE range
(
value_range DOUBLE ARRAY [32] NOT NULL,
time_stamp_first UINT64 NOT NULL,
time_stamp_last UINT64 PRIMARY KEY
);

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Template Parameters
SOURCE_AGGREGATE_T The actual type of the range received.
Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
[in] source_range The source range sent to this class
transactional [IN] Is the put required to be transactional
543 {
544RDM_RETCODE rc = sOKAY;
545
546 prev_aggregate = aggregate;
547
548if (n == 0)
549 {
550 aggregate.time_stamp_first =
551 source_range->time_stamp_first;
552for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
553 {
554 agg_set (source_range->value_range[i], aggregate.value_range[i]);
555 }
556 }
557else
558 {
559for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
560 {
561 agg_add (source_range->value_range[i], aggregate.value_range[i]);
562 }
563 }
564 aggregate.time_stamp_last =
565 source_range->time_stamp_last;
566
567if (n == N - 1)
568 {
569 AGGREGATE_T scaled_aggregate = aggregate;
570
571for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
572 {
573 agg_scale (N, scaled_aggregate.value_range[i]);
574 }
575
576 rc = next.put_range (&scaled_aggregate, transactional);
577if (rc == sOKAY)
578 {
579 n_just_before_last_put = n;
580 n = 0;
581 }
582else
583 {
584 aggregate = prev_aggregate;
585 }
586 }
587else
588 {
589 n++;
590 }
591
592return rc;
593 }

References RDM_LEN, and sOKAY.

put_value()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<class SOURCE_VALUE_T >
RDM_RETCODE RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::put_value ( SOURCE_VALUE_T * source_value,
RDM::DB::TRANSACTIONAL_T transactional = RDM::DB::NOT_TRANSACTIONAL
)
inline

Template method for receiving a data values.

Receive one data value and return an error.

The type for the value provided is required to have columns for 'time_stamp_current' and 'value_current' with appropriate types. Such a type can be generated using rdm-compile with a schema including a table similar to this:

CREATE TABLE measurement
(
time_stamp_current UINT64 PRIMARY KEY,
value_current DOUBLE NOT NULL
);

This operation can be specified as being transactional. However, if the caller always rolls back the transaction in the case of a failure, there is no need to specify single operations to be transactional.

Template Parameters
SOURCE_VALUE_T The actual type of the source values received
Return values
sOKAY Normal, successful return.
eNOSTARTUPDATE An update operation was attempted when no rdm_dbStartUpdate() is active.
eNOTLOCKED Attempt to access a table for reading or update without proper locks.
eCURSORDB Cursor is associated with a different database.
eDBNOTOPEN Database not open.
ePRECOMMITTED A precommitted transaction must be committed or rolled back before further operations on this database are allowed.
eDUPLICATE Attempt to insert a duplicate value as a unique/primary key.
eREADONLY Database is read-only and cannot be updated.
eREFINTEGRITY Integrity constraint violation.
eROWLIMIT Table row limit reached.
eINVARG Invalid argument.
Parameters
[in] source_value The source value sent to this class
transactional [IN] Is the put required to be transactional
455 {
456RDM_RETCODE rc = sOKAY;
457
458 prev_aggregate = aggregate;
459
460if (n == 0)
461 {
462 aggregate.time_stamp_first =
463 source_value->time_stamp_current;
464 agg_set (source_value->value_current, aggregate.value_range[0]);
465 }
466else
467 {
468 agg_add (source_value->value_current, aggregate.value_range[0]);
469 }
470 aggregate.time_stamp_last =
471 source_value->time_stamp_current;
472
473if (n == N - 1)
474 {
475 AGGREGATE_T scaled_aggregate = aggregate;
476
477 agg_scale (N, scaled_aggregate.value_range[0]);
478
479 rc = next.put_range (&scaled_aggregate, transactional);
480if (rc == sOKAY)
481 {
482 n_just_before_last_put = n;
483 n = 0;
484 }
485else
486 {
487 aggregate = prev_aggregate;
488 }
489 }
490else
491 {
492 n++;
493 }
494
495return rc;
496 }

References sOKAY.

reset()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
void RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::reset ( void )
inline

Reset this object.

Call this method to discard all internally kept data values, ranges, and statistics that have not yet been persisted and start over from scratch.

235 {
236 next.reset ();
237 n = 0;
238 }

serialize()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
uint8_t* RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::serialize ( uint8_t * buffer )
inline
173 {
174 memcpy (buffer, &prev_aggregate, sizeof (prev_aggregate));
175 buffer += sizeof (prev_aggregate);
176 memcpy (buffer, &aggregate, sizeof (aggregate));
177 buffer += sizeof (aggregate);
178 memcpy (buffer, &n, sizeof (n));
179 buffer += sizeof (n);
180 memcpy (buffer, &n_just_before_last_put, sizeof (n_just_before_last_put));
181 buffer += sizeof (n_just_before_last_put);
182 memcpy (buffer, &n_just_before_last_flush, sizeof (n_just_before_last_flush));
183 buffer += sizeof (n_just_before_last_flush);
184return next.serialize (buffer);
185 }

unserialize()

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
uint8_t* RDM::TIME_SERIES::mean< N, AGGREGATE_T, AGG_ELEMENT_T, NEXT >::unserialize ( uint8_t * buffer )
inline
194 {
195 memcpy (&prev_aggregate, buffer, sizeof (prev_aggregate));
196 buffer += sizeof (prev_aggregate);
197 memcpy (&aggregate, buffer, sizeof (aggregate));
198 buffer += sizeof (aggregate);
199 memcpy (&n, buffer, sizeof (n));
200 buffer += sizeof (n);
201 memcpy (&n_just_before_last_put, buffer, sizeof (n_just_before_last_put));
202 buffer += sizeof (n_just_before_last_put);
203 memcpy (&n_just_before_last_flush, buffer, sizeof (n_just_before_last_flush));
204 buffer += sizeof (n_just_before_last_flush);
205return next.unserialize (buffer);
206 }

Friends And Related Function Documentation

collect

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<uint32_t ANY_N, class ANY_RANGE_T , class ANY_NEXT >
friend class collect
friend

custom

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<class ANY_NEXT >
friend class custom
friend

downsample

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<uint32_t ANY_N, class ANY_NEXT >
friend class downsample
friend

fft

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<uint32_t ANY_N, class ANY_RANGE_T , class ANY_INDATA_T , class ANY_NEXT >
friend class fft
friend

mean

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<uint32_t ANY_N, class ANY_AGGREGATE_T , class ANY_AGG_ELEMENT_T , class ANY_NEXT >
friend class mean
friend

RDM::DB::transaction

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<class ANY_NEXT >
friend class RDM::DB::transaction
friend

scale

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<class ANY_RATIO , class ANY_NEXT >
friend class scale
friend

split

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<class ANY_NEXT_1 , class ANY_NEXT_2 >
friend class split
friend

stats

template<uint32_t N, class AGGREGATE_T , class AGG_ELEMENT_T , class NEXT >
template<uint32_t ANY_N, class ANY_STATS_T , class ANY_NEXT >
friend class stats
friend

The documentation for this class was generated from the following files:
RDM_RETCODE rdm_transEnd(RDM_TRANS trans)
End a transactional operation.
@ NOT_TRANSACTIONAL
Definition: rdm_db_transaction.h:36
RDM_RETCODE rdm_transEndRollback(RDM_TRANS trans)
End a transactional operation with a rollback.
@ sOKAY
Definition: rdmretcodetypes.h:100
struct RDM_TRANS_S * RDM_TRANS
Definition: rdmtypes.h:328
enum RDM_RETCODE_E RDM_RETCODE
RaimaDB status and error return codes.
RDM_RETCODE rdm_dbStartUpdate(RDM_DB db, const RDM_TABLE_ID *writeTableIds, uint32_t numWriteTableIds, const RDM_TABLE_ID *readTableIds, uint32_t numReadTableIds, RDM_TRANS *pTrans)
Get write locks.
#define RDM_LEN(x)
Definition: psptypes.h:106
@ TRANSACTIONAL
Definition: rdm_db_transaction.h:35