CARMA C++
MonitorPointAverageT.h
Go to the documentation of this file.
1 #ifndef CARMA_MONITOR_MONITORPOINTAVERAGET_H
2 #define CARMA_MONITOR_MONITORPOINTAVERAGET_H
3 
4 /*
5  * MonitorPointAverageT.h - Template file for monitor point average
6  * values of various types.
7  */
8 
23 #include "carma/monitor/types.h"
25 
26 
27 namespace carma {
28 namespace monitor {
29 
30 
37 struct AveProperties {
43  int nValidSamples; // # of samples not marked invalid in some fashion
44 
51  int nTotalSamples; // total # of samples for this monitor point
52 
59 
65  // cumulative blanking for all valid samples
67 };
68 
69 
70 class MonitorPointAverageBase {
71  public:
72 
78  int getNumTotalSamples( ) const;
79 
85  void setNumTotalSamples( int nTotalSamples );
86 
92  void incrementNumTotalSamples( int nTotalSamples = 1 );
93 
99  int getNumValidSamples( ) const;
100 
106  void setNumValidSamples( int nValidSamples );
107 
113  void incrementNumValidSamples( int nValidSamples = 1 );
114 
120  enum MonitorPoint::VALIDITY getValidity( ) const;
121 
127  void setValidity( enum MonitorPoint::VALIDITY validity );
128 
129 
135  enum MonitorPoint::BLANKING_FLAGGING getBlanking( ) const;
136 
142  void setBlanking( enum MonitorPoint::BLANKING_FLAGGING blanking );
143 
144  ushort getDbBlanking( ) const;
145 
146  ushort getDbValidity( ) const;
147 
148  void writeAvePropsToFile( FILE * f ) const;
149 
150  void writeAvePropsToBuf( char * c ) const;
151 
157  void resetAveProperties( );
158 
159  protected:
160 
161  MonitorPointAverageBase( );
162 
163  ~MonitorPointAverageBase( ); // no v-table
164 
165  private:
166  class TableInit;
167 
168  static ushort gBfToDbTable_[ MonitorPoint::MAX_BLANKING_FLAGGING ];
169  static ushort gValToDbTable_[ MonitorPoint::MAX_VALIDITY ];
170 
171  static char gBfToDbFileTable_[ MonitorPoint::MAX_BLANKING_FLAGGING ][4];
172  static char gValToDbFileTable_[ MonitorPoint::MAX_VALIDITY ][4];
173 
174  AveProperties properties_;
175 };
176 
177 
189 template < typename U >
190 class MonitorPointAverageT : public MonitorPointAverageBase {
191  public:
192 
199  MonitorPointAverageT( const U & initialValue,
200  const U & max,
201  const U & min );
202 
211 
217  ~MonitorPointAverageT( ); // no v-table
218 
219 
225  U getAccumulator( ) const;
226 
232  void setAccumulator( const U & value );
233 
239  void incrementAccumulator(const U& value);
240 
241 
247  U getMaxValue( ) const;
248 
254  void setMaxValue( const U & value );
255 
256 
262  U getMinValue( ) const;
263 
269  void setMinValue( const U & value );
270 
271 
272  private:
273  U accumulator_;
274  U maxValue_;
275  U minValue_;
276 }; // template MonitorPointAverageT
277 
278 
279 } // end namespace monitor
280 } // end namespace carma
281 
282 
283 inline
284 carma::monitor::MonitorPointAverageBase::MonitorPointAverageBase( )
285 {
286  resetAveProperties();
287 }
288 
289 
290 inline
291 carma::monitor::MonitorPointAverageBase::~MonitorPointAverageBase( )
292 {
293 }
294 
295 
296 inline void
297 carma::monitor::MonitorPointAverageBase::resetAveProperties( )
298 {
299  properties_.nTotalSamples = 0;
300  properties_.nValidSamples = 0;
301  properties_.validity = MonitorPoint::INVALID_NO_DATA;
302  properties_.blanking = MonitorPoint::UNDETERMINED;
303 }
304 
305 
306 inline int
307 carma::monitor::MonitorPointAverageBase::getNumTotalSamples( ) const
308 {
309  return properties_.nTotalSamples;
310 }
311 
312 
313 inline void
314 carma::monitor::MonitorPointAverageBase::setNumTotalSamples(
315  const int nTotalSamples )
316 {
317  properties_.nTotalSamples = nTotalSamples;
318 }
319 
320 
321 inline void
322 carma::monitor::MonitorPointAverageBase::incrementNumTotalSamples(
323  const int nTotalSamples )
324 {
325  properties_.nTotalSamples += nTotalSamples;
326 }
327 
328 
329 
330 inline int
331 carma::monitor::MonitorPointAverageBase::getNumValidSamples( ) const
332 {
333  return properties_.nValidSamples;
334 }
335 
336 
337 inline void
338 carma::monitor::MonitorPointAverageBase::setNumValidSamples(
339  const int nValidSamples )
340 {
341  properties_.nValidSamples = nValidSamples;
342 }
343 
344 
345 inline void
346 carma::monitor::MonitorPointAverageBase::incrementNumValidSamples(
347  const int nValidSamples )
348 {
349  properties_.nValidSamples += nValidSamples;
350 }
351 
352 
354 carma::monitor::MonitorPointAverageBase::getValidity( ) const
355 {
356  return properties_.validity;
357 }
358 
359 
360 inline void
361 carma::monitor::MonitorPointAverageBase::setValidity(
362  const enum MonitorPoint::VALIDITY validity )
363 {
364  properties_.validity = validity;
365 }
366 
367 
368 
370 carma::monitor::MonitorPointAverageBase::getBlanking( ) const
371 {
372  return properties_.blanking;
373 }
374 
375 
376 inline void
377 carma::monitor::MonitorPointAverageBase::setBlanking(
378  const enum MonitorPoint::BLANKING_FLAGGING blanking )
379 {
380  properties_.blanking = blanking;
381 }
382 
383 
384 inline ushort
385 carma::monitor::MonitorPointAverageBase::getDbBlanking( ) const
386 {
387  const int bf = properties_.blanking;
388 
389  if ( (bf >= 0) && (bf < MonitorPoint::MAX_BLANKING_FLAGGING) )
390  return gBfToDbTable_[ bf ];
391 
392  return gBfToDbTable_[ MonitorPoint::UNDETERMINED ];
393 }
394 
395 
396 inline ushort
397 carma::monitor::MonitorPointAverageBase::getDbValidity( ) const
398 {
399  const int val = properties_.validity;
400 
401  if ( (val >= 0) && (val < MonitorPoint::MAX_VALIDITY) )
402  return gValToDbTable_[ val ];
403 
404  return gValToDbTable_[ MonitorPoint::INVALID_NO_DATA ];
405 }
406 
407 
408 inline void
409 carma::monitor::MonitorPointAverageBase::writeAvePropsToFile( FILE * f ) const
410 {
411  {
412  const int bf = properties_.blanking;
413 
414  const char * sBf;
415  if ( (bf >= 0) && (bf < MonitorPoint::MAX_BLANKING_FLAGGING) )
416  sBf = gBfToDbFileTable_[ bf ];
417  else
418  sBf = gBfToDbFileTable_[ MonitorPoint::UNDETERMINED ];
419 
420  fputs( sBf, f );
421  }
422 
423  {
424  const int val = properties_.validity;
425 
426  const char * sVal;
427  if ( (val >= 0) && (val < MonitorPoint::MAX_VALIDITY) )
428  sVal = gValToDbFileTable_[ val ];
429  else
430  sVal = gValToDbFileTable_[ MonitorPoint::INVALID_NO_DATA ];
431 
432  fputs( sVal, f );
433  }
434 }
435 
436 
437 inline void
438 carma::monitor::MonitorPointAverageBase::writeAvePropsToBuf( char * c ) const
439 {
440  {
441  const int bf = properties_.blanking;
442 
443  const char * sBf;
444  if ( (bf >= 0) && (bf < MonitorPoint::MAX_BLANKING_FLAGGING) )
445  sBf = gBfToDbFileTable_[ bf ];
446  else
447  sBf = gBfToDbFileTable_[ MonitorPoint::UNDETERMINED ];
448 
449  c[0] = sBf[0];
450  c[1] = sBf[1];
451  c[2] = sBf[2];
452  }
453 
454  {
455  const int val = properties_.validity;
456 
457  const char * sVal;
458  if ( (val >= 0) && (val < MonitorPoint::MAX_VALIDITY) )
459  sVal = gValToDbFileTable_[ val ];
460  else
461  sVal = gValToDbFileTable_[ MonitorPoint::INVALID_NO_DATA ];
462 
463  c[3] = sVal[0];
464  c[4] = sVal[1];
465  c[5] = sVal[2];
466  }
467 
468  c[6] = '\0';
469 }
470 
471 
472 template< typename U >
473 inline
475  const U & initialValue,
476  const U & max,
477  const U & min ) :
478 accumulator_( initialValue ),
479 maxValue_( max ),
480 minValue_( min )
481 {
482 }
483 
484 
485 template< typename U >
486 inline
488 {
489 }
490 
491 
492 template< typename U >
493 inline U
495 {
496  return accumulator_ ;
497 }
498 
499 
500 template< typename U >
501 inline void
503 {
504  accumulator_ = value;
505 }
506 
507 template< typename U >
508 inline void
510 {
511  accumulator_ += value;
512 }
513 
514 
515 template< typename U >
516 inline U
518 {
519  return maxValue_ ;
520 }
521 
522 
523 template< typename U >
524 inline void
526 {
527  maxValue_ = value;
528 }
529 
530 
531 template< typename U >
532 inline U
534 {
535  return minValue_ ;
536 }
537 
538 
539 template< typename U >
540 inline void
542 {
543  minValue_ = value;
544 }
545 
546 
547 // Specialize the default constructor to do the right thing for each type we
548 // care about
549 
550 namespace carma {
551 namespace monitor {
552 
553 template< >
554 inline
557 accumulator_(),
558 maxValue_(),
559 minValue_()
560 {
561 }
562 
563 
564 template< >
565 inline
568 accumulator_( false ),
569 maxValue_( false ),
570 minValue_( false )
571 {
572 }
573 
574 
575 template< >
576 inline
579 accumulator_( 0 ),
580 maxValue_( 0 ),
581 minValue_( 0 )
582 {
583 }
584 
585 
586 template< >
587 inline
590 accumulator_( 0 ),
591 maxValue_( 0 ),
592 minValue_( 0 )
593 {
594 }
595 
596 
597 template< >
598 inline
601 accumulator_( 0 ),
602 maxValue_( 0 ),
603 minValue_( 0 )
604 {
605 }
606 
607 
608 template< >
609 inline
612 accumulator_( 0 ),
613 maxValue_( 0 ),
614 minValue_( 0 )
615 {
616 }
617 
618 
619 template< >
620 inline
623 accumulator_( 0 ),
624 maxValue_( 0 ),
625 minValue_( 0 )
626 {
627 }
628 
629 
630 template< >
631 inline
634 accumulator_( 0 ),
635 maxValue_( 0 ),
636 minValue_( 0 )
637 {
638 }
639 
640 
641 template< >
642 inline
645 accumulator_( 0 ),
646 maxValue_( 0 ),
647 minValue_( 0 )
648 {
649 }
650 
651 
652 template< >
653 inline
656 accumulator_( 0 ),
657 maxValue_( 0 ),
658 minValue_( 0 )
659 {
660 }
661 
662 
663 template< >
664 inline
667 accumulator_( 0 ),
668 maxValue_( 0 ),
669 minValue_( 0 )
670 {
671 }
672 
673 
674 template< >
675 inline
678 accumulator_( 0 ),
679 maxValue_( 0 ),
680 minValue_( 0 )
681 {
682 }
683 
684 
685 template< >
686 inline
689 accumulator_( 0.0 ),
690 maxValue_( 0.0 ),
691 minValue_( 0.0 )
692 {
693 }
694 
695 
696 template< >
697 inline
700 accumulator_( 0.0 ),
701 maxValue_( 0.0 ),
702 minValue_( 0.0 )
703 {
704 }
705 
706 
707 template< >
708 inline
711 accumulator_( 0.0 ),
712 maxValue_( 0.0 ),
713 minValue_( 0.0 )
714 {
715 }
716 
717 
718 template< >
719 inline
721  MonitorPointAverageT( ) :
722 accumulator_( 0.0 ),
723 maxValue_( 0.0 ),
724 minValue_( 0.0 )
725 {
726 }
727 
728 
729 template< >
730 inline
732  MonitorPointAverageT( ) :
733 accumulator_( 0.0 ),
734 maxValue_( 0.0 ),
735 minValue_( 0.0 )
736 {
737 }
738 
739 
740 template< >
741 inline
743  MonitorPointAverageT( ) :
744 accumulator_( 0.0 ),
745 maxValue_( 0.0 ),
746 minValue_( 0.0 )
747 {
748 }
749 
750 
751 }} // namespace carma::monitor
752 #endif
VALIDITY
Validity states of the data value.
Definition: MonitorPoint.h:132
MonitorPointAverageT()
Default constructor - sets all values to zero using template specialization to do it appropriately...
Abstract base class for all monitor points.
void setMinValue(const U &value)
Set minimum across all accumulated samples.
BLANKING_FLAGGING
Blanking/flagging status of the data.
Definition: MonitorPoint.h:159
Structure keeps track of sample properties of a monitor point for the purposes of calculating various...
U getMinValue() const
Get minimum value across all accumulated samples.
int nValidSamples
of samples not marked invalid in some fashion
enum MonitorPoint::VALIDITY validity
Cumulative validity for all valid samples.
U getMaxValue() const
Get maximum of sample values.
void setAccumulator(const U &value)
Set cumulative value of samples.
void setMaxValue(const U &value)
Set maximum sample value.
void incrementAccumulator(const U &value)
Increment cumulative value of samples.
enum MonitorPoint::BLANKING_FLAGGING blanking
Cumulative blanking for all valid samples.
Template for collecting data for computing average associated with one monitor point.
~MonitorPointAverageT()
Destructor - Doesnt do anything by default as the compiler takes care of deleting component members...
U getAccumulator() const
Get cumulative value of samples.
type definitions for monitor system
int nTotalSamples
total # of samples associated with a monitor point - half of sampling frequency for that monitor poin...