1 #ifndef CARMA_MONITOR_ACCUMULATORT_H
2 #define CARMA_MONITOR_ACCUMULATORT_H
33 class MonitorPointAccumulatorBase {
35 static void valueToFile(
const bool & avgAcc,
38 static void valueToFile( const ::std::complex< float > & avgAcc,
41 static void valueToFile(
const double & avgAcc,
44 static void valueToFile(
const float & avgAcc,
47 static void valueToFile(
const int & avgAcc,
50 static void valueToFile(
const long & avgAcc,
53 static void valueToFile(
const short & avgAcc,
56 static void valueToFile( const ::std::string & avgAcc,
59 static void valueToFileThrice(
const bool & avgAcc,
62 static void valueToFileThrice( const ::std::complex< float > & avgAcc,
65 static void valueToFileThrice(
const double & avgAcc,
68 static void valueToFileThrice(
const float & avgAcc,
71 static void valueToFileThrice(
const int & avgAcc,
74 static void valueToFileThrice(
const long & avgAcc,
77 static void valueToFileThrice(
const short & avgAcc,
80 static void valueToFileThrice( const ::std::string & avgAcc,
83 static void cstringToFileThrice(
const char * b,
100 template <
typename T,
typename U >
154 const typename T::AccumReportType
getAverage(
int index = 0 )
const;
199 carma::dbms::dbFFIO & file )
const;
208 FILE *
const file )
const;
212 typedef ::std::vector< MonitorPointAverageT< U > > AverageVec;
215 AverageVec averageVec_;
224 carma::monitor::MonitorPointAccumulatorBase::
225 cstringToFileThrice(
const char *
const b,
237 carma::monitor::MonitorPointAccumulatorBase::
238 valueToFile(
const bool & v,
241 fprintf( file,
"%2d", v );
246 carma::monitor::MonitorPointAccumulatorBase::
247 valueToFileThrice(
const bool & v,
252 sprintf( b,
"%2d", v );
254 cstringToFileThrice( b, file );
259 carma::monitor::MonitorPointAccumulatorBase::
260 valueToFile( const ::std::complex< float > & v,
263 fprintf( file,
"%15.8e\t%15.8e", v.real(), v.imag() );
268 carma::monitor::MonitorPointAccumulatorBase::
269 valueToFileThrice( const ::std::complex< float > & v,
274 sprintf( b,
"%15.8e\t%15.8e", v.real(), v.imag() );
276 cstringToFileThrice( b, file );
281 carma::monitor::MonitorPointAccumulatorBase::
282 valueToFile(
const double & v,
285 fprintf( file,
"%23.16e", v );
290 carma::monitor::MonitorPointAccumulatorBase::
291 valueToFileThrice(
const double & v,
296 sprintf( b,
"%23.16e", v );
298 cstringToFileThrice( b, file );
303 carma::monitor::MonitorPointAccumulatorBase::
304 valueToFile(
const float & v,
307 fprintf( file,
"%15.8e", v );
312 carma::monitor::MonitorPointAccumulatorBase::
313 valueToFileThrice(
const float & v,
318 sprintf( b,
"%15.8e", v );
320 cstringToFileThrice( b, file );
325 carma::monitor::MonitorPointAccumulatorBase::
326 valueToFile(
const int & v,
329 fprintf( file,
"%12d", v );
334 carma::monitor::MonitorPointAccumulatorBase::
335 valueToFileThrice(
const int & v,
340 sprintf( b,
"%12d", v );
342 cstringToFileThrice( b, file );
347 carma::monitor::MonitorPointAccumulatorBase::
348 valueToFile(
const long & v,
351 fprintf( file,
"%12ld", v );
356 carma::monitor::MonitorPointAccumulatorBase::
357 valueToFileThrice(
const long & v,
362 sprintf( b,
"%12ld", v );
364 cstringToFileThrice( b, file );
369 carma::monitor::MonitorPointAccumulatorBase::
370 valueToFile(
const short & v,
373 fprintf( file,
"%7d", v );
378 carma::monitor::MonitorPointAccumulatorBase::
379 valueToFileThrice(
const short & v,
384 sprintf( b,
"%7d", v );
386 cstringToFileThrice( b, file );
391 carma::monitor::MonitorPointAccumulatorBase::
392 valueToFile( const ::std::string & v,
395 fputs( v.c_str(), file );
400 carma::monitor::MonitorPointAccumulatorBase::
401 valueToFileThrice( const ::std::string & v,
404 cstringToFileThrice( v.c_str(), file );
408 template <
typename T,
typename U >
412 typedPoint_( &typedPoint ),
415 size_t numAccumulators;
417 if ( typedPoint_->isTimeSeries() )
420 numAccumulators = ::std::max( 1, typedPoint_->getNumSamples() );
422 averageVec_.resize( numAccumulators );
428 template <
typename T,
typename U >
435 template <
typename T,
typename U >
440 ::std::swap( typedPoint_, rhs.typedPoint_ );
441 averageVec_.swap( rhs.averageVec_ );
445 template <
typename T,
typename U >
449 typename AverageVec::iterator i = averageVec_.begin();
450 const typename AverageVec::iterator iEnd = averageVec_.end();
452 for ( ; i != iEnd; ++i )
453 typedPoint_->resetAccumulator( *i );
457 template <
typename T,
typename U >
461 typename AverageVec::iterator i = averageVec_.begin();
462 const typename AverageVec::iterator iEnd = averageVec_.end();
464 if ( typedPoint_->isTimeSeries() ) {
465 for ( ; i != iEnd; ++i )
466 typedPoint_->accumulate( *i );
468 for (
int averageIndex = 0; i != iEnd; ++i, ++averageIndex )
469 typedPoint_->accumulateSample( *i, averageIndex );
474 template <
typename T,
typename U >
478 typename AverageVec::iterator i = averageVec_.begin();
479 const typename AverageVec::iterator iEnd = averageVec_.end();
481 if ( typedPoint_->isTimeSeries() ) {
482 for ( ; i != iEnd; ++i )
483 typedPoint_->accumulateAverage( *i );
485 for (
int averageIndex = 0; i != iEnd; ++i, ++averageIndex )
486 typedPoint_->accumulateSample( *i, averageIndex );
491 template <
typename T,
typename U >
492 inline const typename T::AccumReportType
494 const int index )
const
496 return typedPoint_->getAccumulatedAverage( averageVec_[ index ] );
500 template <
typename T,
typename U >
505 return (typedPoint_->getTagID() == rhs.getTagID());
509 template <
typename T,
typename U >
514 return (typedPoint_->getTagID() < rhs.getTagID());
518 template <
typename T,
typename U >
521 const long frameCount,
522 FILE *
const file )
const
524 const tagIDType tagID = typedPoint_->getTagID();
525 const bool isNotString =
526 (typedPoint_->getValuetype() != MONITOR_VALUE_TYPE_STRING);
528 typename AverageVec::const_iterator i = averageVec_.begin();
529 const typename AverageVec::const_iterator iEnd = averageVec_.end();
531 for (
int averageIndex = 0; i != iEnd; ++i, ++averageIndex ) {
532 fprintf( file,
"%11ld\t%11ld\t", frameCount, tagID );
534 i->writeAvePropsToFile( file );
536 valueToFile( typedPoint_->getAccumulatedAverage( *i ), file );
540 fprintf( file,
"\t%2d", averageIndex );
548 template <
typename T,
typename U >
551 const long frameCount,
552 carma::dbms::dbFFIO & file )
const
554 const long fc = frameCount;
555 const long tid = typedPoint_->getTagID();
557 typename AverageVec::const_iterator i = averageVec_.begin();
558 const typename AverageVec::const_iterator iEnd = averageVec_.end();
560 for (
int averageIndex = 0; i != iEnd; ++i, ++averageIndex ) {
561 const ushort blanking = i->getDbBlanking();
562 const ushort validity = i->getDbValidity();
564 file.dumpInstAverage( fc,
568 typedPoint_->getAccumulatedAverage( *i ),
574 template <
typename T,
typename U >
577 const char *
const frameCountText,
578 FILE *
const file )
const
580 char numTotalSampsText[ 16 ];
581 char tagIdText[ 16 ];
583 const bool isString =
584 (typedPoint_->getValuetype() == MONITOR_VALUE_TYPE_STRING);
586 sprintf( tagIdText,
"\t%11ld\t", typedPoint_->getTagID() );
588 typename AverageVec::const_iterator i = averageVec_.begin();
589 const typename AverageVec::const_iterator iEnd = averageVec_.end();
591 for (
int averageIndex = 0; i != iEnd; ++i, ++averageIndex ) {
592 fputs( frameCountText, file );
593 fputs( tagIdText, file );
595 i->writeAvePropsToFile( file );
599 valueToFile( typedPoint_->getAccumulatedAverage( *i ),
602 const typename T::AccumReportType avgVal =
603 typedPoint_->getAccumulatedAverage( *i );
605 const typename T::AccumReportType maxVal =
606 typedPoint_->getMaxValue( *i );
608 const typename T::AccumReportType minVal =
609 typedPoint_->getMinValue( *i );
611 if ( (avgVal == maxVal) && (avgVal == minVal) )
612 valueToFileThrice( avgVal, file );
614 valueToFile( avgVal, file );
616 valueToFile( maxVal, file );
618 valueToFile( minVal, file );
621 if ( averageIndex == 0 )
622 fputs(
"\t 0", file );
624 fprintf( file,
"\t%2d", averageIndex );
627 const int numTotalSamps = i->getNumTotalSamples();
629 sprintf( numTotalSampsText,
"\t%2d", numTotalSamps );
631 const int numValidSamps = i->getNumValidSamples();
633 if ( numValidSamps == numTotalSamps )
634 fputs( numTotalSampsText, file );
635 else if ( numValidSamps == 0 )
636 fputs(
"\t 0", file );
638 fprintf( file,
"\t%2d", numValidSamps );
640 fputs( numTotalSampsText, file );
void accumulate()
Method to accumulate sample values in associated average objects - walks through samples and accumula...
Classes that provide the pecializations of monitor points and sense poiints for different datatypes...
Abstract base class for all monitor points.
~MonitorPointAccumulatorT()
Destructor Destroys the created set of average objects.
bool operator==(const MonitorPointAccumulatorT &rhs) const
Method to test for equality of two MonitorPointAccumulator objects.
const T::AccumReportType getAverage(int index=0) const
Method to compute average value from accumulated sample values in the associated average objects...
void swap(MonitorPointAccumulatorT &rhs)
swap two instances
void dumpLongAveragesToFile(const char *const frameCountText, FILE *const file) const
dump long (minute,subarray) averages to a file for the dbloader to read
void accumulateAverage()
Method to accumulate sample averages in associated average objects - uses pre-computed average values...
Class(es) to read & write dbms flat file information in ASCII or binary.
void dumpInstAveragesToFile(long frameCount, FILE *file) const
dump instantaneous (frame) averages to a file for the dbloader to read
void resetAccumulator()
Method to reset associated average objects so they're initialized for a fresh average calculation...
type definitions for monitor system
bool operator<(const MonitorPointAccumulatorT &rhs) const
Method to test ordering of two MonitorPointAccumulator objects.
MonitorPointAccumulatorT< T, U >
This is the interface file for extra APIs for program logging.
MonitorPointAccumulatorT(T &typedPoint)
Constructor Creates an array of average objects for a monitor point with spectral data...