aqnwb 0.2.0
Loading...
Searching...
No Matches
DynamicTable.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <any>
4#include <string>
5
6#include "Utils.hpp"
7#include "io/BaseIO.hpp"
8#include "io/ReadIO.hpp"
13#include "spec/hdmf_common.hpp"
14
15namespace AQNWB::NWB
16{
24class DynamicTable : public Container
25{
26public:
27 // Register the TimeSeries as a subclass of Container
31
32protected:
38 DynamicTable(const std::string& path, std::shared_ptr<IO::BaseIO> io);
39
40public:
44 virtual ~DynamicTable();
45
53 Status initialize(const std::string& description);
54
63 Status finalize() override;
64
75 Status addColumn(const std::shared_ptr<VectorData>& vectorData,
76 const std::vector<std::string>& values);
77
85 Status addReferenceColumn(const std::string& name,
86 const std::string& colDescription,
87 const std::vector<std::string>& dataset);
88
95 Status setRowIDs(const std::shared_ptr<ElementIdentifiers>& elementIDs,
96 const std::vector<int>& values);
97
112 virtual void setColNames(const std::vector<std::string>& newColNames)
113 {
114 m_colNames = newColNames;
115 }
116
127 template<typename DTYPE = std::any>
128 std::shared_ptr<VectorDataTyped<DTYPE>> readColumn(const std::string& colName)
129 {
130 std::string columnPath = AQNWB::mergePaths(m_path, colName);
131 auto ioPtr = getIO();
132 if (ioPtr != nullptr) {
133 if (ioPtr->objectExists(columnPath)) {
134 if (ioPtr->getStorageObjectType(columnPath)
135 == StorageObjectType::Dataset)
136 {
137 return VectorDataTyped<DTYPE>::create(columnPath, ioPtr);
138 }
139 }
140 } else {
141 std::cerr << "IO object has been deleted. Can't read column: " << colName
142 << " in DynamicTable: " << m_path << std::endl;
143 }
144 return nullptr;
145 }
146
148 std::string,
149 "colnames",
150 The names of the columns in the table)
151
153 std::string,
154 "description",
155 Description of what is in this dynamic table)
156
160 "id",
161 "unique identifiers for the rows of this dynamic table")
162
163protected:
168 SizeType addColumnName(const std::string& colName);
169
173 std::vector<std::string> m_colNames;
174
178 std::unique_ptr<IO::RecordingObjects> m_recordingColumns;
179
184};
185} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:22
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:501
#define DEFINE_ATTRIBUTE_FIELD(name, default_type, fieldPath, description)
Defines a lazy-loaded attribute field accessor function.
Definition RegisteredType.hpp:534
#define DEFINE_REGISTERED_FIELD(name, registeredType, fieldPath, description)
Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes.
Definition RegisteredType.hpp:638
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
std::vector< std::string > m_colNames
Names of the columns in the table.
Definition DynamicTable.hpp:173
SizeType addColumnName(const std::string &colName)
Add a column name to m_colNames while preventing duplicates.
Definition DynamicTable.cpp:55
Status setRowIDs(const std::shared_ptr< ElementIdentifiers > &elementIDs, const std::vector< int > &values)
Adds a column of element identifiers to the table.
Definition DynamicTable.cpp:90
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readDescription() const
std::shared_ptr< VectorDataTyped< DTYPE > > readColumn(const std::string &colName)
Read an arbitrary column of the DynamicTable.
Definition DynamicTable.hpp:128
virtual ~DynamicTable()
Destructor.
Definition DynamicTable.cpp:36
DynamicTable(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition DynamicTable.cpp:12
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readColNames() const
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:117
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:69
virtual void setColNames(const std::vector< std::string > &newColNames)
Sets the column names of the DynamicTable.
Definition DynamicTable.hpp:112
std::shared_ptr< ElementIdentifiers > m_rowElementIdentifiers
The row ids data object for write.
Definition DynamicTable.hpp:183
Status finalize() override
Finalizes writing the DynamicTable.
Definition DynamicTable.cpp:150
std::shared_ptr< RTYPE > readIdColumn() const
std::unique_ptr< IO::RecordingObjects > m_recordingColumns
The columns added for recording.
Definition DynamicTable.hpp:178
A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable.
Definition ElementIdentifiers.hpp:13
std::string m_path
The path of the registered type.
Definition RegisteredType.hpp:410
std::shared_ptr< AQNWB::IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition RegisteredType.hpp:77
static std::shared_ptr< VectorDataTyped > create(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Factor method to create a VectorDataTyped object.
Definition VectorData.hpp:141
The namespace for IO components of AqNWB.
Namespace for all classes related to the NWB data standard.
const std::string namespaceName
Definition hdmf_common.hpp:21
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:112