aqnwb 0.3.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 if (dataConfig.isLink()) {
87 // For links, we don't set attributes since there is no dataset to attach
88 // them to. Validate that the target has the required "description"
89 // attribute.
90 const auto* linkConfig =
91 dynamic_cast<const IO::LinkArrayDataSetConfig*>(&dataConfig);
92 if (linkConfig) {
93 return dataStatus
94 && linkConfig->validateTarget(*ioPtr, {}, {}, {"description"});
95 }
96 return dataStatus;
97 } else {
98 Status attrStatus =
99 ioPtr->createAttribute(description, m_path, "description");
100 return dataStatus && attrStatus;
101 }
102 }
103
105 std::string,
106 "description",
107 Description of what these vectors represent)
108};
109
124template<typename DTYPE = std::any>
126{
127 friend class AQNWB::NWB::RegisteredType; /* base can call constructor */
128
129protected:
136 VectorDataTyped(const std::string& path, std::shared_ptr<IO::BaseIO> io)
137 : VectorData(path, io)
138 {
139 }
140
141 using VectorData::VectorData; /* inherit from immediate base */
142
143public:
154 static std::shared_ptr<VectorDataTyped> create(
155 const std::string& path, std::shared_ptr<AQNWB::IO::BaseIO> io)
156 {
158 }
159
163 virtual ~VectorDataTyped() override {}
164
178 static std::shared_ptr<VectorDataTyped<DTYPE>> fromVectorData(
179 const std::shared_ptr<VectorData>& data)
180 {
181 return VectorDataTyped<DTYPE>::create(data->getPath(), data->getIO());
182 }
183
186
187 // Define the data fields to expose for lazy read access
188 DEFINE_DATASET_FIELD(readData, recordData, DTYPE, "", The main data)
189};
190} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:21
#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
Base class for array dataset configuration.
Definition BaseIO.hpp:205
virtual bool isLink() const
Checks if this configuration represents a link.
Definition BaseIO.hpp:216
Status initialize(const IO::BaseArrayDataSetConfig &dataConfig)
Initialize the dataset for the Data object.
Definition Data.cpp:14
Data(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.cpp:9
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
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::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)
Status initialize(const IO::BaseArrayDataSetConfig &dataConfig, const std::string &description)
Initialize the dataset for the VectorData object.
Definition VectorData.hpp:76
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
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:178
VectorDataTyped(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition VectorData.hpp:136
virtual ~VectorDataTyped() override
Virtual destructor.
Definition VectorData.hpp:163
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:154
Namespace for all classes related to the NWB data standard.
const std::string namespaceName
Definition hdmf_common.hpp:21