9 #ifndef H5SLICE_TRAITS_MISC_HPP
10 #define H5SLICE_TRAITS_MISC_HPP
22 #include <boost/multi_array.hpp>
23 #include <boost/numeric/ublas/matrix.hpp>
26 #include <H5Dpublic.h>
27 #include <H5Ppublic.h>
29 #include "../H5DataSpace.hpp"
30 #include "../H5DataType.hpp"
31 #include "../H5Selection.hpp"
62 : _ids(element_ids) {}
64 template <
typename Derivate>
67 const std::vector<size_t>& count,
68 const std::vector<size_t>& stride)
const {
71 std::vector<hsize_t> offset_local(offset.size());
72 std::vector<hsize_t> count_local(count.size());
73 std::vector<hsize_t> stride_local(stride.size());
74 std::copy(offset.begin(), offset.end(), offset_local.begin());
75 std::copy(count.begin(), count.end(), count_local.begin());
76 std::copy(stride.begin(), stride.end(), stride_local.begin());
78 DataSpace space =
static_cast<const Derivate*
>(
this)->getSpace().
clone();
79 if (H5Sselect_hyperslab(space.
getId(), H5S_SELECT_SET, offset_local.data(),
80 stride.empty() ?
NULL : stride_local.data(),
81 count_local.data(),
NULL) < 0) {
82 HDF5ErrMapper::ToException<DataSpaceException>(
83 "Unable to select hyperslap");
90 template <
typename Derivate>
94 const DataSpace& space =
static_cast<const Derivate*
>(
this)->getSpace();
98 std::vector<hsize_t> counts(dims.size());
99 std::copy(dims.begin(), dims.end(), counts.begin());
100 counts[dims.size() - 1] = 1;
101 std::vector<hsize_t> offsets(dims.size(), 0);
103 H5Sselect_none(space.
getId());
104 for (std::vector<size_t>::const_iterator i = columns.begin();
105 i != columns.end(); ++i) {
107 offsets[offsets.size() - 1] = *i;
108 if (H5Sselect_hyperslab(space.
getId(), H5S_SELECT_OR, offsets.data(),
109 0, counts.data(), 0) < 0) {
110 HDF5ErrMapper::ToException<DataSpaceException>(
111 "Unable to select hyperslap");
115 dims[dims.size() - 1] = columns.size();
119 template <
typename Derivate>
122 hsize_t* data =
NULL;
123 const std::size_t length = elements.
_ids.size();
124 std::vector<hsize_t> raw_elements;
128 if (std::is_same<std::size_t, hsize_t>::value) {
129 data = (hsize_t*)(&(elements.
_ids[0]));
131 raw_elements.resize(length);
132 std::copy(elements.
_ids.begin(), elements.
_ids.end(),
133 raw_elements.begin());
134 data = &(raw_elements[0]);
137 DataSpace space =
static_cast<const Derivate*
>(
this)->getSpace().
clone();
138 if (H5Sselect_elements(space.
getId(), H5S_SELECT_SET, length, data) < 0) {
139 HDF5ErrMapper::ToException<DataSpaceException>(
140 "Unable to select elements");
147 template <
typename Derivate>
148 template <
typename T>
150 typedef typename std::remove_const<T>::type type_no_const;
152 type_no_const& nocv_array =
const_cast<type_no_const&
>(array);
155 DataSpace space =
static_cast<const Derivate*
>(
this)->getSpace();
156 DataSpace mem_space =
static_cast<const Derivate*
>(
this)->getMemSpace();
159 std::ostringstream ss;
160 ss <<
"Impossible to read DataSet of dimensions "
175 array_datatype.
getId(),
177 space.
getId(), H5P_DEFAULT,
179 HDF5ErrMapper::ToException<DataSetException>(
180 "Error during HDF5 Read: ");
187 template <
typename Derivate>
188 template <
typename T>
191 DataSpace space =
static_cast<const Derivate*
>(
this)->getSpace();
192 DataSpace mem_space =
static_cast<const Derivate*
>(
this)->getMemSpace();
199 array_datatype.
getId(),
201 space.
getId(), H5P_DEFAULT,
202 static_cast<void*
>(array)) < 0) {
203 HDF5ErrMapper::ToException<DataSetException>(
204 "Error during HDF5 Read: ");
208 template <
typename Derivate>
209 template <
typename T>
211 typedef typename std::remove_const<T>::type type_no_const;
213 type_no_const& nocv_buffer =
const_cast<type_no_const&
>(buffer);
216 DataSpace space =
static_cast<const Derivate*
>(
this)->getSpace();
217 DataSpace mem_space =
static_cast<const Derivate*
>(
this)->getMemSpace();
220 std::ostringstream ss;
221 ss <<
"Impossible to write buffer of dimensions " << dim_buffer
233 array_datatype.
getId(),
235 space.
getId(), H5P_DEFAULT,
236 static_cast<const void*
>(
238 HDF5ErrMapper::ToException<DataSetException>(
239 "Error during HDF5 Write: ");
243 template <
typename Derivate>
244 template <
typename T>
247 DataSpace space =
static_cast<const Derivate*
>(
this)->getSpace();
248 DataSpace mem_space =
static_cast<const Derivate*
>(
this)->getMemSpace();
253 array_datatype.
getId(),
255 space.
getId(), H5P_DEFAULT,
256 static_cast<const void*
>(buffer)) < 0) {
257 HDF5ErrMapper::ToException<DataSetException>(
258 "Error during HDF5 Write: ");
263 #endif // H5SLICE_TRAITS_MISC_HPP