From 6fb6a680ea943ede19809e9997fd5c8b702e444d Mon Sep 17 00:00:00 2001 From: deegan Date: Tue, 27 Aug 2024 12:04:48 +0200 Subject: [PATCH] highfive sync --- src/diagnostic/detail/h5writer.hpp | 15 +++++++-------- src/hdf5/detail/h5/h5_file.hpp | 11 ++++------- tests/diagnostic/test_diagnostics.hpp | 9 ++++----- tests/simulator/test_diagnostics.py | 3 ++- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/diagnostic/detail/h5writer.hpp b/src/diagnostic/detail/h5writer.hpp index 5c5aa4590..378c8e901 100644 --- a/src/diagnostic/detail/h5writer.hpp +++ b/src/diagnostic/detail/h5writer.hpp @@ -50,14 +50,13 @@ class H5Writer static constexpr auto dimension = GridLayout::dimension; static constexpr auto interpOrder = GridLayout::interp_order; - static constexpr auto READ_WRITE = HiFile::ReadWrite | HiFile::Create; + static constexpr auto READ_WRITE = HiFile::AccessMode::OpenOrCreate; // flush_never: disables manual file closing, but still occurrs via RAII static constexpr std::size_t flush_never = 0; template - H5Writer(Hierarchy& hier, Model& model, std::string const hifivePath, - unsigned _flags /* = HiFile::ReadWrite | HiFile::Create | HiFile::Truncate */) + H5Writer(Hierarchy& hier, Model& model, std::string const hifivePath, HiFile::AccessMode _flags) : flags{_flags} , filePath_{hifivePath} , modelView_{hier, model} @@ -69,8 +68,8 @@ class H5Writer template static auto make_unique(Hierarchy& hier, Model& model, initializer::PHAREDict const& dict) { - std::string filePath = dict["filePath"].template to(); - unsigned flags = READ_WRITE; + std::string filePath = dict["filePath"].template to(); + HiFile::AccessMode flags = READ_WRITE; if (dict.contains("mode") and dict["mode"].template to() == "overwrite") flags |= HiFile::Truncate; return std::make_unique(hier, model, filePath, flags); @@ -95,7 +94,7 @@ class H5Writer return fileStr + ".h5"; } - auto makeFile(std::string const filename, unsigned file_flag) + auto makeFile(std::string const filename, HiFile::AccessMode const file_flag) { return std::make_unique(filePath_ + "/" + filename, file_flag); } @@ -169,7 +168,7 @@ class H5Writer auto& modelView() { return modelView_; } std::size_t minLevel = 0, maxLevel = 10; // TODO hard-coded to be parametrized somehow - unsigned flags; + HiFile::AccessMode flags; private: @@ -179,7 +178,7 @@ class H5Writer ModelView modelView_; Attributes fileAttributes_; - std::unordered_map file_flags; + std::unordered_map file_flags; std::unordered_map>> typeWriters_{ {"info", make_writer>()}, diff --git a/src/hdf5/detail/h5/h5_file.hpp b/src/hdf5/detail/h5/h5_file.hpp index 4f92645ff..dd4e12735 100644 --- a/src/hdf5/detail/h5/h5_file.hpp +++ b/src/hdf5/detail/h5/h5_file.hpp @@ -13,7 +13,7 @@ namespace PHARE::hdf5::h5 { using HiFile = HighFive::File; - +using FileOp = HighFive::File::AccessMode; @@ -43,7 +43,7 @@ class HighFiveFile { public: template - static auto createHighFiveFile(std::string const path, unsigned flags, bool para, + static auto createHighFiveFile(std::string const path, FileOp flags, bool para, FileAccessProps& fapl) { if (para) @@ -61,7 +61,7 @@ class HighFiveFile return HiFile{path, flags, fapl}; } - HighFiveFile(std::string const path, unsigned flags = HiFile::ReadWrite, bool para = true) + HighFiveFile(std::string const path, FileOp flags = HiFile::ReadWrite, bool para = true) : fapl_{} , h5file_{createHighFiveFile(path, flags, para, fapl_)} { @@ -69,10 +69,7 @@ class HighFiveFile ~HighFiveFile() {} - NO_DISCARD HiFile& file() - { - return h5file_; - } + NO_DISCARD HiFile& file() { return h5file_; } template diff --git a/tests/diagnostic/test_diagnostics.hpp b/tests/diagnostic/test_diagnostics.hpp index bb16242da..f397148a8 100644 --- a/tests/diagnostic/test_diagnostics.hpp +++ b/tests/diagnostic/test_diagnostics.hpp @@ -16,8 +16,7 @@ using namespace PHARE; using namespace PHARE::diagnostic; using namespace PHARE::diagnostic::h5; -constexpr unsigned NEW_HI5_FILE - = HighFive::File::ReadWrite | HighFive::File::Create | HighFive::File::Truncate; +constexpr auto NEW_HI5_FILE = HighFive::File::AccessMode::Overwrite; template @@ -48,7 +47,7 @@ struct Hi5Diagnostic using Writer_t = H5Writer; Hi5Diagnostic(Hierarchy& hierarchy, HybridModel& hybridModel, std::string out, - unsigned flags = NEW_HI5_FILE) + auto const flags = NEW_HI5_FILE) : hierarchy_{hierarchy} , model_{hybridModel} , out_{out} @@ -92,8 +91,8 @@ struct Hi5Diagnostic Hierarchy& hierarchy_; HybridModel& model_; - std::string out_; - unsigned flags_; + std::string const out_; + HiFile::AccessMode const flags_; DiagnosticsManager dMan; Writer_t& writer; diff --git a/tests/simulator/test_diagnostics.py b/tests/simulator/test_diagnostics.py index 4814dc474..4763dd882 100644 --- a/tests/simulator/test_diagnostics.py +++ b/tests/simulator/test_diagnostics.py @@ -206,7 +206,8 @@ def _test_dump_diags(self, dim, **simInput): h5_version = h5_file["py_attrs"].attrs["highfive_version"].split(".") self.assertTrue(len(h5_version) == 3) - self.assertTrue(all(i.isdigit() for i in h5_version)) + # semver patch version may contain "-beta" so ignore + self.assertTrue(all(i.isdigit() for i in h5_version[:2])) self.assertTrue( ph.simulation.deserialize(