15#include "../H5Utility.hpp"
26 unsigned res_open = 0;
28 res_open |= H5F_ACC_RDONLY;
30 res_open |= H5F_ACC_RDWR;
32 res_open |= H5F_ACC_CREAT;
34 res_open |= H5F_ACC_TRUNC;
36 res_open |= H5F_ACC_EXCL;
37#if H5_VERSION_GE(1, 10, 0)
39 res_open |= H5F_ACC_SWMR_READ | H5F_ACC_RDONLY;
41 res_open |= H5F_ACC_SWMR_WRITE | H5F_ACC_RDWR;
44 throw FileException(
"Your HDF5 library is too old for SWMR mode, you need at least 1.10");
60 unsigned openFlags = convert_open_flag(access_mode);
62 unsigned createMode = openFlags & (H5F_ACC_TRUNC | H5F_ACC_EXCL);
63 unsigned openMode = openFlags & (H5F_ACC_RDWR | H5F_ACC_RDONLY);
64#if H5_VERSION_GE(1, 10, 0)
65 openMode |= openFlags & (H5F_ACC_SWMR_READ | H5F_ACC_SWMR_WRITE);
67 bool mustCreate = createMode > 0;
68 bool openOrCreate = (openFlags & H5F_ACC_CREAT) > 0;
74 std::unique_ptr<SilenceHDF5> silencer;
76 silencer = std::make_unique<SilenceHDF5>();
79 _hid = detail::nothrow::h5f_open(filename.c_str(), openMode, fileAccessProps.
getId());
87 createMode = H5F_ACC_EXCL;
89 HDF5ErrMapper::ToException<FileException>(
90 std::string(
"Unable to open file " + filename));
94 auto fcpl = fileCreateProps.
getId();
95 auto fapl = fileAccessProps.
getId();
96 _hid = detail::h5f_create(filename.c_str(), createMode, fcpl, fapl);
100 if (_filename.empty()) {
101 _filename = details::get_name([
this](
char* buffer,
size_t length) {
102 return detail::h5f_get_name(
getId(), buffer, length);
116 return fileVer.getVersion();
119#if H5_VERSION_GE(1, 10, 1)
120inline H5F_fspace_strategy_t File::getFileSpaceStrategy()
const {
122 FileSpaceStrategy spaceStrategy(fcpl);
123 return spaceStrategy.getStrategy();
126inline hsize_t File::getFileSpacePageSize()
const {
129 if (getFileSpaceStrategy() != H5F_FSPACE_STRATEGY_PAGE) {
130 HDF5ErrMapper::ToException<FileException>(
131 std::string(
"Cannot obtain page size as paged allocation is not used."));
134 return FileSpacePageSize(fcpl).getPageSize();
139 detail::h5f_flush(
_hid, H5F_SCOPE_GLOBAL);
142#if H5_VERSION_GE(1, 10, 0)
143inline void File::startSWMRWrite() {
144 detail::h5f_start_swmr_write(
_hid);
149 hsize_t sizeValue = 0;
150 detail::h5f_get_filesize(
_hid, &sizeValue);
151 return static_cast<size_t>(sizeValue);
155 return static_cast<size_t>(detail::h5f_get_freespace(
_hid));
File class.
Definition H5File.hpp:25
FileCreateProps getCreatePropertyList() const
Get the list of properties for creation of this file.
Definition H5File.hpp:137
size_t getFileSize() const
Get the size of this file in bytes.
Definition H5File_misc.hpp:148
static constexpr AccessMode Truncate
Definition H5File.hpp:55
static constexpr AccessMode Create
Definition H5File.hpp:58
std::pair< H5F_libver_t, H5F_libver_t > getVersionBounds() const
Returns the HDF5 version compatibility bounds.
Definition H5File_misc.hpp:113
void flush()
flush
Definition H5File_misc.hpp:138
static constexpr AccessMode ReadOnly
Definition H5File.hpp:53
size_t getFreeSpace() const
Get the amount of tracked, unused space in bytes.
Definition H5File_misc.hpp:154
AccessMode
Definition H5File.hpp:29
static constexpr AccessMode WriteSWMR
Definition H5File.hpp:62
FileAccessProps getAccessPropertyList() const
Get the list of properties for accession of this file.
Definition H5File.hpp:142
hsize_t getMetadataBlockSize() const
Returns the block size for metadata in bytes.
Definition H5File_misc.hpp:108
static constexpr AccessMode Excl
Definition H5File.hpp:56
const std::string & getName() const
Return the name of the file.
Definition H5File_misc.hpp:99
static constexpr AccessMode ReadWrite
Definition H5File.hpp:54
static constexpr AccessMode ReadSWMR
Definition H5File.hpp:61
Configure the version bounds for the file.
Definition H5PropertyList.hpp:317
hid_t getId() const noexcept
getId
Definition H5Object_misc.hpp:75
bool isValid() const noexcept
isValid
Definition H5Object_misc.hpp:71
hid_t _hid
Definition H5Object.hpp:98
HDF5 property Lists.
Definition H5PropertyList.hpp:138
Definition assert_compatible_spaces.hpp:15
bool any(File::AccessMode mode)
Definition H5File.hpp:203