31inline const DataSet& get_dataset(
const Selection& sel) {
32 return sel.getDataset();
35inline const DataSet& get_dataset(
const DataSet& ds) {
42inline hid_t get_memspace_id(
const Selection& ptr) {
43 return ptr.getMemSpace().getId();
46inline hid_t get_memspace_id(
const DataSet&) {
55 :
ElementSet(std::vector<std::vector<std::size_t>>(list)) {}
58 : _ids(element_ids) {}
61 for (
const auto& vec: element_ids) {
62 std::copy(vec.begin(), vec.end(), std::back_inserter(_ids));
66template <
typename Derivate>
75 const auto& slice =
static_cast<const Derivate&
>(*this);
76 auto filespace = hyperslab.
apply(slice.getSpace());
78 return detail::make_selection(memspace, filespace, details::get_dataset(slice));
81template <
typename Derivate>
83 const auto& slice =
static_cast<const Derivate&
>(*this);
85 filespace = hyper_slab.
apply(filespace);
87 auto n_elements = detail::h5s_get_select_npoints(filespace.getId());
88 auto memspace =
DataSpace(std::array<size_t, 1>{size_t(n_elements)});
90 return detail::make_selection(memspace, filespace, details::get_dataset(slice));
94template <
typename Derivate>
96 const std::vector<size_t>& count,
97 const std::vector<size_t>& stride,
98 const std::vector<size_t>& block)
const {
101 return select(slab, memspace);
104template <
typename Derivate>
106 const auto& slice =
static_cast<const Derivate&
>(*this);
107 const DataSpace& space = slice.getSpace();
110 std::vector<size_t> counts = dims;
113 std::vector<size_t> offsets(dims.size(), 0);
116 for (
const auto& column: columns) {
117 offsets.back() = column;
121 std::vector<size_t> memdims = dims;
122 memdims.back() = columns.size();
127template <
typename Derivate>
129 const auto& slice =
static_cast<const Derivate&
>(*this);
130 const hsize_t* data =
nullptr;
132 const std::size_t length = elements._ids.size();
135 "Number of coordinates in elements picking "
136 "should be a multiple of the dimensions.");
139 std::vector<hsize_t> raw_elements;
143 if (std::is_same<std::size_t, hsize_t>::value) {
145 data =
reinterpret_cast<const hsize_t*
>(&(elements._ids[0]));
147 raw_elements.resize(length);
148 std::copy(elements._ids.begin(), elements._ids.end(), raw_elements.begin());
149 data = raw_elements.data();
152 detail::h5s_select_elements(space.
getId(), H5S_SELECT_SET, num_elements, data);
154 return detail::make_selection(
DataSpace(num_elements), space, details::get_dataset(slice));
158template <
typename Derivate>
162 read(array, xfer_props);
167template <
typename Derivate>
170 const auto& slice =
static_cast<const Derivate&
>(*this);
171 const DataSpace& mem_space = slice.getMemSpace();
173 auto file_datatype = slice.getDataType();
175 const details::BufferInfo<T> buffer_info(
177 [&slice]() -> std::string {
return details::get_dataset(slice).getPath(); },
178 details::BufferInfo<T>::Operation::read);
180 if (!details::checkDimensions(mem_space, buffer_info.n_dimensions)) {
181 std::ostringstream ss;
183 <<
" into arrays of dimensions " << buffer_info.n_dimensions;
188 auto r = details::data_converter::get_reader<T>(dims, array, file_datatype);
189 read_raw(r.getPointer(), buffer_info.data_type, xfer_props);
191 r.unserialize(array);
193 auto t = buffer_info.data_type;
194 auto c = t.getClass();
196#if H5_VERSION_GE(1, 12, 0)
199 detail::h5t_reclaim(t.getId(), mem_space.
getId(), xfer_props.
getId(), r.getPointer());
202 (void) detail::h5d_vlen_reclaim(t.getId(),
210template <
typename Derivate>
215 read_raw(array, mem_datatype, xfer_props);
218template <
typename Derivate>
221 read_raw(array, xfer_props);
225template <
typename Derivate>
230 static_assert(!std::is_const<T>::value,
231 "read() requires a non-const structure to read data into");
233 const auto& slice =
static_cast<const Derivate&
>(*this);
235 detail::h5d_read(details::get_dataset(slice).getId(),
236 mem_datatype.
getId(),
237 details::get_memspace_id(slice),
238 slice.getSpace().getId(),
240 static_cast<void*
>(array));
244template <
typename Derivate>
247 using element_type =
typename details::inspector<T>::base_type;
248 const DataType& mem_datatype = create_and_check_datatype<element_type>();
250 read_raw(array, mem_datatype, xfer_props);
254template <
typename Derivate>
257 const auto& slice =
static_cast<const Derivate&
>(*this);
258 const DataSpace& mem_space = slice.getMemSpace();
260 auto file_datatype = slice.getDataType();
262 const details::BufferInfo<T> buffer_info(
264 [&slice]() -> std::string {
return details::get_dataset(slice).getPath(); },
265 details::BufferInfo<T>::Operation::write);
267 if (!details::checkDimensions(mem_space, buffer_info.n_dimensions)) {
268 std::ostringstream ss;
269 ss <<
"Impossible to write buffer of dimensions "
271 <<
" into dataset with n = " << buffer_info.n_dimensions <<
" dimensions.";
274 auto w = details::data_converter::serialize<T>(buffer, file_datatype);
275 write_raw(w.getPointer(), buffer_info.data_type, xfer_props);
279template <
typename Derivate>
284 const auto& slice =
static_cast<const Derivate&
>(*this);
286 detail::h5d_write(details::get_dataset(slice).getId(),
287 mem_datatype.
getId(),
288 details::get_memspace_id(slice),
289 slice.getSpace().getId(),
291 static_cast<const void*
>(buffer));
295template <
typename Derivate>
298 using element_type =
typename details::inspector<T>::base_type;
299 const auto& mem_datatype = create_and_check_datatype<element_type>();
301 write_raw(buffer, mem_datatype, xfer_props);
Exception specific to HighFive DataSpace interface.
Definition H5Exception.hpp:112
Class representing the space (dimensions) of a DataSet.
Definition H5DataSpace.hpp:39
size_t getNumberDimensions() const
Returns the number of dimensions of a DataSpace.
Definition H5Dataspace_misc.hpp:100
std::vector< size_t > getDimensions() const
Returns the size of the dataset in each dimension.
Definition H5Dataspace_misc.hpp:104
DataSpace clone() const
Create a copy of the DataSpace which will have different id.
Definition H5Dataspace_misc.hpp:94
HDF5 Data Type.
Definition H5DataType.hpp:61
Definition H5Slice_traits.hpp:22
ElementSet(std::initializer_list< std::size_t > list)
Create a list of points of N-dimension for selection.
Definition H5Slice_traits_misc.hpp:51
Definition H5Slice_traits.hpp:121
DataSpace apply(const DataSpace &space_) const
Definition H5Slice_traits.hpp:174
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
HDF5 property Lists.
Definition H5PropertyList.hpp:160
Selection: represent a view on a slice/part of a dataset.
Definition H5Selection.hpp:27
DataSpace getSpace() const noexcept
getSpace
Definition H5Selection_misc.hpp:20
T read(const DataTransferProps &xfer_props=DataTransferProps()) const
Definition H5Slice_traits_misc.hpp:160
void write(const T &buffer, const DataTransferProps &xfer_props=DataTransferProps())
Definition H5Slice_traits_misc.hpp:256
Selection select(const HyperSlab &hyperslab) const
Select an hyperslab in the current Slice/Dataset.
Definition H5Slice_traits_misc.hpp:82
void read_raw(T *array, const DataType &dtype, const DataTransferProps &xfer_props=DataTransferProps()) const
Definition H5Slice_traits_misc.hpp:227
void write_raw(const T *buffer, const DataType &mem_datatype, const DataTransferProps &xfer_props=DataTransferProps())
Definition H5Slice_traits_misc.hpp:281
Definition H5_definitions.hpp:22
Definition H5Slice_traits.hpp:73