cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
mtsStateTable Class Reference

#include <mtsStateTable.h>

Inheritance diagram for mtsStateTable:
cmnGenericObject

Classes

class  Accessor
 
class  AccessorBase
 
class  DataCollectionInfo
 
class  IndexRange
 

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::AccessorBaseGetAccessor (const _elementType &element) const
 
mtsStateTable::AccessorBaseGetAccessor (const std::string &name) const
 
mtsStateTable::AccessorBaseGetAccessor (const char *name) const
 
mtsStateTable::AccessorBaseGetAccessor (const size_t id) const
 
mtsStateIndex GetIndexWriter (void) const
 
void Start (void)
 
void StartIfAutomatic (void)
 
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
 
double GetAveragePeriod (void) const
 
void ToStream (std::ostream &out) const
 
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)
 
template<class _elementType >
mtsStateTable::AccessorBaseGetAccessor (const _elementType &element) const
 
void DataCollectionStart (const mtsDouble &delay)
 
void DataCollectionStop (const mtsDouble &delay)
 
- Public Member Functions inherited from cmnGenericObject
virtual ~cmnGenericObject (void)
 
virtual const
cmnClassServicesBase
Services (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 throw (std::out_of_range)
 
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

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::TimeTicksType
Ticks
 
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 ( size_t  size,
const std::string &  name 
)

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

mtsStateTable::~mtsStateTable ( )

Default destructor.

Member Function Documentation

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

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

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.

void mtsStateTable::AdvanceIfAutomatic ( void  )

Advance if automatic advance is set and does nothing otherwise.

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

Get method for auto advance flag. See AutomaticAdvanceFlag

void mtsStateTable::Cleanup ( void  )

Cleanup called when the task is being stopped.

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.

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

Determine a ratio to generate a data collection event.

void mtsStateTable::DataCollectionStart ( const mtsDouble delay)

Methods used to control the data collection start/stop

void mtsStateTable::DataCollectionStop ( const mtsDouble delay)
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.

template<class _elementType >
mtsStateTable::AccessorBase* mtsStateTable::GetAccessor ( 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)
Note
This method is overloaded to accept the element pointer or string name.
mtsStateTable::AccessorBase* mtsStateTable::GetAccessor ( 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)
Note
This method is overloaded to accept the element pointer or string name.
mtsStateTable::AccessorBase* mtsStateTable::GetAccessor ( const char *  name) const
mtsStateTable::AccessorBase* mtsStateTable::GetAccessor ( const size_t  id) const
template<class _elementType >
mtsStateTable::AccessorBase* mtsStateTable::GetAccessor ( const _elementType &  element) const
double mtsStateTable::GetAveragePeriod ( void  ) const
inline

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

size_t mtsStateTable::GetHistoryLength ( void  ) const
inline
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.

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.

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

Get a handle for data to be used by a writer

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

Return the name of this state table.

size_t mtsStateTable::GetNumberOfElements ( void  ) const
inline
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.

mtsGenericObject* mtsStateTable::GetStateVectorElement ( size_t  id) const
inline
int mtsStateTable::GetStateVectorID ( const std::string &  dataName) const

Check if the signal has been registered.

double mtsStateTable::GetTic ( void  ) const
inline
double mtsStateTable::GetToc ( void  ) const
inline
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.

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.

void mtsStateTable::SetAutomaticAdvance ( bool  automaticAdvance)
inline

Set method for auto advance flag. See AutoAdvanceFlag.

size_t mtsStateTable::SetDelay ( size_t  newDelay)

Set delay in number of rows.

bool mtsStateTable::SetSize ( const size_t  size)

Method to change the size of the table

void mtsStateTable::Start ( void  )

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

void mtsStateTable::StartIfAutomatic ( void  )

Start if automatic advance is set and does nothing otherwise.

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

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

Reimplemented from cmnGenericObject.

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

Verifies if the data is valid.

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

Write specified data.

Friends And Related Function Documentation

friend class mtsCollectorBaseTest
friend
friend class mtsCollectorState
friend
friend class mtsComponent
friend
friend class mtsStateTableTest
friend
friend class mtsTaskTest
friend

Member Data Documentation

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.

double mtsStateTable::AveragePeriod
protected

The average period over the last HistoryLength samples.

DataCollectionInfo mtsStateTable::DataCollection
protected

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

size_t mtsStateTable::Delay
protected

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

size_t mtsStateTable::HistoryLength
protected

The number of rows of the state data table.

size_t mtsStateTable::IndexDelayed
protected

The index of the delayed reader in the table.

size_t mtsStateTable::IndexReader
protected

The index of the reader in the table.

size_t mtsStateTable::IndexWriter
protected

The index of the writer in the data table.

std::string mtsStateTable::Name
protected

The name of this state table.

mtsDouble mtsStateTable::Period

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

mtsStateDataId mtsStateTable::PeriodId
protected
mtsIntervalStatistics mtsStateTable::PeriodStats

Periodicist Statistics

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

The vector contains pointers to individual columns.

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

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

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

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

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.

double mtsStateTable::SumOfPeriods
protected

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

mtsDouble mtsStateTable::Tic
mtsStateDataId mtsStateTable::TicId
protected

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

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.

const osaTimeServer* mtsStateTable::TimeServer
protected

The time server used to provide absolute and relative times.

mtsDouble mtsStateTable::Toc
mtsStateDataId mtsStateTable::TocId
protected

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