Template Class for collecting data values into ranges. More...

#include "rdm_time_series_collect.h"

Public Member Functions

RDM_RETCODE init (RDM_DB 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...
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 value. More...

Protected Member Functions

uint32_t init_tables_to_write_lock (RDM_TABLE_ID *tables)
IDs of the tables where rows are inserted. More...
uint32_t init_tables_to_read_lock (RDM_TABLE_ID *tables)
IDs of the tables where rows are read. More...
void unput (void)
Undo a previous put operation. More...
void unflush (void)
Undo a previous flush operation. More...

Static Protected Member Functions

constexpr static int number_of_tables_to_write_lock (void)
Number of tables where rows are inserted. More...
constexpr static int number_of_tables_to_read_lock (void)
Number of tables where rows are read. More...

Protected Attributes

RANGE_T aggregate_range
uint32_t n

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 RANGE_T, class NEXT>
class RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >

Template Class for collecting data values into ranges.

What is received will be collected and used to produce ranges. The ranges will be forwarded to the next class in the chain.

Upon destruction of this class, there might be incomplete aggregations that have not yet been passed to the next class in the chain. flush() cannot be used to force those incomplete aggregations to be sent to the next class as this class needs to have exactly N values before passing them on to the next class in the chain. The proper approach may be to restore the state of this class the next time this class is instantiated. See restore_aggregate for details.

Template Parameters
N The number of data points for each range.
RANGE_T The aggregate FFT class for which objects will be passed to the next class.
INDATA_T The type of the data that is passed to this class.
NEXT The class in the chain to receive the result of the ranges.
Examples
time_series_range.cpp.

Member Function Documentation

flush_value()

template<uint32_t N, class RANGE_T , class NEXT >
RDM_RETCODE RDM::TIME_SERIES::collect< N, RANGE_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
202 {
203RDM_RETCODE rc = next.flush_range (threshold, transactional);
204
205return rc;
206 }

init()

template<uint32_t N, class RANGE_T , class NEXT >
RDM_RETCODE RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::init ( RDM_DB db )
inline

Initialize this object.

Call this method before sending it any data values 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
db [IN] Use this database for chained classes that need to insert rows
151 {
152RDM_RETCODE rc = next.init (db);
153
154if (rc == sOKAY)
155 {
156n = 0;
157 }
158
159return rc;
160 }

References RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::n, and sOKAY.

init_tables_to_read_lock()

template<uint32_t N, class RANGE_T , class NEXT >
uint32_t RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::init_tables_to_read_lock ( RDM_TABLE_ID * tables )
inlineprotected

IDs of the tables where rows are read.

Use this method to initialize an array of table IDs. This array can then be used to start a transaction where those tables are specified.

111 {
112return next.init_tables_to_read_lock (tables);
113 }

init_tables_to_write_lock()

template<uint32_t N, class RANGE_T , class NEXT >
uint32_t RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::init_tables_to_write_lock ( RDM_TABLE_ID * tables )
inlineprotected

IDs of the tables where rows are inserted.

Use this method to initialize an array of table IDs. This array can then be used to start a transaction where those tables are specified.

90 {
91return next.init_tables_to_write_lock (tables);
92 }

number_of_tables_to_read_lock()

template<uint32_t N, class RANGE_T , class NEXT >
constexpr static int RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::number_of_tables_to_read_lock ( void )
inlinestaticconstexprprotected

Number of tables where rows are read.

Constant expression method used to statically calculate the size of the array needed for table locking.

100 {
101return NEXT::number_of_tables_to_read_lock ();
102 }

number_of_tables_to_write_lock()

template<uint32_t N, class RANGE_T , class NEXT >
constexpr static int RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::number_of_tables_to_write_lock ( void )
inlinestaticconstexprprotected

Number of tables where rows are inserted.

Constant expression method used to statically calculate the size of the array needed for table locking.

79 {
80return NEXT::number_of_tables_to_write_lock ();
81 }

put_value()

template<uint32_t N, class RANGE_T , class NEXT >
template<class SOURCE_VALUE_T >
RDM_RETCODE RDM::TIME_SERIES::collect< N, RANGE_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 value.

Receive one data value and process it accordingly.

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
251 {
252RDM_RETCODE rc = sOKAY;
253
254if (n == 0)
255 {
256aggregate_range.time_stamp_first =
257 source_value->time_stamp_current;
258 }
259if (n == N - 1)
260 {
261aggregate_range.time_stamp_last =
262 source_value->time_stamp_current;
263 }
264
265aggregate_range.value_range[n] = source_value->value_current;
266
267if (n == N - 1)
268 {
269 rc = next.put_range (&aggregate_range, transactional);
270if (rc == sOKAY)
271 {
272n = 0;
273 }
274 }
275else
276 {
277n++;
278 }
279
280return rc;
281 }

References RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::aggregate_range, RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::n, and sOKAY.

reset()

template<uint32_t N, class RANGE_T , class NEXT >
void RDM::TIME_SERIES::collect< N, RANGE_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.

169 {
170 next.reset ();
171n = 0;
172 }

References RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::n.

unflush()

template<uint32_t N, class RANGE_T , class NEXT >
void RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::unflush ( void )
inlineprotected

Undo a previous flush operation.

133 {
134 next.unflush ();
135 }

unput()

template<uint32_t N, class RANGE_T , class NEXT >
void RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::unput ( void )
inlineprotected

Undo a previous put operation.

118 {
119if (n == 0)
120 {
121 next.unput ();
122n = N - 1;;
123 }
124else
125 {
126n--;
127 }
128 }

References RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::n.

Friends And Related Function Documentation

collect

template<uint32_t N, class RANGE_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 RANGE_T , class NEXT >
template<class ANY_NEXT >
friend class custom
friend

downsample

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

fft

template<uint32_t N, class RANGE_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 RANGE_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 RANGE_T , class NEXT >
template<class ANY_NEXT >
friend class RDM::DB::transaction
friend

scale

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

split

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

stats

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

Field Documentation

aggregate_range

template<uint32_t N, class RANGE_T , class NEXT >
RANGE_T RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::aggregate_range
protected

The aggregated FFTs are placed here

Referenced by RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::put_value().

n

template<uint32_t N, class RANGE_T , class NEXT >
uint32_t RDM::TIME_SERIES::collect< N, RANGE_T, NEXT >::n
protected

The documentation for this class was generated from the following files:
uint32_t n
Definition: rdm_time_series_collect.h:61
RANGE_T aggregate_range
Definition: rdm_time_series_collect.h:60
@ sOKAY
Definition: rdmretcodetypes.h:96
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:44