nidas v1.2.3
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
nidas::core::Variable Class Reference

Class describing a sampled variable. More...

#include <Variable.h>

Inheritance diagram for nidas::core::Variable:
Inheritance graph
[legend]

Public Types

enum  var_type {
  CONTINUOUS , COUNTER , CLOCK , OTHER ,
  WEIGHT
}
 
typedef enum nidas::core::Variable::var_type type_t
 

Public Member Functions

 Variable ()
 Create a variable.
 
 Variable (const Variable &)
 Copy constructor.
 
Variableoperator= (const Variable &)
 Assignment.
 
virtual ~Variable ()
 
bool operator== (const Variable &x) const
 Equivalence operator for Variable, checks equivalence of their length, the variables's names without any site suffix, and their sites.
 
bool operator!= (const Variable &x) const
 
bool operator< (const Variable &x) const
 
bool closeMatch (const Variable &x) const
 A more loose check of the equivalence of two variables, This will also return a value of true if either Site is NULL.
 
void setSite (const Site *val)
 Set the Site where this variable was measured.
 
const SitegetSite () const
 Return the measurement site for this variable.
 
int getStation () const
 Station number of this variable:
 
void setStation (int val)
 
type_t getType () const
 
void setType (type_t val)
 
const SampleTaggetSampleTag () const
 What sample am I a part of?
 
void setSampleTag (const SampleTag *val)
 Set the sample tag pointer.
 
float getSampleRate () const
 Convenience routine to get the SampleTag rate.
 
void setPrefix (const std::string &val)
 Set the name prefix.
 
const std::string & getPrefix () const
 
const std::string & getSuffix () const
 Variable suffix, which is added to the name.
 
void setSuffix (const std::string &val)
 
const std::string & getSiteSuffix () const
 Site suffix, which is added to the name.
 
void setName (const std::string &val)
 Set the full name.
 
const std::string & getName () const
 
const std::string & getNameWithoutSite () const
 Get the name without the site suffix.
 
void setLongName (const std::string &val)
 Descriptive, long name, e.g.
 
const std::string & getLongName () const
 
void setA2dChannel (int val)
 The A2D channel for this variable.
 
int getA2dChannel () const
 
void setUnits (const std::string &val)
 The string discription of the units for this variable.
 
const std::string & getUnits () const
 
unsigned int getLength () const
 How many values in this variable?
 
void setLength (unsigned int val)
 
void setConverter (VariableConverter *val)
 Set the VariableConverter for this Variable.
 
const VariableConvertergetConverter () const
 
VariableConvertergetConverter ()
 
floatconvert (dsm_time_t ttag, float *values, int nvalues=0, float *results=0)
 Apply the conversions for this Variable to the floats pointed to by values, putting the results in results, up to nvalues.
 
void addParameter (Parameter *val)
 Add a parameter to this Variable.
 
const std::list< const Parameter * > & getParameters () const
 Get full list of parameters.
 
const ParametergetParameter (const std::string &name) const
 Fetch a parameter by name.
 
void setMissingValue (float val)
 
float getMissingValue () const
 
void setMinValue (float val)
 Set the minimum allowed value for this variable.
 
float getMinValue () const
 
void setMaxValue (float val)
 
float getMaxValue () const
 
void setPlotRange (float minv, float maxv)
 
void getPlotRange (float &minv, float &maxv) const
 
void setDynamic (bool val)
 A dynamic variable is one that can come and go.
 
bool isDynamic () const
 
void fromDOMElement (const xercesc::DOMElement *)
 
xercesc::DOMElement * toDOMParent (xercesc::DOMElement *parent, bool complete) const
 
xercesc::DOMElement * toDOMElement (xercesc::DOMElement *node, bool complete) const
 

Static Public Member Functions

static const XMLChgetNamespaceURI ()
 

Private Member Functions

void setSiteSuffix (const std::string &val)
 

Private Attributes

std::string _name
 
const Site_site
 
int _station
 
std::string _nameWithoutSite
 
std::string _prefix
 
std::string _suffix
 
std::string _siteSuffix
 
std::string _longname
 
const SampleTag_sampleTag
 
int _A2dChannel
 
std::string _units
 
type_t _type
 
unsigned int _length
 
VariableConverter_converter
 
std::list< Parameter * > _parameters
 List of pointers to Parameters.
 
std::list< const Parameter * > _constParameters
 List of const pointers to Parameters for providing via getParameters().
 
float _missingValue
 
float _minValue
 
float _maxValue
 
float _plotRange [2]
 
bool _dynamic
 

Static Private Attributes

static XMLChnamespaceURI = 0
 

Detailed Description

Class describing a sampled variable.

Member Typedef Documentation

◆ type_t

Member Enumeration Documentation

◆ var_type

Enumerator
CONTINUOUS 
COUNTER 
CLOCK 
OTHER 
WEIGHT 

Constructor & Destructor Documentation

◆ Variable() [1/2]

Variable::Variable ( )

Create a variable.

References _plotRange, and nidas::core::floatNAN.

◆ Variable() [2/2]

Variable::Variable ( const Variable & x)

◆ ~Variable()

Variable::~Variable ( )
virtual

Member Function Documentation

◆ addParameter()

void nidas::core::Variable::addParameter ( Parameter * val)
inline

Add a parameter to this Variable.

Variable will then own the pointer and will delete it in its destructor.

References _constParameters, and _parameters.

Referenced by fromDOMElement(), operator=(), and Variable().

◆ closeMatch()

bool Variable::closeMatch ( const Variable & x) const

A more loose check of the equivalence of two variables, This will also return a value of true if either Site is NULL.

References nidas::core::Site::_name, _name, _nameWithoutSite, getLength(), and getSite().

◆ convert()

float * Variable::convert ( dsm_time_t ttag,
float * values,
int nvalues = 0,
float * results = 0 )

Apply the conversions for this Variable to the floats pointed to by values, putting the results in results, up to nvalues.

Any calibrations are looked up using time ttag. The min/max value limits of a variable are applied also, so if a variable value is converted but lies outside the min/max range, the value is set to floatNAN.

If nvalues is null, then multiple values will be converted up to the length of the Variable, otherwise only the number given in nvalues. If results is null, then the converted values will be written back into the array pointed to by values. Both values and results must point to enough memory to hold nvalues floats. Typically the results of the conversions are written over the values passed in, and values points into the memory in a DSMSensor output sample. However, if a sensor needs custom handling of the results, then the inputs and outputs can be kept separate. For example, The TRH Wisard sensor can keep the Ifan value as it was but convert T and RH to floatNAN if the Ifan result is NAN, meaning Ifan was bad or out of range. It is safe to pass results equal to values, the effect is the same as calling convert() with results=null.

Usually this conversion is the last step applied to the output sample of a sensor's process() method, and this method is called from the DSMSensor::applyConversions() method.

If this Variable has a Site (getSite() returns non-null) and the Site's getApplyVariableConversions() returns false, then no conversions are applied, not even the min/max limit filter. Otherwise the conversions are applied.

Originally, the getApplyVariableConversions() was called on DSMSensor, usually inside a sensor subclass process() method. However, that value is usually copied from the Site's applyCals attribute. So the value of the flag should be the same for both Site and DSMSensor, unless there are some uses out there which change the DSMSensor's value, such as in the sensor subclass itself. However, if a Sensor does not want to apply conversions, then it can just avoid calling any conversion methods.

The original code limit filtered values whether conversion was applied or not, and there was some inconsistency in the domain of the min/max values: Did they apply to values before or after conversion? The convention will be that min/max are in the converted space, so now no filtering happens based on min/max if conversions not applied first. It also makes sense that disabling conversions, presumably to see the more raw values, implies not limit filtering any values either. In practice this change should have little effect, since the 'applyCals' Site attribute is rarely enabled.

The return value points just past the last element in values to be converted. Note that results is not passed by reference, therefore if non-null it must be advanced after the call to convert().

References _site, nidas::core::floatNAN, getConverter(), getLength(), getMaxValue(), getMinValue(), getMissingValue(), and nidas::core::getSample().

Referenced by nidas::dynld::IEEE_Float::process(), and nidas::dynld::ModbusRTU::process().

◆ fromDOMElement()

void Variable::fromDOMElement ( const xercesc::DOMElement * node)
virtual

◆ getA2dChannel()

int nidas::core::Variable::getA2dChannel ( ) const
inline

References _A2dChannel.

Referenced by parseAnalog().

◆ getConverter() [1/2]

VariableConverter * nidas::core::Variable::getConverter ( )
inline

References _converter.

◆ getConverter() [2/2]

const VariableConverter * nidas::core::Variable::getConverter ( ) const
inline

◆ getLength()

unsigned int nidas::core::Variable::getLength ( ) const
inline

◆ getLongName()

const std::string & nidas::core::Variable::getLongName ( ) const
inline

◆ getMaxValue()

float nidas::core::Variable::getMaxValue ( ) const
inline

References _maxValue.

Referenced by convert().

◆ getMinValue()

float nidas::core::Variable::getMinValue ( ) const
inline

References _minValue.

Referenced by convert().

◆ getMissingValue()

float nidas::core::Variable::getMissingValue ( ) const
inline

References _missingValue.

Referenced by convert().

◆ getName()

const std::string & nidas::core::Variable::getName ( ) const
inline

◆ getNamespaceURI()

static const XMLCh * nidas::core::DOMable::getNamespaceURI ( )
inlinestaticinherited

◆ getNameWithoutSite()

const std::string & nidas::core::Variable::getNameWithoutSite ( ) const
inline

Get the name without the site suffix.

References _nameWithoutSite.

Referenced by operator<().

◆ getParameter()

const Parameter * Variable::getParameter ( const std::string & name) const

Fetch a parameter by name.

Returns a NULL pointer if no such parameter exists.

References _constParameters, and nidas::core::getSample().

◆ getParameters()

const std::list< const Parameter * > & nidas::core::Variable::getParameters ( ) const
inline

Get full list of parameters.

References _constParameters.

Referenced by nidas::dynld::raf::A2D_Serial::validate().

◆ getPlotRange()

void nidas::core::Variable::getPlotRange ( float & minv,
float & maxv ) const
inline

References _plotRange.

◆ getPrefix()

const std::string & nidas::core::Variable::getPrefix ( ) const
inline

References _prefix.

Referenced by SampleCounter::collectMetadata().

◆ getSampleRate()

float Variable::getSampleRate ( ) const

Convenience routine to get the SampleTag rate.

References _sampleTag.

◆ getSampleTag()

const SampleTag * nidas::core::Variable::getSampleTag ( ) const
inline

What sample am I a part of?

References _sampleTag.

Referenced by fromDOMElement().

◆ getSite()

const Site * nidas::core::Variable::getSite ( ) const
inline

Return the measurement site for this variable.

References _site.

Referenced by closeMatch(), nidas::core::NearestResampler::ctorCommon(), operator<(), operator==(), and setSampleTag().

◆ getSiteSuffix()

const std::string & nidas::core::Variable::getSiteSuffix ( ) const
inline

Site suffix, which is added to the name.

References _siteSuffix.

◆ getStation()

int nidas::core::Variable::getStation ( ) const
inline

Station number of this variable:

Returns
-1: not specified 0: the "non" site, or the project-wide site, 1-N: a site number

Variables can be grouped by a station number.

A measured variable is associated with a Site. A Site also has a non-negative station number. A Site may have an associated suffix, like ".bigtower".

By default, all DSMSensors at a site will be assigned the site's station number. To support the logical grouping of variables into stations, the station number of a DSMSensor can be set to a different value than the Site's number.

All variables sampled by a DSMSensor will get assigned its station number.

If the station number of a variable is 0, then the site suffix will be appended to the variable name.

Otherwise, if the station number of a variable is positive, the site suffix is not appended to its name. In this way we can have variables with a common name, like "RH.2m" at different sites, which will have different station numbers.

References _station.

Referenced by nidas::dynld::StatisticsCruncher::connect(), nidas::core::NearestResampler::ctorCommon(), DataPrep::run(), setSampleTag(), and setSite().

◆ getSuffix()

const std::string & nidas::core::Variable::getSuffix ( ) const
inline

Variable suffix, which is added to the name.

The full variable name is created from prefix + suffix + siteSuffix. suffix and/or siteSuffix may be empty strings. The suffix commonly comes from the DSMSensor::getFullSuffix(), containing an optional sensor suffix and a height/depth string.

References _suffix.

◆ getType()

type_t nidas::core::Variable::getType ( ) const
inline

References _type.

◆ getUnits()

const std::string & nidas::core::Variable::getUnits ( ) const
inline

◆ isDynamic()

bool nidas::core::Variable::isDynamic ( ) const
inline

References _dynamic.

Referenced by toDOMElement().

◆ operator!=()

bool Variable::operator!= ( const Variable & x) const

References operator==().

◆ operator<()

bool Variable::operator< ( const Variable & x) const

◆ operator=()

Variable & Variable::operator= ( const Variable & rhs)

◆ operator==()

bool Variable::operator== ( const Variable & x) const

Equivalence operator for Variable, checks equivalence of their length, the variables's names without any site suffix, and their sites.

References _name, _nameWithoutSite, _station, getLength(), and getSite().

Referenced by operator!=().

◆ setA2dChannel()

void nidas::core::Variable::setA2dChannel ( int val)
inline

The A2D channel for this variable.

References _A2dChannel, and nidas::core::getSample().

◆ setConverter()

void nidas::core::Variable::setConverter ( VariableConverter * val)
inline

Set the VariableConverter for this Variable.

Variable will own the pointer and will delete it.

References _converter, and nidas::core::getSample().

Referenced by fromDOMElement().

◆ setDynamic()

void nidas::core::Variable::setDynamic ( bool val)
inline

A dynamic variable is one that can come and go.

The dynamic attribute is typically used by a display application which will scan all the variables for a project and create a plot for each. If a variable is dynamic, then that application should wait to create a plot for the variable until data is received for it.

References _dynamic, and nidas::core::getSample().

Referenced by fromDOMElement().

◆ setLength()

void nidas::core::Variable::setLength ( unsigned int val)
inline

References _length, and nidas::core::getSample().

Referenced by fromDOMElement().

◆ setLongName()

void nidas::core::Variable::setLongName ( const std::string & val)
inline

Descriptive, long name, e.g.

"Ambient air temperature".

References _longname, and nidas::core::getSample().

Referenced by fromDOMElement().

◆ setMaxValue()

void nidas::core::Variable::setMaxValue ( float val)
inline

◆ setMinValue()

void nidas::core::Variable::setMinValue ( float val)
inline

Set the minimum allowed value for this variable.

Variable values less than val will be set to NAN. Support for this check must be supported by each DSMSensor class.

References _minValue, _plotRange, and nidas::core::getSample().

Referenced by fromDOMElement().

◆ setMissingValue()

void nidas::core::Variable::setMissingValue ( float val)
inline

References _missingValue, and nidas::core::getSample().

Referenced by fromDOMElement().

◆ setName()

void nidas::core::Variable::setName ( const std::string & val)
inline

◆ setPlotRange()

void nidas::core::Variable::setPlotRange ( float minv,
float maxv )
inline

References _plotRange, and nidas::core::getSample().

Referenced by fromDOMElement().

◆ setPrefix()

void nidas::core::Variable::setPrefix ( const std::string & val)
inline

Set the name prefix.

The full variable name will be the concatenation of: prefix + suffix + site

References _name, _nameWithoutSite, _prefix, _siteSuffix, _suffix, and nidas::core::getSample().

Referenced by nidas::dynld::isff::WisardMote::createSampleTags(), and fromDOMElement().

◆ setSampleTag()

void Variable::setSampleTag ( const SampleTag * val)

Set the sample tag pointer.

Variable does not own the pointer. This also copies attributes from the sample, such as site and station if they have not been set on this Variable.

References _sampleTag, nidas::core::getSample(), getSite(), getStation(), setSite(), and setStation().

◆ setSite()

void nidas::core::Variable::setSite ( const Site * val)
inline

Set the Site where this variable was measured.

References _site, nidas::core::getSample(), getStation(), and setSiteSuffix().

Referenced by setSampleTag().

◆ setSiteSuffix()

void Variable::setSiteSuffix ( const std::string & val)
private

◆ setStation()

void nidas::core::Variable::setStation ( int val)
inline

◆ setSuffix()

void nidas::core::Variable::setSuffix ( const std::string & val)
inline

◆ setType()

void nidas::core::Variable::setType ( type_t val)
inline

◆ setUnits()

void nidas::core::Variable::setUnits ( const std::string & val)
inline

◆ toDOMElement()

xercesc::DOMElement * Variable::toDOMElement ( xercesc::DOMElement * node,
bool complete ) const
virtual
Exceptions
xercesc::DOMException

Reimplemented from nidas::core::DOMable.

References _plotRange, getConverter(), getLength(), getLongName(), getName(), nidas::core::getSample(), getUnits(), and isDynamic().

Referenced by toDOMParent().

◆ toDOMParent()

xercesc::DOMElement * Variable::toDOMParent ( xercesc::DOMElement * parent,
bool complete ) const
virtual
Exceptions
xercesc::DOMException

Reimplemented from nidas::core::DOMable.

References nidas::core::DOMable::getNamespaceURI(), and toDOMElement().

Referenced by nidas::core::SampleTag::toDOMElement().

Member Data Documentation

◆ _A2dChannel

int nidas::core::Variable::_A2dChannel
private

◆ _constParameters

std::list<const Parameter*> nidas::core::Variable::_constParameters
private

List of const pointers to Parameters for providing via getParameters().

Referenced by addParameter(), getParameter(), and getParameters().

◆ _converter

VariableConverter* nidas::core::Variable::_converter
private

◆ _dynamic

bool nidas::core::Variable::_dynamic
private

Referenced by isDynamic(), operator=(), and setDynamic().

◆ _length

unsigned int nidas::core::Variable::_length
private

Referenced by getLength(), operator=(), and setLength().

◆ _longname

std::string nidas::core::Variable::_longname
private

Referenced by getLongName(), operator=(), and setLongName().

◆ _maxValue

float nidas::core::Variable::_maxValue
private

Referenced by getMaxValue(), operator=(), and setMaxValue().

◆ _minValue

float nidas::core::Variable::_minValue
private

Referenced by getMinValue(), operator=(), and setMinValue().

◆ _missingValue

float nidas::core::Variable::_missingValue
private

◆ _name

std::string nidas::core::Variable::_name
private

◆ _nameWithoutSite

std::string nidas::core::Variable::_nameWithoutSite
private

◆ _parameters

std::list<Parameter*> nidas::core::Variable::_parameters
private

List of pointers to Parameters.

Referenced by addParameter(), operator=(), and ~Variable().

◆ _plotRange

float nidas::core::Variable::_plotRange[2]
private

◆ _prefix

std::string nidas::core::Variable::_prefix
private

◆ _sampleTag

const SampleTag* nidas::core::Variable::_sampleTag
private

◆ _site

const Site* nidas::core::Variable::_site
private

◆ _siteSuffix

std::string nidas::core::Variable::_siteSuffix
private

◆ _station

int nidas::core::Variable::_station
private

◆ _suffix

std::string nidas::core::Variable::_suffix
private

◆ _type

type_t nidas::core::Variable::_type
private

Referenced by getType(), operator=(), and setType().

◆ _units

std::string nidas::core::Variable::_units
private

Referenced by getUnits(), operator=(), and setUnits().

◆ namespaceURI

XMLCh * DOMable::namespaceURI = 0
staticprivateinherited

The documentation for this class was generated from the following files: