CARMA C++
MonitorPoint.h
Go to the documentation of this file.
1 #ifndef CARMA_MONITOR_MONITORPOINT_H
2 #define CARMA_MONITOR_MONITORPOINT_H
3 
4 
17 #include <complex>
18 #include <string>
19 
20 #include "carma/monitor/types.h"
24 
25 namespace carma {
26 namespace monitor {
27 
28 struct ScratchAverages;
29 class MonitorContainer;
30 class MonitorPointThreshold;
31 
69 public:
70 
132  enum VALIDITY {
133  INVALID_NO_DATA,
134  INVALID_NO_HW,
135  INVALID_HW_BAD,
136  VALID,
137  VALID_NOT_CHECKED,
138  VALID_GOOD,
139  VALID_WARNING,
140  VALID_ERROR,
141  VALID_WARNING_LOW,
142  VALID_WARNING_HIGH,
143  VALID_ERROR_LOW,
144  VALID_ERROR_HIGH,
145  MAX_VALIDITY
146  };
147 
160  UNDETERMINED,
161  OK,
162  BLANKED,
163  FLAGGED,
164  BLANKED_FLAGGED,
165  MAX_BLANKING_FLAGGING
166  };
167 
176 
181  };
182 
183 
190  MonitorPoint( const std::string & name,
191  MonitorValueType valuetype,
192  MONITOR_POINT_TYPE monitorPointType = MONITOR );
193 
198  virtual ~MonitorPoint( );
199 
207  std::string getUnits() const;
208 
215  void setUnits(const std::string& units);
216 
223  void setWidth(short width) const;
224 
231  virtual short getWidth() const;
232 
243  void setPrecision(short precision);
244 
251  short getPrecision() const;
252 
262  void setPersistent(bool persistent) ;
263 
268  bool isPersistent( ) const;
269 
276  void setErrorHighDefault( const MonitorValue threshold );
277 
284  void setWarnHighDefault( const MonitorValue threshold );
285 
292  void setWarnLowDefault( const MonitorValue threshold );
293 
300  void setErrorLowDefault( const MonitorValue threshold );
301 
314 
327 
340 
353 
362  bool warnLowDefaultIsSet() const;
363 
372  bool errorLowDefaultIsSet() const;
373 
382  bool warnHighDefaultIsSet() const;
383 
392  bool errorHighDefaultIsSet() const;
393 
403  virtual void evaluateTolerance( const MonitorPointThreshold & threshold );
404 
417  void setComment( const std::string & text );
418 
427  void setComment( const std::string & text,
428  const std::string & user,
429  double mjd );
430 
434  void clearComment( );
435 
443  std::string getComment() const;
444 
450  std::string getCommentUser() const;
451 
457  double getCommentTime() const;
458 
464  virtual void updateFrameAverage( ScratchAverages & scratchAvgs ) = 0;
465 
472  virtual std::string getValueToString(int sampleIndex) const = 0;
473 
479  virtual std::string getAverageToString() const = 0;
480 
490  std::string getPaddedValueString(int width, int sampleIndex) const;
491 
500  std::string getPaddedValueString(int sampleIndex) const;
501 
510  std::string getPaddedAverageString(int width) const;
511 
519  std::string getPaddedAverageString() const;
520 
526  std::string getCoreValueAsString( int sampleIndex = 0 ) const;
527 
534  virtual std::string toStringShort(int sampleIndex = 0) const;
535 
536  // Virtual, so doc is inherited
537  std::string toString(bool canonicalName = false, bool verbose = false,
538  bool value = true, int sampleIndex = 0, int indent = 0) const;
539 
540  // Virtual, so doc is inherited
541  std::string toStringAverage(bool canonicalName = false,
542  bool verbose = false, bool value = true, int indent = 0) const;
543 
544  // Virtual, so doc is inherited
545  virtual std::string monitorPointTags(bool untagged = false) const;
546 
553 
560 
565  tagIDType getTagID( ) const;
566 
572  int getNumSamples( ) const;
573 
581  virtual void setNumSamples(int nSamples) const;
582 
589  VALIDITY getValidity( int sampleIndex ) const;
590  VALIDITY getValidity( ) const;
591 
598  void setValidity(VALIDITY validity, int sampleIndex = 0) const;
599 
605  void setAllValidity(VALIDITY validity, bool markMpAsModified = true ) const;
606 
615  virtual VALIDITY getAveValidity() const;
616 
621  static bool isValid(VALIDITY validity) ;
622 
627  bool isAveValid() const;
628 
633  bool isValid( int sampleIndex ) const;
634  bool isValid( ) const;
635 
640  void setAveValidity(VALIDITY validity) const;
641 
647  int getNumValidSamples() const;
648 
656 
663  void setBlankingFlagging(BLANKING_FLAGGING flag) const;
664 
670  void setArchivePriority(ARCHIVE_PRIORITY priority);
671 
679 
684 
692  void setUpdateInterval(int interval);
693 
697  int getUpdateInterval( ) const;
698 
708  virtual void setTimeSeries(bool timeSeries);
709 
713  bool isTimeSeries( ) const;
714 
719  static std::string valuetypeToString(MonitorValueType valuetype);
720 
724  std::string valuetypeToString() const;
725 
730  static std::string monitorPointTypeToString(MONITOR_POINT_TYPE monitorPointType);
731 
736  std::string monitorPointTypeToString() const;
737 
742  static std::string validityToString(VALIDITY validity);
743 
748  static std::string blankingFlaggingToString(BLANKING_FLAGGING flag);
749 
753  std::string archivePriorityToString() const;
754 
762  virtual std::string dumpSamples(bool includeAverage = true,
763  bool includeValidity = true) const;
764 
771 
777  void setTagID(tagIDType tagID, bool assignedOTF);
778 
786  void setSnapshotAverage(bool state);
787 
792  bool isSnapshotAverage() const;
793 
794 
795 //-----------------------------------------------------------------
796 // The methods that make this a monitor component
797 
798  // Specialize the docs..
805  virtual bool operator==( const MonitorComponent & rhs ) const;
806 
813  virtual bool operator==( const MonitorPoint & rhs ) const;
814 
822  virtual bool operator<( const MonitorPoint & rhs ) const;
823 
824  // Virtual so docs are inherited
825  void setNoData() const;
826 
827  // Virtual, so docs are inherited
828  bool hasAllData() const;
829 
830  // Virtual, so docs are inherited
831  virtual bool isMonitorPoint() const;
832 
833 
846  void checkThreshold( const MonitorPointThreshold & threshold ) const;
847 
848  // Virtual, so doc is inherited
849  virtual ::std::string hierarchyToString(
850  bool canonical = false,
851  bool verbose = false,
852  bool value = true,
853  int sampleIndex = 0,
854  int indent = 0,
855  int levels = -1 ) const;
856 
857  // Virtual, so doc is inherited
858  virtual void hierarchyToVector(
859  ::std::vector< ::std::string > & hierarchyList,
860  bool canonical = false,
861  bool verbose = false,
862  int sampleIndex = 0 ) const;
863 
864  // Virtual, so doc is inherited
865  virtual ::std::string hierarchyToStringAverage(
866  bool canonical = false,
867  bool verbose = false,
868  bool value = true,
869  int indent = 0,
870  int levels = -1 ) const;
871 
872  // Virtual, so doc is inherited
873  virtual std::string leafToString( bool verbose = false,
874  bool value = true,
875  int sampleIndex = 0 ) const;
876 
877  MonitorPointSample getSampleAverage() const;
878 
879 protected:
880 
885  void clearAllDefaults( );
886 
887 public:
888 
893  MonitorPointSample getMonitorPointSample(int sampleIndex) const;
894  MonitorPointSample getMonitorPointSample0() const;
895 
896 protected:
897 
898  char getValueChar( int sampleIndex ) const;
899  short getValueShort( int sampleIndex ) const;
900  long getValueLong( int sampleIndex ) const;
901  bool getValueBoolean( int sampleIndex ) const;
902  float getValueFloat( int sampleIndex ) const;
903  double getValueDouble( int sampleIndex ) const;
904  ::std::complex< float > getValueComplex( int sampleIndex ) const;
905 
906  MonitorValueStringChunk getValueStringChunk( int sampleIndex ) const;
907 
908  long getValueSerialNo() const;
909 
910  void setValue( char d, int sampleIndex ) const;
911  void setValue( short d, int sampleIndex ) const;
912  void setValue( long d, int sampleIndex ) const;
913  void setValue( bool d, int sampleIndex ) const;
914  void setValue( float d, int sampleIndex ) const;
915  void setValue( double d, int sampleIndex ) const;
916  void setValue( const ::std::complex< float > & d, int sampleIndex ) const;
917 
918  void setValuesStringChunksAndValidities(
919  const MonitorValueStringChunk * chunks,
920  int numChunks,
921  VALIDITY validity ) const;
922 
923  void setValueSerialNo( long d ) const;
924 
925  char getAveChar() const;
926  short getAveShort() const;
927  long getAveLong() const;
928  bool getAveBoolean() const;
929  float getAveFloat() const;
930  double getAveDouble() const;
931  ::std::complex< float > getAveComplex() const;
932  long getAveSerialNo() const;
933 
934  void setAve( char d ) const;
935  void setAve( short d ) const;
936  void setAve( long d ) const;
937  void setAve( bool d ) const;
938  void setAve( float d ) const;
939  void setAve( double d ) const;
940  void setAve( const ::std::complex< float > & d ) const;
941 
942  void setAveSerialNo( long d ) const;
943 
944  bool isEqualTo( const MonitorPoint & mp ) const;
945  std::string getSnapshotAverageToString() const;
946 
947 private:
948  explicit MonitorPoint( );
949 
950  // No copying
951  MonitorPoint( const MonitorPoint & rhs );
952  MonitorPoint & operator=( const MonitorPoint & rhs );
953 
954  std::string toString( bool canonicalName,
955  bool verbose,
956  bool value,
957  int sampleIndex,
958  int indent,
959  bool average ) const;
960 
961  struct CommentAttrs;
962  struct DefThreshAttrs;
963 
964 protected:
965  bool timeSeries_;
966  mutable short width_;
967 
968 private:
969  std::string units_;
970  mutable short precision_;
971  bool persistent_;
972  tagIDType tagID_;
973  const MonitorValueType valuetype_;
974  const MONITOR_POINT_TYPE monitorPointType_;
975  MonitorPointHeader * monitorPointHeader_;
976  ARCHIVE_PRIORITY archivePriority_;
977  int updateInterval_;
978  CommentAttrs * commentAttrs_;
979  bool snapshotAverage_;
980 
981  // These live here permanently - default values picked up from
982  // mpml files.
983  DefThreshAttrs * defThreshAttrs_;
984 };
985 
986 
987 } // namespace carma::monitor
988 } // namespace carma
989 
990 
991 inline bool
993 {
994  return timeSeries_;
995 }
996 
997 
998 inline bool
1000 {
1001  return persistent_ ;
1002 }
1003 
1004 
1005 inline carma::monitor::tagIDType
1007 {
1008  return tagID_;
1009 }
1010 
1011 
1014 {
1015  return valuetype_;
1016 }
1017 
1018 
1021 {
1022  return monitorPointType_;
1023 }
1024 
1025 
1028 {
1029  return archivePriority_;
1030 }
1031 
1032 
1033 inline int
1035 {
1036  return updateInterval_;
1037 }
1038 
1039 
1040 inline int
1042 {
1043  return monitorPointHeader_->getNumSamplesPerCycle();
1044 }
1045 
1046 inline bool
1048 {
1049  return snapshotAverage_;
1050 }
1051 
1052 
1053 inline void
1055  const carma::monitor::tagIDType tagId,
1056  const bool assignedOTF )
1057 {
1058  tagID_ = tagId;
1059 
1060  // Do not archive if the tagID was assigned on-the-fly
1061  if ( assignedOTF )
1062  setArchivePriority( MonitorComponent::DONTARCHIVE );
1063 }
1064 
1065 
1067 carma::monitor::MonitorPoint::getSampleAverage( ) const
1068 {
1069  return monitorPointHeader_->getSampleAverage();
1070 }
1071 
1072 
1073 inline bool
1075 {
1076  return ((v >= VALID) && (v < MAX_VALIDITY));
1077 }
1078 
1079 
1080 inline bool
1082 {
1083  return isValid( getAveValidity() );
1084 }
1085 
1086 
1089 {
1090  return
1091  static_cast< BLANKING_FLAGGING >(
1092  getSampleAverage().getBlankingFlags() );
1093 }
1094 
1095 
1096 inline char
1097 carma::monitor::MonitorPoint::getAveChar( ) const
1098 {
1099  return getSampleAverage().getMonitorValue().byte;
1100 }
1101 
1102 
1103 inline short
1104 carma::monitor::MonitorPoint::getAveShort( ) const
1105 {
1106  return getSampleAverage().getMonitorValue().sh;
1107 }
1108 
1109 
1110 inline long
1111 carma::monitor::MonitorPoint::getAveLong( ) const
1112 {
1113  return getSampleAverage().getMonitorValue().lo;
1114 }
1115 
1116 
1117 inline bool
1118 carma::monitor::MonitorPoint::getAveBoolean( ) const
1119 {
1120  return getSampleAverage().getMonitorValue().bo;
1121 }
1122 
1123 
1124 inline float
1125 carma::monitor::MonitorPoint::getAveFloat( ) const
1126 {
1127  return getSampleAverage().getMonitorValue().fl;
1128 }
1129 
1130 
1131 inline double
1132 carma::monitor::MonitorPoint::getAveDouble( ) const
1133 {
1134  return getSampleAverage().getMonitorValue().db;
1135 }
1136 
1137 
1138 inline ::std::complex< float >
1139 carma::monitor::MonitorPoint::getAveComplex( ) const
1140 {
1141  const float * const c = getSampleAverage().getMonitorValue().complex;
1142  return ::std::complex< float >( c[0], c[1] );
1143 }
1144 
1145 
1146 inline long
1147 carma::monitor::MonitorPoint::getAveSerialNo( ) const
1148 {
1149  return getSampleAverage().getMonitorValue().sn;
1150 }
1151 
1152 
1153 #endif // CARMA_MONITOR_MONITORPOINT_H
bool isSnapshotAverage() const
Returns state of snapshot averaging for this MP.
VALIDITY
Validity states of the data value.
Definition: MonitorPoint.h:132
short MonitorValueType
Enumeration of possible types for monitor point values.
std::string getPaddedValueString(int width, int sampleIndex) const
Gets the data value as a string, padded to requested width.
void setPersistent(bool persistent)
Set the persistent state of the data.
ARCHIVE_PRIORITY getArchivePriority() const
Get the archive priority.
virtual std::string getAverageToString() const =0
Abstract method that returns the average value as a string.
virtual VALIDITY getAveValidity() const
Get the validity for the average.
ARCHIVE_PRIORITY
Archiving priority.
int getUpdateInterval() const
Get the basic sampling update interval in frames.
std::string getUnits() const
Get the units string for the monitor point.
bool isTimeSeries() const
Are multiple samples in a frame a time series or an array.
Definition: MonitorPoint.h:992
virtual std::string monitorPointTags(bool untagged=false) const
Write list of monitor points and their tagIDs to a string, one monitor point per line.
void setWidth(short width) const
Set the maximum width(length) of the string for interpreting the value to a string.
short getPrecision() const
Get the number of digits to the right of the decimal point when translating the value to a string...
The MonitorComponent class is an interface used to build the monitor hierarchy.
void setBlankingFlagging(BLANKING_FLAGGING flag) const
Set the blanking/flagging flag for the average.
std::string getComment() const
Get a comment for the monitor point.
Class representing a data sample for a MonitorPoint.
std::string archivePriorityToString() const
Get a string for the archive priority for this monitor point.
virtual bool isMonitorPoint() const
Identifies this component as a MonitorPoint or any derivative Should be over-ridden by the MonitorPoi...
std::string toStringAverage(bool canonicalName=false, bool verbose=false, bool value=true, int indent=0) const
Write this monitor component to a string, using frame average values.
std::string getCoreValueAsString(int sampleIndex=0) const
Get value as a string using the underlying basic type representation.
virtual ::std::string hierarchyToStringAverage(bool canonical=false, bool verbose=false, bool value=true, int indent=0, int levels=-1) const
Dump this and all contained monitor components to a string.
void setSnapshotAverage(bool state)
Controls whether averaging is done as a normal true average or if it is just a snapshot of the last v...
MONITOR_POINT_TYPE getMonitorPointType() const
Get the type of the monitor point.
void setAveValidity(VALIDITY validity) const
Set the validity for the average.
std::string valuetypeToString() const
Get a string representation for the datatype of this monitor point.
double getCommentTime() const
Get time last comment was inserted.
BLANKING_FLAGGING getBlankingFlagging() const
Get the blanking/flagging flag for the average.
virtual bool operator<(const MonitorPoint &rhs) const
Compares monitor point for precedence to the one passed.
virtual std::string dumpSamples(bool includeAverage=true, bool includeValidity=true) const
Create a string with sample and average values and validities.
std::string monitorPointTypeToString() const
Get a string representation for the monitor point type of this monitor point.
void setUpdateInterval(int interval)
Set the basic sampling update interval.
BLANKING_FLAGGING
Blanking/flagging status of the data.
Definition: MonitorPoint.h:159
void clearAllDefaults()
Clears all default threshold values (makes them zero) and sets thresholdFlags_ to THRESHOLD_NONE_SET...
std::string getPaddedAverageString() const
Gets the average value as a string, padded to internal width.
The data should never be archived.
static bool isValid(VALIDITY validity)
Check for any of the valid states.
MonitorValueType getValuetype() const
Get the datatype of the value.
void setValidity(VALIDITY validity, int sampleIndex=0) const
Set the validity for a single sample.
std::string getCommentUser() const
Get username that generated comment for the monitor point.
int getNumSamples() const
Get the number of samples per frame.
bool errorLowDefaultIsSet() const
Returns true if a default value was set for errorLow for this monitor point.
bool warnHighDefaultIsSet() const
Returns true if a default value was set for warnHigh for this monitor point.
Class wrapper for monitor point headers stored in a subsystem frame.
void clearComment()
Clear all comment attributes for the monitor point.
MonitorValue getErrorLowDefault() const
Get the upper error default threshold.
static std::string blankingFlaggingToString(BLANKING_FLAGGING flag)
Get a string representation for a blanking/flagging flag.
bool warnLowDefaultIsSet() const
Returns true if a default value was set for warnLow for this monitor point.
MonitorValue getErrorHighDefault() const
Get the upper error default threshold.
int getNumValidSamples() const
Get the number of valid samples per frame.
void setTagID(tagIDType tagID, bool assignedOTF)
Set tagID.
bool isPersistent() const
Returns the persistent state of the data.
Definition: MonitorPoint.h:999
void setErrorHighDefault(const MonitorValue threshold)
Set the upper error default threshold.
void setWarnLowDefault(const MonitorValue threshold)
Set the lower warning default threshold.
MonitorValue getWarnLowDefault() const
Get the lower warning default threshold.
virtual ::std::string hierarchyToString(bool canonical=false, bool verbose=false, bool value=true, int sampleIndex=0, int indent=0, int levels=-1) const
Dump this and all contained monitor components to a string.
bool isAveValid() const
Check to see if the average is valid.
std::string toString(bool canonicalName=false, bool verbose=false, bool value=true, int sampleIndex=0, int indent=0) const
Write this monitor component to a string.
void setPrecision(short precision)
Set the number of digits to the right of the decimal point when translating the value to a string...
virtual std::string toStringShort(int sampleIndex=0) const
Dumps name and value of monitor point as a short string (name=value).
virtual void setTimeSeries(bool timeSeries)
Determines whether data should be interpreted as time series or as an array (spectrum) when there are...
void checkThreshold(const MonitorPointThreshold &threshold) const
Method checks that threshold object corresponds to this monitor point - checks to see that threshold&#39;...
virtual bool operator==(const MonitorComponent &rhs) const
Compares monitor point for equality to the monitor component passed.
void setMonitorPointHeader(MonitorPointHeader header)
Set the monitor point header.
Abstract base class for a monitor point.
Definition: MonitorPoint.h:68
virtual std::string getValueToString(int sampleIndex) const =0
Abstract method that returns the data value as a string.
tagIDType getTagID() const
Get the tagID (unique identifier of monitor point).
Class wrapper for monitor point samples stored in a subsystem frame.
virtual void hierarchyToVector(::std::vector< ::std::string > &hierarchyList, bool canonical=false, bool verbose=false, int sampleIndex=0) const
Dump this and all contained monitor component strings into a map hierarchy.
MonitorValue getWarnHighDefault() const
Get the upper warning default threshold.
void setDefaultArchivePriority(ARCHIVE_PRIORITY priority)
Set the default archive priority If the archive priority is set to DEFAULT, it is replaced with the n...
MONITOR_POINT_TYPE
Monitor point type.
Definition: MonitorPoint.h:171
void setComment(const std::string &text)
Set a comment for the monitor point.
A composite interface used to build the monitor system hierarchy.
virtual ~MonitorPoint()
Destructor.
type definitions for monitor system
bool errorHighDefaultIsSet() const
Returns true if a default value was set for errorHigh for this monitor point.
void setNoData() const
Recursively mark all data samples as INVALID_NO_DATA.
virtual void updateFrameAverage(ScratchAverages &scratchAvgs)=0
Abstract method that updates the average value/validity for the frame.
void setArchivePriority(ARCHIVE_PRIORITY priority)
Set the archive priority Priority may be used by archiver to control data volume.,.
void setUnits(const std::string &units)
Get the units string for the monitor point.
static std::string validityToString(VALIDITY validity)
Get a string representation for a validity.
void setWarnHighDefault(const MonitorValue threshold)
Set the upper warning default threshold.
bool hasAllData() const
See if all MPs in this component and below have data samples.
MonitorPointSample getMonitorPointSample(int sampleIndex) const
Get the monitor point sample.
virtual void setNumSamples(int nSamples) const
Set the number of samples per frame.
void setAllValidity(VALIDITY validity, bool markMpAsModified=true) const
Set the validity for all samples and the average.
Union of all possible types of monitor sample values.
virtual short getWidth() const
Get the string length to use when interpreting the value to a string.
Wrapper class for monitor point header information.
virtual void evaluateTolerance(const MonitorPointThreshold &threshold)
Set the validity flags for the MonitorPoint using the threshold limits stored in the input MonitorPoi...
void setErrorLowDefault(const MonitorValue threshold)
Set the upper error default threshold.
virtual std::string leafToString(bool verbose=false, bool value=true, int sampleIndex=0) const
Dump all leaf nodes below this component to a string.