forked from BlueBrain/HighFive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
H5PropertyList.hpp
307 lines (263 loc) · 8 KB
/
H5PropertyList.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Copyright (c), 2017-2018, Adrien Devresse <[email protected]>
* Juan Hernando <[email protected]>
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http:https://www.boost.org/LICENSE_1_0.txt)
*
*/
#ifndef H5PROPERTY_LIST_HPP
#define H5PROPERTY_LIST_HPP
#include <vector>
#include <H5Ppublic.h>
// Required by MPIOFileAccess
#ifdef H5_HAVE_PARALLEL
#include <H5FDmpi.h>
#endif
#include "H5Exception.hpp"
#include "H5Object.hpp"
namespace HighFive {
///
/// \brief Types of property lists
///
enum class PropertyType : int {
OBJECT_CREATE,
FILE_CREATE,
FILE_ACCESS,
DATASET_CREATE,
DATASET_ACCESS,
DATASET_XFER,
GROUP_CREATE,
GROUP_ACCESS,
DATATYPE_CREATE,
DATATYPE_ACCESS,
STRING_CREATE,
ATTRIBUTE_CREATE,
OBJECT_COPY,
LINK_CREATE,
LINK_ACCESS,
};
///
/// \brief Base Class for Property lists, providing global default
class PropertyListBase: public Object {
public:
PropertyListBase() noexcept;
static const PropertyListBase& Default() noexcept {
static const PropertyListBase plist{};
return plist;
}
};
///
/// \brief HDF5 property Lists
///
template <PropertyType T>
class PropertyList: public PropertyListBase {
public:
///
/// \brief return the type of this PropertyList
constexpr PropertyType getType() const noexcept {
return T;
}
///
/// Add a property to this property list.
/// A property is an object which is expected to have a method with the
/// following signature void apply(hid_t hid) const
///
template <typename P>
void add(const P& property);
///
/// Return the Default property type object
static const PropertyList<T>& Default() noexcept {
return static_cast<const PropertyList<T>&>(PropertyListBase::Default());
}
protected:
void _initializeIfNeeded();
};
using ObjectCreateProps = PropertyList<PropertyType::OBJECT_CREATE>;
using FileCreateProps = PropertyList<PropertyType::FILE_CREATE>;
using FileAccessProps = PropertyList<PropertyType::FILE_ACCESS>;
using DataSetCreateProps = PropertyList<PropertyType::DATASET_CREATE>;
using DataSetAccessProps = PropertyList<PropertyType::DATASET_ACCESS>;
using DataTransferProps = PropertyList<PropertyType::DATASET_XFER>;
using GroupCreateProps = PropertyList<PropertyType::GROUP_CREATE>;
using GroupAccessProps = PropertyList<PropertyType::GROUP_ACCESS>;
using DataTypeCreateProps = PropertyList<PropertyType::DATATYPE_CREATE>;
using DataTypeAccessProps = PropertyList<PropertyType::DATATYPE_ACCESS>;
using StringCreateProps = PropertyList<PropertyType::STRING_CREATE>;
using AttributeCreateProps = PropertyList<PropertyType::ATTRIBUTE_CREATE>;
using ObjectCopyProps = PropertyList<PropertyType::OBJECT_COPY>;
using LinkCreateProps = PropertyList<PropertyType::LINK_CREATE>;
using LinkAccessProps = PropertyList<PropertyType::LINK_ACCESS>;
///
/// RawPropertyLists are to be used when advanced H5 properties
/// are desired and are not part of the HighFive API.
/// Therefore this class is mainly for internal use.
template <PropertyType T>
class RawPropertyList: public PropertyList<T> {
public:
template <typename F, typename... Args>
void add(const F& funct, const Args&... args);
};
#ifdef H5_HAVE_PARALLEL
///
/// \brief Configure MPI access for the file
///
/// All further modifications to the structure of the file will have to be
/// done with collective operations
///
class MPIOFileAccess {
public:
MPIOFileAccess(MPI_Comm comm, MPI_Info info)
: _comm(comm)
, _info(info) {}
void apply(const hid_t list) const {
if (H5Pset_fapl_mpio(list, _comm, _info) < 0) {
HDF5ErrMapper::ToException<FileException>("Unable to set-up MPIO Driver configuration");
}
}
private:
MPI_Comm _comm;
MPI_Info _info;
};
#endif
///
/// \brief Configure the version bounds for the file
///
/// Used to define the compatibility of objects created within HDF5 files,
/// and affects the format of groups stored in the file.
///
/// See also the documentation of \c H5P_SET_LIBVER_BOUNDS in HDF5.
///
/// Possible values for \c low and \c high are:
/// * \c H5F_LIBVER_EARLIEST
/// * \c H5F_LIBVER_V18
/// * \c H5F_LIBVER_V110
/// * \c H5F_LIBVER_NBOUNDS
/// * \c H5F_LIBVER_LATEST currently defined as \c H5F_LIBVER_V110 within
/// HDF5
///
class FileVersionBounds {
public:
FileVersionBounds(H5F_libver_t low, H5F_libver_t high)
: _low(low)
, _high(high) {}
private:
friend FileAccessProps;
void apply(const hid_t list) const {
if (H5Pset_libver_bounds(list, _low, _high) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Error setting file version bounds");
}
}
const H5F_libver_t _low;
const H5F_libver_t _high;
};
///
/// \brief Configure the metadata block size to use writing to files
///
/// \param size Metadata block size in bytes
///
class MetadataBlockSize {
public:
MetadataBlockSize(hsize_t size)
: _size(size) {}
private:
friend FileAccessProps;
void apply(const hid_t list) const {
if (H5Pset_meta_block_size(list, _size) < 0) {
HDF5ErrMapper::ToException<PropertyException>("Error setting metadata block size");
}
}
const hsize_t _size;
};
///
/// \brief Set hints as to how many links to expect and their average length
///
class EstimatedLinkInfo {
public:
explicit EstimatedLinkInfo(unsigned entries, unsigned length)
: _entries(entries)
, _length(length) {}
private:
friend GroupCreateProps;
void apply(hid_t hid) const;
const unsigned _entries;
const unsigned _length;
};
class Chunking {
public:
explicit Chunking(const std::vector<hsize_t>& dims)
: _dims(dims) {}
Chunking(const std::initializer_list<hsize_t>& items)
: Chunking(std::vector<hsize_t>{items}) {}
template <typename... Args>
explicit Chunking(hsize_t item, Args... args)
: Chunking(std::vector<hsize_t>{item, static_cast<hsize_t>(args)...}) {}
const std::vector<hsize_t>& getDimensions() const noexcept {
return _dims;
}
private:
friend DataSetCreateProps;
void apply(hid_t hid) const;
const std::vector<hsize_t> _dims;
};
class Deflate {
public:
explicit Deflate(unsigned level)
: _level(level) {}
private:
friend DataSetCreateProps;
friend GroupCreateProps;
void apply(hid_t hid) const;
const unsigned _level;
};
class Szip {
public:
explicit Szip(unsigned options_mask = H5_SZIP_EC_OPTION_MASK,
unsigned pixels_per_block = H5_SZIP_MAX_PIXELS_PER_BLOCK)
: _options_mask(options_mask)
, _pixels_per_block(pixels_per_block) {}
private:
friend DataSetCreateProps;
void apply(hid_t hid) const;
const unsigned _options_mask;
const unsigned _pixels_per_block;
};
class Shuffle {
public:
Shuffle() = default;
private:
friend DataSetCreateProps;
void apply(hid_t hid) const;
};
/// Dataset access property to control chunk cache configuration.
/// Do not confuse with the similar file access property for H5Pset_cache
class Caching {
public:
/// https://support.hdfgroup.org/HDF5/doc/RM/H5P/H5Pset_chunk_cache.html for
/// details.
Caching(const size_t numSlots,
const size_t cacheSize,
const double w0 = static_cast<double>(H5D_CHUNK_CACHE_W0_DEFAULT))
: _numSlots(numSlots)
, _cacheSize(cacheSize)
, _w0(w0) {}
private:
friend DataSetAccessProps;
void apply(hid_t hid) const;
const size_t _numSlots;
const size_t _cacheSize;
const double _w0;
};
class CreateIntermediateGroup {
public:
explicit CreateIntermediateGroup(bool create = true)
: _create(create) {}
private:
friend ObjectCreateProps;
friend LinkCreateProps;
void apply(hid_t hid) const;
const bool _create;
};
} // namespace HighFive
#include "bits/H5PropertyList_misc.hpp"
#endif // H5PROPERTY_LIST_HPP