File indexing completed on 2025-04-19 08:55:34
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "h5p_wrapper.hpp"
0012
0013 namespace HighFive {
0014
0015 namespace {
0016 inline hid_t convert_plist_type(PropertyType propertyType) {
0017
0018
0019 switch (propertyType) {
0020 case PropertyType::OBJECT_CREATE:
0021 return H5P_OBJECT_CREATE;
0022 case PropertyType::FILE_CREATE:
0023 return H5P_FILE_CREATE;
0024 case PropertyType::FILE_ACCESS:
0025 return H5P_FILE_ACCESS;
0026 case PropertyType::DATASET_CREATE:
0027 return H5P_DATASET_CREATE;
0028 case PropertyType::DATASET_ACCESS:
0029 return H5P_DATASET_ACCESS;
0030 case PropertyType::DATASET_XFER:
0031 return H5P_DATASET_XFER;
0032 case PropertyType::GROUP_CREATE:
0033 return H5P_GROUP_CREATE;
0034 case PropertyType::GROUP_ACCESS:
0035 return H5P_GROUP_ACCESS;
0036 case PropertyType::DATATYPE_CREATE:
0037 return H5P_DATATYPE_CREATE;
0038 case PropertyType::DATATYPE_ACCESS:
0039 return H5P_DATATYPE_ACCESS;
0040 case PropertyType::STRING_CREATE:
0041 return H5P_STRING_CREATE;
0042 case PropertyType::ATTRIBUTE_CREATE:
0043 return H5P_ATTRIBUTE_CREATE;
0044 case PropertyType::OBJECT_COPY:
0045 return H5P_OBJECT_COPY;
0046 case PropertyType::LINK_CREATE:
0047 return H5P_LINK_CREATE;
0048 case PropertyType::LINK_ACCESS:
0049 return H5P_LINK_ACCESS;
0050 default:
0051 HDF5ErrMapper::ToException<PropertyException>("Unsupported property list type");
0052 }
0053 }
0054
0055 }
0056
0057
0058 inline PropertyListBase::PropertyListBase() noexcept
0059 : Object(H5P_DEFAULT) {}
0060
0061
0062 template <PropertyType T>
0063 inline void PropertyList<T>::_initializeIfNeeded() {
0064 if (_hid != H5P_DEFAULT) {
0065 return;
0066 }
0067 _hid = detail::h5p_create(convert_plist_type(T));
0068 }
0069
0070 template <PropertyType T>
0071 template <PropertyInterface P>
0072 inline void PropertyList<T>::add(const P& property) {
0073 _initializeIfNeeded();
0074 property.apply(_hid);
0075 }
0076
0077 template <PropertyType T>
0078 template <typename F, typename... Args>
0079 inline void RawPropertyList<T>::add(const F& funct, const Args&... args) {
0080 this->_initializeIfNeeded();
0081 if (funct(this->_hid, args...) < 0) {
0082 HDF5ErrMapper::ToException<PropertyException>("Error setting raw hdf5 property.");
0083 }
0084 }
0085
0086
0087 #if H5_VERSION_GE(1, 10, 1)
0088 inline FileSpaceStrategy::FileSpaceStrategy(H5F_fspace_strategy_t strategy,
0089 hbool_t persist,
0090 hsize_t threshold)
0091 : _strategy(strategy)
0092 , _persist(persist)
0093 , _threshold(threshold) {}
0094
0095 inline FileSpaceStrategy::FileSpaceStrategy(const FileCreateProps& fcpl) {
0096 detail::h5p_get_file_space_strategy(fcpl.getId(), &_strategy, &_persist, &_threshold);
0097 }
0098
0099 inline void FileSpaceStrategy::apply(const hid_t list) const {
0100 detail::h5p_set_file_space_strategy(list, _strategy, _persist, _threshold);
0101 }
0102
0103 inline H5F_fspace_strategy_t FileSpaceStrategy::getStrategy() const {
0104 return _strategy;
0105 }
0106
0107 inline hbool_t FileSpaceStrategy::getPersist() const {
0108 return _persist;
0109 }
0110
0111 inline hsize_t FileSpaceStrategy::getThreshold() const {
0112 return _threshold;
0113 }
0114
0115 inline FileSpacePageSize::FileSpacePageSize(hsize_t page_size)
0116 : _page_size(page_size) {}
0117
0118 inline void FileSpacePageSize::apply(const hid_t list) const {
0119 detail::h5p_set_file_space_page_size(list, _page_size);
0120 }
0121
0122 inline FileSpacePageSize::FileSpacePageSize(const FileCreateProps& fcpl) {
0123 detail::h5p_get_file_space_page_size(fcpl.getId(), &_page_size);
0124 }
0125
0126 inline hsize_t FileSpacePageSize::getPageSize() const {
0127 return _page_size;
0128 }
0129
0130 #ifndef H5_HAVE_PARALLEL
0131 inline PageBufferSize::PageBufferSize(size_t page_buffer_size,
0132 unsigned min_meta_percent,
0133 unsigned min_raw_percent)
0134 : _page_buffer_size(page_buffer_size)
0135 , _min_meta(min_meta_percent)
0136 , _min_raw(min_raw_percent) {}
0137
0138 inline PageBufferSize::PageBufferSize(const FileAccessProps& plist) {
0139 detail::h5p_get_page_buffer_size(plist.getId(), &_page_buffer_size, &_min_meta, &_min_raw);
0140 }
0141
0142 inline void PageBufferSize::apply(const hid_t list) const {
0143 detail::h5p_set_page_buffer_size(list, _page_buffer_size, _min_meta, _min_raw);
0144 }
0145
0146 inline size_t PageBufferSize::getPageBufferSize() const {
0147 return _page_buffer_size;
0148 }
0149
0150 inline unsigned PageBufferSize::getMinMetaPercent() const {
0151 return _min_meta;
0152 }
0153
0154 inline unsigned PageBufferSize::getMinRawPercent() const {
0155 return _min_raw;
0156 }
0157 #endif
0158 #endif
0159
0160 #ifdef H5_HAVE_PARALLEL
0161
0162 inline MPIOFileAccess::MPIOFileAccess(MPI_Comm comm, MPI_Info info)
0163 : _comm(comm)
0164 , _info(info) {}
0165
0166 inline void MPIOFileAccess::apply(const hid_t list) const {
0167 detail::h5p_set_fapl_mpio(list, _comm, _info);
0168 }
0169
0170 #if H5_VERSION_GE(1, 10, 0)
0171 inline void MPIOCollectiveMetadata::apply(const hid_t plist) const {
0172 auto read = MPIOCollectiveMetadataRead{collective_read_};
0173 auto write = MPIOCollectiveMetadataWrite{collective_write_};
0174
0175 read.apply(plist);
0176 write.apply(plist);
0177 }
0178
0179 inline MPIOCollectiveMetadata::MPIOCollectiveMetadata(bool collective)
0180 : collective_read_(collective)
0181 , collective_write_(collective) {}
0182
0183
0184 inline MPIOCollectiveMetadata::MPIOCollectiveMetadata(const FileAccessProps& plist)
0185 : collective_read_(MPIOCollectiveMetadataRead(plist).isCollective())
0186 , collective_write_(MPIOCollectiveMetadataWrite(plist).isCollective()) {}
0187
0188 inline bool MPIOCollectiveMetadata::isCollectiveRead() const {
0189 return collective_read_;
0190 }
0191
0192 inline bool MPIOCollectiveMetadata::isCollectiveWrite() const {
0193 return collective_write_;
0194 }
0195
0196
0197 inline void MPIOCollectiveMetadataRead::apply(const hid_t plist) const {
0198 detail::h5p_set_all_coll_metadata_ops(plist, collective_);
0199 }
0200
0201 inline bool MPIOCollectiveMetadataRead::isCollective() const {
0202 return collective_;
0203 }
0204
0205 inline MPIOCollectiveMetadataRead::MPIOCollectiveMetadataRead(const FileAccessProps& plist) {
0206 detail::h5p_get_all_coll_metadata_ops(plist.getId(), &collective_);
0207 }
0208
0209 inline MPIOCollectiveMetadataRead::MPIOCollectiveMetadataRead(bool collective)
0210 : collective_(collective) {}
0211
0212 inline void MPIOCollectiveMetadataWrite::apply(const hid_t plist) const {
0213 detail::h5p_set_coll_metadata_write(plist, collective_);
0214 }
0215
0216 inline bool MPIOCollectiveMetadataWrite::isCollective() const {
0217 return collective_;
0218 }
0219
0220 inline MPIOCollectiveMetadataWrite::MPIOCollectiveMetadataWrite(const FileAccessProps& plist) {
0221 detail::h5p_get_coll_metadata_write(plist.getId(), &collective_);
0222 }
0223
0224 inline MPIOCollectiveMetadataWrite::MPIOCollectiveMetadataWrite(bool collective)
0225 : collective_(collective) {}
0226
0227 #endif
0228 #endif
0229
0230 inline FileVersionBounds::FileVersionBounds(H5F_libver_t low, H5F_libver_t high)
0231 : _low(low)
0232 , _high(high) {}
0233
0234 inline FileVersionBounds::FileVersionBounds(const FileAccessProps& fapl) {
0235 detail::h5p_get_libver_bounds(fapl.getId(), &_low, &_high);
0236 }
0237
0238 inline std::pair<H5F_libver_t, H5F_libver_t> FileVersionBounds::getVersion() const {
0239 return std::make_pair(_low, _high);
0240 }
0241
0242 inline void FileVersionBounds::apply(const hid_t list) const {
0243 detail::h5p_set_libver_bounds(list, _low, _high);
0244 }
0245
0246 inline MetadataBlockSize::MetadataBlockSize(hsize_t size)
0247 : _size(size) {}
0248
0249 inline MetadataBlockSize::MetadataBlockSize(const FileAccessProps& fapl) {
0250 detail::h5p_get_meta_block_size(fapl.getId(), &_size);
0251 }
0252
0253 inline void MetadataBlockSize::apply(const hid_t list) const {
0254 detail::h5p_set_meta_block_size(list, _size);
0255 }
0256
0257 inline hsize_t MetadataBlockSize::getSize() const {
0258 return _size;
0259 }
0260
0261 inline void EstimatedLinkInfo::apply(const hid_t hid) const {
0262 detail::h5p_set_est_link_info(hid, _entries, _length);
0263 }
0264
0265 inline EstimatedLinkInfo::EstimatedLinkInfo(unsigned entries, unsigned length)
0266 : _entries(entries)
0267 , _length(length) {}
0268
0269 inline EstimatedLinkInfo::EstimatedLinkInfo(const GroupCreateProps& gcpl) {
0270 detail::h5p_get_est_link_info(gcpl.getId(), &_entries, &_length);
0271 }
0272
0273 inline unsigned EstimatedLinkInfo::getEntries() const {
0274 return _entries;
0275 }
0276
0277 inline unsigned EstimatedLinkInfo::getNameLength() const {
0278 return _length;
0279 }
0280
0281 inline void Chunking::apply(const hid_t hid) const {
0282 detail::h5p_set_chunk(hid, static_cast<int>(_dims.size()), _dims.data());
0283 }
0284
0285 inline Chunking::Chunking(const std::vector<hsize_t>& dims)
0286 : _dims(dims) {}
0287
0288 inline Chunking::Chunking(const std::initializer_list<hsize_t>& items)
0289 : Chunking(std::vector<hsize_t>{items}) {}
0290
0291 inline Chunking::Chunking(DataSetCreateProps& plist, size_t max_dims)
0292 : _dims(max_dims + 1) {
0293 auto n_loaded =
0294 detail::h5p_get_chunk(plist.getId(), static_cast<int>(_dims.size()), _dims.data());
0295
0296 if (n_loaded >= static_cast<int>(_dims.size())) {
0297 *this = Chunking(plist, 8 * max_dims);
0298 } else {
0299 _dims.resize(static_cast<size_t>(n_loaded));
0300 }
0301 }
0302
0303 inline const std::vector<hsize_t>& Chunking::getDimensions() const noexcept {
0304 return _dims;
0305 }
0306
0307 template <typename... Args>
0308 inline Chunking::Chunking(hsize_t item, Args... args)
0309 : Chunking(std::vector<hsize_t>{item, static_cast<hsize_t>(args)...}) {}
0310
0311 inline void Deflate::apply(const hid_t hid) const {
0312 if (detail::h5z_filter_avail(H5Z_FILTER_DEFLATE) == 0) {
0313 HDF5ErrMapper::ToException<PropertyException>("Deflate filter unavailable.");
0314 }
0315
0316 detail::h5p_set_deflate(hid, _level);
0317 }
0318
0319 inline Deflate::Deflate(unsigned int level)
0320 : _level(level) {}
0321
0322 inline void Szip::apply(const hid_t hid) const {
0323 if (detail::h5z_filter_avail(H5Z_FILTER_SZIP) == 0) {
0324 HDF5ErrMapper::ToException<PropertyException>("SZIP filter unavailable.");
0325 }
0326
0327 detail::h5p_set_szip(hid, _options_mask, _pixels_per_block);
0328 }
0329
0330 inline Szip::Szip(unsigned int options_mask, unsigned int pixels_per_block)
0331 : _options_mask(options_mask)
0332 , _pixels_per_block(pixels_per_block) {}
0333
0334 inline unsigned Szip::getOptionsMask() const {
0335 return _options_mask;
0336 }
0337
0338 inline unsigned Szip::getPixelsPerBlock() const {
0339 return _pixels_per_block;
0340 }
0341
0342 inline void Shuffle::apply(const hid_t hid) const {
0343 if (detail::h5z_filter_avail(H5Z_FILTER_SHUFFLE) == 0) {
0344 HDF5ErrMapper::ToException<PropertyException>("Shuffle filter unavailable.");
0345 }
0346
0347 detail::h5p_set_shuffle(hid);
0348 }
0349
0350 inline AllocationTime::AllocationTime(H5D_alloc_time_t alloc_time)
0351 : _alloc_time(alloc_time) {}
0352
0353 inline AllocationTime::AllocationTime(const DataSetCreateProps& dcpl) {
0354 detail::h5p_get_alloc_time(dcpl.getId(), &_alloc_time);
0355 }
0356
0357 inline void AllocationTime::apply(hid_t dcpl) const {
0358 detail::h5p_set_alloc_time(dcpl, _alloc_time);
0359 }
0360
0361 inline H5D_alloc_time_t AllocationTime::getAllocationTime() {
0362 return _alloc_time;
0363 }
0364
0365 inline Caching::Caching(const DataSetCreateProps& dcpl) {
0366 detail::h5p_get_chunk_cache(dcpl.getId(), &_numSlots, &_cacheSize, &_w0);
0367 }
0368
0369 inline void Caching::apply(const hid_t hid) const {
0370 detail::h5p_set_chunk_cache(hid, _numSlots, _cacheSize, _w0);
0371 }
0372
0373 inline Caching::Caching(const size_t numSlots, const size_t cacheSize, const double w0)
0374 : _numSlots(numSlots)
0375 , _cacheSize(cacheSize)
0376 , _w0(w0) {}
0377
0378 inline size_t Caching::getNumSlots() const {
0379 return _numSlots;
0380 }
0381
0382 inline size_t Caching::getCacheSize() const {
0383 return _cacheSize;
0384 }
0385
0386 inline double Caching::getW0() const {
0387 return _w0;
0388 }
0389
0390 inline CreateIntermediateGroup::CreateIntermediateGroup(bool create)
0391 : _create(create) {}
0392
0393 inline CreateIntermediateGroup::CreateIntermediateGroup(const ObjectCreateProps& ocpl) {
0394 fromPropertyList(ocpl.getId());
0395 }
0396
0397
0398 inline void CreateIntermediateGroup::apply(const hid_t hid) const {
0399 detail::h5p_set_create_intermediate_group(hid, _create ? 1 : 0);
0400 }
0401
0402 inline CreateIntermediateGroup::CreateIntermediateGroup(const LinkCreateProps& lcpl) {
0403 fromPropertyList(lcpl.getId());
0404 }
0405
0406 inline void CreateIntermediateGroup::fromPropertyList(hid_t hid) {
0407 unsigned c_bool = 0;
0408 _create = bool(detail::h5p_get_create_intermediate_group(hid, &c_bool));
0409 }
0410
0411 inline bool CreateIntermediateGroup::isSet() const {
0412 return _create;
0413 }
0414
0415 #ifdef H5_HAVE_PARALLEL
0416 inline UseCollectiveIO::UseCollectiveIO(bool enable)
0417 : _enable(enable) {}
0418
0419 inline void UseCollectiveIO::apply(const hid_t hid) const {
0420 detail::h5p_set_dxpl_mpio(hid, _enable ? H5FD_MPIO_COLLECTIVE : H5FD_MPIO_INDEPENDENT);
0421 }
0422
0423 inline UseCollectiveIO::UseCollectiveIO(const DataTransferProps& dxpl) {
0424 H5FD_mpio_xfer_t collective;
0425
0426 detail::h5p_get_dxpl_mpio(dxpl.getId(), &collective);
0427
0428 if (collective != H5FD_MPIO_COLLECTIVE && collective != H5FD_MPIO_INDEPENDENT) {
0429 throw std::logic_error("H5Pget_dxpl_mpio returned something strange.");
0430 }
0431
0432 _enable = collective == H5FD_MPIO_COLLECTIVE;
0433 }
0434
0435 inline bool UseCollectiveIO::isCollective() const {
0436 return _enable;
0437 }
0438
0439 inline MpioNoCollectiveCause::MpioNoCollectiveCause(const DataTransferProps& dxpl) {
0440 detail::h5p_get_mpio_no_collective_cause(dxpl.getId(), &_local_cause, &_global_cause);
0441 }
0442
0443 inline bool MpioNoCollectiveCause::wasCollective() const {
0444 return _local_cause == 0 && _global_cause == 0;
0445 }
0446
0447 inline uint32_t MpioNoCollectiveCause::getLocalCause() const {
0448 return _local_cause;
0449 }
0450
0451 inline uint32_t MpioNoCollectiveCause::getGlobalCause() const {
0452 return _global_cause;
0453 }
0454
0455 inline std::pair<uint32_t, uint32_t> MpioNoCollectiveCause::getCause() const {
0456 return {_local_cause, _global_cause};
0457 }
0458 #endif
0459
0460 inline LinkCreationOrder::LinkCreationOrder(const FileCreateProps& fcpl) {
0461 fromPropertyList(fcpl.getId());
0462 }
0463
0464 inline LinkCreationOrder::LinkCreationOrder(const GroupCreateProps& gcpl) {
0465 fromPropertyList(gcpl.getId());
0466 }
0467
0468 inline unsigned LinkCreationOrder::getFlags() const {
0469 return _flags;
0470 }
0471
0472 inline void LinkCreationOrder::apply(const hid_t hid) const {
0473 detail::h5p_set_link_creation_order(hid, _flags);
0474 }
0475
0476 inline void LinkCreationOrder::fromPropertyList(hid_t hid) {
0477 detail::h5p_get_link_creation_order(hid, &_flags);
0478 }
0479
0480 inline AttributePhaseChange::AttributePhaseChange(unsigned max_compact, unsigned min_dense)
0481 : _max_compact(max_compact)
0482 , _min_dense(min_dense) {}
0483
0484 inline AttributePhaseChange::AttributePhaseChange(const GroupCreateProps& gcpl) {
0485 detail::h5p_get_attr_phase_change(gcpl.getId(), &_max_compact, &_min_dense);
0486 }
0487
0488 inline unsigned AttributePhaseChange::max_compact() const {
0489 return _max_compact;
0490 }
0491
0492 inline unsigned AttributePhaseChange::min_dense() const {
0493 return _min_dense;
0494 }
0495
0496 inline void AttributePhaseChange::apply(hid_t hid) const {
0497 detail::h5p_set_attr_phase_change(hid, _max_compact, _min_dense);
0498 }
0499
0500
0501 }