7#include <unordered_map>
40 using RowData = std::unordered_map<std::string, CellValue>;
53 DynamicTable(
const std::string& path, std::shared_ptr<IO::BaseIO> io);
73 const std::vector<DataSpecPtr>& dataSpecs = {});
87 const std::vector<DataSpecPtr>& dataSpecs)
const;
122 const std::vector<std::string>& values);
160 const std::string& colDescription,
161 const std::vector<std::string>& dataset);
170 const std::optional<int>& rowId = std::nullopt);
178 Status addRows(
const std::vector<AQNWB::Types::RowData>& rows,
179 const std::vector<int>& rowIds = {});
200 std::vector<AQNWB::Types::RowData>
readRows(
203 const std::vector<std::string>& colNames = {},
204 bool includeId =
true);
218 const std::vector<std::string>& colNames = {},
219 bool includeId =
true);
240 virtual void setColNames(
const std::vector<std::string>& newColNames);
259 const std::string& columnName,
const SizeType rowChunkSize = 100);
271 typename std::conditional<std::is_base_of<VectorData, T>::value,
287 template<
typename DTYPE>
308 template<
typename T = std::any>
309 std::shared_ptr<typename ColumnReturnType<T>::type>
readColumn(
310 const std::string& colName)
314 auto ioPtr =
getIO();
315 if (ioPtr !=
nullptr) {
316 if (ioPtr->objectExists(columnPath)) {
317 if (ioPtr->getStorageObjectType(columnPath)
318 == StorageObjectType::Dataset)
320 if constexpr (std::is_base_of<VectorData, T>::value
325 return std::dynamic_pointer_cast<ReturnType>(column);
327 return ReturnType::create(columnPath, ioPtr);
332 std::cerr <<
"IO object has been deleted. Can't read column: " << colName
333 <<
" in DynamicTable: " <<
m_path << std::endl;
341 The names of the columns in the table)
346 Description of what is in
this dynamic table)
352 "unique identifiers for the rows of this dynamic table")
367 const std::
string& objectName) const;
384 const std::
string& objectName) const;
418 std::shared_ptr<VectorData>
435 const std::string& name)
const;
509 template<
typename RequiredDataSpec>
511 const std::vector<DataSpecPtr>& dataSpecs,
512 const std::optional<IO::BaseDataType>&
513 expectedDataType = std::nullopt)
const
515 std::vector<IO::BaseDataType> allowedDataTypes;
516 if (expectedDataType.has_value()) {
517 allowedDataTypes.push_back(expectedDataType.value());
520 requiredName, dataSpecs, allowedDataTypes);
539 template<
typename RequiredDataSpec>
541 const std::string& requiredName,
542 const std::vector<DataSpecPtr>& dataSpecs,
543 const std::vector<IO::BaseDataType>& allowedDataTypes)
const
546 for (
const auto& spec : dataSpecs) {
547 if (!spec || spec->name != requiredName) {
552 if (!std::dynamic_pointer_cast<RequiredDataSpec>(spec)) {
553 std::cerr <<
"DynamicTable::checkRequiredColumnSpec: required column '"
555 <<
"' does not use the required concrete DataSpec type."
557 return Status::Failure;
559 if (spec->getShape().size() != 1) {
560 std::cerr <<
"DynamicTable::checkRequiredColumnSpec: required column '"
561 << requiredName <<
"' must be one-dimensional." << std::endl;
562 return Status::Failure;
564 if (!allowedDataTypes.empty()
565 && std::none_of(allowedDataTypes.begin(),
566 allowedDataTypes.end(),
568 { return spec->getType() == dataType; }))
570 std::cerr <<
"DynamicTable::checkRequiredColumnSpec: required column '"
571 << requiredName <<
"' has an invalid data type." << std::endl;
572 return Status::Failure;
577 std::cerr <<
"DynamicTable::checkRequiredColumnSpec: required column '"
578 << requiredName <<
"' not found." << std::endl;
579 return Status::Failure;
581 return Status::Success;
AQNWB::Types::Status Status
Definition BaseIO.hpp:21
AQNWB::Types::SizeType SizeType
Definition Channel.hpp:8
#define REGISTER_SUBCLASS(T, BASE, NAMESPACE)
Macro to register a subclass with the RegisteredType class registry.
Definition RegisteredType.hpp:547
#define DEFINE_ATTRIBUTE_FIELD(name, default_type, fieldPath, description)
Defines a lazy-loaded attribute field accessor function.
Definition RegisteredType.hpp:580
#define DEFINE_REGISTERED_FIELD(name, registeredType, fieldPath, description)
Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes.
Definition RegisteredType.hpp:672
Represents a base data type.
Definition BaseIO.hpp:47
AQNWB::Types::VectorDataVariant BaseDataVectorVariant
Definition BaseIO.hpp:104
Container(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Container.cpp:10
Status initialize()
Initialize the container.
Definition Container.cpp:20
Status flushColNames()
Flush the column names to the file.
Definition DynamicTable.cpp:714
std::vector< std::string > m_colNames
Names of the columns in the table.
Definition DynamicTable.hpp:612
std::vector< ConfiguredColumn > m_configuredColumns
Ordered list of configured columns managed by the table.
Definition DynamicTable.hpp:622
Status addRows(const std::vector< AQNWB::Types::RowData > &rows, const std::vector< int > &rowIds={})
Adds multiple rows to the table.
Definition DynamicTable.cpp:393
SizeType addColumnName(const std::string &colName)
Add a column name to m_colNames while preventing duplicates.
Definition DynamicTable.cpp:113
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readDescription() const
Status configureDataObjects(const std::vector< DataSpecPtr > &dataSpecs)
Configure multiple data objects.
Definition DynamicTable.cpp:849
SizeType registerColumn(const std::shared_ptr< VectorData > &column)
Register a column in the table's column registry.
Definition DynamicTable.cpp:898
std::shared_ptr< MeaningsTable > createMeaningsTableInstance(const std::string &objectName) const
Returns the instance of the class representing the named MeaningsTable field for write.
Definition DynamicTable.cpp:817
Status writeColumnBuffer(const ConfiguredColumn &configuredColumn, const IO::BaseDataType::BaseDataVectorVariant &buffer, SizeType rowCount)
Write a buffer of data to a configured column.
virtual Status validateDataSpecs(const std::vector< DataSpecPtr > &dataSpecs) const
Validates the provided data specifications for the table.
Definition DynamicTable.cpp:73
std::shared_ptr< MeaningsTable > readMeaningsTable(const std::string &objectName) const
Returns the instance of the class representing the named MeaningsTable field.
Definition DynamicTable.cpp:800
std::shared_ptr< typename ColumnReturnType< T >::type > readColumn(const std::string &colName)
Read an arbitrary column of the DynamicTable.
Definition DynamicTable.hpp:309
Status checkRequiredColumnSpec(const std::string &requiredName, const std::vector< DataSpecPtr > &dataSpecs, const std::vector< IO::BaseDataType > &allowedDataTypes) const
Check that a required column spec exists and has one of the allowed data types.
Definition DynamicTable.hpp:540
virtual void setColNames(const std::vector< std::string > &newColNames)
Sets the column names of the DynamicTable.
Definition DynamicTable.cpp:89
DynamicTable(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition DynamicTable.cpp:19
Data::DataSpecBase DataSpec
Definition DynamicTable.hpp:35
~DynamicTable() override
Destructor.
Definition DynamicTable.cpp:41
std::shared_ptr< MeaningsTable > createMeaningsTable(const std::string &columnName, const SizeType rowChunkSize=100)
Create a MeaningsTable for a specific VectorData column in this DynamicTable.
Definition DynamicTable.cpp:737
Status addRow(const AQNWB::Types::RowData &row, const std::optional< int > &rowId=std::nullopt)
Adds a single row to the table.
Definition DynamicTable.cpp:202
std::shared_ptr< DataSpec > DataSpecPtr
Definition DynamicTable.hpp:36
std::unordered_map< std::string, SizeType > m_configuredColumnIndices
Lookup map from column name to its index in m_configuredColumns.
Definition DynamicTable.hpp:627
SizeType getNumberOfRows() const
Get the number of rows in the table.
Definition DynamicTable.cpp:212
Status checkRequiredColumnSpec(const std::string &requiredName, const std::vector< DataSpecPtr > &dataSpecs, const std::optional< IO::BaseDataType > &expectedDataType=std::nullopt) const
Validate the concrete specification, shape, and optionally data type of a required column.
Definition DynamicTable.hpp:510
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readColNames() const
Status loadConfiguredColumnsFromFile()
Load all configured columns and row element identifiers from the file.
Definition DynamicTable.cpp:945
Status setRowIDs(const std::vector< int > &values)
Sets the values of the element identifiers on the table.
Definition DynamicTable.cpp:172
static std::vector< DataSpecPtr > createDefaultDataSpecs(const SizeType rowChunkSize=100)
Create the default data specs for a DynamicTable.
Definition DynamicTable.cpp:80
Status addReferenceColumn(const std::string &name, const std::string &colDescription, const std::vector< std::string > &dataset)
Adds a column of references to the table.
Definition DynamicTable.cpp:682
Status addColumn(const std::shared_ptr< VectorData > &vectorData, const std::vector< std::string > &values)
Adds a column of vector string data to the table.
Definition DynamicTable.cpp:137
Status ensureConfiguredColumnsLoaded()
Ensure that all configured columns are loaded from the file.
Definition DynamicTable.cpp:937
std::vector< AQNWB::Types::RowData > readRows(SizeType start=0, SizeType count=Types::SizeTypeNotSet, const std::vector< std::string > &colNames={}, bool includeId=true)
Read rows from the table.
Definition DynamicTable.cpp:225
std::string toString(SizeType start=0, SizeType count=Types::SizeTypeNotSet, const std::vector< std::string > &colNames={}, bool includeId=true)
Convert the table to a string representation.
Definition DynamicTable.cpp:319
std::vector< int > generateRowIDs(SizeType rowCount)
Generate row IDs for the table.
Definition DynamicTable.cpp:977
AQNWB::NWB::CellValue CellValue
Definition DynamicTable.hpp:39
std::shared_ptr< ElementIdentifiers > m_rowElementIdentifiers
The row ids data object for write.
Definition DynamicTable.hpp:617
std::shared_ptr< VectorData > getConfiguredColumn(const std::string &name) const
Look up an already-configured column by name.
Definition DynamicTable.cpp:831
std::unordered_map< std::string, CellValue > RowData
Definition DynamicTable.hpp:40
Status finalize() override
Finalizes writing the DynamicTable.
Definition DynamicTable.cpp:731
std::shared_ptr< RTYPE > readIdColumn() const
Status configureDataObject(const DataSpec &dataSpec)
Configure a single data object.
Definition DynamicTable.cpp:866
void clearColumns()
Clear all registered columns and column names.
Definition DynamicTable.cpp:841
A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable.
Definition ElementIdentifiers.hpp:13
A table to store information about the meanings of values in a referenced VectorData object....
Definition MeaningsTable.hpp:38
std::string m_path
The path of the registered type.
Definition RegisteredType.hpp:471
static std::shared_ptr< RegisteredType > create(const std::string &fullClassName, const std::string &path, std::shared_ptr< IO::BaseIO > io, bool fallbackToBase=false)
Create or retrieve the canonical instance of a registered subclass.
Definition RegisteredType.cpp:87
std::shared_ptr< AQNWB::IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition RegisteredType.hpp:77
A typed n-dimensional dataset representing a column of a DynamicTable.
Definition VectorData.hpp:143
Namespace for all classes related to the NWB data standard.
AQNWB::Types::CellValue CellValue
Definition Data.hpp:14
const std::string namespaceName
Definition hdmf_common.hpp:21
constexpr SizeType SizeTypeNotSet
Value to use to indicate that a SizeType index is not set.
Definition Types.hpp:109
std::unordered_map< std::string, CellValue > RowData
Represents a row of data in a DynamicTable.
Definition Types.hpp:371
static std::string mergePaths(const std::string &path1, const std::string &path2)
Merge two paths into a single path, handling extra trailing and starting "/".
Definition Utils.hpp:275
Non-templated base class for runtime Data configuration.
Definition Data.hpp:33
Type trait to determine the return type of readColumn.
Definition DynamicTable.hpp:269
typename std::conditional< std::is_base_of< VectorData, T >::value, T, VectorDataTyped< T > >::type type
Definition DynamicTable.hpp:270
Type trait identifying non-registered typed VectorData facades.
Definition DynamicTable.hpp:284