11#include <boost/multi_array.hpp>
77 const std::vector<SizeType>& inShape,
78 const std::type_index& inTypeIndex)
91template<
typename DTYPE>
114 const std::vector<SizeType>& inShape)
128 template<std::
size_t NDIMS>
131 if (
shape.size() != NDIMS) {
132 throw std::invalid_argument(
133 "Shape size does not match the number of dimensions.");
139 expected_size *= dim;
142 if (
data.size() != expected_size) {
143 throw std::invalid_argument(
"Data size does not match the shape.");
147 boost::array<std::size_t, NDIMS> boost_shape;
148 std::copy(
shape.begin(),
shape.end(), boost_shape.begin());
151 return boost::const_multi_array_ref<DTYPE, NDIMS>(
data.data(), boost_shape);
168 std::any_cast<std::vector<DTYPE>>(genericData.
data), genericData.
shape);
175template<StorageObjectType T>
202template<StorageObjectType OTYPE,
typename VTYPE = std::any>
216 template<StorageObjectType U>
218 : std::integral_constant<bool, (U == StorageObjectType::Dataset)>
229 "StorageObjectType not allowed for ReadDataWrapper");
258 return std::is_same_v<VTYPE, T>;
286 inline std::shared_ptr<IO::BaseIO>
getIO()
const {
return m_io; }
295 case StorageObjectType::Dataset: {
298 case StorageObjectType::Attribute: {
302 throw std::runtime_error(
"Unsupported StorageObjectType");
317 case StorageObjectType::Dataset: {
320 case StorageObjectType::Attribute: {
324 throw std::runtime_error(
"Unsupported StorageObjectType");
344 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
346 const std::vector<SizeType>& start,
347 const std::vector<SizeType>& count = {},
348 const std::vector<SizeType>& stride = {},
349 const std::vector<SizeType>& block = {})
const
353 return m_io->readDataset(
m_path, start, count, stride, block);
370 template<
typename T = VTYPE>
399 template<
typename T = VTYPE,
401 typename std::enable_if<isDataset<U>::value,
int>::type = 0>
403 const std::vector<SizeType>& count = {},
404 const std::vector<SizeType>& stride = {},
405 const std::vector<SizeType>& block = {})
const
417 const std::shared_ptr<IO::BaseIO>
m_io;
AQNWB::Types::StorageObjectType StorageObjectType
Definition BaseIO.hpp:19
AQNWB::Types::SizeType SizeType
Definition Channel.hpp:8
Represents a base data type.
Definition BaseIO.hpp:41
Generic structure to hold type-erased data and shape.
Definition ReadIO.hpp:29
std::vector< SizeType > shape
The 1D vector with the n-dimensional shape of the data. Set to empty in case of scalar data.
Definition ReadIO.hpp:43
IO::BaseDataType baseDataType
The base data type for the data block.
Definition ReadIO.hpp:66
DataBlockGeneric()=default
Default constructor.
std::any data
Definition ReadIO.hpp:38
DataBlockGeneric(const std::any &inData, const std::vector< SizeType > &inShape, const std::type_index &inTypeIndex)
Parameterized constructor.
Definition ReadIO.hpp:76
std::type_index typeIndex
Type index of the values stored in the data vector.
Definition ReadIO.hpp:63
Structure to hold data and shape for a typed data vector.
Definition ReadIO.hpp:93
DataBlock(const std::vector< DTYPE > &inData, const std::vector< SizeType > &inShape)
Definition ReadIO.hpp:113
static DataBlock< DTYPE > fromGeneric(const DataBlockGeneric &genericData)
Factory method to create an DataBlock from a DataBlockGeneric.
Definition ReadIO.hpp:164
boost::const_multi_array_ref< DTYPE, NDIMS > as_multi_array() const
Transform the data to a boost multi-dimensional array for convenient access.
Definition ReadIO.hpp:129
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:108
std::vector< DTYPE > data
Definition ReadIO.hpp:98
std::vector< SizeType > shape
The 1D vector with the n-dimensional shape of the data. Set to empty in case of scalar data.
Definition ReadIO.hpp:103
static constexpr bool isType()
Function to check at compile-time whether the object is of a particular VTYPE, e.g....
Definition ReadIO.hpp:256
ReadDataWrapper & operator=(const ReadDataWrapper &)=delete
Deleted copy assignment operator to prevent copying.
std::string m_path
Path to the dataset or attribute to read.
Definition ReadIO.hpp:421
DataBlockGeneric valuesGeneric(const std::vector< SizeType > &start, const std::vector< SizeType > &count={}, const std::vector< SizeType > &stride={}, const std::vector< SizeType > &block={}) const
Reads a dataset and determines the data type.
Definition ReadIO.hpp:345
const std::shared_ptr< IO::BaseIO > m_io
Pointer to the I/O object to use for reading.
Definition ReadIO.hpp:417
DataBlock< VTYPE > values() const
Reads an attribute with a specified data type.
Definition ReadIO.hpp:371
DataBlockGeneric valuesGeneric() const
Reads a dataset and determines the data type.
Definition ReadIO.hpp:314
virtual ~ReadDataWrapper()
Destructor.
Definition ReadIO.hpp:274
std::shared_ptr< IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition ReadIO.hpp:286
bool exists() const
Check that the object exists.
Definition ReadIO.hpp:292
ReadDataWrapper(const std::shared_ptr< IO::BaseIO > io, const std::string &path)
Default constructor.
Definition ReadIO.hpp:239
std::string getPath() const
Gets the path of the registered type.
Definition ReadIO.hpp:280
DataBlock< VTYPE > values(const std::vector< SizeType > &start, const std::vector< SizeType > &count={}, const std::vector< SizeType > &stride={}, const std::vector< SizeType > &block={}) const
Reads an dataset with a specified data type.
Definition ReadIO.hpp:402
ReadDataWrapper(const ReadDataWrapper &)=delete
Deleted copy constructor to prevent construction-copying.
StorageObjectType getStorageObjectType() const
Function to return the AQNWB::Types::StorageObjectType OTYPE of the instance.
Definition ReadIO.hpp:249
StorageObjectType
Types of object used in the NWB schema.
Definition Types.hpp:31
size_t SizeType
Alias for the size type used in the project.
Definition Types.hpp:54
Internal embedded Trait to Check the OTYPE Enum Value at compile time.
Definition ReadIO.hpp:219
Definition ReadIO.hpp:177