MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
mdf::IChannelObserver Class Referenceabstract

The channel observer object shall hold all samples for a channel. More...

#include <ichannelobserver.h>

Inheritance diagram for mdf::IChannelObserver:
Collaboration diagram for mdf::IChannelObserver:

Public Member Functions

 IChannelObserver (const IDataGroup &dataGroup, const IChannel &channel)
 Constructor.
 
 ~IChannelObserver () override=default
 Default destructor.
 
 IChannelObserver (const IChannelObserver &)=delete
 
 IChannelObserver (IChannelObserver &&)=delete
 
IChannelObserveroperator= (const IChannelObserver &)=delete
 
IChannelObserveroperator= (IChannelObserver &&)=delete
 
virtual uint64_t NofSamples () const =0
 Returns number of samples.
 
std::string Name () const
 Channel name.
 
std::string Unit () const
 Channel unit.
 
const IChannelChannel () const
 Returns the channel object.
 
bool IsMaster () const
 True if this is the master channel.
 
bool IsArray () const
 True if this channel is an array channel.
 
std::vector< uint64_t > Shape () const
 Returns a shape vector that describes an array dimension.
 
void ReadVlsdData (bool read_vlsd_data)
 Property interface that defines if the VLSD raw data should be read or not.
 
bool ReadVlsdData () const
 Returns the read VLSD bytes property.
 
uint64_t ArraySize () const
 If this is an array channel, this function returns the array size.
 
template<typename V >
bool GetChannelValue (uint64_t sample, V &value, uint64_t array_index=0) const
 Returns the channel value for a sample.
 
template<typename V >
std::vector< bool > GetChannelSamples (std::vector< V > &values) const
 Simple function that returns all non-scaled samples.
 
template<typename V >
std::vector< bool > GetChannelValues (uint64_t sample, std::vector< V > &values) const
 Returns a vector of array channel values for a specific sample.
 
template<typename V >
bool GetEngValue (uint64_t sample, V &value, uint64_t array_index=0) const
 Returns the engineering value for a specific value.
 
template<typename V >
std::vector< bool > GetEngSamples (std::vector< V > &values) const
 Simple function that returns all scaled samples.
 
template<typename V >
std::vector< bool > GetEngValues (uint64_t sample, std::vector< V > &values) const
 Returns a vector of array values for a specific sample.
 
std::string EngValueToString (uint64_t sample) const
 Support function that convert a sample value to a user friendly string.
 
const std::vector< uint64_t > & GetOffsetList () const
 Returns the sample to VLSD offset list.
 
const std::vector< bool > & GetValidList () const
 Returns the sample to valid list.

 
template<>
bool GetChannelValue (uint64_t sample, std::string &value, uint64_t array_index) const
 Returns the sample channel value as a string.
 
template<>
bool GetChannelValue (uint64_t sample, std::vector< uint8_t > &value, uint64_t array_index) const
 Returns the sample channel value as a byte array.
 
template<>
bool GetEngValue (uint64_t sample, std::vector< uint8_t > &value, uint64_t array_index) const
 Returns the sample engineering (channel) value as a byte array.
 
- Public Member Functions inherited from mdf::ISampleObserver
 ISampleObserver (const IDataGroup &data_group)
 Sample observer constructor.
 
virtual ~ISampleObserver ()
 Destructor.
 
virtual void AttachObserver ()
 Attach the observer to an observer list (publisher).
 
virtual void DetachObserver ()
 Detach the observer from an observer list.
 
virtual bool OnSample (uint64_t sample, uint64_t record_id, const std::vector< uint8_t > &record)
 Observer function that receives the sample record and parse out a channel value.
 
bool IsRecordIdNeeded (uint64_t record_id) const
 Function that test if this observer needs to read a specific record.
 
template<typename V >
bool GetChannelValue (const IChannel &channel, uint64_t sample, const std::vector< uint8_t > &record, V &value, uint64_t array_index=0) const
 The function returns a channel value.
 
template<typename V >
bool GetEngValue (const IChannel &channel, uint64_t sample, const std::vector< uint8_t > &record, V &value, uint64_t array_index=0) const
 Returns the scaled sample value for the channel with the record bytes as input. This function is mainly for internal use but is used together with sample observers.
 

Protected Member Functions

virtual bool GetSampleUnsigned (uint64_t sample, uint64_t &value, uint64_t array_index) const =0
 Returns a unsigned sample value.
 
virtual bool GetSampleSigned (uint64_t sample, int64_t &value, uint64_t array_index) const =0
 Returns a signed sample value.
 
virtual bool GetSampleFloat (uint64_t sample, double &value, uint64_t array_index) const =0
 Returns a float sample value.
 
virtual bool GetSampleText (uint64_t sample, std::string &value, uint64_t array_index) const =0
 Returns a string sample value.
 
virtual bool GetSampleByteArray (uint64_t sample, std::vector< uint8_t > &value) const =0
 Returns a byte array sample value.
 

Protected Attributes

const IChannelchannel_
 Reference to the channel (CN) block.
 
bool read_vlsd_data_ = true
 Defines if the VLSD bytes should be read.
 
std::vector< uint64_t > offset_list_
 Only used for VLSD channels.
 
std::vector< bool > valid_list_
 List of valid samples.
 
- Protected Attributes inherited from mdf::ISampleObserver
std::set< uint64_t > record_id_list_
 List of subscribed channel groups.
 
const IDataGroupdata_group_
 Reference to the data group (DG) block.
 

Additional Inherited Members

- Public Attributes inherited from mdf::ISampleObserver
std::function< bool(uint64_t sample, uint64_t record_id, const std::vector< uint8_t > &record)> DoOnSample
 Function object that is called if assigned.
 

Detailed Description

The main purpose for a channel observer is to store all channel samples for a channel. This object is used when reading data from a MDF file.

Member Function Documentation

◆ ArraySize()

uint64_t mdf::IChannelObserver::ArraySize ( ) const
nodiscard

Returns the array size if the channel is an array channel. The function returns 1 if not is an array channel.

Returns

◆ Channel()

const IChannel & mdf::IChannelObserver::Channel ( ) const
nodiscard

Returns the channel object associated with this observer. The channel is mostly needed to check if the channel is an array channel. Array channels are seldom used and are complex to handle.

Returns
Returns the channel object.

◆ EngValueToString()

std::string mdf::IChannelObserver::EngValueToString ( uint64_t sample) const
nodiscard

Function that convert a sample to a user friendly string. For non-array samples, the function is the same as GetChannelValue but for array sample a JSON array string is returned.

Parameters
sampleSample index
Returns
JSON formatted string

◆ GetChannelSamples()

template<typename V >
std::vector< bool > mdf::IChannelObserver::GetChannelSamples ( std::vector< V > & values) const

Returns all non-scaled sample values. Do not use this function for array channels. Use the GetChannelValues() function for array values.

Template Parameters
VType of values
Parameters
valuesThe destination sample list.
Returns
Returns a list of valid booleans.

◆ GetChannelValue()

template<typename V >
bool mdf::IChannelObserver::GetChannelValue ( uint64_t sample,
V & value,
uint64_t array_index = 0 ) const

Returns the (unscaled) so-called channel value for a specific sample.

Template Parameters
VType of value
Parameters
sampleSample number (0..).
valueThe channel value.
array_indexOptional array index if the channel is an array.
Returns
True if value is valid.

◆ GetChannelValues()

template<typename V >
std::vector< bool > mdf::IChannelObserver::GetChannelValues ( uint64_t sample,
std::vector< V > & values ) const

The function is intended to be used on channel arrays. It returns all scaled array values for a sample. Note that the valid flags are return by the GetValidList() function.

The values vector doesn't need to be sized.

If used on non-array channels, it returns a vector of one values.

Template Parameters
VType of value
Parameters
sampleSample index.
valuesThe destination vector of values.
Returns
Returns a vector of valid booleans.

◆ GetEngSamples()

template<typename V >
std::vector< bool > mdf::IChannelObserver::GetEngSamples ( std::vector< V > & values) const

Returns all scaled sample values. Do not use this function for array channels. Use the GetChannelValues() function for array values.

Template Parameters
VType of values
Parameters
valuesThe destination sample list.
Returns
Returns a list of valid booleans.

◆ GetEngValue()

template<typename V >
bool mdf::IChannelObserver::GetEngValue ( uint64_t sample,
V & value,
uint64_t array_index = 0 ) const

Returns the engineering (scaled) value for a specific value.

Template Parameters
VType of return value
Parameters
sampleSample number (0..).
valueThe return value.
array_indexOptional array index if the channel is an array.
Returns
True if the value is valid.

◆ GetEngValues()

template<typename V >
std::vector< bool > mdf::IChannelObserver::GetEngValues ( uint64_t sample,
std::vector< V > & values ) const

The function is intended to be used on channel arrays. It returns all scaled array values for a sample. Note that the valid flags are return by the GetValidList

If used on non-array channels, the value vector is of size 1.

Template Parameters
VType of value
Parameters
sampleSample index.
valuesList of returning array scaled values.
Returns
Returns a list of valid/invalid flags (boolean).

◆ GetOffsetList()

const std::vector< uint64_t > & mdf::IChannelObserver::GetOffsetList ( ) const
inlinenodiscard

This VLSD offset list is only needed when setting the ReadVLSDData() property to false. By only reading the offset list, the VLSD bytes can be read later as sample by sample or as a range of VSLD bytes. THis read saves primary memory and is much faster if only some samples are needed.

Returns

◆ ReadVlsdData()

void mdf::IChannelObserver::ReadVlsdData ( bool read_vlsd_data)

Reading VLSD raw data may fail if there is no room for the bytes in the primary memory. Normally is this property normally set to true but if set to false, only the offset into the VLSD block is read. This call should be followed buy one or more call to the MdfWriter::ReadVlsdData() function. By this, only partial samples can be read in and thus saving primary memory.

Parameters
read_vlsd_dataSet to false if VLSD bytes shouldn't be read.

◆ Shape()

std::vector< uint64_t > mdf::IChannelObserver::Shape ( ) const
nodiscard

This function is used to size an array in an external library. The Eigen and XTensor C++ libraries are typical

Returns
Shape vector that describes an array dimension.

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