6 #ifndef ECHELON_HDF5_DATASET_HPP 7 #define ECHELON_HDF5_DATASET_HPP 9 #include <echelon/hdf5/object.hpp> 11 #include <echelon/hdf5/type.hpp> 12 #include <echelon/hdf5/type_factory.hpp> 13 #include <echelon/hdf5/object_reference.hpp> 15 #include <echelon/hdf5/slice.hpp> 16 #include <echelon/hdf5/range.hpp> 17 #include <echelon/hdf5/container_adaption.hpp> 18 #include <echelon/hdf5/array_slice.hpp> 20 #include <echelon/hdf5/attribute_repository.hpp> 21 #include <echelon/hdf5/dataset_dimensions.hpp> 22 #include <echelon/hdf5/storage_layer.hpp> 24 #include <echelon/hdf5/precursor/dataset.hpp> 25 #include <echelon/hdf5/precursor/dataspace.hpp> 26 #include <echelon/hdf5/precursor/property_list.hpp> 28 #include <echelon/utility/macros.hpp> 33 #include <type_traits> 44 class invalid_layout_exception :
public std::exception
47 explicit invalid_layout_exception(std::string what_) : what_{std::move(what_)}
51 const char* what() const noexcept
override 73 dataset(
const object& parent,
const std::string& name,
const type& datatype,
74 const std::vector<hsize_t>& shape,
const std::vector<hsize_t>& max_dims,
int comp_level,
75 bool auto_chunking,
bool shuffle_filter,
const std::vector<hsize_t> chunk_shape);
95 const auto& current_shape = shape_adl(source);
97 std::vector<hsize_t> mem_shape(begin(current_shape), end(current_shape));
99 hdf5::precursor::dataspace mem_space(mem_shape);
100 hdf5::precursor::dataspace file_space = sink.dataset_handle_.get_space();
101 hdf5::precursor::type datatype = sink.dataset_handle_.datatype();
103 write(sink.dataset_handle_, datatype, mem_space, file_space, source);
114 template <
typename T>
120 const auto& current_shape = shape_adl(sink);
122 std::vector<hsize_t> mem_shape(begin(current_shape), end(current_shape));
124 hdf5::precursor::dataspace mem_space(mem_shape);
125 hdf5::precursor::dataspace file_space = source.dataset_handle_.get_space();
126 hdf5::precursor::type datatype = source.dataset_handle_.datatype();
128 read(source.dataset_handle_, datatype, mem_space, file_space, sink);
140 template <
typename T>
141 friend void operator<<=(dataset& sink, const array_slice<T>& source)
146 const auto& current_shape = source.original_shape();
148 std::vector<hsize_t> mem_shape(begin(current_shape), end(current_shape));
150 hdf5::precursor::dataspace mem_space(mem_shape);
151 hdf5::precursor::dataspace file_space = sink.dataset_handle_.get_space();
152 hdf5::precursor::type datatype = sink.dataset_handle_.datatype();
154 auto slice_shape = source.shape();
155 std::vector<hsize_t> count;
157 for (std::size_t i = 0; i < slice_shape.size(); ++i)
159 count.push_back(slice_shape[i] / source.stride()[i]);
162 mem_space.select_hyperslab(H5S_SELECT_SET, source.offset(), source.stride(), count);
164 write(sink.dataset_handle_, datatype, mem_space, file_space, source);
174 template <
typename T>
175 friend void operator<<=(const array_slice<T>& sink,
const dataset& source)
180 const auto& current_shape = sink.original_shape();
182 std::vector<hsize_t> mem_shape(begin(current_shape), end(current_shape));
184 hdf5::precursor::dataspace mem_space(mem_shape);
185 hdf5::precursor::dataspace file_space = source.dataset_handle_.get_space();
186 hdf5::precursor::type datatype = source.dataset_handle_.datatype();
188 auto slice_shape = sink.shape();
189 std::vector<hsize_t> count;
191 for (std::size_t i = 0; i < slice_shape.size(); ++i)
193 count.push_back(slice_shape[i] / sink.stride()[i]);
196 mem_space.select_hyperslab(H5S_SELECT_SET, sink.offset(), sink.stride(), count);
198 read(source.dataset_handle_, datatype, mem_space, file_space, sink);
209 template <
typename Container>
210 void extend_along(std::size_t dimension_index,
const Container& container)
const 215 auto extent = shape();
216 auto new_extent = extent;
217 auto container_shape = shape_adl(container);
219 for (std::size_t i = 0; i < extent.size(); ++i)
221 if (i != dimension_index && container_shape[i] != extent[i])
222 throw invalid_layout_exception(
223 "extent of non-extended dimension differs between container and dataset");
226 new_extent[dimension_index] += container_shape[dimension_index];
228 dataset_handle_.set_extent(new_extent);
231 std::vector<hsize_t> mem_shape(begin(container_shape), end(container_shape));
233 hdf5::precursor::dataspace mem_space(mem_shape);
234 hdf5::precursor::dataspace file_space = dataset_handle_.get_space();
235 hdf5::precursor::type datatype = dataset_handle_.datatype();
237 std::vector<hsize_t> offset(rank());
238 offset[dimension_index] = extent[dimension_index];
240 file_space.select_hyperslab(H5S_SELECT_SET, offset, mem_shape);
242 write(dataset_handle_, datatype, mem_space, file_space, container);
247 std::vector<hsize_t> shape()
const;
251 std::size_t rank()
const;
255 type datatype()
const;
312 template <
typename... Args>
315 std::vector<hsize_t> current_shape = shape();
317 std::vector<totally_bound_range_t> boundaries;
319 detail::calculate_slice_boundaries<0, Args...>::eval(current_shape, boundaries, args...);
321 return slice(dataset_handle_, boundaries);
334 explicit operator bool()
const;
336 hdf5::precursor::dataset dataset_handle_;
echelon's core namespace
Definition: attribute.cpp:10
A handle to an HDF5 dataset.
Definition: hdf5/dataset.hpp:62
Accessor class for the dimensions of a dataset.
Definition: hdf5/dataset_dimensions.hpp:87
void extend_along(std::size_t dimension_index, const Container &container) const
Extends the dataset along a given dimension.
Definition: hdf5/dataset.hpp:210
A slice (rectangular portion) of an HDF5 dataset.
Definition: hdf5/slice.hpp:27
friend void operator<<=(T &sink, const dataset &source)
Reads the content of the dataset into a data sink.
Definition: hdf5/dataset.hpp:115
friend void operator<<=(dataset &sink, const T &source)
Writes the content of a data source into the dataset.
Definition: hdf5/dataset.hpp:90
A handle to an HDF5 type.
Definition: hdf5/type.hpp:23
Attribute manager, which should be embedded into a parent object, which supports attributes.
Definition: hdf5/attribute_repository.hpp:52
A reference to an HDF5 object.
Definition: hdf5/object_reference.hpp:25
slice operator()(Args...args) const
Slices the dataset.
Definition: hdf5/dataset.hpp:313
hdf5::precursor::dataset native_handle_type
Type of the underlying HDF5 low-level handle.
Definition: hdf5/dataset.hpp:67