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 {};
230 template<
size_type N = NDIMS,
typename std::enable_if_t<N == 1,
int> = 0>
243 template<
size_type N = NDIMS,
typename std::enable_if_t<N == 1,
int> = 0>
272template<
typename DTYPE>
312 template<std::
size_t NDIMS>
315 if (
shape.size() != NDIMS) {
316 throw std::invalid_argument(
317 "Shape size does not match the number of dimensions.");
321 SizeType expected_size = std::accumulate(
324 if (
data.size() != expected_size) {
325 throw std::invalid_argument(
"Data size does not match the shape.");
328 std::array<std::size_t, NDIMS> shape_array {};
329 for (std::size_t i = 0; i < NDIMS; ++i) {
330 shape_array[i] =
static_cast<std::size_t
>(
shape[i]);
333 std::array<std::size_t, NDIMS> strides {};
334 std::size_t stride = 1;
336 for (std::size_t i = NDIMS; i-- > 0;) {
338 stride *= shape_array[i];
358 std::any_cast<std::vector<DTYPE>>(genericData.
data), genericData.
shape);
380template<StorageObjectType T>
407template<StorageObjectType OTYPE,
typename VTYPE = std::any>
421 template<StorageObjectType U>
423 : std::integral_constant<bool, (U == StorageObjectType::Dataset)>
434 "StorageObjectType not allowed for ReadDataWrapper");
463 return std::is_same_v<VTYPE, T>;
491 inline std::shared_ptr<IO::BaseIO>
getIO()
const {
return m_io; }
515 return m_io->getStorageObjectDataType(
m_path);
531 return m_io->getStorageObjectChunking(
m_path);
549 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
562 case StorageObjectType::Dataset: {
565 case StorageObjectType::Attribute: {
569 throw std::runtime_error(
"Unsupported StorageObjectType");
584 case StorageObjectType::Dataset: {
587 case StorageObjectType::Attribute: {
591 throw std::runtime_error(
"Unsupported StorageObjectType");
611 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
619 return m_io->readDataset(
m_path, start, count, stride, block);
636 template<
typename T = VTYPE>
665 template<
typename T = VTYPE,
667 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
683 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
AQNWB::Types::VectorDataVariant BaseDataVectorVariant
Definition BaseIO.hpp:104
@ 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
static BaseDataType fromTypeId(const std::type_index &typeIndex)
Get the BaseDataType from a std::type_index.
Definition BaseIO.hpp:194
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:259
std::array< size_type, NDIMS > m_strides
Stride per dimension.
Definition ReadIO.hpp:264
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:244
std::array< size_type, NDIMS > m_shape
Size of each dimension.
Definition ReadIO.hpp:263
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:262
const DTYPE * begin() const
Returns a pointer to the beginning of the data for 1D arrays.
Definition ReadIO.hpp:231
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:274
SizeArray shape
The 1D vector with the n-dimensional shape of the data. Set to empty in case of scalar data.
Definition ReadIO.hpp:284
static DataBlock< DTYPE > fromGeneric(const DataBlockGeneric &genericData)
Factory method to create an DataBlock from a DataBlockGeneric.
Definition ReadIO.hpp:354
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:289
std::vector< DTYPE > data
Definition ReadIO.hpp:279
DataBlock(const std::vector< DTYPE > &inData, const SizeArray &inShape)
Definition ReadIO.hpp:294
BaseDataType getBaseDataType() const
Get the BaseDataType for the data.
Definition ReadIO.hpp:372
ConstMultiArrayView< DTYPE, NDIMS > as_multi_array() const
Transform the data to a multi-dimensional array view for convenient access.
Definition ReadIO.hpp:313
Configuration for creating a soft-link to an existing dataset.
Definition BaseIO.hpp:400
IO::LinkArrayDataSetConfig toLinkArrayDataSetConfig() const
Constructs a AQNWB::IO::LinkArrayDataSetConfig from this wrapper.
Definition ReadIO.hpp:550
static constexpr bool isType()
Function to check at compile-time whether the object is of a particular VTYPE, e.g....
Definition ReadIO.hpp:461
SizeArray getChunking() const
Get the chunking configuration of the data object.
Definition ReadIO.hpp:529
SizeType getNumDimensions() const
Get the number of dimensions of the data object.
Definition ReadIO.hpp:506
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:513
std::string m_path
Path to the dataset or attribute to read.
Definition ReadIO.hpp:687
const std::shared_ptr< IO::BaseIO > m_io
Pointer to the I/O object to use for reading.
Definition ReadIO.hpp:683
DataBlock< VTYPE > values() const
Reads an attribute with a specified data type.
Definition ReadIO.hpp:637
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:668
DataBlockGeneric valuesGeneric() const
Reads a dataset and determines the data type.
Definition ReadIO.hpp:581
virtual ~ReadDataWrapper()
Destructor.
Definition ReadIO.hpp:479
const std::string & getPath() const
Gets the path of the registered type.
Definition ReadIO.hpp:485
static StorageObjectType getStorageObjectType()
Function to return the AQNWB::Types::StorageObjectType OTYPE of the instance.
Definition ReadIO.hpp:454
std::shared_ptr< IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition ReadIO.hpp:491
bool exists() const
Check that the object exists.
Definition ReadIO.hpp:559
ReadDataWrapper(const std::shared_ptr< IO::BaseIO > io, const std::string &path)
Default constructor.
Definition ReadIO.hpp:444
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:612
SizeArray getShape() const
Get the shape of the data object.
Definition ReadIO.hpp:497
ReadDataWrapper(const ReadDataWrapper &)=delete
Deleted copy constructor to prevent construction-copying.
The namespace for IO components of AqNWB.
StorageObjectType
Types of object used in the NWB schema.
Definition Types.hpp:60
size_t SizeType
Alias for the size type used in the project.
Definition Types.hpp:104
Internal embedded Trait to Check the OTYPE Enum Value at compile time.
Definition ReadIO.hpp:424
Definition ReadIO.hpp:382