RTC Toolkit 5.1.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | List of all members
rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType > Class Template Referenceabstract

Base class for Data Task computations. More...

#include <rtctk/dataTask/computationBase.hpp>

Public Types

enum class  State : uint8_t { RUNNING , IDLE , ERROR , OFF }
 Current state of the worker thread. More...
 
using TopicType = TopicTypeX
 
using ServiceContainer = rtctk::componentFramework::ServiceContainer
 
using ComponentMetricsIf = rtctk::componentFramework::ComponentMetricsIf
 

Public Member Functions

 ComputationBase (ServiceContainer &services, const std::string &shm_name, size_t to_read, size_t to_skip, std::chrono::milliseconds sample_timeout, std::optional< numapp::NumaPolicies > thread_policies)
 Constructor.
 
virtual ~ComputationBase ()=default
 Destructor.
 
void SetSamplesToRead (size_t value)
 Sets the number of samples to read.
 
size_t GetSamplesToRead () const
 Gets the number of samples to read.
 
void SetSamplesToSkip (size_t value)
 Sets the number of samples to skip.
 
size_t GetSamplesToSkip () const
 Gets the number of samples to skip.
 
void Spawn ()
 Spawns the worker thread (sync method).
 
void Join ()
 Terminates the worker thread (sync method).
 
void Run (std::optional< size_t > cycles=std::nullopt)
 Commands the worker thread to perform number of computation cycles (async method).
 
void RunOnceSync (std::optional< std::chrono::milliseconds > poll_interval=std::nullopt)
 Commands the worker thread to perform a single computation cycle (sync method).
 
void Idle ()
 Commands the worker thread to stop performing computation cycles (async method).
 
State GetState () const
 Returns the current state of the worker thread.
 
size_t GetCycles () const
 Retrieves number of computation cycles performed since running.
 
void CheckErrors ()
 Checks for errors in the worker thread and rethrows them to the caller.
 

Protected Member Functions

virtual void OnThreadStart ()
 Optional user-hook called after worker thread started and reader was created.
 
virtual void OnCycleStart (size_t to_read)
 Optional user-hook called immediately before a read-cycle from SHM starts.
 
virtual void CopyData (size_t sample_idx, const TopicType &sample) noexcept=0
 User-hook used to copy data of a single computation cycle into user-owned sample buffer.
 
virtual void Compute ()=0
 User-hook to perform a computation cycle.
 
virtual void Publish ()=0
 User-hook to publish a computation result.
 

Detailed Description

template<typename TopicTypeX, typename ReaderType = ipcq::Reader<TopicTypeX>>
class rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >

Base class for Data Task computations.

This class will take care of reading data from shared memory and then invoking user-defined methods to accumulate data and then perform a computation.

Both continuous and on-demand computations are supported.

Template Parameters
TopicTypeXThe shared memory queue topic.
ReaderTypeType of IPCQ reader to be used defaults to ipcq::Reader<TopicTypeX>.

Member Typedef Documentation

◆ ComponentMetricsIf

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
using rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::ComponentMetricsIf = rtctk::componentFramework::ComponentMetricsIf

◆ ServiceContainer

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
using rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::ServiceContainer = rtctk::componentFramework::ServiceContainer

◆ TopicType

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
using rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::TopicType = TopicTypeX

Member Enumeration Documentation

◆ State

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
enum class rtctk::dataTask::ComputationBase::State : uint8_t
strong

Current state of the worker thread.

Enumerator
RUNNING 
IDLE 
ERROR 
OFF 

Constructor & Destructor Documentation

◆ ComputationBase()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::ComputationBase ( ServiceContainer & services,
const std::string & shm_name,
size_t to_read,
size_t to_skip,
std::chrono::milliseconds sample_timeout,
std::optional< numapp::NumaPolicies > thread_policies )
inline

Constructor.

Parameters
servicesService container object to get access to monitoring metrics or OLDB.
shm_nameName of the shared memory queue.
to_readNumber of samples to read per cycle.
to_skipNumber of samples to skip per cycle.
sample_timeoutMaximum time to wait for a single cycle until error.
thread_policiesUsed to set CPU or memory policy.

◆ ~ComputationBase()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
virtual rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::~ComputationBase ( )
virtualdefault

Destructor.

Note, we cannot call Join in here since this will result in virtual methods being called when the derived class has already been destroyed. Therefore, do not forget to call Join() in your derived class destructor in oder to properly terminate the worker thread.

Member Function Documentation

◆ CheckErrors()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::CheckErrors ( )
inline

Checks for errors in the worker thread and rethrows them to the caller.

Useful for detecting async errors in states RUNNING or IDLE.

◆ Compute()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
virtual void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::Compute ( )
protectedpure virtual

User-hook to perform a computation cycle.

Duration is automatically measured and published via ComponentMetrics service.

◆ CopyData()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
virtual void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::CopyData ( size_t sample_idx,
const TopicType & sample )
protectedpure virtualnoexcept

User-hook used to copy data of a single computation cycle into user-owned sample buffer.

Duration is automatically measured and published via ComponentMetrics service.

◆ GetCycles()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
size_t rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::GetCycles ( ) const
inline

Retrieves number of computation cycles performed since running.

Useful for waiting after async command methods (Run, Idle).

Returns
cycles

◆ GetSamplesToRead()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
size_t rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::GetSamplesToRead ( ) const
inline

Gets the number of samples to read.

◆ GetSamplesToSkip()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
size_t rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::GetSamplesToSkip ( ) const
inline

Gets the number of samples to skip.

◆ GetState()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
State rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::GetState ( ) const
inline

Returns the current state of the worker thread.

Useful for waiting after async command methods (Run, Idle).

Returns
State

◆ Idle()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::Idle ( )
inline

Commands the worker thread to stop performing computation cycles (async method).

State IDLE is entered where the shared memory queue is continuously being reset.

◆ Join()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::Join ( )
inline

Terminates the worker thread (sync method).

Once joined the worker thread will be in the OFF state.

◆ OnCycleStart()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
virtual void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::OnCycleStart ( size_t to_read)
inlineprotectedvirtual

Optional user-hook called immediately before a read-cycle from SHM starts.

Useful for resizing the sample buffer in case it can change dynamically.

◆ OnThreadStart()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
virtual void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::OnThreadStart ( )
inlineprotectedvirtual

Optional user-hook called after worker thread started and reader was created.

Useful for GPU computations to initialise the GPU in the worker thread.

◆ Publish()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
virtual void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::Publish ( )
protectedpure virtual

User-hook to publish a computation result.

Duration is automatically measured and published via ComponentMetrics service.

◆ Run()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::Run ( std::optional< size_t > cycles = std::nullopt)
inline

Commands the worker thread to perform number of computation cycles (async method).

State RUNNING is entered and the shared memory queue is read and computations are invoked. Once the requested number of cycles are performed the worker thread auto-transitions to state IDLE.

Parameters
cyclesNumber of computation cycles to perform (default no limit on cycles).

◆ RunOnceSync()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::RunOnceSync ( std::optional< std::chrono::milliseconds > poll_interval = std::nullopt)
inline

Commands the worker thread to perform a single computation cycle (sync method).

This method will unblock once one cycle has been completed or an error occurs.

Parameters
poll_intervalTime to wait between checking for completion.

◆ SetSamplesToRead()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::SetSamplesToRead ( size_t value)
inline

Sets the number of samples to read.

This is useful if samples to read is a dynamic configuration parameter that can change after class construction.

◆ SetSamplesToSkip()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::SetSamplesToSkip ( size_t value)
inline

Sets the number of samples to skip.

This is useful if samples to skip is a dynamic configuration parameter that can change after class construction.

◆ Spawn()

template<typename TopicTypeX , typename ReaderType = ipcq::Reader<TopicTypeX>>
void rtctk::dataTask::ComputationBase< TopicTypeX, ReaderType >::Spawn ( )
inline

Spawns the worker thread (sync method).

Once spawned the worker thread will be in the IDLE state.


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