hops
H5Easy_public.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 H5EASY_BITS_PUBLIC_HPP
10 #define H5EASY_BITS_PUBLIC_HPP
11 
12 #include "../H5Easy.hpp"
13 
14 namespace H5Easy {
15 
16 inline Compression::Compression(bool enable)
17 {
18  if (enable) {
19  m_compression_level = 9;
20  } else {
21  m_compression_level = 0;
22  }
23 }
24 
25 template <class T>
26 inline Compression::Compression(T level) : m_compression_level(static_cast<unsigned>(level))
27 {
28 }
29 
30 inline unsigned Compression::get() const
31 {
32  return m_compression_level;
33 }
34 
35 inline void DumpOptions::set(DumpMode mode)
36 {
37  m_overwrite = static_cast<bool>(mode);
38 }
39 
40 inline void DumpOptions::set(Flush mode)
41 {
42  m_flush = static_cast<bool>(mode);
43 }
44 
45 inline void DumpOptions::set(const Compression& level)
46 {
47  m_compression_level = level.get();
48 }
49 
50 template <class T, class... Args>
51 inline void DumpOptions::set(T arg, Args... args)
52 {
53  set(arg);
54  set(args...);
55 }
56 
57 template <class T>
58 inline void DumpOptions::setChunkSize(const std::vector<T>& shape)
59 {
60  m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
61 }
62 
63 inline void DumpOptions::setChunkSize(std::initializer_list<size_t> shape)
64 {
65  m_chunk_size = std::vector<hsize_t>(shape.begin(), shape.end());
66 }
67 
68 inline bool DumpOptions::overwrite() const
69 {
70  return m_overwrite;
71 }
72 
73 inline bool DumpOptions::flush() const
74 {
75  return m_flush;
76 }
77 
78 inline bool DumpOptions::compress() const
79 {
80  return m_compression_level > 0;
81 }
82 
83 inline unsigned DumpOptions::getCompressionLevel() const
84 {
85  return m_compression_level;
86 }
87 
88 inline bool DumpOptions::isChunked() const
89 {
90  return m_chunk_size.size() > 0;
91 }
92 
93 inline std::vector<hsize_t> DumpOptions::getChunkSize() const
94 {
95  return m_chunk_size;
96 }
97 
98 inline size_t getSize(const File& file, const std::string& path) {
99  return file.getDataSet(path).getElementCount();
100 }
101 
102 inline std::vector<size_t> getShape(const File& file, const std::string& path) {
103  return file.getDataSet(path).getDimensions();
104 }
105 
106 template <class T>
107 inline DataSet dump(File& file,
108  const std::string& path,
109  const T& data,
110  const DumpOptions& options) {
111  return detail::io_impl<T>::dump(file, path, data, options);
112 }
113 
114 template <class T>
115 inline DataSet dump(File& file,
116  const std::string& path,
117  const T& data,
118  DumpMode mode) {
119  return detail::io_impl<T>::dump(file, path, data, DumpOptions(mode));
120 }
121 
122 template <class T>
123 inline DataSet dump(File& file,
124  const std::string& path,
125  const T& data,
126  const std::vector<size_t>& idx,
127  const DumpOptions& options) {
128  return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
129 }
130 
131 template <class T>
132 inline DataSet dump(File& file,
133  const std::string& path,
134  const T& data,
135  const std::initializer_list<size_t>& idx,
136  const DumpOptions& options) {
137  return detail::io_impl<T>::dump_extend(file, path, data, idx, options);
138 }
139 
140 template <class T>
141 inline DataSet dump(File& file,
142  const std::string& path,
143  const T& data,
144  const std::vector<size_t>& idx) {
145  return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
146 }
147 
148 template <class T>
149 inline DataSet dump(File& file,
150  const std::string& path,
151  const T& data,
152  const std::initializer_list<size_t>& idx) {
153  return detail::io_impl<T>::dump_extend(file, path, data, idx, DumpOptions());
154 }
155 
156 template <class T>
157 inline T load(const File& file, const std::string& path, const std::vector<size_t>& idx) {
158  return detail::io_impl<T>::load_part(file, path, idx);
159 }
160 
161 template <class T>
162 inline T load(const File& file, const std::string& path) {
163  return detail::io_impl<T>::load(file, path);
164 }
165 
166 template <class T>
168  const std::string& path,
169  const std::string& key,
170  const T& data,
171  DumpMode mode) {
172  return detail::io_impl<T>::dumpAttribute(file, path, key, data, DumpOptions(mode));
173 }
174 
175 template <class T>
177  const std::string& path,
178  const std::string& key,
179  const T& data,
180  const DumpOptions& options) {
181  return detail::io_impl<T>::dumpAttribute(file, path, key, data, options);
182 }
183 
184 template <class T>
185 inline T loadAttribute(const File& file, const std::string& path, const std::string& key) {
186  return detail::io_impl<T>::loadAttribute(file, path, key);
187 }
188 
189 } // namespace H5Easy
190 
191 #endif // H5EASY_BITS_MISC_HPP
H5Easy::DumpMode
DumpMode
Write mode for DataSets.
Definition: H5Easy.hpp:67
H5Easy::load
T load(const File &file, const std::string &path, const std::vector< size_t > &idx)
Load entry "(i,j)" from a rank-two DataSet in an open HDF5 file to a scalar.
Definition: H5Easy_public.hpp:157
H5Easy::DumpOptions::setChunkSize
void setChunkSize(const std::vector< T > &shape)
Set chunk-size. If the input is rank (size) zero, automatic chunking is enabled.
Definition: H5Easy_public.hpp:58
H5Easy::DumpOptions::compress
bool compress() const
Check to compress.
Definition: H5Easy_public.hpp:78
H5Easy::Compression
Set compression level for written DataSets.
Definition: H5Easy.hpp:82
H5Easy::Flush
Flush
Enable/disable automatic flushing after write operations.
Definition: H5Easy.hpp:74
HighFive::NodeTraits::getDataSet
DataSet getDataSet(const std::string &dataset_name, const DataSetAccessProps &accessProps=DataSetAccessProps()) const
get an existing dataset in the current file
Definition: H5Node_traits_misc.hpp:95
H5Easy::DumpOptions::set
void set(DumpMode mode)
Overwrite setting.
Definition: H5Easy_public.hpp:35
H5Easy::DumpOptions::getChunkSize
std::vector< hsize_t > getChunkSize() const
Get chunk size.
Definition: H5Easy_public.hpp:93
H5Easy::DumpOptions::getCompressionLevel
unsigned getCompressionLevel() const
Get compression level.
Definition: H5Easy_public.hpp:83
H5Easy::detail::io_impl::dumpAttribute
static Attribute dumpAttribute(File &file, const std::string &path, const std::string &key, const T &data, const DumpOptions &options)
Definition: H5Easy_scalar.hpp:45
H5Easy::DumpOptions
Options for dumping data.
Definition: H5Easy.hpp:112
H5Easy::detail::io_impl::load_part
static T load_part(const File &file, const std::string &path, const std::vector< size_t > &idx)
Definition: H5Easy_scalar.hpp:121
HighFive::DataSet::getDimensions
std::vector< size_t > getDimensions() const
Get the dimensions of the whole DataSet. This is a shorthand for getSpace().getDimensions()
Definition: H5DataSet.hpp:83
H5Easy::getSize
size_t getSize(const File &file, const std::string &path)
Get the size of an existing DataSet in an open HDF5 file.
Definition: H5Easy_public.hpp:98
H5Easy::getShape
std::vector< size_t > getShape(const File &file, const std::string &path)
Get the shape of an existing DataSet in an readable file.
Definition: H5Easy_public.hpp:102
H5Easy
Definition: H5Easy.hpp:51
H5Easy::DumpOptions::isChunked
bool isChunked() const
Check if chunk-size is manually set (or should be computed automatically).
Definition: H5Easy_public.hpp:88
HighFive::File
File class.
Definition: H5File.hpp:24
HighFive::Attribute
Class representing an attribute of a dataset or group.
Definition: H5Attribute.hpp:23
H5Easy::Compression::get
unsigned get() const
Definition: H5Easy_public.hpp:30
H5Easy::DumpOptions::overwrite
bool overwrite() const
Check to overwrite.
Definition: H5Easy_public.hpp:68
H5Easy::detail::io_impl::loadAttribute
static T loadAttribute(const File &file, const std::string &path, const std::string &key)
Definition: H5Easy_scalar.hpp:58
H5Easy::dumpAttribute
Attribute dumpAttribute(File &file, const std::string &path, const std::string &key, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) Attribute in an open HDF5 file.
Definition: H5Easy_public.hpp:167
string
NAME string(REPLACE ".cpp" "_bin" example_name ${example_filename}) if($
Definition: hops/Third-party/HighFive/src/examples/CMakeLists.txt:6
H5Easy::dump
DataSet dump(File &file, const std::string &path, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) DataSet in an open HDF5 file.
Definition: H5Easy_public.hpp:115
H5Easy::Compression::Compression
Compression(bool enable=true)
Definition: H5Easy_public.hpp:16
H5Easy::detail::io_impl::load
static T load(const File &file, const std::string &path)
Definition: H5Easy_scalar.hpp:38
H5Easy::DumpOptions::flush
bool flush() const
Check to flush.
Definition: H5Easy_public.hpp:73
H5Easy::loadAttribute
T loadAttribute(const File &file, const std::string &path, const std::string &key)
Load a Attribute in an open HDF5 file to an object (templated).
Definition: H5Easy_public.hpp:185
HighFive::DataSet::getElementCount
size_t getElementCount() const
Get the total number of elements in the current dataset. E.g. 2x2x2 matrix has size 8....
Definition: H5DataSet.hpp:92
H5Easy::detail::io_impl::dump
static DataSet dump(File &file, const std::string &path, const T &data, const DumpOptions &options)
Definition: H5Easy_scalar.hpp:26
HighFive::DataSet
Class representing a dataset.
Definition: H5DataSet.hpp:27
H5Easy::detail::io_impl::dump_extend
static DataSet dump_extend(File &file, const std::string &path, const T &data, const std::vector< size_t > &idx, const DumpOptions &options)
Definition: H5Easy_scalar.hpp:68