aqnwb 0.4.0
Loading...
Searching...
No Matches
Data.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <any>
4#include <memory>
5
6#include "Types.hpp"
7#include "io/BaseIO.hpp"
10
11namespace AQNWB::NWB
12{
13
15
20class Data : public RegisteredType
21{
22public:
33 {
40 DataSpecBase(const std::string& datasetName,
41 const IO::ArrayDataSetConfig& dataConfig)
42 : IO::ArrayDataSetConfig(dataConfig)
43 , name(datasetName)
44 {
45 }
46
47 virtual ~DataSpecBase() = default;
48
55 virtual std::shared_ptr<Data> create(
56 const std::string& path, std::shared_ptr<IO::BaseIO> io) const = 0;
57
63 virtual Status initialize(Data& data) const = 0;
64
66 std::string name;
67 };
68
77 template<typename DataT>
78 struct DataSpec : public DataSpecBase
79 {
86 DataSpec(const std::string& datasetName,
87 const IO::ArrayDataSetConfig& dataConfig)
88 : DataSpecBase(datasetName, dataConfig)
89 {
90 }
91
98 std::shared_ptr<Data> create(const std::string& path,
99 std::shared_ptr<IO::BaseIO> io) const override
100 {
101 return DataT::create(path, io);
102 }
103 };
104
105 // Register the Data class with the type registry
107
108protected:
115 Data(const std::string& path, std::shared_ptr<IO::BaseIO> io);
116
117public:
121 virtual ~Data() override {}
122
132
136 inline bool isInitialized() { return this->readData()->exists(); }
137
155 virtual std::vector<AQNWB::Types::CellValue> readCellValues(
156 const SizeArray& start = {},
157 const SizeArray& count = {},
158 const SizeArray& stride = {},
159 const SizeArray& block = {});
160
161 // Define the data fields to expose for lazy read access
162 DEFINE_DATASET_FIELD(readData, recordData, std::any, "", The main data)
163
165 std::string,
166 "neurodata_type",
167 The name of the type)
168
170 std::string,
171 "namespace",
172 The name of the namespace)
173};
174
189template<typename DTYPE = std::any>
190class DataTyped : public Data
191{
192 friend class AQNWB::NWB::RegisteredType; /* base can call constructor */
193
194protected:
201 DataTyped(const std::string& path, std::shared_ptr<IO::BaseIO> io)
202 : Data(path, io)
203 {
204 }
205
206 using Data::Data; /* inherit from immediate base */
207
208public:
219 static std::shared_ptr<DataTyped> create(
220 const std::string& path, std::shared_ptr<AQNWB::IO::BaseIO> io);
221
225 virtual ~DataTyped() override {}
226
240 static std::shared_ptr<DataTyped<DTYPE>> fromData(
241 const std::shared_ptr<Data>& data)
242 {
243 return DataTyped<DTYPE>::create(data->getPath(), data->getIO());
244 }
245
246 // Define the data fields to expose for lazy read access
247 DEFINE_DATASET_FIELD(readData, recordData, DTYPE, "", The main data)
248
251};
252} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:21
AQNWB::Types::SizeArray SizeArray
Definition BaseIO.hpp:22
#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
ArrayDataSetConfig(const BaseDataType &type, const SizeArray &shape, const SizeArray &chunking)
Constructs an ArrayDataSetConfig object with the specified type, shape, and chunking.
Definition BaseIO.cpp:37
Base class for array dataset configuration.
Definition BaseIO.hpp:277
bool isInitialized()
Check whether the dataset has been initialized.
Definition Data.hpp:136
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordData(bool reset=false)
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readNeurodataType() const
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readData() const
Status initialize(const IO::BaseArrayDataSetConfig &dataConfig)
Initialize the dataset for the Data object.
Definition Data.cpp:18
Data(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.cpp:13
virtual std::vector< AQNWB::Types::CellValue > readCellValues(const SizeArray &start={}, const SizeArray &count={}, const SizeArray &stride={}, const SizeArray &block={})
Reads a range of cell values from the dataset.
Definition Data.cpp:55
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readNamespace() const
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readData() const
DataTyped(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.hpp:201
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordData(bool reset=false)
static std::shared_ptr< DataTyped< DTYPE > > fromData(const std::shared_ptr< Data > &data)
Create a DataTyped object from a Data object.
Definition Data.hpp:240
virtual ~DataTyped() override
Virtual destructor.
Definition Data.hpp:225
static std::shared_ptr< DataTyped > create(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Factor method to create a DataTyped object.
Definition Data.cpp:169
Data(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.cpp:13
Base class for types defined in the NWB schema.
Definition RegisteredType.hpp:48
const std::string & getPath() const
Gets the path of the registered type.
Definition RegisteredType.hpp:59
RegisteredType(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Constructor.
Definition RegisteredType.cpp:18
std::shared_ptr< AQNWB::IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition RegisteredType.hpp:77
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
virtual std::shared_ptr< Data > create(const std::string &path, std::shared_ptr< IO::BaseIO > io) const =0
Create the concrete Data object represented by this spec.
DataSpecBase(const std::string &datasetName, const IO::ArrayDataSetConfig &dataConfig)
Construct the DataSpecBase.
Definition Data.hpp:40
std::string name
Dataset name relative to the owning table/container.
Definition Data.hpp:66
virtual ~DataSpecBase()=default
virtual Status initialize(Data &data) const =0
Initialize the created concrete Data object from this spec.
DataSpec(const std::string &datasetName, const IO::ArrayDataSetConfig &dataConfig)
Construct the typed DataSpec.
Definition Data.hpp:86
std::shared_ptr< Data > create(const std::string &path, std::shared_ptr< IO::BaseIO > io) const override
Create the concrete Data object represented by this typed spec.
Definition Data.hpp:98
Represents a single cell value in a DynamicTable row.
Definition Types.hpp:190