83 const std::type_index& inTypeIndex,
114 return std::any_cast<std::vector<uint8_t>>(
data);
116 return std::any_cast<std::vector<uint16_t>>(
data);
118 return std::any_cast<std::vector<uint32_t>>(
data);
120 return std::any_cast<std::vector<uint64_t>>(
data);
122 return std::any_cast<std::vector<int8_t>>(
data);
124 return std::any_cast<std::vector<int16_t>>(
data);
126 return std::any_cast<std::vector<int32_t>>(
data);
128 return std::any_cast<std::vector<int64_t>>(
data);
130 return std::any_cast<std::vector<float>>(
data);
132 return std::any_cast<std::vector<double>>(
data);
134 return std::any_cast<std::vector<std::string>>(
data);
136 return std::monostate {};
138 }
catch (
const std::bad_any_cast&) {
143 return std::monostate {};
164template<
typename DTYPE, std::
size_t NDIMS>
179 const std::array<size_type, NDIMS>&
shape,
180 const std::array<size_type, NDIMS>& strides)
194 template<
size_type N = NDIMS,
typename std::enable_if_t<N == 1,
int> = 0>
209 template<
size_type N = NDIMS,
typename std::enable_if_t<(N > 1),
int> = 0>
213 std::array<
size_type, NDIMS - 1> sub_shape {};
214 std::array<
size_type, NDIMS - 1> sub_strides {};
229 template<
size_type N = NDIMS,
typename std::enable_if_t<N == 1,
int> = 0>
242 template<
size_type N = NDIMS,
typename std::enable_if_t<N == 1,
int> = 0>
271template<
typename DTYPE>
311 template<std::
size_t NDIMS>
314 if (
shape.size() != NDIMS) {
315 throw std::invalid_argument(
316 "Shape size does not match the number of dimensions.");
320 SizeType expected_size = std::accumulate(
323 if (
data.size() != expected_size) {
324 throw std::invalid_argument(
"Data size does not match the shape.");
327 std::array<std::size_t, NDIMS> shape_array {};
328 for (std::size_t i = 0; i < NDIMS; ++i) {
329 shape_array[i] =
static_cast<std::size_t
>(
shape[i]);
332 std::array<std::size_t, NDIMS> strides {};
333 std::size_t stride = 1;
334 for (std::size_t i = NDIMS; i-- > 0;) {
336 stride *= shape_array[i];
356 std::any_cast<std::vector<DTYPE>>(genericData.
data), genericData.
shape);
378template<StorageObjectType T>
405template<StorageObjectType OTYPE,
typename VTYPE = std::any>
419 template<StorageObjectType U>
421 : std::integral_constant<bool, (U == StorageObjectType::Dataset)>
432 "StorageObjectType not allowed for ReadDataWrapper");
461 return std::is_same_v<VTYPE, T>;
489 inline std::shared_ptr<IO::BaseIO>
getIO()
const {
return m_io; }
513 return m_io->getStorageObjectDataType(
m_path);
529 return m_io->getStorageObjectChunking(
m_path);
547 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
560 case StorageObjectType::Dataset: {
563 case StorageObjectType::Attribute: {
567 throw std::runtime_error(
"Unsupported StorageObjectType");
582 case StorageObjectType::Dataset: {
585 case StorageObjectType::Attribute: {
589 throw std::runtime_error(
"Unsupported StorageObjectType");
609 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
617 return m_io->readDataset(
m_path, start, count, stride, block);
634 template<
typename T = VTYPE>
663 template<
typename T = VTYPE,
665 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
681 const std::shared_ptr<IO::BaseIO>
m_io;
AQNWB::Types::StorageObjectType StorageObjectType
Definition BaseIO.hpp:20
AQNWB::Types::SizeArray SizeArray
Definition BaseIO.hpp:22
AQNWB::Types::SizeType SizeType
Definition Channel.hpp:8
Represents a base data type.
Definition BaseIO.hpp:47
@ T_I32
Signed 32-bit integer.
Definition BaseIO.hpp:60
@ T_I64
Signed 64-bit integer.
Definition BaseIO.hpp:61
@ T_I8
Signed 8-bit integer.
Definition BaseIO.hpp:58
@ T_U32
Unsigned 32-bit integer.
Definition BaseIO.hpp:56
@ T_U64
Unsigned 64-bit integer.
Definition BaseIO.hpp:57
@ T_U8
Unsigned 8-bit integer.
Definition BaseIO.hpp:54
@ T_F32
32-bit floating point
Definition BaseIO.hpp:62
@ T_STR
String.
Definition BaseIO.hpp:64
@ T_F64
64-bit floating point
Definition BaseIO.hpp:63
@ T_U16
Unsigned 16-bit integer.
Definition BaseIO.hpp:55
@ T_I16
Signed 16-bit integer.
Definition BaseIO.hpp:59
std::variant< std::monostate, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< uint64_t >, std::vector< int8_t >, std::vector< int16_t >, std::vector< int32_t >, std::vector< int64_t >, std::vector< float >, std::vector< double >, std::vector< std::string > > BaseDataVectorVariant
Definition BaseIO.hpp:101
static BaseDataType fromTypeId(const std::type_index &typeIndex)
Get the BaseDataType from a std::type_index.
Definition BaseIO.hpp:122
Non-owning, multi-dimensional, read-only array view for contiguous data.
Definition ReadIO.hpp:166
const std::array< size_type, NDIMS > & shape() const
Get the shape of the multi-dimensional array view.
Definition ReadIO.hpp:258
std::array< size_type, NDIMS > m_strides
Stride per dimension.
Definition ReadIO.hpp:263
ConstMultiArrayView< DTYPE, NDIMS - 1 > operator[](size_type index) const
Access a sub-array view at the given index for multi-dimensional arrays.
Definition ReadIO.hpp:210
ConstMultiArrayView(const DTYPE *data, const std::array< size_type, NDIMS > &shape, const std::array< size_type, NDIMS > &strides)
Construct a multi-dimensional view over a contiguous data buffer.
Definition ReadIO.hpp:178
std::size_t size_type
Definition ReadIO.hpp:168
const DTYPE * end() const
Returns a pointer to one past the last element for 1D arrays.
Definition ReadIO.hpp:243
std::array< size_type, NDIMS > m_shape
Size of each dimension.
Definition ReadIO.hpp:262
const DTYPE & operator[](size_type index) const
Access element at the given index for 1D arrays.
Definition ReadIO.hpp:195
const DTYPE * m_data
Pointer to the data buffer.
Definition ReadIO.hpp:261
const DTYPE * begin() const
Returns a pointer to the beginning of the data for 1D arrays.
Definition ReadIO.hpp:230
Generic structure to hold type-erased data and shape.
Definition ReadIO.hpp:34
SizeArray shape
The 1D vector with the n-dimensional shape of the data. Set to empty in case of scalar data.
Definition ReadIO.hpp:48
IO::BaseDataType baseDataType
The base data type for the data block.
Definition ReadIO.hpp:71
DataBlockGeneric()=default
Default constructor.
BaseDataType getBaseDataType() const
Get the BaseDataType for the data.
Definition ReadIO.hpp:97
std::any data
Definition ReadIO.hpp:43
BaseDataType::BaseDataVectorVariant as_variant() const
Cast the data to an std::variant for convenient access.
Definition ReadIO.hpp:109
DataBlockGeneric(const std::any &inData, const SizeArray &inShape, const std::type_index &inTypeIndex, const IO::BaseDataType inBaseDataType)
Parameterized constructor.
Definition ReadIO.hpp:81
std::type_index typeIndex
Type index of the values stored in the data vector.
Definition ReadIO.hpp:68
Structure to hold data and shape for a typed data vector.
Definition ReadIO.hpp:273
SizeArray shape
The 1D vector with the n-dimensional shape of the data. Set to empty in case of scalar data.
Definition ReadIO.hpp:283
static DataBlock< DTYPE > fromGeneric(const DataBlockGeneric &genericData)
Factory method to create an DataBlock from a DataBlockGeneric.
Definition ReadIO.hpp:352
const std::type_index typeIndex
Type index of the values stored in the data vector. Here this is fixed to typeid(DTYPE).
Definition ReadIO.hpp:288
std::vector< DTYPE > data
Definition ReadIO.hpp:278
DataBlock(const std::vector< DTYPE > &inData, const SizeArray &inShape)
Definition ReadIO.hpp:293
BaseDataType getBaseDataType() const
Get the BaseDataType for the data.
Definition ReadIO.hpp:370
ConstMultiArrayView< DTYPE, NDIMS > as_multi_array() const
Transform the data to a multi-dimensional array view for convenient access.
Definition ReadIO.hpp:312
Configuration for creating a soft-link to an existing dataset.
Definition BaseIO.hpp:328
IO::LinkArrayDataSetConfig toLinkArrayDataSetConfig() const
Constructs a AQNWB::IO::LinkArrayDataSetConfig from this wrapper.
Definition ReadIO.hpp:548
static constexpr bool isType()
Function to check at compile-time whether the object is of a particular VTYPE, e.g....
Definition ReadIO.hpp:459
SizeArray getChunking() const
Get the chunking configuration of the data object.
Definition ReadIO.hpp:527
SizeType getNumDimensions() const
Get the number of dimensions of the data object.
Definition ReadIO.hpp:504
ReadDataWrapper & operator=(const ReadDataWrapper &)=delete
Deleted copy assignment operator to prevent copying.
IO::BaseDataType getDataType() const
Get the data type of the data object.
Definition ReadIO.hpp:511
std::string m_path
Path to the dataset or attribute to read.
Definition ReadIO.hpp:685
const std::shared_ptr< IO::BaseIO > m_io
Pointer to the I/O object to use for reading.
Definition ReadIO.hpp:681
DataBlock< VTYPE > values() const
Reads an attribute with a specified data type.
Definition ReadIO.hpp:635
DataBlock< VTYPE > values(const SizeArray &start, const SizeArray &count={}, const SizeArray &stride={}, const SizeArray &block={}) const
Reads an dataset with a specified data type.
Definition ReadIO.hpp:666
DataBlockGeneric valuesGeneric() const
Reads a dataset and determines the data type.
Definition ReadIO.hpp:579
virtual ~ReadDataWrapper()
Destructor.
Definition ReadIO.hpp:477
const std::string & getPath() const
Gets the path of the registered type.
Definition ReadIO.hpp:483
static StorageObjectType getStorageObjectType()
Function to return the AQNWB::Types::StorageObjectType OTYPE of the instance.
Definition ReadIO.hpp:452
std::shared_ptr< IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition ReadIO.hpp:489
bool exists() const
Check that the object exists.
Definition ReadIO.hpp:557
ReadDataWrapper(const std::shared_ptr< IO::BaseIO > io, const std::string &path)
Default constructor.
Definition ReadIO.hpp:442
DataBlockGeneric valuesGeneric(const SizeArray &start, const SizeArray &count={}, const SizeArray &stride={}, const SizeArray &block={}) const
Reads a dataset and determines the data type.
Definition ReadIO.hpp:610
SizeArray getShape() const
Get the shape of the data object.
Definition ReadIO.hpp:495
ReadDataWrapper(const ReadDataWrapper &)=delete
Deleted copy constructor to prevent construction-copying.
StorageObjectType
Types of object used in the NWB schema.
Definition Types.hpp:56
size_t SizeType
Alias for the size type used in the project.
Definition Types.hpp:100
The namespace for IO components of AqNWB.
Internal embedded Trait to Check the OTYPE Enum Value at compile time.
Definition ReadIO.hpp:422
Definition ReadIO.hpp:380