H5Attribute_misc.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Ali Can Demiralp <ali.demiralp@rwth-aachen.de>
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 H5ATTRIBUTE_MISC_HPP
10 #define H5ATTRIBUTE_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 <H5Apublic.h>
23 #include <H5Ppublic.h>
24 
25 #include "../H5Attribute.hpp"
26 #include "../H5DataSpace.hpp"
27 #include "../H5DataType.hpp"
28 
29 #include "H5Converter_misc.hpp"
30 #include "H5Utils.hpp"
31 
32 namespace HighFive {
33 
35 
36 inline size_t Attribute::getStorageSize() const {
37  return H5Aget_storage_size(_hid);
38 }
39 
41  DataType res;
42  res._hid = H5Aget_type(_hid);
43  return res;
44 }
45 
47  DataSpace space;
48  if ((space._hid = H5Aget_space(_hid)) < 0) {
49  HDF5ErrMapper::ToException<AttributeException>(
50  "Unable to get DataSpace out of Attribute");
51  }
52  return space;
53 }
54 
55 inline DataSpace Attribute::getMemSpace() const { return getSpace(); }
56 
57 template <typename T>
58 inline void Attribute::read(T& array) const {
59  typedef typename std::remove_const<T>::type type_no_const;
60 
61  type_no_const& nocv_array = const_cast<type_no_const&>(array);
62 
63  const size_t dim_array = details::array_dims<type_no_const>::value;
64  DataSpace space = getSpace();
65  DataSpace mem_space = getMemSpace();
66 
67  if (!details::checkDimensions(mem_space, dim_array)) {
68  std::ostringstream ss;
69  ss << "Impossible to read attribute of dimensions "
70  << mem_space.getNumberDimensions() << " into arrays of dimensions "
71  << dim_array;
72  throw DataSpaceException(ss.str());
73  }
74 
75  // Create mem datatype
77  array_datatype;
78 
79  // Apply pre read convertions
80  details::data_converter<type_no_const> converter(nocv_array, mem_space);
81 
82  if (H5Aread(getId(), array_datatype.getId(),
83  static_cast<void*>(converter.transform_read(nocv_array))) < 0) {
84  HDF5ErrMapper::ToException<AttributeException>(
85  "Error during HDF5 Read: ");
86  }
87 
88  // re-arrange results
89  converter.process_result(nocv_array);
90 }
91 
92 template <typename T>
93 inline void Attribute::write(const T& buffer) {
94  typedef typename std::remove_const<T>::type type_no_const;
95 
96  type_no_const& nocv_buffer = const_cast<type_no_const&>(buffer);
97 
98  const size_t dim_buffer = details::array_dims<type_no_const>::value;
99  DataSpace space = getSpace();
100  DataSpace mem_space = getMemSpace();
101 
102  if (!details::checkDimensions(mem_space, dim_buffer)) {
103  std::ostringstream ss;
104  ss << "Impossible to write buffer of dimensions " << dim_buffer
105  << " into attribute of dimensions "
106  << mem_space.getNumberDimensions();
107  throw DataSpaceException(ss.str());
108  }
109 
111  array_datatype;
112 
113  // Apply pre write convertions
114  details::data_converter<type_no_const> converter(nocv_buffer, mem_space);
115 
116  if (H5Awrite(getId(), array_datatype.getId(),
117  static_cast<const void*>(
118  converter.transform_write(nocv_buffer))) < 0) {
119  HDF5ErrMapper::ToException<DataSetException>(
120  "Error during HDF5 Write: ");
121  }
122 }
123 }
124 
125 #endif // H5ATTRIBUTE_MISC_HPP
HighFive::Attribute::getSpace
DataSpace getSpace() const
getSpace
Definition: H5Attribute_misc.hpp:46
HighFive::DataType
HDF5 Data Type.
Definition: H5DataType.hpp:21
HighFive::details::data_converter::process_result
void process_result(Scalar &)
Definition: H5Converter_misc.hpp:137
HighFive::Attribute::read
void read(T &array) const
Definition: H5Attribute_misc.hpp:58
HighFive::details::array_dims
Definition: H5Utils.hpp:42
HighFive::Attribute::getMemSpace
DataSpace getMemSpace() const
getMemSpace
Definition: H5Attribute_misc.hpp:55
HighFive::Object::getId
hid_t getId() const
getId
Definition: H5Object_misc.hpp:51
HighFive::details::data_converter::transform_read
Scalar * transform_read(Scalar &datamem)
Definition: H5Converter_misc.hpp:133
HighFive::Attribute::Attribute
Attribute()
Definition: H5Attribute_misc.hpp:34
HighFive::AtomicType
create an HDF5 DataType from a C++ type
Definition: H5DataType.hpp:41
HighFive::details::data_converter::transform_write
Scalar * transform_write(Scalar &datamem)
Definition: H5Converter_misc.hpp:135
HighFive::Attribute::getStorageSize
size_t getStorageSize() const
Definition: H5Attribute_misc.hpp:36
HighFive::Object::_hid
hid_t _hid
Definition: H5Object.hpp:48
HighFive::Attribute::getDataType
DataType getDataType() const
getDataType
Definition: H5Attribute_misc.hpp:40
HighFive::DataSpace
Definition: H5DataSpace.hpp:30
H5Converter_misc.hpp
HighFive::details::data_converter
Definition: H5Converter_misc.hpp:123
H5Utils.hpp
HighFive::details::checkDimensions
bool checkDimensions(const DataSpace &mem_space, size_t input_dims)
dimension checks
Definition: H5Dataspace_misc.hpp:191
HighFive::DataSpace::getNumberDimensions
size_t getNumberDimensions() const
getNumberDimensions
Definition: H5Dataspace_misc.hpp:95
HighFive
Definition: H5Annotate_traits.hpp:14
HighFive::DataSpaceException
Exception specific to HighFive DataSpace interface.
Definition: H5Exception.hpp:98
HighFive::Attribute::write
void write(const T &buffer)
Definition: H5Attribute_misc.hpp:93


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 Wed Mar 2 2022 00:37:23