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

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...
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...

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
300 {
301RDM_RETCODE rc = sOKAY;
302
303if (n >= threshold && n > 0)
304 {
305 AGGREGATE_T scaled_aggregate = aggregate;
306
307for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
308 {
309 agg_scale (n, scaled_aggregate.value_range[i]);
310 }
311
312RDM_TRANS trans;
313
314if (transactional == RDM::DB::TRANSACTIONAL)
315 {
316 rc = rdm_dbStartUpdate (db, NULL, 0, NULL, 0, &trans);
317 }
318
319if (rc == sOKAY)
320 {
321 rc = next.put_range (&scaled_aggregate, RDM::DB::NOT_TRANSACTIONAL);
322if (rc == sOKAY)
323 {
324 n_just_before_last_flush = n;
325 rc = next.flush_range (threshold, RDM::DB::NOT_TRANSACTIONAL);
326if (rc == sOKAY)
327 {
328 n = 0;
329 }
330else
331 {
332 next.unput ();
333 }
334 }
335if (transactional == RDM::DB::TRANSACTIONAL)
336 {
337if (rc == sOKAY)
338 {
339 rc = rdm_transEnd (trans);
340 }
341else
342 {
344 }
345 }
346 }
347 }
348else
349 {
350if (n == 0)
351 {
352 n_just_before_last_flush = 0;
353 }
354 rc = next.flush_range (threshold, transactional);
355 }
356
357return rc;
358 }

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
215 {
216RDM_RETCODE rc = sOKAY;
217
218if (n >= threshold && n > 0)
219 {
220 AGGREGATE_T scaled_aggregate = aggregate;
221
222 agg_scale (n, scaled_aggregate.value_range[0]);
223
224RDM_TRANS trans;
225
226if (transactional == RDM::DB::TRANSACTIONAL)
227 {
228 rc = rdm_dbStartUpdate (db, NULL, 0, NULL, 0, &trans);
229 }
230
231if (rc == sOKAY)
232 {
233 rc = next.put_range (&scaled_aggregate, RDM::DB::NOT_TRANSACTIONAL);
234if (rc == sOKAY)
235 {
236 n_just_before_last_flush = n;
237 rc = next.flush_range (threshold, RDM::DB::NOT_TRANSACTIONAL);
238if (rc == sOKAY)
239 {
240 n = 0;
241 }
242else
243 {
244 next.unput ();
245 }
246 }
247if (transactional == RDM::DB::TRANSACTIONAL)
248 {
249if (rc == sOKAY)
250 {
251 rc = rdm_transEnd (trans);
252 }
253else
254 {
256 }
257 }
258 }
259 }
260else
261 {
262if (n == 0)
263 {
264 n_just_before_last_flush = 0;
265 }
266 rc = next.flush_range (threshold, transactional);
267 }
268
269return rc;
270 }

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

Here is the call graph for this function:

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 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
db [IN] Use this database for chained classes that need to insert rows
168 {
169RDM_RETCODE rc = next.init (db);
170 n = 0;
171
172return rc;
173 }

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
490 {
491RDM_RETCODE rc = sOKAY;
492
493 prev_aggregate = aggregate;
494
495if (n == 0)
496 {
497 aggregate.time_stamp_first =
498 source_range->time_stamp_first;
499for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
500 {
501 agg_set (source_range->value_range[i], aggregate.value_range[i]);
502 }
503 }
504else
505 {
506for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
507 {
508 agg_add (source_range->value_range[i], aggregate.value_range[i]);
509 }
510 }
511 aggregate.time_stamp_last =
512 source_range->time_stamp_last;
513
514if (n == N - 1)
515 {
516 AGGREGATE_T scaled_aggregate = aggregate;
517
518for (uint32_t i = 0; i < RDM_LEN(aggregate.value_range); i++)
519 {
520 agg_scale (N, scaled_aggregate.value_range[i]);
521 }
522
523 rc = next.put_range (&scaled_aggregate, transactional);
524if (rc == sOKAY)
525 {
526 n_just_before_last_put = n;
527 n = 0;
528 }
529else
530 {
531 aggregate = prev_aggregate;
532 }
533 }
534else
535 {
536 n++;
537 }
538
539return rc;
540 }

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
402 {
403RDM_RETCODE rc = sOKAY;
404
405 prev_aggregate = aggregate;
406
407if (n == 0)
408 {
409 aggregate.time_stamp_first =
410 source_value->time_stamp_current;
411 agg_set (source_value->value_current, aggregate.value_range[0]);
412 }
413else
414 {
415 agg_add (source_value->value_current, aggregate.value_range[0]);
416 }
417 aggregate.time_stamp_last =
418 source_value->time_stamp_current;
419
420if (n == N - 1)
421 {
422 AGGREGATE_T scaled_aggregate = aggregate;
423
424 agg_scale (N, scaled_aggregate.value_range[0]);
425
426 rc = next.put_range (&scaled_aggregate, transactional);
427if (rc == sOKAY)
428 {
429 n_just_before_last_put = n;
430 n = 0;
431 }
432else
433 {
434 aggregate = prev_aggregate;
435 }
436 }
437else
438 {
439 n++;
440 }
441
442return rc;
443 }

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.

182 {
183 next.reset ();
184 n = 0;
185 }

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:97
struct RDM_TRANS_S * RDM_TRANS
Definition: rdmtypes.h:307
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:78
@ TRANSACTIONAL
Definition: rdm_db_transaction.h:35
RDM_RETCODE
RDM status and error return codes.
Definition: rdmretcodetypes.h:43