cisst-saw
Loading...
Searching...
No Matches
mtsStateTable Class Reference

#include <mtsStateTable.h>

Inheritance diagram for mtsStateTable:
cmnGenericObject

Classes

class  IndexRange
class  DataCollectionInfo
class  AccessorBase
class  Accessor

Public Member Functions

 mtsStateTable (size_t size, const std::string &name)
 ~mtsStateTable ()
bool SetSize (const size_t size)
mtsStateIndex GetIndexReader (void) const
void GetIndexReader (mtsStateIndex &timeIndex) const
mtsStateIndex GetIndexDelayed (void) const
size_t SetDelay (size_t newDelay)
bool ValidateReadIndex (const mtsStateIndex &timeIndex) const
const bool & AutomaticAdvance (void) const
void SetAutomaticAdvance (bool automaticAdvance)
int GetStateVectorID (const std::string &dataName) const
template<class _elementType>
mtsStateDataId NewElement (const std::string &name="", _elementType *element=0)
template<class _elementType>
void AddData (_elementType &element, const std::string &name="")
template<class _elementType>
_elementType * GetStateDataElement (mtsStateDataId id) const
mtsGenericObjectGetStateVectorElement (size_t id) const
template<class _elementType>
mtsStateTable::AccessorBaseGetAccessorByInstance (const _elementType &element) const
mtsStateTable::AccessorBaseGetAccessorByName (const std::string &name) const
mtsStateTable::AccessorBaseGetAccessorByName (const char *name) const
mtsStateTable::AccessorBaseGetAccessorById (const size_t id) const
template<class _elementType>
CISST_DEPRECATED mtsStateTable::AccessorBaseGetAccessor (const _elementType &element) const
CISST_DEPRECATED mtsStateTable::AccessorBaseGetAccessor (const std::string &name) const
CISST_DEPRECATED mtsStateTable::AccessorBaseGetAccessor (const char *name) const
CISST_DEPRECATED mtsStateTable::AccessorBaseGetAccessor (const size_t id) const
mtsStateIndex GetIndexWriter (void) const
void Start (void)
void StartIfAutomatic (void)
bool Started (void) const
void Advance (void)
void AdvanceIfAutomatic (void)
bool ReplayAdvance (void)
void Cleanup (void)
double GetTic (void) const
double GetToc (void) const
size_t GetHistoryLength (void) const
size_t GetNumberOfElements (void) const
const std::vector< std::string > & GetDataNames (void) const
double GetAveragePeriod (void) const
void ToStream (std::ostream &out) const override
void Debug (std::ostream &out, unsigned int *listColumn, unsigned int number) const
void CSVWrite (std::ostream &out, bool nonZeroOnly=false)
void CSVWrite (std::ostream &out, unsigned int *listColumn, unsigned int number, bool nonZeroOnly=false)
void CSVWrite (std::ostream &out, mtsGenericObject **listColumn, unsigned int number, bool nonZeroOnly=false)
const std::string & GetName (void) const
void DataCollectionEventTriggeringRatio (const mtsDouble &eventTriggeringRatio)
void DataCollectionStart (const mtsDouble &delay)
void DataCollectionStop (const mtsDouble &delay)
Public Member Functions inherited from cmnGenericObject
virtual ~cmnGenericObject (void)
virtual const cmnClassServicesBaseServices (void) const =0
bool ReconstructFrom (const cmnGenericObject &other)
std::string ToString (void) const
virtual void ToStreamRaw (std::ostream &outputStream, const char delimiter=' ', bool headerOnly=false, const std::string &headerPrefix="") const
virtual bool FromStreamRaw (std::istream &inputStream, const char delimiter=' ')
virtual void SerializeRaw (std::ostream &outputStream) const
virtual void DeSerializeRaw (std::istream &inputStream)
virtual cmnLogger::StreamBufTypeGetLogMultiplexer (void) const
virtual size_t ScalarNumber (void) const
virtual bool ScalarNumberIsFixed (void) const
virtual double Scalar (const size_t CMN_UNUSED(index)) const CISST_THROW(std
virtual std::string ScalarDescription (const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const

Public Attributes

mtsDouble Tic
mtsDouble Toc
mtsDouble Period
mtsIntervalStatistics PeriodStats

Protected Member Functions

bool Write (mtsStateDataId id, const mtsGenericObject &obj)

Protected Attributes

bool mStarted
size_t HistoryLength
size_t IndexWriter
size_t IndexReader
size_t IndexDelayed
size_t Delay
bool AutomaticAdvanceFlag
std::vector< mtsStateArrayBase * > StateVector
std::vector< mtsGenericObject * > StateVectorElements
std::vector< std::string > StateVectorDataNames
std::vector< AccessorBase * > StateVectorAccessors
std::vector< mtsStateIndex::TimeTicksTypeTicks
mtsStateDataId TicId
mtsStateDataId TocId
mtsStateDataId PeriodId
const osaTimeServerTimeServer
double SumOfPeriods
double AveragePeriod
std::string Name
DataCollectionInfo DataCollection

Friends

class mtsCollectorState
class mtsComponent
class mtsTaskTest
class mtsStateTableTest
class mtsCollectorBaseTest

Detailed Description

The state data table is the storage for the state of the task that the table is associated with. It is a heterogenous circular buffer and can contain data of any type so long as it is derived from mtsGenericObject. The state data table also resolves conflicts between reads and writes to the state, by ensuring that the reader head is always one behind the write head. To ensure this we have an assumption here that there is only one writer, though there can be multiple readers. State Data Table is also refered as Data Table or State Table elsewhere in the documentation.

Constructor & Destructor Documentation

◆ mtsStateTable()

mtsStateTable::mtsStateTable ( size_t size,
const std::string & name )

Constructor. Constructs a state table with a default size of 256 rows.

◆ ~mtsStateTable()

mtsStateTable::~mtsStateTable ( )

Default destructor.

Member Function Documentation

◆ AddData()

template<class _elementType>
void mtsStateTable::AddData ( _elementType & element,
const std::string & name = "" )
inline

Add an element to the table (alternative to NewElement).

◆ Advance()

void mtsStateTable::Advance ( void )

Advance the pointers of the circular buffer. Note that since there is only a single writer, it is not necessary to use mutual exclusion primitives; the critical section can be handled by updating (incrementing) the write index before the read index.

◆ AdvanceIfAutomatic()

void mtsStateTable::AdvanceIfAutomatic ( void )

Advance if automatic advance is set and does nothing otherwise.

◆ AutomaticAdvance()

const bool & mtsStateTable::AutomaticAdvance ( void ) const
inline

Get method for auto advance flag. See AutomaticAdvanceFlag

◆ Cleanup()

void mtsStateTable::Cleanup ( void )

Cleanup called when the task is being stopped.

◆ CSVWrite() [1/3]

void mtsStateTable::CSVWrite ( std::ostream & out,
bool nonZeroOnly = false )

This method is to dump the state data table in the csv format, allowing easy import into matlab. Assumes that individual columns are also printed in csv format. By default print all rows, if nonZeroOnly == true then print only those rows which have a nonzero Ticks value i.e, those rows that have been written to at least once.

◆ CSVWrite() [2/3]

void mtsStateTable::CSVWrite ( std::ostream & out,
mtsGenericObject ** listColumn,
unsigned int number,
bool nonZeroOnly = false )

◆ CSVWrite() [3/3]

void mtsStateTable::CSVWrite ( std::ostream & out,
unsigned int * listColumn,
unsigned int number,
bool nonZeroOnly = false )

◆ DataCollectionEventTriggeringRatio()

void mtsStateTable::DataCollectionEventTriggeringRatio ( const mtsDouble & eventTriggeringRatio)

Determine a ratio to generate a data collection event.

◆ DataCollectionStart()

void mtsStateTable::DataCollectionStart ( const mtsDouble & delay)

Methods used to control the data collection start/stop

◆ DataCollectionStop()

void mtsStateTable::DataCollectionStop ( const mtsDouble & delay)

◆ Debug()

void mtsStateTable::Debug ( std::ostream & out,
unsigned int * listColumn,
unsigned int number ) const

For debugging, dumps some values of the current data table to output stream.

◆ GetAccessor() [1/4]

template<class _elementType>
CISST_DEPRECATED mtsStateTable::AccessorBase * mtsStateTable::GetAccessor ( const _elementType & element) const
inline

◆ GetAccessor() [2/4]

CISST_DEPRECATED mtsStateTable::AccessorBase * mtsStateTable::GetAccessor ( const char * name) const
inline

◆ GetAccessor() [3/4]

CISST_DEPRECATED mtsStateTable::AccessorBase * mtsStateTable::GetAccessor ( const size_t id) const
inline

◆ GetAccessor() [4/4]

CISST_DEPRECATED mtsStateTable::AccessorBase * mtsStateTable::GetAccessor ( const std::string & name) const
inline

◆ GetAccessorById()

mtsStateTable::AccessorBase * mtsStateTable::GetAccessorById ( const size_t id) const

Return pointer to accessor functions for the state data element.

Parameters
idId of state data element
Returns
Pointer to accessor class (0 if not found)

◆ GetAccessorByInstance()

template<class _elementType>
mtsStateTable::AccessorBase * mtsStateTable::GetAccessorByInstance ( const _elementType & element) const

Return pointer to accessor functions for the state data element.

Parameters
elementPointer to state data element (i.e., working copy)
Returns
Pointer to accessor class (0 if not found)

◆ GetAccessorByName() [1/2]

mtsStateTable::AccessorBase * mtsStateTable::GetAccessorByName ( const char * name) const

◆ GetAccessorByName() [2/2]

mtsStateTable::AccessorBase * mtsStateTable::GetAccessorByName ( const std::string & name) const

Return pointer to accessor functions for the state data element.

Parameters
nameName of state data element
Returns
Pointer to accessor class (0 if not found)

◆ GetAveragePeriod()

double mtsStateTable::GetAveragePeriod ( void ) const
inline

Return the moving average of the measured period (i.e., average of last HistoryLength values).

◆ GetDataNames()

const std::vector< std::string > & mtsStateTable::GetDataNames ( void ) const
inline

◆ GetHistoryLength()

size_t mtsStateTable::GetHistoryLength ( void ) const
inline

◆ GetIndexDelayed()

mtsStateIndex mtsStateTable::GetIndexDelayed ( void ) const

Get a handle for data to be used by a reader with a given delay. All the const methods, that can be called from a reader and writer.

◆ GetIndexReader() [1/2]

void mtsStateTable::GetIndexReader ( mtsStateIndex & timeIndex) const
inline

◆ GetIndexReader() [2/2]

mtsStateIndex mtsStateTable::GetIndexReader ( void ) const

Get a handle for data to be used by a reader. All the const methods, that can be called from a reader and writer.

◆ GetIndexWriter()

mtsStateIndex mtsStateTable::GetIndexWriter ( void ) const

Get a handle for data to be used by a writer

◆ GetName()

const std::string & mtsStateTable::GetName ( void ) const
inline

Return the name of this state table.

◆ GetNumberOfElements()

size_t mtsStateTable::GetNumberOfElements ( void ) const
inline

◆ GetStateDataElement()

template<class _elementType>
_elementType * mtsStateTable::GetStateDataElement ( mtsStateDataId id) const
inline

Return pointer to the state data element specified by the id. This element is the same type as the state data table entry.

◆ GetStateVectorElement()

mtsGenericObject * mtsStateTable::GetStateVectorElement ( size_t id) const
inline

◆ GetStateVectorID()

int mtsStateTable::GetStateVectorID ( const std::string & dataName) const

Check if the signal has been registered.

◆ GetTic()

double mtsStateTable::GetTic ( void ) const
inline

◆ GetToc()

double mtsStateTable::GetToc ( void ) const
inline

◆ NewElement()

template<class _elementType>
mtsStateDataId mtsStateTable::NewElement ( const std::string & name = "",
_elementType * element = 0 )

Add an element to the table. Should be called during startup of a real time loop. All the non-const methods, that can be called from a writer only. Returns index of data within state data table.

◆ ReplayAdvance()

bool mtsStateTable::ReplayAdvance ( void )

Advance for replay mode, be very careful this should only be used in replay mode as this method only increments the reader index.

◆ SetAutomaticAdvance()

void mtsStateTable::SetAutomaticAdvance ( bool automaticAdvance)
inline

Set method for auto advance flag. See AutoAdvanceFlag.

◆ SetDelay()

size_t mtsStateTable::SetDelay ( size_t newDelay)

Set delay in number of rows.

◆ SetSize()

bool mtsStateTable::SetSize ( const size_t size)

Method to change the size of the table

◆ Start()

void mtsStateTable::Start ( void )

Start the current cycle. This just records the starting timestamp (Tic).

◆ Started()

bool mtsStateTable::Started ( void ) const
inline

Check if state table is "started", i.e. between Start() and Advance() calls.

◆ StartIfAutomatic()

void mtsStateTable::StartIfAutomatic ( void )

Start if automatic advance is set and does nothing otherwise.

◆ ToStream()

void mtsStateTable::ToStream ( std::ostream & out) const
overridevirtual

For debugging, dumps the current data table to output stream.

Reimplemented from cmnGenericObject.

◆ ValidateReadIndex()

bool mtsStateTable::ValidateReadIndex ( const mtsStateIndex & timeIndex) const
inline

Verifies if the data is valid.

◆ Write()

bool mtsStateTable::Write ( mtsStateDataId id,
const mtsGenericObject & obj )
protected

Write specified data.

◆ mtsCollectorBaseTest

friend class mtsCollectorBaseTest
friend

◆ mtsCollectorState

friend class mtsCollectorState
friend

◆ mtsComponent

friend class mtsComponent
friend

◆ mtsStateTableTest

friend class mtsStateTableTest
friend

◆ mtsTaskTest

friend class mtsTaskTest
friend

Member Data Documentation

◆ AutomaticAdvanceFlag

bool mtsStateTable::AutomaticAdvanceFlag
protected

Automatic advance flag. This flag is used by the method AdvanceIfAutomatic to decide if this state table should advance or not. The method AdvanceIsAutomatic is used by mtsTask on all the registered state tables. If a user wishes to Advance the state table manually, he or she will have to set this flag to false (see SetAutomaticAdvance). This flag is set to true by default.

◆ AveragePeriod

double mtsStateTable::AveragePeriod
protected

The average period over the last HistoryLength samples.

◆ DataCollection

DataCollectionInfo mtsStateTable::DataCollection
protected

Information used for the state table data collection, see also mtsCollectorState.

◆ Delay

size_t mtsStateTable::Delay
protected

Delay used for GetIndexDelayed and GetDelayed. In number of rows in state tables.

◆ HistoryLength

size_t mtsStateTable::HistoryLength
protected

The number of rows of the state data table.

◆ IndexDelayed

size_t mtsStateTable::IndexDelayed
protected

The index of the delayed reader in the table.

◆ IndexReader

size_t mtsStateTable::IndexReader
protected

The index of the reader in the table.

◆ IndexWriter

size_t mtsStateTable::IndexWriter
protected

The index of the writer in the data table.

◆ mStarted

bool mtsStateTable::mStarted
protected

Flag to indicate if the table has started. True between Start() and Advance() calls, false otherwise.

◆ Name

std::string mtsStateTable::Name
protected

The name of this state table.

◆ Period

mtsDouble mtsStateTable::Period

The measured task period (difference between current Tic and previous Tic).

◆ PeriodId

mtsStateDataId mtsStateTable::PeriodId
protected

◆ PeriodStats

mtsIntervalStatistics mtsStateTable::PeriodStats

Periodicist Statistics

◆ StateVector

std::vector<mtsStateArrayBase *> mtsStateTable::StateVector
protected

The vector contains pointers to individual columns.

◆ StateVectorAccessors

std::vector<AccessorBase *> mtsStateTable::StateVectorAccessors
protected

The vector contains pointers to the accessor methods (e.g., Get, GetLatest) from which command objects are created.

◆ StateVectorDataNames

std::vector<std::string> mtsStateTable::StateVectorDataNames
protected

The columns entries can be accessed by name. This vector stores the names corresponding to the columns.

◆ StateVectorElements

std::vector<mtsGenericObject *> mtsStateTable::StateVectorElements
protected

The vector contains pointers to the current values of elements that are to be added to the state when we advance.

◆ SumOfPeriods

double mtsStateTable::SumOfPeriods
protected

The sum of all the periods (time differences between consecutive Tic values); used to compute average period.

◆ Tic

mtsDouble mtsStateTable::Tic

◆ TicId

mtsStateDataId mtsStateTable::TicId
protected

The state table indices for Tic, Toc, and Period.

◆ Ticks

std::vector<mtsStateIndex::TimeTicksType> mtsStateTable::Ticks
protected

The vector contains the time stamp in counts or ticks per period of the task that the state table is associated with.

◆ TimeServer

const osaTimeServer* mtsStateTable::TimeServer
protected

The time server used to provide absolute and relative times.

◆ Toc

mtsDouble mtsStateTable::Toc

◆ TocId

mtsStateDataId mtsStateTable::TocId
protected

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