aqnwb 0.4.0
Loading...
Searching...
No Matches
VectorIndex.hpp
Go to the documentation of this file.
1#pragma once
2
3// Common STL includes
4#include <memory>
5#include <optional>
6#include <string>
7#include <vector>
8// Base AqNWB includes for IO and RegisteredType
9#include "io/BaseIO.hpp"
10#include "io/ReadIO.hpp"
12// Include for parent type
14// Includes for types that are referenced and used
17// Include for the namespace schema header
18#include "spec/hdmf_common.hpp"
19
20namespace AQNWB::NWB
21{
22
40{
41protected:
47 VectorIndex(const std::string& path, std::shared_ptr<AQNWB::IO::BaseIO> io);
48
49public:
54 struct DataSpec : public Data::DataSpec<VectorIndex>
55 {
56 DataSpec(const std::string& datasetName,
57 const IO::ArrayDataSetConfig& dataConfig,
58 const std::string& columnDescription,
59 const std::string& columnTargetPath)
60 : Data::DataSpec<VectorIndex>(datasetName, dataConfig)
61 , description(columnDescription)
62 , targetPath(columnTargetPath)
63 {
64 }
65
66 virtual ~DataSpec() = default;
67
68 std::string description;
69 std::string targetPath;
70
71 Status initialize(Data& data) const override
72 {
73 auto* vectorIndex = dynamic_cast<VectorIndex*>(&data);
74 if (!vectorIndex) {
75 std::cerr << "VectorIndex::DataSpec::initialize received incompatible "
76 "VectorIndex object"
77 << std::endl;
78 return Status::Failure;
79 }
80 return vectorIndex->initialize(
81 static_cast<const IO::ArrayDataSetConfig&>(*this),
84 }
85 };
86
90 virtual ~VectorIndex() override {}
91
105 const std::string& description,
106 const std::string& targetPath);
107
121 Status appendData(const AQNWB::Types::CellValue& targetValues,
122 size_t& elementsAppended) override;
123
129 std::shared_ptr<VectorData> getTargetColumn();
130
149 std::vector<AQNWB::Types::CellValue> readIndexedCellValues(
151
152 // Define read methods
156 "target",
157 "Reference to the target dataset that this index applies to.")
158
160 std::string,
161 "description",
162 "Description of what these vectors represent.")
163
165 readData,
167 uint32_t,
168 "",
169 "Used with VectorData to encode a ragged array. An array of indices into "
170 "the first dimension of the target VectorData - and forming a map "
171 "between the rows of a DynamicTable and the indices of the VectorData. "
172 "The name of the VectorIndex is expected to be the name of the target "
173 "VectorData object followed by _index.")
174
177 AQNWB::SPEC::HDMF_COMMON::namespaceName)
178
179private:
185 uint64_t m_currentIndex = 0;
186
192
197 std::shared_ptr<VectorData> m_targetColumn;
198
202 IO::BaseDataType m_dataType;
203
208
216
227 uint64_t extractIndexValue(const AQNWB::Types::CellValue& cell) const;
228
243 const std::vector<AQNWB::Types::CellValue>& cells,
244 size_t offset,
245 size_t count) const;
246};
247
248} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:21
AQNWB::Types::SizeType SizeType
Definition Channel.hpp:8
#define DEFINE_REFERENCED_REGISTERED_FIELD(name, registeredType, fieldPath, description)
Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes that are linked t...
Definition RegisteredType.hpp:766
#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_DATASET_FIELD(readName, writeName, default_type, fieldPath, description)
Defines a lazy-loaded dataset field accessor function.
Definition RegisteredType.hpp:619
The configuration for an array dataset.
Definition BaseIO.hpp:321
Base class for array dataset configuration.
Definition BaseIO.hpp:277
An abstract data type for a dataset.
Definition Data.hpp:21
An n-dimensional dataset representing a column of a DynamicTable.
Definition VectorData.hpp:23
VectorData(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition VectorData.cpp:10
uint64_t m_currentIndex
The current index value, representing the total number of elements currently in the target VectorData...
Definition VectorIndex.hpp:185
std::shared_ptr< RTYPE > readTarget() const
bool m_dataTypeInitialized
Flag indicating whether m_dataType has been initialized.
Definition VectorIndex.hpp:207
std::shared_ptr< VectorData > getTargetColumn()
Gets the cached target VectorData column, or reads it if not cached.
Definition VectorIndex.cpp:84
Status appendData(const AQNWB::Types::CellValue &targetValues, size_t &elementsAppended) override
Appends data to the target VectorData and updates this index.
Definition VectorIndex.cpp:469
uint64_t extractIndexValue(const AQNWB::Types::CellValue &cell) const
Extracts the integer index value from a CellValue variant.
Definition VectorIndex.cpp:92
IO::BaseDataType m_dataType
Cached data type of the VectorIndex dataset.
Definition VectorIndex.hpp:202
std::vector< AQNWB::Types::CellValue > readIndexedCellValues(SizeType start=0, SizeType count=AQNWB::Types::SizeTypeNotSet)
Reads a range of ragged array vectors from the target VectorData.
Definition VectorIndex.cpp:199
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readDescription() const
Status initialize(const IO::BaseArrayDataSetConfig &dataConfig, const std::string &description, const std::string &targetPath)
Initialize the dataset for the VectorIndex object.
Definition VectorIndex.cpp:21
AQNWB::Types::CellValue combineCellsToVector(const std::vector< AQNWB::Types::CellValue > &cells, size_t offset, size_t count) const
Combines multiple scalar CellValues into a single vector CellValue.
Definition VectorIndex.cpp:123
VectorIndex(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Constructor.
Definition VectorIndex.cpp:14
bool m_currentIndexInitialized
Flag indicating whether m_currentIndex has been initialized from the file.
Definition VectorIndex.hpp:191
std::shared_ptr< VectorData > m_targetColumn
Cached target VectorData column to avoid reading it from the file repeatedly.
Definition VectorIndex.hpp:197
Status initializeAppendState()
Initializes m_currentIndex and m_dataType by reading the last value from the dataset,...
Definition VectorIndex.cpp:366
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readData() const
virtual ~VectorIndex() override
Virtual destructor.
Definition VectorIndex.hpp:90
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordData(bool reset=false)
The namespace for IO components of AqNWB.
Namespace for all classes related to the NWB data standard.
AQNWB::Types::CellValue CellValue
Definition Data.hpp:14
The namespace for managing format schema and namespaces.
Provides definitions for various types used in the project.
Definition Types.hpp:24
constexpr SizeType SizeTypeNotSet
Value to use to indicate that a SizeType index is not set.
Definition Types.hpp:109
The main namespace for AqNWB.
Definition Channel.hpp:11
Typed runtime configuration for a concrete Data subclass.
Definition Data.hpp:79
Status initialize(Data &data) const override
Initialize the created concrete Data object from this spec.
Definition VectorIndex.hpp:71
DataSpec(const std::string &datasetName, const IO::ArrayDataSetConfig &dataConfig, const std::string &columnDescription, const std::string &columnTargetPath)
Definition VectorIndex.hpp:56
std::string description
Definition VectorIndex.hpp:68
std::string targetPath
Definition VectorIndex.hpp:69
Represents a single cell value in a DynamicTable row.
Definition Types.hpp:190