Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 09:13:30

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