hops
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 "H5Utils.hpp"
26 
27 namespace HighFive {
28 
29 inline std::string DataSet::getPath() const {
30  return details::get_name([&](char *buffer, hsize_t length) {
31  return H5Iget_name(_hid, buffer, length);
32  });
33 }
34 
35 inline uint64_t DataSet::getStorageSize() const {
36  return H5Dget_storage_size(_hid);
37 }
38 
40  return DataType(H5Dget_type(_hid));
41 }
42 
43 inline DataSpace DataSet::getSpace() const {
44  DataSpace space;
45  if ((space._hid = H5Dget_space(_hid)) < 0) {
46  HDF5ErrMapper::ToException<DataSetException>(
47  "Unable to get DataSpace out of DataSet");
48  }
49  return space;
50 }
51 
53  return getSpace();
54 }
55 
56 inline uint64_t DataSet::getOffset() const {
57  uint64_t addr = H5Dget_offset(_hid);
58  if (addr == HADDR_UNDEF) {
59  HDF5ErrMapper::ToException<DataSetException>(
60  "Cannot get offset of DataSet.");
61  }
62  return addr;
63 }
64 
65 inline void DataSet::resize(const std::vector<size_t>& dims) {
66 
67  const size_t numDimensions = getSpace().getDimensions().size();
68  if (dims.size() != numDimensions) {
69  HDF5ErrMapper::ToException<DataSetException>(
70  "Invalid dataspace dimensions, got " + std::to_string(dims.size()) +
71  " expected " + std::to_string(numDimensions));
72  }
73 
74  std::vector<hsize_t> real_dims(dims.begin(), dims.end());
75 
76  if (H5Dset_extent(getId(), real_dims.data()) < 0) {
77  HDF5ErrMapper::ToException<DataSetException>(
78  "Could not resize dataset.");
79  }
80 }
81 
82 } // namespace HighFive
83 
84 #endif // H5DATASET_MISC_HPP
HighFive::DataSet::getDataType
DataType getDataType() const
getDataType
Definition: H5DataSet_misc.hpp:39
HighFive::details::get_name
std::string get_name(T fct)
Definition: H5Utils.hpp:252
HighFive::DataSet::getPath
std::string getPath() const
return the path to the current dataset
Definition: H5DataSet_misc.hpp:29
HighFive::DataSpace::getDimensions
std::vector< size_t > getDimensions() const
getDimensions
Definition: H5Dataspace_misc.hpp:99
HighFive::DataType
HDF5 Data Type.
Definition: H5DataType.hpp:42
HighFive::DataSet::getOffset
uint64_t getOffset() const
getOffset
Definition: H5DataSet_misc.hpp:56
HighFive::DataSet::getMemSpace
DataSpace getMemSpace() const
getMemSpace
Definition: H5DataSet_misc.hpp:52
HighFive::Object::getId
hid_t getId() const noexcept
getId
Definition: H5Object_misc.hpp:55
HighFive::DataSet::getSpace
DataSpace getSpace() const
getSpace
Definition: H5DataSet_misc.hpp:43
HighFive::DataSet::getStorageSize
uint64_t getStorageSize() const
getStorageSize
Definition: H5DataSet_misc.hpp:35
HighFive::DataSet::resize
void resize(const std::vector< size_t > &dims)
Change the size of the dataset.
Definition: H5DataSet_misc.hpp:65
HighFive::Object::_hid
hid_t _hid
Definition: H5Object.hpp:81
HighFive::DataSpace
Class representing the space (dimensions) of a dataset.
Definition: H5DataSpace.hpp:37
string
NAME string(REPLACE ".cpp" "_bin" example_name ${example_filename}) if($
Definition: hops/Third-party/HighFive/src/examples/CMakeLists.txt:6
H5Utils.hpp
HighFive
Definition: H5_definitions.hpp:15