ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
ChimeraTK::NDRegisterAccessor< UserType > Class Template Reference

N-dimensional register accessor. More...

#include <NDRegisterAccessor.h>

+ Inheritance diagram for ChimeraTK::NDRegisterAccessor< UserType >:
+ Collaboration diagram for ChimeraTK::NDRegisterAccessor< UserType >:

Classes

struct  Buffer
 Data type to create individual buffers. More...
 

Public Member Functions

 NDRegisterAccessor (std::string const &name, AccessModeFlags accessModeFlags, std::string const &unit=std::string(TransferElement::unitNotSet), std::string const &description=std::string())
 Creates an NDRegisterAccessor with the specified name (passed on to the transfer element).
 
UserType & accessData (size_t sample)
 Get or set register accessor's buffer content (1D version).
 
const UserType & accessData (size_t sample) const
 
UserType & accessData (unsigned int channel, unsigned int sample)
 Get or set register accessor's buffer content (2D version).
 
const UserType & accessData (unsigned int channel, unsigned int sample) const
 
std::vector< UserType > & accessChannel (unsigned int channel)
 Get or set register accessor's channel vector.
 
const std::vector< UserType > & accessChannel (unsigned int channel) const
 
std::vector< std::vector< UserType > > & accessChannels ()
 Get or set register accessor's 2D channel vector.
 
const std::vector< std::vector< UserType > > & accessChannels () const
 
unsigned int getNumberOfSamples () const
 Return number of elements per channel.
 
unsigned int getNumberOfChannels () const
 Return number of channels.
 
const std::type_info & getValueType () const override
 Returns the std::type_info for the value type of this transfer element.
 
template<typename COOKED_TYPE >
COOKED_TYPE getAsCooked (unsigned int channel, unsigned int sample) const
 
 DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE (getAsCooked_impl, T const(unsigned int, unsigned int))
 
template<typename COOKED_TYPE >
COOKED_TYPE getAsCooked_impl (unsigned int channel, unsigned int sample) const
 
template<typename COOKED_TYPE >
void setAsCooked (unsigned int channel, unsigned int sample, COOKED_TYPE value)
 
 DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE (setAsCooked_impl, void(unsigned int, unsigned int, T))
 
template<typename COOKED_TYPE >
void setAsCooked_impl (unsigned int channel, unsigned int sample, COOKED_TYPE value)
 
boost::shared_ptr< TransferElementmakeCopyRegisterDecorator () override
 Create a CopyRegisterDecorator of the right type decorating this TransferElement.
 
virtual boost::shared_ptr< NDRegisterAccessor< UserType > > decorateDeepInside (std::function< boost::shared_ptr< NDRegisterAccessor< UserType > >(const boost::shared_ptr< NDRegisterAccessor< UserType > > &)> factory)
 Decorate the innermost TransferElement of the stack of decorators or decorator-like accessors.
 
- Public Member Functions inherited from ChimeraTK::TransferElement
 TransferElement (std::string name, AccessModeFlags accessModeFlags, std::string unit=std::string(unitNotSet), std::string description=std::string())
 Creates a transfer element with the specified name.
 
 TransferElement (const TransferElement &other)=delete
 Copying and moving is not allowed.
 
 TransferElement (TransferElement &&other)=delete
 
TransferElementoperator= (const TransferElement &other)=delete
 
TransferElementoperator= (TransferElement &&other)=delete
 
virtual ~TransferElement ()=default
 Abstract base classes need a virtual destructor.
 
const std::string & getName () const
 Returns the name that identifies the process variable.
 
const std::string & getUnit () const
 Returns the engineering unit.
 
const std::string & getDescription () const
 Returns the description of this variable/register.
 
AccessModeFlags getAccessModeFlags () const
 Return the AccessModeFlags for this TransferElement.
 
void setDataValidity (DataValidity validity=DataValidity::ok)
 Set the current DataValidity for this TransferElement.
 
DataValidity dataValidity () const
 Return current validity of the data.
 
void read ()
 Read the data from the device.
 
bool readNonBlocking ()
 Read the next value, if available in the input buffer.
 
bool readLatest ()
 Read the latest value, discarding any other update since the last read if present.
 
bool write (ChimeraTK::VersionNumber versionNumber={})
 Write the data to device.
 
bool writeDestructively (ChimeraTK::VersionNumber versionNumber={})
 Just like write(), but allows the implementation to destroy the content of the user buffer in the process.
 
ChimeraTK::VersionNumber getVersionNumber () const
 Returns the version number that is associated with the last transfer (i.e.
 
virtual bool isReadOnly () const =0
 Check if transfer element is read only, i.e.
 
virtual bool isReadable () const =0
 Check if transfer element is readable.
 
virtual bool isWriteable () const =0
 Check if transfer element is writeable.
 
void setActiveException (std::exception_ptr &setThisException)
 Set an active exception.
 
virtual void setExceptionBackend (boost::shared_ptr< DeviceBackend > exceptionBackend)
 Set the backend to which the exception has to be reported.
 
boost::shared_ptr< DeviceBackendgetExceptionBackend ()
 Return the exception backend.
 
cppext::future_queue< void > getReadQueue ()
 Function to get a copy of the read queue.
 
void readTransfer ()
 Read the data from the device but do not fill it into the user buffer of this TransferElement.
 
bool readTransferNonBlocking ()
 Read the data from the device but do not fill it into the user buffer of this TransferElement.
 
void preRead (TransferType type)
 Perform any pre-read tasks if necessary.
 
void postRead (TransferType type, bool updateDataBuffer)
 Transfer the data from the device receive buffer into the user buffer, while converting the data into the user data format if needed.
 
void preWrite (TransferType type, ChimeraTK::VersionNumber versionNumber)
 Transfer the data from the user buffer into the device send buffer, while converting the data from then user data format if needed.
 
void postWrite (TransferType type, VersionNumber versionNumber)
 Perform any post-write clean-ups if necessary.
 
bool writeTransfer (ChimeraTK::VersionNumber versionNumber)
 Write the data to the device.
 
bool writeTransferDestructively (ChimeraTK::VersionNumber versionNumber)
 Write the data to the device.
 
virtual bool mayReplaceOther (const boost::shared_ptr< TransferElement const > &other) const
 Check whether the TransferElement can be used in places where the TransferElement "other" is currently used, e.g.
 
virtual std::vector< boost::shared_ptr< TransferElement > > getHardwareAccessingElements ()=0
 Obtain the underlying TransferElements with actual hardware access.
 
virtual std::list< boost::shared_ptr< TransferElement > > getInternalElements ()=0
 Obtain the full list of TransferElements internally used by this TransferElement.
 
virtual boost::shared_ptr< TransferElementgetHighLevelImplElement ()
 Obtain the highest level implementation TransferElement.
 
virtual void replaceTransferElement (boost::shared_ptr< TransferElement > newElement)
 Search for all underlying TransferElements which are considered identical (see sameRegister()) with the given TransferElement.
 
virtual void setPersistentDataStorage (boost::shared_ptr< ChimeraTK::PersistentDataStorage >)
 Associate a persistent data storage object to be updated on each write operation of this ProcessArray.
 
TransferElementID getId () const
 Obtain unique ID for this TransferElement, see TransferElementID for details.
 
virtual void interrupt ()
 Return from a blocking read immediately and throw boost::thread_interrupted.
 
template<typename QUEUE_TYPE >
void interrupt_impl (QUEUE_TYPE &dataTransportQueue)
 Implementation of interrupt()
 
bool isReadTransactionInProgress () const
 Check whether a read transaction is in progress, i.e.
 
bool isWriteTransactionInProgress () const
 Check whether a write transaction is in progress, i.e.
 
ReadAnyGroupgetReadAnyGroup () const
 Obtain the ReadAnyGroup this TransferElement is part of, or nullptr if not in a ReadAnyGroup.
 
virtual void setInReadAnyGroup (ReadAnyGroup *rag)
 Set the ReadAnyGroup of which this TransferElement is part of.
 

Protected Member Functions

 DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER (NDRegisterAccessor< UserType >, getAsCooked_impl, 2)
 
 DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER (NDRegisterAccessor< UserType >, setAsCooked_impl, 3)
 
- Protected Member Functions inherited from ChimeraTK::TransferElement
virtual void doReadTransferSynchronously ()=0
 Implementation version of readTransfer() for synchronous reads.
 
virtual void doPreRead (TransferType)
 Backend specific implementation of preRead().
 
virtual void doPostRead (TransferType, bool)
 Backend specific implementation of postRead().
 
virtual void doPreWrite (TransferType, VersionNumber)
 Backend specific implementation of preWrite().
 
virtual void doPostWrite (TransferType, VersionNumber)
 Backend specific implementation of postWrite().
 
virtual bool doWriteTransfer (ChimeraTK::VersionNumber versionNumber)=0
 Implementation version of writeTransfer().
 
virtual bool doWriteTransferDestructively (ChimeraTK::VersionNumber versionNumber)
 Implementation version of writeTransferDestructively().
 
void makeUniqueId ()
 Allow generating a unique ID from derived classes.
 

Protected Attributes

std::vector< std::vector< UserType > > buffer_2D
 Buffer of converted data elements.
 
- Protected Attributes inherited from ChimeraTK::TransferElement
boost::shared_ptr< DeviceBackend_exceptionBackend
 The backend to which the runtime_errors are reported via DeviceBackend::setException().
 
std::string _name
 Identifier uniquely identifying the TransferElement.
 
std::string _unit
 Engineering unit.
 
std::string _description
 Description of this variable/register.
 
TransferElementID _id
 The ID of this TransferElement.
 
bool _isInTransferGroup {false}
 Flag whether this TransferElement has been added to a TransferGroup or not.
 
ReadAnyGroup_inReadAnyGroup {nullptr}
 ReadAnyGroup this TransferElement has been added to, nullptr if not in a ReadAnyGroup.
 
AccessModeFlags _accessModeFlags
 The access mode flags for this transfer element.
 
cppext::future_queue< void > _readQueue
 The queue for asynchronous read transfers.
 
VersionNumber _versionNumber {nullptr}
 The version number of the last successful transfer.
 
DataValidity _dataValidity {DataValidity::ok}
 The validity of the data in the application buffer.
 
std::exception_ptr _activeException {nullptr}
 Exception to be rethrown in postXXX() in case hasSeenException == true Can be set via setActiveException().
 

Friends

class RegisterAccessor
 the compatibility layers need access to the buffer_2D
 

Additional Inherited Members

- Public Types inherited from ChimeraTK::TransferElement
using SharedPtr = boost::shared_ptr< TransferElement >
 A typedef for more compact syntax.
 
- Static Public Attributes inherited from ChimeraTK::TransferElement
static constexpr char unitNotSet [] = "n./a."
 Constant string to be used as a unit when the unit is not provided or known.
 

Detailed Description

template<user_type UserType>
class ChimeraTK::NDRegisterAccessor< UserType >

N-dimensional register accessor.

Base class for all register accessor implementations. The user frontend classes ScalarRegisterAccessor, OneDRegisterAccessor, TwoDRegisterAccessor and VoidRegisterAccessor are using implementations based on this class to perform the actual IO.

Definition at line 21 of file NDRegisterAccessor.h.

Constructor & Destructor Documentation

◆ NDRegisterAccessor()

template<user_type UserType>
ChimeraTK::NDRegisterAccessor< UserType >::NDRegisterAccessor ( std::string const &  name,
AccessModeFlags  accessModeFlags,
std::string const &  unit = std::string(TransferElement::unitNotSet),
std::string const &  description = std::string() 
)
inline

Creates an NDRegisterAccessor with the specified name (passed on to the transfer element).

Definition at line 25 of file NDRegisterAccessor.h.

Member Function Documentation

◆ accessChannel() [1/2]

template<user_type UserType>
std::vector< UserType > & ChimeraTK::NDRegisterAccessor< UserType >::accessChannel ( unsigned int  channel)
inline

Get or set register accessor's channel vector.

Attention
No bounds checking is performed, use getNumberOfChannels() to obtain the number of elements in the register.

Definition at line 50 of file NDRegisterAccessor.h.

◆ accessChannel() [2/2]

template<user_type UserType>
const std::vector< UserType > & ChimeraTK::NDRegisterAccessor< UserType >::accessChannel ( unsigned int  channel) const
inline

Definition at line 51 of file NDRegisterAccessor.h.

◆ accessChannels() [1/2]

template<user_type UserType>
std::vector< std::vector< UserType > > & ChimeraTK::NDRegisterAccessor< UserType >::accessChannels ( )
inline

Get or set register accessor's 2D channel vector.

Definition at line 54 of file NDRegisterAccessor.h.

◆ accessChannels() [2/2]

template<user_type UserType>
const std::vector< std::vector< UserType > > & ChimeraTK::NDRegisterAccessor< UserType >::accessChannels ( ) const
inline

Definition at line 55 of file NDRegisterAccessor.h.

◆ accessData() [1/4]

template<user_type UserType>
UserType & ChimeraTK::NDRegisterAccessor< UserType >::accessData ( size_t  sample)
inline

Get or set register accessor's buffer content (1D version).

Attention
No bounds checking is performed, use getNumberOfSamples() to obtain the number of elements in the register.

Definition at line 37 of file NDRegisterAccessor.h.

◆ accessData() [2/4]

template<user_type UserType>
const UserType & ChimeraTK::NDRegisterAccessor< UserType >::accessData ( size_t  sample) const
inline

Definition at line 38 of file NDRegisterAccessor.h.

◆ accessData() [3/4]

template<user_type UserType>
UserType & ChimeraTK::NDRegisterAccessor< UserType >::accessData ( unsigned int  channel,
unsigned int  sample 
)
inline

Get or set register accessor's buffer content (2D version).

Attention
No bounds checking is performed, use getNumberOfChannels() and getNumberOfSamples() to obtain the number of channels and samples in the register.

Definition at line 44 of file NDRegisterAccessor.h.

◆ accessData() [4/4]

template<user_type UserType>
const UserType & ChimeraTK::NDRegisterAccessor< UserType >::accessData ( unsigned int  channel,
unsigned int  sample 
) const
inline

Definition at line 45 of file NDRegisterAccessor.h.

◆ decorateDeepInside()

template<user_type UserType>
virtual boost::shared_ptr< NDRegisterAccessor< UserType > > ChimeraTK::NDRegisterAccessor< UserType >::decorateDeepInside ( std::function< boost::shared_ptr< NDRegisterAccessor< UserType > >(const boost::shared_ptr< NDRegisterAccessor< UserType > > &)>  factory)
inlinevirtual

Decorate the innermost TransferElement of the stack of decorators or decorator-like accessors.

Decorators (and certain decorator-like accessors which shall allow this type of "inside" decoration) shall first attempt to delegate a call to decorateDeepInside() to their target. Accessors which cannot decorate an internal target simply do not implement this function, so the default implementation returns a nulled shared_ptr. Only if a decorator (or decorator-like accessor) sees that the delegated call returns a nulled shared_ptr, it shall use the factory to decorate its target, and then return its new (now decorated) target. If the delegated call returned a non-nulled shared_ptr, that shared_ptr must be passed through unaltered.

Parameters
[in]factoryFunctor object to create the decorator. The functor takes one argument, which is the target accessor to be decorated. The functor may return a nulled pointer if the target is not suitable for decoration, in which case it will be retired on level further out, if applicable.
Returns
{nullptr} if no decoration can be done inside, otherwise the decorator created by the factory function.

Reimplemented in ChimeraTK::NDRegisterAccessorDecorator< ChimeraTK::Void, ChimeraTK::Void >, ChimeraTK::NDRegisterAccessorDecorator< ChimeraTK::Void, IMPL_T >, ChimeraTK::NDRegisterAccessorDecorator< ChimeraTK::Void, std::string >, ChimeraTK::NDRegisterAccessorDecorator< std::string, ChimeraTK::Void >, ChimeraTK::NDRegisterAccessorDecorator< std::string, IMPL_T >, ChimeraTK::NDRegisterAccessorDecorator< T >, ChimeraTK::NDRegisterAccessorDecorator< T, ChimeraTK::Void >, ChimeraTK::NDRegisterAccessorDecorator< T, IMPL_T >, ChimeraTK::NDRegisterAccessorDecorator< T, std::string >, ChimeraTK::NDRegisterAccessorDecorator< TargetUserType >, ChimeraTK::NDRegisterAccessorDecorator< UserType, TargetUserType >, ChimeraTK::NDRegisterAccessorDecorator< UserType, double >, ChimeraTK::NDRegisterAccessorDecorator< UserType, TargetType >, ChimeraTK::NDRegisterAccessorDecorator< UserType, TargetUserType >, ChimeraTK::NDRegisterAccessorDecorator< UserType, uint32_t >, and ChimeraTK::NDRegisterAccessorDecorator< UserType, UserType >.

Definition at line 95 of file NDRegisterAccessor.h.

◆ DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE() [1/2]

template<user_type UserType>
ChimeraTK::NDRegisterAccessor< UserType >::DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE ( getAsCooked_impl  ,
T const   unsigned int, unsigned int 
)

◆ DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE() [2/2]

template<user_type UserType>
ChimeraTK::NDRegisterAccessor< UserType >::DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE ( setAsCooked_impl  ,
void(unsigned int, unsigned int, T)   
)

◆ DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER() [1/2]

template<user_type UserType>
ChimeraTK::NDRegisterAccessor< UserType >::DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER ( NDRegisterAccessor< UserType >  ,
getAsCooked_impl  ,
 
)
protected

◆ DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER() [2/2]

template<user_type UserType>
ChimeraTK::NDRegisterAccessor< UserType >::DEFINE_VIRTUAL_FUNCTION_TEMPLATE_VTABLE_FILLER ( NDRegisterAccessor< UserType >  ,
setAsCooked_impl  ,
 
)
protected

◆ getAsCooked()

template<user_type UserType>
template<typename COOKED_TYPE >
COOKED_TYPE ChimeraTK::NDRegisterAccessor< UserType >::getAsCooked ( unsigned int  channel,
unsigned int  sample 
) const

Definition at line 158 of file NDRegisterAccessor.h.

◆ getAsCooked_impl()

template<user_type UserType>
template<typename COOKED_TYPE >
COOKED_TYPE ChimeraTK::NDRegisterAccessor< UserType >::getAsCooked_impl ( unsigned int  channel,
unsigned int  sample 
) const

Definition at line 164 of file NDRegisterAccessor.h.

◆ getNumberOfChannels()

template<user_type UserType>
unsigned int ChimeraTK::NDRegisterAccessor< UserType >::getNumberOfChannels ( ) const
inline

Return number of channels.

Definition at line 61 of file NDRegisterAccessor.h.

◆ getNumberOfSamples()

template<user_type UserType>
unsigned int ChimeraTK::NDRegisterAccessor< UserType >::getNumberOfSamples ( ) const
inline

Return number of elements per channel.

Definition at line 58 of file NDRegisterAccessor.h.

◆ getValueType()

template<user_type UserType>
const std::type_info & ChimeraTK::NDRegisterAccessor< UserType >::getValueType ( ) const
inlineoverridevirtual

Returns the std::type_info for the value type of this transfer element.

This can be used to determine the type at runtime.

Implements ChimeraTK::TransferElement.

Definition at line 63 of file NDRegisterAccessor.h.

◆ makeCopyRegisterDecorator()

template<user_type UserType>
boost::shared_ptr< TransferElement > ChimeraTK::NDRegisterAccessor< UserType >::makeCopyRegisterDecorator ( )
overridevirtual

Create a CopyRegisterDecorator of the right type decorating this TransferElement.

This is used by TransferElementAbstractor::replaceTransferElement() to decouple two accessors which are replaced on the abstractor level.

Implements ChimeraTK::TransferElement.

Definition at line 11 of file NDRegisterAccessor.cc.

◆ setAsCooked()

template<user_type UserType>
template<typename COOKED_TYPE >
void ChimeraTK::NDRegisterAccessor< UserType >::setAsCooked ( unsigned int  channel,
unsigned int  sample,
COOKED_TYPE  value 
)

Definition at line 170 of file NDRegisterAccessor.h.

◆ setAsCooked_impl()

template<user_type UserType>
template<typename COOKED_TYPE >
void ChimeraTK::NDRegisterAccessor< UserType >::setAsCooked_impl ( unsigned int  channel,
unsigned int  sample,
COOKED_TYPE  value 
)

Definition at line 176 of file NDRegisterAccessor.h.

Friends And Related Symbol Documentation

◆ RegisterAccessor

template<user_type UserType>
friend class RegisterAccessor
friend

the compatibility layers need access to the buffer_2D

Definition at line 150 of file NDRegisterAccessor.h.

Member Data Documentation

◆ buffer_2D

template<user_type UserType>
std::vector<std::vector<UserType> > ChimeraTK::NDRegisterAccessor< UserType >::buffer_2D
protected

Buffer of converted data elements.

The buffer is always two dimensional. If a register with a single dimension should be accessed, the outer vector has only a single element. For a scalar register, only a single element is present in total (buffer_2D[0][0]). This has a negligible performance impact when optimisations are enabled, but allows a coherent interface for all accessors independent of their dimension.

Implementation note: The buffer must be created with the right number of elements in the constructor!

Definition at line 146 of file NDRegisterAccessor.h.


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