H5DataSet_misc.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse <adrien.devresse@epfl.ch>
3  *
4  * Distributed under the Boost Software License, Version 1.0.
5  * (See accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9 #ifndef H5DATASET_MISC_HPP
10 #define H5DATASET_MISC_HPP
11 
12 #include <algorithm>
13 #include <functional>
14 #include <numeric>
15 #include <sstream>
16 #include <string>
17 
18 #ifdef H5_USE_BOOST
19 #include <boost/multi_array.hpp>
20 #endif
21 
22 #include <H5Dpublic.h>
23 #include <H5Ppublic.h>
24 
25 #include "../H5DataSet.hpp"
26 #include "../H5DataSpace.hpp"
27 #include "../H5DataType.hpp"
28 
29 #include "H5Slice_traits_misc.hpp"
30 #include "H5Utils.hpp"
31 
32 namespace HighFive {
33 
34 inline DataSet::DataSet() {}
35 
36 inline size_t DataSet::getStorageSize() const {
37  return H5Dget_storage_size(_hid);
38 }
39 
41  DataType res;
42  res._hid = H5Dget_type(_hid);
43  return res;
44 }
45 
46 inline DataSpace DataSet::getSpace() const {
47  DataSpace space;
48  if ((space._hid = H5Dget_space(_hid)) < 0) {
49  HDF5ErrMapper::ToException<DataSetException>(
50  "Unable to get DataSpace out of DataSet");
51  }
52  return space;
53 }
54 
55 inline DataSpace DataSet::getMemSpace() const { return getSpace(); }
56 
57 inline size_t DataSet::getOffset() const {
58  haddr_t addr = H5Dget_offset(_hid);
59  if (addr == HADDR_UNDEF) {
60  HDF5ErrMapper::ToException<DataSetException>(
61  "Cannot get offset of DataSet.");
62  }
63  return addr;
64 }
65 
66 inline void DataSet::resize(const std::vector<size_t>& dims) {
67 
68  const size_t numDimensions = getSpace().getDimensions().size();
69  if (dims.size() != numDimensions) {
70  HDF5ErrMapper::ToException<DataSetException>(
71  "Invalid dataspace dimensions, got " + std::to_string(dims.size()) +
72  " expected " + std::to_string(numDimensions));
73  }
74 
75  std::vector<hsize_t> real_dims(dims.begin(), dims.end());
76 
77  if (H5Dset_extent(getId(), real_dims.data()) < 0) {
78  HDF5ErrMapper::ToException<DataSetException>(
79  "Could not resize dataset.");
80  }
81 }
82 
83 } // namespace HighFive
84 
85 #endif // H5DATASET_MISC_HPP
DataSpace getSpace() const
getSpace
void resize(const std::vector< size_t > &dims)
Change the size of the dataset.
hid_t getId() const
getId
DataSpace getMemSpace() const
getMemSpace
DataType getDataType() const
getDataType
size_t getOffset() const
getOffset
HDF5 Data Type.
Definition: H5DataType.hpp:21
size_t getStorageSize() const
std::vector< size_t > getDimensions() const
getDimensions


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:06