Skip to content

Commit

Permalink
highfive sync
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed Aug 27, 2024
1 parent 5933e40 commit 6fb6a68
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
15 changes: 7 additions & 8 deletions src/diagnostic/detail/h5writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Hierarchy, typename Model>
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}
Expand All @@ -69,8 +68,8 @@ class H5Writer
template<typename Hierarchy, typename Model>
static auto make_unique(Hierarchy& hier, Model& model, initializer::PHAREDict const& dict)
{
std::string filePath = dict["filePath"].template to<std::string>();
unsigned flags = READ_WRITE;
std::string filePath = dict["filePath"].template to<std::string>();
HiFile::AccessMode flags = READ_WRITE;
if (dict.contains("mode") and dict["mode"].template to<std::string>() == "overwrite")
flags |= HiFile::Truncate;
return std::make_unique<This>(hier, model, filePath, flags);
Expand All @@ -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<HighFiveFile>(filePath_ + "/" + filename, file_flag);
}
Expand Down Expand Up @@ -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:
Expand All @@ -179,7 +178,7 @@ class H5Writer
ModelView modelView_;
Attributes fileAttributes_;

std::unordered_map<std::string, unsigned> file_flags;
std::unordered_map<std::string, HiFile::AccessMode> file_flags;

std::unordered_map<std::string, std::shared_ptr<H5TypeWriter<This>>> typeWriters_{
{"info", make_writer<InfoDiagnosticWriter<This>>()},
Expand Down
11 changes: 4 additions & 7 deletions src/hdf5/detail/h5/h5_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace PHARE::hdf5::h5
{
using HiFile = HighFive::File;

using FileOp = HighFive::File::AccessMode;



Expand Down Expand Up @@ -43,7 +43,7 @@ class HighFiveFile
{
public:
template<typename FileAccessProps>
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)
Expand All @@ -61,18 +61,15 @@ 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_)}
{
}

~HighFiveFile() {}

NO_DISCARD HiFile& file()
{
return h5file_;
}
NO_DISCARD HiFile& file() { return h5file_; }


template<typename T, std::size_t dim = 1>
Expand Down
9 changes: 4 additions & 5 deletions tests/diagnostic/test_diagnostics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename GridLayout, typename Field, typename FieldFilter = PHARE::FieldNullFilter>
Expand Down Expand Up @@ -48,7 +47,7 @@ struct Hi5Diagnostic
using Writer_t = H5Writer<ModelView_t>;

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}
Expand Down Expand Up @@ -92,8 +91,8 @@ struct Hi5Diagnostic

Hierarchy& hierarchy_;
HybridModel& model_;
std::string out_;
unsigned flags_;
std::string const out_;
HiFile::AccessMode const flags_;

DiagnosticsManager<Writer_t> dMan;
Writer_t& writer;
Expand Down
3 changes: 2 additions & 1 deletion tests/simulator/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 6fb6a68

Please sign in to comment.