HighFive 2.7.1
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 <H5Ppublic.h>
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 if ((_hid = H5Pcreate(convert_plist_type(T))) < 0) {
68 HDF5ErrMapper::ToException<PropertyException>("Unable to create property list");
69 }
70}
71
72template <PropertyType T>
73template <typename P>
74inline void PropertyList<T>::add(const P& property) {
75 _initializeIfNeeded();
76 property.apply(_hid);
77}
78
79template <PropertyType T>
80template <typename F, typename... Args>
81inline void RawPropertyList<T>::add(const F& funct, const Args&... args) {
82 this->_initializeIfNeeded();
83 if (funct(this->_hid, args...) < 0) {
84 HDF5ErrMapper::ToException<PropertyException>("Error setting raw hdf5 property.");
85 }
86}
87
88// Specific options to be added to Property Lists
89#if H5_VERSION_GE(1, 10, 1)
90inline FileSpaceStrategy::FileSpaceStrategy(H5F_fspace_strategy_t strategy,
91 hbool_t persist,
92 hsize_t threshold)
93 : _strategy(strategy)
94 , _persist(persist)
95 , _threshold(threshold) {}
96
97inline FileSpaceStrategy::FileSpaceStrategy(const FileCreateProps& fcpl) {
98 if (H5Pget_file_space_strategy(fcpl.getId(), &_strategy, &_persist, &_threshold) < 0) {
99 HDF5ErrMapper::ToException<PropertyException>("Unable to get file space strategy");
100 }
101}
102
103inline void FileSpaceStrategy::apply(const hid_t list) const {
104 if (H5Pset_file_space_strategy(list, _strategy, _persist, _threshold) < 0) {
105 HDF5ErrMapper::ToException<PropertyException>("Error setting file space strategy.");
106 }
107}
108
109inline H5F_fspace_strategy_t FileSpaceStrategy::getStrategy() const {
110 return _strategy;
111}
112
113inline hbool_t FileSpaceStrategy::getPersist() const {
114 return _persist;
115}
116
117inline hsize_t FileSpaceStrategy::getThreshold() const {
118 return _threshold;
119}
120
121inline FileSpacePageSize::FileSpacePageSize(hsize_t page_size)
122 : _page_size(page_size) {}
123
124inline void FileSpacePageSize::apply(const hid_t list) const {
125 if (H5Pset_file_space_page_size(list, _page_size) < 0) {
126 HDF5ErrMapper::ToException<PropertyException>("Error setting file space page size.");
127 }
128}
129
130inline FileSpacePageSize::FileSpacePageSize(const FileCreateProps& fcpl) {
131 if (H5Pget_file_space_page_size(fcpl.getId(), &_page_size) < 0) {
132 HDF5ErrMapper::ToException<PropertyException>("Unable to get file space page size");
133 }
134}
135
136inline hsize_t FileSpacePageSize::getPageSize() const {
137 return _page_size;
138}
139
140#ifndef H5_HAVE_PARALLEL
141inline PageBufferSize::PageBufferSize(size_t page_buffer_size,
142 unsigned min_meta_percent,
143 unsigned min_raw_percent)
144 : _page_buffer_size(page_buffer_size)
145 , _min_meta(min_meta_percent)
146 , _min_raw(min_raw_percent) {}
147
148inline PageBufferSize::PageBufferSize(const FileAccessProps& plist) {
149 if (H5Pget_page_buffer_size(plist.getId(), &_page_buffer_size, &_min_meta, &_min_raw) < 0) {
150 HDF5ErrMapper::ToException<PropertyException>("Error setting page buffer size.");
151 }
152}
153
154inline void PageBufferSize::apply(const hid_t list) const {
155 if (H5Pset_page_buffer_size(list, _page_buffer_size, _min_meta, _min_raw) < 0) {
156 HDF5ErrMapper::ToException<PropertyException>("Error setting page buffer size.");
157 }
158}
159
160inline size_t PageBufferSize::getPageBufferSize() const {
161 return _page_buffer_size;
162}
163
164inline unsigned PageBufferSize::getMinMetaPercent() const {
165 return _min_meta;
166}
167
168inline unsigned PageBufferSize::getMinRawPercent() const {
169 return _min_raw;
170}
171#endif
172#endif
173
174#ifdef H5_HAVE_PARALLEL
175
176inline MPIOFileAccess::MPIOFileAccess(MPI_Comm comm, MPI_Info info)
177 : _comm(comm)
178 , _info(info) {}
179
180inline void MPIOFileAccess::apply(const hid_t list) const {
181 if (H5Pset_fapl_mpio(list, _comm, _info) < 0) {
182 HDF5ErrMapper::ToException<FileException>("Unable to set-up MPIO Driver configuration");
183 }
184}
185
186inline void MPIOCollectiveMetadata::apply(const hid_t plist) const {
187 auto read = MPIOCollectiveMetadataRead{collective_read_};
188 auto write = MPIOCollectiveMetadataWrite{collective_write_};
189
190 read.apply(plist);
191 write.apply(plist);
192}
193
195 : collective_read_(collective)
196 , collective_write_(collective) {}
197
198
200 : collective_read_(MPIOCollectiveMetadataRead(plist).isCollective())
201 , collective_write_(MPIOCollectiveMetadataWrite(plist).isCollective()) {}
202
204 return collective_read_;
205}
206
208 return collective_write_;
209}
210
211
212inline void MPIOCollectiveMetadataRead::apply(const hid_t plist) const {
213 if (H5Pset_all_coll_metadata_ops(plist, collective_) < 0) {
214 HDF5ErrMapper::ToException<FileException>("Unable to request collective metadata reads");
215 }
216}
217
219 return collective_;
220}
221
223 if (H5Pget_all_coll_metadata_ops(plist.getId(), &collective_) < 0) {
224 HDF5ErrMapper::ToException<PropertyException>("Error loading MPI metadata read.");
225 }
226}
227
229 : collective_(collective) {}
230
231inline void MPIOCollectiveMetadataWrite::apply(const hid_t plist) const {
232 if (H5Pset_coll_metadata_write(plist, collective_) < 0) {
233 HDF5ErrMapper::ToException<FileException>("Unable to request collective metadata writes");
234 }
235}
236
238 return collective_;
239}
240
242 if (H5Pget_coll_metadata_write(plist.getId(), &collective_) < 0) {
243 HDF5ErrMapper::ToException<PropertyException>("Error loading MPI metadata write.");
244 }
245}
246
248 : collective_(collective) {}
249
250#endif
251
252inline FileVersionBounds::FileVersionBounds(H5F_libver_t low, H5F_libver_t high)
253 : _low(low)
254 , _high(high) {}
255
257 if (H5Pget_libver_bounds(fapl.getId(), &_low, &_high) < 0) {
258 HDF5ErrMapper::ToException<PropertyException>("Unable to access file version bounds");
259 }
260}
261
262inline std::pair<H5F_libver_t, H5F_libver_t> FileVersionBounds::getVersion() const {
263 return std::make_pair(_low, _high);
264}
265
266inline void FileVersionBounds::apply(const hid_t list) const {
267 if (H5Pset_libver_bounds(list, _low, _high) < 0) {
268 HDF5ErrMapper::ToException<PropertyException>("Error setting file version bounds");
269 }
270}
271
273 : _size(size) {}
274
276 if (H5Pget_meta_block_size(fapl.getId(), &_size) < 0) {
277 HDF5ErrMapper::ToException<PropertyException>("Unable to access file metadata block size");
278 }
279}
280
281inline void MetadataBlockSize::apply(const hid_t list) const {
282 if (H5Pset_meta_block_size(list, _size) < 0) {
283 HDF5ErrMapper::ToException<PropertyException>("Error setting metadata block size");
284 }
285}
286
287inline hsize_t MetadataBlockSize::getSize() const {
288 return _size;
289}
290
291inline void EstimatedLinkInfo::apply(const hid_t hid) const {
292 if (H5Pset_est_link_info(hid, _entries, _length) < 0) {
293 HDF5ErrMapper::ToException<PropertyException>("Error setting estimated link info");
294 }
295}
296
297inline EstimatedLinkInfo::EstimatedLinkInfo(unsigned entries, unsigned length)
298 : _entries(entries)
299 , _length(length) {}
300
302 if (H5Pget_est_link_info(gcpl.getId(), &_entries, &_length) < 0) {
303 HDF5ErrMapper::ToException<PropertyException>("Unable to access group link size property");
304 }
305}
306
307inline unsigned EstimatedLinkInfo::getEntries() const {
308 return _entries;
309}
310
311inline unsigned EstimatedLinkInfo::getNameLength() const {
312 return _length;
313}
314
315inline void Chunking::apply(const hid_t hid) const {
316 if (H5Pset_chunk(hid, static_cast<int>(_dims.size()), _dims.data()) < 0) {
317 HDF5ErrMapper::ToException<PropertyException>("Error setting chunk property");
318 }
319}
320
321inline Chunking::Chunking(const std::vector<hsize_t>& dims)
322 : _dims(dims) {}
323
324inline Chunking::Chunking(const std::initializer_list<hsize_t>& items)
325 : Chunking(std::vector<hsize_t>{items}) {}
326
327inline Chunking::Chunking(DataSetCreateProps& plist, size_t max_dims)
328 : _dims(max_dims + 1) {
329 auto n_loaded = H5Pget_chunk(plist.getId(), static_cast<int>(_dims.size()), _dims.data());
330 if (n_loaded < 0) {
331 HDF5ErrMapper::ToException<PropertyException>("Error getting chunk size");
332 }
333
334 if (n_loaded >= static_cast<int>(_dims.size())) {
335 *this = Chunking(plist, 8 * max_dims);
336 } else {
337 _dims.resize(static_cast<size_t>(n_loaded));
338 }
339}
340
341inline const std::vector<hsize_t>& Chunking::getDimensions() const noexcept {
342 return _dims;
343}
344
345template <typename... Args>
346inline Chunking::Chunking(hsize_t item, Args... args)
347 : Chunking(std::vector<hsize_t>{item, static_cast<hsize_t>(args)...}) {}
348
349inline void Deflate::apply(const hid_t hid) const {
350 if (!H5Zfilter_avail(H5Z_FILTER_DEFLATE) || H5Pset_deflate(hid, _level) < 0) {
351 HDF5ErrMapper::ToException<PropertyException>("Error setting deflate property");
352 }
353}
354
355inline Deflate::Deflate(unsigned int level)
356 : _level(level) {}
357
358inline void Szip::apply(const hid_t hid) const {
359 if (!H5Zfilter_avail(H5Z_FILTER_SZIP)) {
360 HDF5ErrMapper::ToException<PropertyException>("Error setting szip property");
361 }
362
363 if (H5Pset_szip(hid, _options_mask, _pixels_per_block) < 0) {
364 HDF5ErrMapper::ToException<PropertyException>("Error setting szip property");
365 }
366}
367
368inline Szip::Szip(unsigned int options_mask, unsigned int pixels_per_block)
369 : _options_mask(options_mask)
370 , _pixels_per_block(pixels_per_block) {}
371
372inline unsigned Szip::getOptionsMask() const {
373 return _options_mask;
374}
375
376inline unsigned Szip::getPixelsPerBlock() const {
377 return _pixels_per_block;
378}
379
380inline void Shuffle::apply(const hid_t hid) const {
381 if (!H5Zfilter_avail(H5Z_FILTER_SHUFFLE)) {
382 HDF5ErrMapper::ToException<PropertyException>("Error setting shuffle property");
383 }
384
385 if (H5Pset_shuffle(hid) < 0) {
386 HDF5ErrMapper::ToException<PropertyException>("Error setting shuffle property");
387 }
388}
389
390inline AllocationTime::AllocationTime(H5D_alloc_time_t alloc_time)
391 : _alloc_time(alloc_time) {}
392
394 if (H5Pget_alloc_time(dcpl.getId(), &_alloc_time) < 0) {
395 HDF5ErrMapper::ToException<PropertyException>("Error getting allocation time");
396 }
397}
398
399inline void AllocationTime::apply(hid_t dcpl) const {
400 if (H5Pset_alloc_time(dcpl, _alloc_time) < 0) {
401 HDF5ErrMapper::ToException<PropertyException>("Error setting allocation time");
402 }
403}
404
405inline H5D_alloc_time_t AllocationTime::getAllocationTime() {
406 return _alloc_time;
407}
408
410 if (H5Pget_chunk_cache(dcpl.getId(), &_numSlots, &_cacheSize, &_w0) < 0) {
411 HDF5ErrMapper::ToException<PropertyException>("Error getting dataset cache parameters");
412 }
413}
414
415inline void Caching::apply(const hid_t hid) const {
416 if (H5Pset_chunk_cache(hid, _numSlots, _cacheSize, _w0) < 0) {
417 HDF5ErrMapper::ToException<PropertyException>("Error setting dataset cache parameters");
418 }
419}
420
421inline Caching::Caching(const size_t numSlots, const size_t cacheSize, const double w0)
422 : _numSlots(numSlots)
423 , _cacheSize(cacheSize)
424 , _w0(w0) {}
425
426inline size_t Caching::getNumSlots() const {
427 return _numSlots;
428}
429
430inline size_t Caching::getCacheSize() const {
431 return _cacheSize;
432}
433
434inline double Caching::getW0() const {
435 return _w0;
436}
437
439 : _create(create) {}
440
442 fromPropertyList(ocpl.getId());
443}
444
445
446inline void CreateIntermediateGroup::apply(const hid_t hid) const {
447 if (H5Pset_create_intermediate_group(hid, _create ? 1 : 0) < 0) {
448 HDF5ErrMapper::ToException<PropertyException>(
449 "Error setting property for create intermediate groups");
450 }
451}
452
454 fromPropertyList(lcpl.getId());
455}
456
458 unsigned c_bool = 0;
459 if (H5Pget_create_intermediate_group(hid, &c_bool) < 0) {
460 HDF5ErrMapper::ToException<PropertyException>(
461 "Error getting property for create intermediate groups");
462 }
463
464 _create = bool(c_bool);
465}
466
468 return _create;
469}
470
471#ifdef H5_HAVE_PARALLEL
473 : _enable(enable) {}
474
475inline void UseCollectiveIO::apply(const hid_t hid) const {
476 if (H5Pset_dxpl_mpio(hid, _enable ? H5FD_MPIO_COLLECTIVE : H5FD_MPIO_INDEPENDENT) < 0) {
477 HDF5ErrMapper::ToException<PropertyException>("Error setting H5Pset_dxpl_mpio.");
478 }
479}
480
482 H5FD_mpio_xfer_t collective;
483
484 if (H5Pget_dxpl_mpio(dxpl.getId(), &collective) < 0) {
485 HDF5ErrMapper::ToException<PropertyException>("Error getting H5Pset_dxpl_mpio.");
486 }
487
488 if (collective != H5FD_MPIO_COLLECTIVE && collective != H5FD_MPIO_INDEPENDENT) {
489 throw std::logic_error("H5Pget_dxpl_mpio returned something strange.");
490 }
491
492 _enable = collective == H5FD_MPIO_COLLECTIVE;
493}
494
495inline bool UseCollectiveIO::isCollective() const {
496 return _enable;
497}
498
500 if (H5Pget_mpio_no_collective_cause(dxpl.getId(), &_local_cause, &_global_cause) < 0) {
501 HDF5ErrMapper::ToException<PropertyException>("Failed to check mpio_no_collective_cause.");
502 }
503}
504
506 return _local_cause == 0 && _global_cause == 0;
507}
508
510 return _local_cause;
511}
512
514 return _global_cause;
515}
516
517inline std::pair<uint32_t, uint32_t> MpioNoCollectiveCause::getCause() const {
518 return {_local_cause, _global_cause};
519}
520#endif
521
523 fromPropertyList(fcpl.getId());
524}
525
527 fromPropertyList(gcpl.getId());
528}
529
530inline unsigned LinkCreationOrder::getFlags() const {
531 return _flags;
532}
533
534inline void LinkCreationOrder::apply(const hid_t hid) const {
535 if (H5Pset_link_creation_order(hid, _flags) < 0) {
536 HDF5ErrMapper::ToException<PropertyException>("Error setting LinkCreationOrder.");
537 }
538}
539
541 if (H5Pget_link_creation_order(hid, &_flags) < 0) {
542 HDF5ErrMapper::ToException<PropertyException>(
543 "Error getting property for link creation order");
544 }
545}
546} // namespace HighFive
H5D_alloc_time_t getAllocationTime()
Definition H5PropertyList_misc.hpp:405
AllocationTime(H5D_alloc_time_t alloc_time)
Definition H5PropertyList_misc.hpp:390
size_t getNumSlots() const
Definition H5PropertyList_misc.hpp:426
Caching(const size_t numSlots, const size_t cacheSize, const double w0=static_cast< double >(H5D_CHUNK_CACHE_W0_DEFAULT))
Definition H5PropertyList_misc.hpp:421
size_t getCacheSize() const
Definition H5PropertyList_misc.hpp:430
double getW0() const
Definition H5PropertyList_misc.hpp:434
Definition H5PropertyList.hpp:405
const std::vector< hsize_t > & getDimensions() const noexcept
Definition H5PropertyList_misc.hpp:341
Chunking(const std::vector< hsize_t > &dims)
Definition H5PropertyList_misc.hpp:321
CreateIntermediateGroup(bool create=true)
Definition H5PropertyList_misc.hpp:438
void fromPropertyList(hid_t hid)
Definition H5PropertyList_misc.hpp:457
bool isSet() const
Definition H5PropertyList_misc.hpp:467
Deflate(unsigned level)
Definition H5PropertyList_misc.hpp:355
std::pair< H5F_libver_t, H5F_libver_t > getVersion() const
Definition H5PropertyList_misc.hpp:262
FileVersionBounds(H5F_libver_t low, H5F_libver_t high)
Definition H5PropertyList_misc.hpp:252
bool isCollectiveWrite() const
Definition H5PropertyList_misc.hpp:207
MPIOCollectiveMetadata(bool collective=true)
Definition H5PropertyList_misc.hpp:194
bool isCollectiveRead() const
Definition H5PropertyList_misc.hpp:203
Use collective MPI-IO for metadata read?
Definition H5PropertyList.hpp:186
bool isCollective() const
Definition H5PropertyList_misc.hpp:218
MPIOCollectiveMetadataRead(bool collective=true)
Definition H5PropertyList_misc.hpp:228
Use collective MPI-IO for metadata write?
Definition H5PropertyList.hpp:212
bool isCollective() const
Definition H5PropertyList_misc.hpp:237
MPIOCollectiveMetadataWrite(bool collective=true)
Definition H5PropertyList_misc.hpp:247
MPIOFileAccess(MPI_Comm comm, MPI_Info info)
Definition H5PropertyList_misc.hpp:176
MetadataBlockSize(hsize_t size)
Definition H5PropertyList_misc.hpp:272
hsize_t getSize() const
Definition H5PropertyList_misc.hpp:287
uint32_t getGlobalCause() const
The global cause for a non-collective I/O.
Definition H5PropertyList_misc.hpp:513
bool wasCollective() const
Was the datatransfer collective?
Definition H5PropertyList_misc.hpp:505
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:517
MpioNoCollectiveCause(const DataTransferProps &dxpl)
Definition H5PropertyList_misc.hpp:499
uint32_t getLocalCause() const
The local cause for a non-collective I/O.
Definition H5PropertyList_misc.hpp:509
Definition H5Object.hpp:54
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:65
PropertyListBase() noexcept
Definition H5PropertyList_misc.hpp:58
HDF5 property Lists.
Definition H5PropertyList.hpp:79
void _initializeIfNeeded()
Definition H5PropertyList_misc.hpp:63
void add(const P &property)
Definition H5PropertyList_misc.hpp:74
void add(const F &funct, const Args &... args)
Definition H5PropertyList_misc.hpp:81
Szip(unsigned options_mask=H5_SZIP_EC_OPTION_MASK, unsigned pixels_per_block=H5_SZIP_MAX_PIXELS_PER_BLOCK)
Definition H5PropertyList_misc.hpp:368
unsigned getPixelsPerBlock() const
Definition H5PropertyList_misc.hpp:376
unsigned getOptionsMask() const
Definition H5PropertyList_misc.hpp:372
bool isCollective() const
Does the property request collective IO?
Definition H5PropertyList_misc.hpp:495
UseCollectiveIO(bool enable=true)
Definition H5PropertyList_misc.hpp:472
Definition H5_definitions.hpp:15
PropertyType
Types of property lists.
Definition H5PropertyList.hpp:28
PropertyList< PropertyType::LINK_CREATE > LinkCreateProps
Definition H5PropertyList.hpp:118
PropertyList< PropertyType::FILE_CREATE > FileCreateProps
Definition H5PropertyList.hpp:106
PropertyList< PropertyType::FILE_ACCESS > FileAccessProps
Definition H5PropertyList.hpp:107