aqnwb 0.2.0
Loading...
Searching...
No Matches
VectorData.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5#include "Utils.hpp"
6#include "io/ReadIO.hpp"
9
10namespace AQNWB::NWB
11{
15class VectorData : public Data
16{
17public:
19
20protected:
27 VectorData(const std::string& path, std::shared_ptr<IO::BaseIO> io);
28
29public:
33 virtual ~VectorData() override {}
34
45 static std::shared_ptr<VectorData> createReferenceVectorData(
46 const std::string& path,
47 std::shared_ptr<IO::BaseIO> io,
48 const std::string& description,
49 const std::vector<std::string>& references)
50 {
51 Status dataStatus = io->createReferenceDataSet(path, references);
52 if (dataStatus != Status::Success) {
53 return nullptr;
54 }
55
56 auto vectorData = VectorData::create(path, io);
57 Status commonAttrsStatus = io->createCommonNWBAttributes(
58 path, vectorData->getNamespace(), vectorData->getTypeName());
59 Status attrStatus = io->createAttribute(description, path, "description");
60 if ((attrStatus && commonAttrsStatus) != Status::Success) {
61 return nullptr;
62 }
63
64 return vectorData;
65 }
66
77 const std::string& description)
78 {
79 auto ioPtr = getIO();
80 if (ioPtr == nullptr) {
81 std::cerr << "IO object has been deleted. Can't initialize VectorData: "
82 << m_path << std::endl;
83 return Status::Failure;
84 }
85 Status dataStatus = Data::initialize(dataConfig);
86 Status attrStatus =
87 ioPtr->createAttribute(description, m_path, "description");
88 return dataStatus && attrStatus;
89 }
90
92 std::string,
93 "description",
94 Description of what these vectors represent)
95};
96
111template<typename DTYPE = std::any>
113{
114 friend class AQNWB::NWB::RegisteredType; /* base can call constructor */
115
116protected:
123 VectorDataTyped(const std::string& path, std::shared_ptr<IO::BaseIO> io)
124 : VectorData(path, io)
125 {
126 }
127
128 using VectorData::VectorData; /* inherit from immediate base */
129
130public:
141 static std::shared_ptr<VectorDataTyped> create(
142 const std::string& path, std::shared_ptr<AQNWB::IO::BaseIO> io)
143 {
145 }
146
150 virtual ~VectorDataTyped() override {}
151
165 static std::shared_ptr<VectorDataTyped<DTYPE>> fromVectorData(
166 const std::shared_ptr<VectorData>& data)
167 {
168 return VectorDataTyped<DTYPE>::create(data->getPath(), data->getIO());
169 }
170
173
174 // Define the data fields to expose for lazy read access
175 DEFINE_DATASET_FIELD(readData, recordData, DTYPE, "", The main data)
176};
177} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:22
#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_DATASET_FIELD(readName, writeName, default_type, fieldPath, description)
Defines a lazy-loaded dataset field accessor function.
Definition RegisteredType.hpp:573
The configuration for an array dataset.
Definition BaseIO.hpp:204
Data(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.cpp:9
Status initialize(const IO::ArrayDataSetConfig &dataConfig)
Initialize the dataset for the Data object.
Definition Data.cpp:14
Base class for types defined in the NWB schema.
Definition RegisteredType.hpp:48
std::string m_path
The path of the registered type.
Definition RegisteredType.hpp:410
static std::shared_ptr< RegisteredType > create(const std::string &fullClassName, const std::string &path, std::shared_ptr< IO::BaseIO > io, bool fallbackToBase=false)
Create an instance of a registered subclass by name.
Definition RegisteredType.cpp:75
std::string getPath() const
Gets the path of the registered type.
Definition RegisteredType.hpp:59
std::shared_ptr< AQNWB::IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition RegisteredType.hpp:77
static std::shared_ptr< VectorData > create(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readDescription() const
VectorData(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition VectorData.cpp:8
Status initialize(const IO::ArrayDataSetConfig &dataConfig, const std::string &description)
Initialize the dataset for the VectorData object.
Definition VectorData.hpp:76
static std::shared_ptr< VectorData > createReferenceVectorData(const std::string &path, std::shared_ptr< IO::BaseIO > io, const std::string &description, const std::vector< std::string > &references)
Create a VectorData object with a reference dataset.
Definition VectorData.hpp:45
virtual ~VectorData() override
Virtual destructor.
Definition VectorData.hpp:33
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordData(bool reset=false)
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readData() const
VectorData(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition VectorData.cpp:8
static std::shared_ptr< VectorDataTyped< DTYPE > > fromVectorData(const std::shared_ptr< VectorData > &data)
Create a VectorDataTyped object from a Data object.
Definition VectorData.hpp:165
VectorDataTyped(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition VectorData.hpp:123
virtual ~VectorDataTyped() override
Virtual destructor.
Definition VectorData.hpp:150
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
Namespace for all classes related to the NWB data standard.
const std::string namespaceName
Definition hdmf_common.hpp:21