ChimeraTK-DeviceAccess  03.18.00
ChimeraTK::FixedPointConverter Class Reference

The fixed point converter provides conversion functions between a user type and up to 32 bit fixed point (signed or unsigned). More...

#include <FixedPointConverter.h>

Classes

struct  vectorToCooked_impl
 
struct  vectorToCooked_impl< std::string, RAW_ITERATOR, COOKED_ITERATOR >
 

Public Member Functions

 FixedPointConverter (std::string variableName, unsigned int nBits=32, int fractionalBits=0, bool isSignedFlag=true)
 The constructor defines the conversion factor. More...
 
template<typename UserType >
uint32_t toRaw (UserType cookedValue) const
 Conversion function from type T to fixed point. More...
 
template<typename UserType , typename RAW_ITERATOR , typename COOKED_ITERATOR >
void vectorToCooked (const RAW_ITERATOR &raw_begin, const RAW_ITERATOR &raw_end, const COOKED_ITERATOR &cooked_begin) const
 Conversion function from fixed-point values to type T. More...
 
template<typename UserType >
UserType scalarToCooked (int32_t const &raw) const
 Inefficient convenience function for converting a single value to cooked. More...
 
unsigned int getNBits () const
 Read back the number of bits the converter is using. More...
 
int getFractionalBits () const
 Read back the fractional bits the converter is using. More...
 
bool isSigned () const
 Read back wether the conversion is using signed values. More...
 
void reconfigure (unsigned int nBits=32, int fractionalBits=0, bool isSignedFlag=true)
 Reconfigure the fixed point converter with new type information. More...
 
bool operator== (const FixedPointConverter &other) const
 Compare two fixed point converters. More...
 
bool operator!= (const FixedPointConverter &other) const
 
template<>
uint32_t toRaw (Boolean cookedValue) const
 
template<>
uint32_t toRaw (__attribute__((unused)) Void cookedValue) const
 
template<>
uint32_t toRaw (std::string cookedValue) const
 
template<>
uint32_t toRaw (Boolean cookedValue) const
 
template<>
uint32_t toRaw (__attribute__((unused)) Void cookedValue) const
 

Detailed Description

The fixed point converter provides conversion functions between a user type and up to 32 bit fixed point (signed or unsigned).

Definition at line 28 of file FixedPointConverter.h.

Constructor & Destructor Documentation

◆ FixedPointConverter()

ChimeraTK::FixedPointConverter::FixedPointConverter ( std::string  variableName,
unsigned int  nBits = 32,
int  fractionalBits = 0,
bool  isSignedFlag = true 
)
explicit

The constructor defines the conversion factor.

Parameters
variableNameThe name of the variable. It is used in case an exception is thrown which significantly simplifies the debugging.
nBitsThe number of total bits must not exceed 32.
fractionalBitsThe number of fractional bits can range from -1024+nBits to 1021-nBits (in case of a double user type). For integer user types, no fractional bits are allowed.
isSignedFlagFlag whether the most significant bit is interpreted as sign bit. Negative numbers are interpreted as two's complement number of the respective number of bits (i.e. in signed 6 bit, 0 fractional bits 0x3F is -1)

Definition at line 14 of file FixedPointConverter.cc.

+ Here is the call graph for this function:

Member Function Documentation

◆ getFractionalBits()

int ChimeraTK::FixedPointConverter::getFractionalBits ( ) const
inline

Read back the fractional bits the converter is using.

Definition at line 96 of file FixedPointConverter.h.

+ Here is the caller graph for this function:

◆ getNBits()

unsigned int ChimeraTK::FixedPointConverter::getNBits ( ) const
inline

Read back the number of bits the converter is using.

Definition at line 93 of file FixedPointConverter.h.

+ Here is the caller graph for this function:

◆ isSigned()

bool ChimeraTK::FixedPointConverter::isSigned ( ) const
inline

Read back wether the conversion is using signed values.

Definition at line 99 of file FixedPointConverter.h.

+ Here is the caller graph for this function:

◆ operator!=()

bool ChimeraTK::FixedPointConverter::operator!= ( const FixedPointConverter other) const
inline

Definition at line 109 of file FixedPointConverter.h.

+ Here is the call graph for this function:

◆ operator==()

bool ChimeraTK::FixedPointConverter::operator== ( const FixedPointConverter other) const
inline

Compare two fixed point converters.

The variable name is ignored in this comparison.

Definition at line 106 of file FixedPointConverter.h.

+ Here is the caller graph for this function:

◆ reconfigure()

void ChimeraTK::FixedPointConverter::reconfigure ( unsigned int  nBits = 32,
int  fractionalBits = 0,
bool  isSignedFlag = true 
)

Reconfigure the fixed point converter with new type information.

Definition at line 23 of file FixedPointConverter.cc.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scalarToCooked()

template<typename UserType >
UserType ChimeraTK::FixedPointConverter::scalarToCooked ( int32_t const &  raw) const
inline

Inefficient convenience function for converting a single value to cooked.

Definition at line 86 of file FixedPointConverter.h.

+ Here is the caller graph for this function:

◆ toRaw() [1/6]

template<>
uint32_t ChimeraTK::FixedPointConverter::toRaw ( __attribute__((unused)) Void  cookedValue) const

Definition at line 110 of file FixedPointConverter.cc.

◆ toRaw() [2/6]

template<>
uint32_t ChimeraTK::FixedPointConverter::toRaw ( __attribute__((unused)) Void  cookedValue) const

◆ toRaw() [3/6]

template<>
uint32_t ChimeraTK::FixedPointConverter::toRaw ( Boolean  cookedValue) const

Definition at line 102 of file FixedPointConverter.cc.

◆ toRaw() [4/6]

template<>
uint32_t ChimeraTK::FixedPointConverter::toRaw ( Boolean  cookedValue) const

◆ toRaw() [5/6]

template<>
uint32_t ChimeraTK::FixedPointConverter::toRaw ( std::string  cookedValue) const

Definition at line 90 of file FixedPointConverter.cc.

◆ toRaw() [6/6]

template<typename UserType >
uint32_t ChimeraTK::FixedPointConverter::toRaw ( UserType  cookedValue) const

Conversion function from type T to fixed point.

This conversion usually will introduce rounding errors due to this limited resolution of the fixed point number compared to the double. In case of a high number of fractional bits this can mean that the most significant digits are cut and only the 'noise' in the less significant bits is represented.

Definition at line 336 of file FixedPointConverter.h.

+ Here is the caller graph for this function:

◆ vectorToCooked()

template<typename UserType , typename RAW_ITERATOR , typename COOKED_ITERATOR >
void ChimeraTK::FixedPointConverter::vectorToCooked ( const RAW_ITERATOR &  raw_begin,
const RAW_ITERATOR &  raw_end,
const COOKED_ITERATOR &  cooked_begin 
) const
inline

Conversion function from fixed-point values to type T.

The two vectors passed must be of equal size (i.e. cookedValues must already be properly allocated).

Definition at line 61 of file FixedPointConverter.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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