Class PacketTableConfig#
Defined in File DataLogger.h
Inheritance Relationships#
Base Type#
public Karana::Core::LockingBase(Class LockingBase)
Class Documentation#
-
class PacketTableConfig : public Karana::Core::LockingBase#
Define the columns and associated update functions for a PacketTable. The PacketTable is the table that stores data in the H5 log file.
Public Functions
-
PacketTableConfig(std::string_view name)#
PacketTableConfig constructor. The constructor is not meant to be called directly. Please use the create(…) method instead to create an instance.
- Parameters:
name – Name of the table. A / will be interpreted as a new group. Groups will be added as needed.
-
~PacketTableConfig()#
Destroy packet table config.
-
inline void addData(const kc::ks_ptr<kc::Var_T<km::Vec>> &var, bool as_scalars = false)#
Add data to the table via a Var_T<km::Vec>.
- Parameters:
var – The Var_T<km::Vec> to add to the table.
as_scalars – Rather than using one column for the vector, use multiple. This logs each vector component as a scalar. The column names will be appended with a _X where “X” is an integer that corresponds with the index in the vector.
-
inline void addData(const kc::ks_ptr<kc::Var_T<km::Mat>> &var, bool as_scalars = false)#
Add data to the table via a Var_T<km::Mat>.
- Parameters:
var – The Var_T<km::Mat> to add to the table.
as_scalars – Rather than using one column for the vector, use multiple. This logs each vector component as a scalar. The column names will be appended with a _X where “X” is an integer that corresponds with the index in the vector.
-
template<int rows>
inline void addData(const kc::ks_ptr<kc::Var_T<Eigen::Matrix<double, rows, 1>>> &var, bool as_scalars = false)# Add data to the table via a vector-valued Var_T with fixed size, e.g., Var_T<km::Vec3>.
- Parameters:
var – The fixed-size, vector-valued Var_T to add to the table.
as_scalars – Rather than using one column for the vector, use multiple. This logs each vector component as a scalar. The column names will be appended with a _X where “X” is an integer that corresponds with the index in the vector.
-
template<int rows, int cols>
inline void addData(const kc::ks_ptr<kc::Var_T<Eigen::Matrix<double, rows, cols, Eigen::RowMajor>>> &var, bool as_scalars = false)# Add data to the table via a matrix-valued Var_T with fixed size, e.g., Var_T<km::Mat33>.
- Parameters:
var – The fixed-size, matrix-valued Var_T to add to the table.
as_scalars – Rather than using one column for the matrix, use multiple. This logs each matrix component as a scalar. The column names will be appended with a _X_Y where “X” and “Y” are integers that correspond with the row and index of the element in the matrix.
-
template<class T>
inline void addData(const kc::ks_ptr<kc::Var_T<T>> &var)# Add data to the table via a Var_T with loggable data.
- Parameters:
var – The Var_T to add to the table.
-
template<class T>
inline void addData(std::string_view name, const T &f, int vector_size, bool as_scalars = false)# Add data to the table via function.
- Parameters:
name – The name of the column in the table.
f – The function that produces the data (dynamic vector). This vector must always be the same size.
vector_size – The size of the vector that the function produces. This vector must always be the same size.
as_scalars – Rather than using one column for the vector, use multiple. This logs each vector component as a scalar. The column names will be appended with a _X where “X” is an integer that corresponds with the index in the vector.
-
template<class T>
inline void addData(std::string_view name, const T &f, int matrix_rows, int matrix_cols, bool as_scalars = false)# Add data to the table via function.
- Parameters:
name – The name of the column in the table.
f – The function that produces the data (dynamic matrix). This matrix must always be the same size.
matrix_rows – The number of rows in the matrix that the function produces. This matrix must always be the same size.
matrix_cols – The number of columns in the matrix that the function produces. This matrix must always be the same size.
as_scalars – Rather than using one column for the matrix, use multiple. This logs each matrix component as a scalar. The column names will be appended with a _X_Y where “X” and “Y” are integers that correspond with the row and index of the element in the matrix.
-
template<class T, class R = typename std::invoke_result<T>::type>
inline void addData(std::string_view name, const T &f, bool as_scalars = false)# Add data to the table via function.
- Parameters:
name – The name of the column in the table.
f – The function that produces the data.
as_scalars – Rather than using one column for the vector, use multiple. This logs each vector component as a scalar. The column names will be appended with a _X where “X” is an integer that corresponds with the index in the vector.
-
template<class T, class R = typename std::invoke_result<T>::type>
inline void addData(std::string_view name, const T &f, bool as_scalars = false) Add data to the table via function.
- Parameters:
name – The name of the column in the table.
f – The function that produces the data.
as_scalars – Rather than using one column for the matrix, use multiple. This logs each matrix component as a scalar. The column names will be appended with a _X_Y where “X” and “Y” are integers that correspond with the row and index of the element in the matrix.
-
template<class T, class R = typename std::invoke_result<T>::type>
inline void addData(std::string_view name, const T &f)# Add data to the table via function.
- Parameters:
name – The name of the column in the table.
f – The function that produces the data.
-
bool appendRecord()#
Add another record to the buffer.
- Returns:
Whether the buffer is full and ready to write to file.
-
void setBufferSize(unsigned int num_rows)#
Set the size of internal buffer (in number of records) to store before writing to disk.
- Parameters:
num_rows – Number of records to store before flushing. Pass 0 or 1 to disable buffering entirely (write on every log() call).
-
void setAsyncQueueSize(unsigned int size)#
Set the number of slots in the async queue; when these are full data writes will block until a slot is free.
The size of each slot in rows can be set via setBufferSize().
- Parameters:
size – Number of slots for the writer thread queue.
-
void markFlushed()#
Mark the table as flushed so we know it can be filled again.
-
void setAsync(bool is_async = true)#
Mark whether this table should write asynchronously.
- Parameters:
is_async – Boolean flag.
-
bool isAsync() const noexcept#
Check whether this table should write asynchronously.
- Returns:
Whether writing is asynchronous
Public Static Functions
-
static kc::ks_ptr<PacketTableConfig> create(std::string_view name)#
Create a packet table config.
- Parameters:
name – Name of the table. A / will be interpreted as a new group. Groups will be added as needed.
- Returns:
A ks_ptr to the newly created instance of PacketTableConfig.
Protected Functions
-
void _addVector(std::string_view name, int rows, bool as_scalars)#
Add a vector type to this PacketTableConfig.
- Parameters:
name – The name of the data to log.
rows – The number of rows the vector has.
as_scalars – Whether to add the vector as individual scalars or as one vector.
-
void _addMatrix(std::string_view name, int rows, int cols, bool as_scalars)#
Add a matrix type to this PacketTableConfig.
- Parameters:
name – The name of the data to log.
rows – The number of rows the matrix has.
cols – The number of cols the matrix has.
as_scalars – Whether to add the matrix as individual scalars or as one matrix.
-
virtual void _makeHealthy()#
Create the data type and buffer for the data. This can only be done once.
-
virtual void _makeNotHealthy()#
This should never be called. If it is, then there is an issue.
-
void _acquireSlot()#
Atomically acquire a slot from the queue.
-
std::optional<unsigned int> _publishCurrentSlot(bool force = false)#
Publish the current slot so H5Writer can submit it to the writer thread.
This only marks the slot as no longer owned by the producer. H5Writer is responsible for submitting the task that writes the slot and returns it to the free queue.
- Parameters:
force – Publish a partially-filled slot. Empty slots are never published.
- Returns:
The published slot index, or std::nullopt if there is nothing to publish.
Protected Attributes
-
PacketTableWriteMode _write_mode = PacketTableWriteMode::DIRECT#
Writing mode (DIRECT for synchronous file writes).
-
unsigned int _num_async_slots = 16#
Number of slots in the ringbuffer.
-
std::vector<PacketTableSlot> _slots#
Slots for writing; each one contains a buffer and a counter.
-
std::unique_ptr<boost::lockfree::spsc_queue<unsigned int>> _free_slots = nullptr#
SPSC Queue for tracking free slots for writing. Uses a pointer because the queue is not default-constructible.
-
int _current_slot = -1#
Current slot that we are writing to, or negative for no slot.
-
PacketTableConfig(std::string_view name)#