HighFive 2.10.0
HighFive - Header-only C++ HDF5 interface
Loading...
Searching...
No Matches
H5PropertyList_misc.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c), 2017-2018, Adrien Devresse <adrien.devresse@epfl.ch>
3 * Juan Hernando <juan.hernando@epfl.ch>
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#pragma once
10
11#include "h5p_wrapper.hpp"
12
13namespace HighFive {
14
15namespace {
16inline hid_t convert_plist_type(PropertyType propertyType) {
17 // The HP5_XXX are macros with function calls so we can't assign
18 // them as the enum values
19 switch (propertyType) {
21 return H5P_OBJECT_CREATE;
23 return H5P_FILE_CREATE;
25 return H5P_FILE_ACCESS;
27 return H5P_DATASET_CREATE;
29 return H5P_DATASET_ACCESS;
31 return H5P_DATASET_XFER;
33 return H5P_GROUP_CREATE;
35 return H5P_GROUP_ACCESS;
37 return H5P_DATATYPE_CREATE;
39 return H5P_DATATYPE_ACCESS;
41 return H5P_STRING_CREATE;
43 return H5P_ATTRIBUTE_CREATE;
45 return H5P_OBJECT_COPY;
47 return H5P_LINK_CREATE;
49 return H5P_LINK_ACCESS;
50 default:
51 HDF5ErrMapper::ToException<PropertyException>("Unsupported property list type");
52 }
53}
54
55} // namespace
56
57
59 : Object(H5P_DEFAULT) {}
60
61
62template <PropertyType T>
64 if (_hid != H5P_DEFAULT) {
65 return;
66 }
67 _hid = detail::h5p_create(convert_plist_type(T));
68}
69
70template <PropertyType T>
71template <PropertyInterface P>
72inline void PropertyList<T>::add(const P& property) {
73 _initializeIfNeeded();
74 property.apply(_hid);
75}
76
77template <PropertyType T>
78template <typename F, typename... Args>
79inline void RawPropertyList<T>::add(const F& funct, const Args&... args) {
80 this->_initializeIfNeeded();
81 if (funct(this->_hid, args...) < 0) {
82 HDF5ErrMapper::ToException<PropertyException>("Error setting raw hdf5 property.");
83 }
84}
85
86// Specific options to be added to Property Lists
87#if H5_VERSION_GE(1, 10, 1)
88inline FileSpaceStrategy::FileSpaceStrategy(H5F_fspace_strategy_t strategy,
89 hbool_t persist,
90 hsize_t threshold)
91 : _strategy(strategy)
92 , _persist(persist)
93 , _threshold(threshold) {}
94
95inline FileSpaceStrategy::FileSpaceStrategy(const FileCreateProps& fcpl) {
96 detail::h5p_get_file_space_strategy(fcpl.getId(), &_strategy, &_persist, &_threshold);
97}
98
99inline void FileSpaceStrategy::apply(const hid_t list) const {
100 detail::h5p_set_file_space_strategy(list, _strategy, _persist, _threshold);
101}
102
103inline H5F_fspace_strategy_t FileSpaceStrategy::getStrategy() const {
104 return _strategy;
105}
106
107inline hbool_t FileSpaceStrategy::getPersist() const {
108 return _persist;
109}
110
111inline hsize_t FileSpaceStrategy::getThreshold() const {
112 return _threshold;
113}
114
115inline FileSpacePageSize::FileSpacePageSize(hsize_t page_size)
116 : _page_size(page_size) {}
117
118inline void FileSpacePageSize::apply(const hid_t list) const {
119 detail::h5p_set_file_space_page_size(list, _page_size);
120}
121
122inline FileSpacePageSize::FileSpacePageSize(const FileCreateProps& fcpl) {
123 detail::h5p_get_file_space_page_size(fcpl.getId(), &_page_size);
124}
125
126inline hsize_t FileSpacePageSize::getPageSize() const {
127 return _page_size;
128}
129
130#ifndef H5_HAVE_PARALLEL
131inline PageBufferSize::PageBufferSize(size_t page_buffer_size,
132 unsigned min_meta_percent,
133 unsigned min_raw_percent)
134 : _page_buffer_size(page_buffer_size)
135 , _min_meta(min_meta_percent)
136 , _min_raw(min_raw_percent) {}
137
138inline PageBufferSize::PageBufferSize(const FileAccessProps& plist) {
139 detail::h5p_get_page_buffer_size(plist.getId(), &_page_buffer_size, &_min_meta, &_min_raw);
140}
141
142inline void PageBufferSize::apply(const hid_t list) const {
143 detail::h5p_set_page_buffer_size(list, _page_buffer_size, _min_meta, _min_raw);
144}
145
146inline size_t PageBufferSize::getPageBufferSize() const {
147 return _page_buffer_size;
148}
149
150inline unsigned PageBufferSize::getMinMetaPercent() const {
151 return _min_meta;
152}
153
154inline unsigned PageBufferSize::getMinRawPercent() const {
155 return _min_raw;
156}
157#endif
158#endif
159
160#ifdef H5_HAVE_PARALLEL
161
162inline MPIOFileAccess::MPIOFileAccess(MPI_Comm comm, MPI_Info info)
163 : _comm(comm)
164 , _info(info) {}
165
166inline void MPIOFileAccess::apply(const hid_t list) const {
167 detail::h5p_set_fapl_mpio(list, _comm, _info);
168}
169
170#if H5_VERSION_GE(1, 10, 0)
171inline void MPIOCollectiveMetadata::apply(const hid_t plist) const {
172 auto read = MPIOCollectiveMetadataRead{collective_read_};
173 auto write = MPIOCollectiveMetadataWrite{collective_write_};
174
175 read.apply(plist);
176 write.apply(plist);
177}
178
179inline MPIOCollectiveMetadata::MPIOCollectiveMetadata(bool collective)
180 : collective_read_(collective)
181 , collective_write_(collective) {}
182
183
184inline MPIOCollectiveMetadata::MPIOCollectiveMetadata(const FileAccessProps& plist)
185 : collective_read_(MPIOCollectiveMetadataRead(plist).isCollective())
186 , collective_write_(MPIOCollectiveMetadataWrite(plist).isCollective()) {}
187
188inline bool MPIOCollectiveMetadata::isCollectiveRead() const {
189 return collective_read_;
190}
191
192inline bool MPIOCollectiveMetadata::isCollectiveWrite() const {
193 return collective_write_;
194}
195
196
197inline void MPIOCollectiveMetadataRead::apply(const hid_t plist) const {
198 detail::h5p_set_all_coll_metadata_ops(plist, collective_);
199}
200
201inline bool MPIOCollectiveMetadataRead::isCollective() const {
202 return collective_;
203}
204
205inline MPIOCollectiveMetadataRead::MPIOCollectiveMetadataRead(const FileAccessProps& plist) {
206 detail::h5p_get_all_coll_metadata_ops(plist.getId(), &collective_);
207}
208
209inline MPIOCollectiveMetadataRead::MPIOCollectiveMetadataRead(bool collective)
210 : collective_(collective) {}
211
212inline void MPIOCollectiveMetadataWrite::apply(const hid_t plist) const {
213 detail::h5p_set_coll_metadata_write(plist, collective_);
214}
215
216inline bool MPIOCollectiveMetadataWrite::isCollective() const {
217 return collective_;
218}
219
220inline MPIOCollectiveMetadataWrite::MPIOCollectiveMetadataWrite(const FileAccessProps& plist) {
221 detail::h5p_get_coll_metadata_write(plist.getId(), &collective_);
222}
223
224inline MPIOCollectiveMetadataWrite::MPIOCollectiveMetadataWrite(bool collective)
225 : collective_(collective) {}
226
227#endif
228#endif
229
230inline FileVersionBounds::FileVersionBounds(H5F_libver_t low, H5F_libver_t high)
231 : _low(low)
232 , _high(high) {}
233
235 detail::h5p_get_libver_bounds(fapl.getId(), &_low, &_high);
236}
237
238inline std::pair<H5F_libver_t, H5F_libver_t> FileVersionBounds::getVersion() const {
239 return std::make_pair(_low, _high);
240}
241
242inline void FileVersionBounds::apply(const hid_t list) const {
243 detail::h5p_set_libver_bounds(list, _low, _high);
244}
245
247 : _size(size) {}
248
250 detail::h5p_get_meta_block_size(fapl.getId(), &_size);
251}
252
253inline void MetadataBlockSize::apply(const hid_t list) const {
254 detail::h5p_set_meta_block_size(list, _size);
255}
256
257inline hsize_t MetadataBlockSize::getSize() const {
258 return _size;
259}
260
261inline void EstimatedLinkInfo::apply(const hid_t hid) const {
262 detail::h5p_set_est_link_info(hid, _entries, _length);
263}
264
265inline EstimatedLinkInfo::EstimatedLinkInfo(unsigned entries, unsigned length)
266 : _entries(entries)
267 , _length(length) {}
268
270 detail::h5p_get_est_link_info(gcpl.getId(), &_entries, &_length);
271}
272
273inline unsigned EstimatedLinkInfo::getEntries() const {
274 return _entries;
275}
276
277inline unsigned EstimatedLinkInfo::getNameLength() const {
278 return _length;
279}
280
281inline void Chunking::apply(const hid_t hid) const {
282 detail::h5p_set_chunk(hid, static_cast<int>(_dims.size()), _dims.data());
283}
284
285inline Chunking::Chunking(const std::vector<hsize_t>& dims)
286 : _dims(dims) {}
287
288inline Chunking::Chunking(const std::initializer_list<hsize_t>& items)
289 : Chunking(std::vector<hsize_t>{items}) {}
290
291inline Chunking::Chunking(DataSetCreateProps& plist, size_t max_dims)
292 : _dims(max_dims + 1) {
293 auto n_loaded =
294 detail::h5p_get_chunk(plist.getId(), static_cast<int>(_dims.size()), _dims.data());
295
296 if (n_loaded >= static_cast<int>(_dims.size())) {
297 *this = Chunking(plist, 8 * max_dims);
298 } else {
299 _dims.resize(static_cast<size_t>(n_loaded));
300 }
301}
302
303inline const std::vector<hsize_t>& Chunking::getDimensions() const noexcept {
304 return _dims;
305}
306
307template <typename... Args>
308inline Chunking::Chunking(hsize_t item, Args... args)
309 : Chunking(std::vector<hsize_t>{item, static_cast<hsize_t>(args)...}) {}
310
311inline void Deflate::apply(const hid_t hid) const {
312 if (detail::h5z_filter_avail(H5Z_FILTER_DEFLATE) == 0) {
313 HDF5ErrMapper::ToException<PropertyException>("Deflate filter unavailable.");
314 }
315
316 detail::h5p_set_deflate(hid, _level);
317}
318
319inline Deflate::Deflate(unsigned int level)
320 : _level(level) {}
321
322inline void Szip::apply(const hid_t hid) const {
323 if (detail::h5z_filter_avail(H5Z_FILTER_SZIP) == 0) {
324 HDF5ErrMapper::ToException<PropertyException>("SZIP filter unavailable.");
325 }
326
327 detail::h5p_set_szip(hid, _options_mask, _pixels_per_block);
328}
329
330inline Szip::Szip(unsigned int options_mask, unsigned int pixels_per_block)
331 : _options_mask(options_mask)
332 , _pixels_per_block(pixels_per_block) {}
333
334inline unsigned Szip::getOptionsMask() const {
335 return _options_mask;
336}
337
338inline unsigned Szip::getPixelsPerBlock() const {
339 return _pixels_per_block;
340}
341
342inline void Shuffle::apply(const hid_t hid) const {
343 if (detail::h5z_filter_avail(H5Z_FILTER_SHUFFLE) == 0) {
344 HDF5ErrMapper::ToException<PropertyException>("Shuffle filter unavailable.");
345 }
346
347 detail::h5p_set_shuffle(hid);
348}
349
350inline AllocationTime::AllocationTime(H5D_alloc_time_t alloc_time)
351 : _alloc_time(alloc_time) {}
352
354 detail::h5p_get_alloc_time(dcpl.getId(), &_alloc_time);
355}
356
357inline void AllocationTime::apply(hid_t dcpl) const {
358 detail::h5p_set_alloc_time(dcpl, _alloc_time);
359}
360
361inline H5D_alloc_time_t AllocationTime::getAllocationTime() {
362 return _alloc_time;
363}
364
366 detail::h5p_get_chunk_cache(dcpl.getId(), &_numSlots, &_cacheSize, &_w0);
367}
368
369inline void Caching::apply(const hid_t hid) const {
370 detail::h5p_set_chunk_cache(hid, _numSlots, _cacheSize, _w0);
371}
372
373inline Caching::Caching(const size_t numSlots, const size_t cacheSize, const double w0)
374 : _numSlots(numSlots)
375 , _cacheSize(cacheSize)
376 , _w0(w0) {}
377
378inline size_t Caching::getNumSlots() const {
379 return _numSlots;
380}
381
382inline size_t Caching::getCacheSize() const {
383 return _cacheSize;
384}
385
386inline double Caching::getW0() const {
387 return _w0;
388}
389
391 : _create(create) {}
392
396
397
398inline void CreateIntermediateGroup::apply(const hid_t hid) const {
399 detail::h5p_set_create_intermediate_group(hid, _create ? 1 : 0);
400}
401
403 fromPropertyList(lcpl.getId());
404}
405
407 unsigned c_bool = 0;
408 _create = bool(detail::h5p_get_create_intermediate_group(hid, &c_bool));
409}
410
412 return _create;
413}
414
415#ifdef H5_HAVE_PARALLEL
417 : _enable(enable) {}
418
419inline void UseCollectiveIO::apply(const hid_t hid) const {
420 detail::h5p_set_dxpl_mpio(hid, _enable ? H5FD_MPIO_COLLECTIVE : H5FD_MPIO_INDEPENDENT);
421}
422
424 H5FD_mpio_xfer_t collective;
425
426 detail::h5p_get_dxpl_mpio(dxpl.getId(), &collective);
427
428 if (collective != H5FD_MPIO_COLLECTIVE && collective != H5FD_MPIO_INDEPENDENT) {
429 throw std::logic_error("H5Pget_dxpl_mpio returned something strange.");
430 }
431
432 _enable = collective == H5FD_MPIO_COLLECTIVE;
433}
434
435inline bool UseCollectiveIO::isCollective() const {
436 return _enable;
437}
438
440 detail::h5p_get_mpio_no_collective_cause(dxpl.getId(), &_local_cause, &_global_cause);
441}
442
444 return _local_cause == 0 && _global_cause == 0;
445}
446
448 return _local_cause;
449}
450
452 return _global_cause;
453}
454
455inline std::pair<uint32_t, uint32_t> MpioNoCollectiveCause::getCause() const {
456 return {_local_cause, _global_cause};
457}
458#endif
459
463
465 fromPropertyList(gcpl.getId());
466}
467
468inline unsigned LinkCreationOrder::getFlags() const {
469 return _flags;
470}
471
472inline void LinkCreationOrder::apply(const hid_t hid) const {
473 detail::h5p_set_link_creation_order(hid, _flags);
474}
475
477 detail::h5p_get_link_creation_order(hid, &_flags);
478}
479
480inline AttributePhaseChange::AttributePhaseChange(unsigned max_compact, unsigned min_dense)
481 : _max_compact(max_compact)
482 , _min_dense(min_dense) {}
483
485 detail::h5p_get_attr_phase_change(gcpl.getId(), &_max_compact, &_min_dense);
486}
487
488inline unsigned AttributePhaseChange::max_compact() const {
489 return _max_compact;
490}
491
492inline unsigned AttributePhaseChange::min_dense() const {
493 return _min_dense;
494}
495
496inline void AttributePhaseChange::apply(hid_t hid) const {
497 detail::h5p_set_attr_phase_change(hid, _max_compact, _min_dense);
498}
499
500
501} // namespace HighFive
H5D_alloc_time_t getAllocationTime()
Definition H5PropertyList_misc.hpp:361
AllocationTime(H5D_alloc_time_t alloc_time)
Definition H5PropertyList_misc.hpp:350
unsigned max_compact() const
Definition H5PropertyList_misc.hpp:488
AttributePhaseChange(unsigned max_compact, unsigned min_dense)
Create the property from the threshold values.
Definition H5PropertyList_misc.hpp:480
unsigned min_dense() const
Definition H5PropertyList_misc.hpp:492
size_t getNumSlots() const
Definition H5PropertyList_misc.hpp:378
Caching(const size_t numSlots, const size_t cacheSize, const double w0=static_cast< double >(H5D_CHUNK_CACHE_W0_DEFAULT))
Definition H5PropertyList_misc.hpp:373
size_t getCacheSize() const
Definition H5PropertyList_misc.hpp:382
double getW0() const
Definition H5PropertyList_misc.hpp:386
Definition H5PropertyList.hpp:503
const std::vector< hsize_t > & getDimensions() const noexcept
Definition H5PropertyList_misc.hpp:303
Chunking(const std::vector< hsize_t > &dims)
Definition H5PropertyList_misc.hpp:285
CreateIntermediateGroup(bool create=true)
Definition H5PropertyList_misc.hpp:390
void fromPropertyList(hid_t hid)
Definition H5PropertyList_misc.hpp:406
bool isSet() const
Definition H5PropertyList_misc.hpp:411
Deflate(unsigned level)
Definition H5PropertyList_misc.hpp:319
std::pair< H5F_libver_t, H5F_libver_t > getVersion() const
Definition H5PropertyList_misc.hpp:238
FileVersionBounds(H5F_libver_t low, H5F_libver_t high)
Definition H5PropertyList_misc.hpp:230
MPIOFileAccess(MPI_Comm comm, MPI_Info info)
Definition H5PropertyList_misc.hpp:162
MetadataBlockSize(hsize_t size)
Definition H5PropertyList_misc.hpp:246
hsize_t getSize() const
Definition H5PropertyList_misc.hpp:257
uint32_t getGlobalCause() const
The global cause for a non-collective I/O.
Definition H5PropertyList_misc.hpp:451
bool wasCollective() const
Was the datatransfer collective?
Definition H5PropertyList_misc.hpp:443
std::pair< uint32_t, uint32_t > getCause() const
A pair of the local and global cause for non-collective I/O.
Definition H5PropertyList_misc.hpp:455
MpioNoCollectiveCause(const DataTransferProps &dxpl)
Definition H5PropertyList_misc.hpp:439
uint32_t getLocalCause() const
The local cause for a non-collective I/O.
Definition H5PropertyList_misc.hpp:447
Definition H5Object.hpp:54
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:69
PropertyListBase() noexcept
Definition H5PropertyList_misc.hpp:58
HDF5 property Lists.
Definition H5PropertyList.hpp:160
void _initializeIfNeeded()
Definition H5PropertyList_misc.hpp:63
void add(const P &property)
Definition H5PropertyList_misc.hpp:72
void add(const F &funct, const Args &... args)
Definition H5PropertyList_misc.hpp:79
Szip(unsigned options_mask=H5_SZIP_EC_OPTION_MASK, unsigned pixels_per_block=H5_SZIP_MAX_PIXELS_PER_BLOCK)
Definition H5PropertyList_misc.hpp:330
unsigned getPixelsPerBlock() const
Definition H5PropertyList_misc.hpp:338
unsigned getOptionsMask() const
Definition H5PropertyList_misc.hpp:334
bool isCollective() const
Does the property request collective IO?
Definition H5PropertyList_misc.hpp:435
UseCollectiveIO(bool enable=true)
Definition H5PropertyList_misc.hpp:416
PropertyType
Types of property lists.
Definition H5PropertyList.hpp:89
PropertyList< PropertyType::LINK_CREATE > LinkCreateProps
Definition H5PropertyList.hpp:211
PropertyList< PropertyType::FILE_ACCESS > FileAccessProps
Definition H5PropertyList.hpp:200
PropertyList< PropertyType::FILE_CREATE > FileCreateProps
Definition H5PropertyList.hpp:199
Definition H5_definitions.hpp:22
static void ToException(const std::string &prefix_msg)
Definition H5Exception_misc.hpp:43