aqnwb 0.1.0
Loading...
Searching...
No Matches
HDF5IO.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <memory>
5#include <string>
6
7#include <H5Opublic.h>
8
9#include "BaseIO.hpp"
10#include "Types.hpp"
11
12namespace H5
13{
14class DataSet;
15class H5File;
16class DataType;
17class Exception;
18} // namespace H5
19
24namespace AQNWB::HDF5
25{
26class HDF5RecordingData; // declare here because gets used in HDF5IO class
27
32class HDF5IO : public BaseIO
33{
34public:
44 HDF5IO(const std::string& fileName, const bool disableSWMRMode = false);
45
49 ~HDF5IO();
50
55 Status open() override;
56
62 Status open(bool newfile) override;
63
68 Status close() override;
69
74 Status flush() override;
75
86 const void* data,
87 const std::string& path,
88 const std::string& name,
89 const SizeType& size = 1) override;
90
98 Status createAttribute(const std::string& data,
99 const std::string& path,
100 const std::string& name) override;
101
109 Status createAttribute(const std::vector<std::string>& data,
110 const std::string& path,
111 const std::string& name) override;
112
121 Status createAttribute(const std::vector<const char*>& data,
122 const std::string& path,
123 const std::string& name,
124 const SizeType& maxSize) override;
125
133 Status createReferenceAttribute(const std::string& referencePath,
134 const std::string& path,
135 const std::string& name) override;
136
142 Status createGroup(const std::string& path) override;
143
151 Status createLink(const std::string& path,
152 const std::string& reference) override;
153
160 Status createStringDataSet(const std::string& path,
161 const std::string& value) override;
162
169 Status createStringDataSet(const std::string& path,
170 const std::vector<std::string>& values) override;
171
180 const std::string& path,
181 const std::vector<std::string>& references) override;
182
187 Status startRecording() override;
188
193 Status stopRecording() override;
194
201 bool canModifyObjects() override;
202
212 std::unique_ptr<BaseRecordingData> createArrayDataSet(
213 const BaseDataType& type,
214 const SizeArray& size,
215 const SizeArray& chunking,
216 const std::string& path) override;
217
223 std::unique_ptr<BaseRecordingData> getDataSet(
224 const std::string& path) override;
225
232 bool objectExists(const std::string& path) override;
233
239 H5O_type_t getObjectType(const std::string& path);
240
246 static H5::DataType getNativeType(BaseDataType type);
247
253 static H5::DataType getH5Type(BaseDataType type);
254
255protected:
261 Status createGroupIfDoesNotExist(const std::string& path) override;
262
263private:
267 std::unique_ptr<H5::H5File> m_file;
271 bool m_disableSWMRMode;
272};
273
282{
283public:
288 HDF5RecordingData(std::unique_ptr<H5::DataSet> data);
289
294
299
304
313 Status writeDataBlock(const std::vector<SizeType>& dataShape,
314 const std::vector<SizeType>& positionOffset,
315 const BaseDataType& type,
316 const void* data);
317
322 inline const H5::DataSet* getDataSet() const { return m_dataset.get(); }
323
324private:
328 Status checkStatus(int status);
329
333 std::unique_ptr<H5::DataSet> m_dataset;
334};
335} // namespace AQNWB::HDF5
AQNWB::Types::SizeType SizeType
Definition BaseIO.hpp:16
AQNWB::Types::SizeArray SizeArray
Definition BaseIO.hpp:15
Represents a base data type.
Definition BaseIO.hpp:35
The BaseIO class is an abstract base class that defines the interface for input/output (IO) operation...
Definition BaseIO.hpp:92
The base class to represent recording data that can be extended.
Definition BaseIO.hpp:379
The HDF5IO class provides an interface for reading and writing data to HDF5 files.
Definition HDF5IO.hpp:33
Status stopRecording() override
Stops the recording process.
Definition HDF5IO.cpp:402
Status createGroup(const std::string &path) override
Creates a new group in the file.
Definition HDF5IO.cpp:276
std::unique_ptr< BaseRecordingData > createArrayDataSet(const BaseDataType &type, const SizeArray &size, const SizeArray &chunking, const std::string &path) override
Creates an extendable dataset with a given base data type, size, chunking, and path.
Definition HDF5IO.cpp:465
Status createLink(const std::string &path, const std::string &reference) override
Creates a soft link to another location in the file.
Definition HDF5IO.cpp:303
Status createAttribute(const BaseDataType &type, const void *data, const std::string &path, const std::string &name, const SizeType &size=1) override
Creates an attribute at a given location in the file.
Definition HDF5IO.cpp:85
Status createReferenceDataSet(const std::string &path, const std::vector< std::string > &references) override
Creates a dataset that holds an array of references to groups within the file.
Definition HDF5IO.cpp:317
static H5::DataType getNativeType(BaseDataType type)
Returns the HDF5 native data type for a given base data type.
Definition HDF5IO.cpp:526
~HDF5IO()
Destructor for the HDF5IO class.
Definition HDF5IO.cpp:24
Status startRecording() override
Start SWMR write to start recording process.
Definition HDF5IO.cpp:390
static H5::DataType getH5Type(BaseDataType type)
Returns the HDF5 data type for a given base data type.
Definition HDF5IO.cpp:577
Status createReferenceAttribute(const std::string &referencePath, const std::string &path, const std::string &name) override
Sets an object reference attribute for a given location in the file.
Definition HDF5IO.cpp:221
Status close() override
Closes the file.
Definition HDF5IO.cpp:60
bool canModifyObjects() override
Checks whether the file is in a mode where objects can be added or deleted. Note, this does not apply...
Definition HDF5IO.cpp:413
std::unique_ptr< BaseRecordingData > getDataSet(const std::string &path) override
Returns a pointer to a dataset at a given path.
Definition HDF5IO.cpp:442
HDF5IO(const std::string &fileName, const bool disableSWMRMode=false)
Constructor for the HDF5IO class that takes a file name as input.
Definition HDF5IO.cpp:18
Status createStringDataSet(const std::string &path, const std::string &value) override
Creates a non-modifiable dataset with a string value.
Definition HDF5IO.cpp:352
H5O_type_t getObjectType(const std::string &path)
Returns the HDF5 type of object at a given path.
Definition HDF5IO.cpp:509
Status open() override
Opens an existing file or creates a new file for writing.
Definition HDF5IO.cpp:29
Status flush() override
Flush data to disk.
Definition HDF5IO.cpp:79
Status createGroupIfDoesNotExist(const std::string &path) override
Creates a new group if it does not exist.
Definition HDF5IO.cpp:290
bool objectExists(const std::string &path) override
Checks whether a Dataset, Group, or Link already exists at the location in the file.
Definition HDF5IO.cpp:432
Represents an HDF5 Dataset that can be extended indefinitely in blocks.
Definition HDF5IO.hpp:282
const H5::DataSet * getDataSet() const
Gets a const pointer to the HDF5 dataset.
Definition HDF5IO.hpp:322
HDF5RecordingData(const HDF5RecordingData &)=delete
Deleted copy constructor to prevent construction-copying.
Status writeDataBlock(const std::vector< SizeType > &dataShape, const std::vector< SizeType > &positionOffset, const BaseDataType &type, const void *data)
Writes a block of data to the HDF5 dataset.
Definition HDF5IO.cpp:659
~HDF5RecordingData()
Destroys the HDF5RecordingData object.
Definition HDF5IO.cpp:653
HDF5RecordingData & operator=(const HDF5RecordingData &)=delete
Deleted copy assignment operator to prevent copying.
HDF5RecordingData(std::unique_ptr< H5::DataSet > data)
Constructs an HDF5RecordingData object.
Definition HDF5IO.cpp:629
Status
Represents the status of an operation.
Definition Types.hpp:22
Namespace for all components of the HDF5 I/O backend.
Definition HDF5IO.hpp:13