Skip to content

Commit

Permalink
Add openPMD 2.0 standard setting
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Nov 21, 2023
1 parent 71aa0e9 commit c7e86d4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 8 deletions.
6 changes: 6 additions & 0 deletions include/openPMD/Error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ namespace error
public:
NoSuchAttribute(std::string attributeName);
};

class IllegalInOpenPMDStandard : public Error
{
public:
IllegalInOpenPMDStandard(std::string what);
};
} // namespace error

/**
Expand Down
20 changes: 18 additions & 2 deletions include/openPMD/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@
* compile-time)
* @{
*/
#define OPENPMD_STANDARD_MAJOR 1
#define OPENPMD_STANDARD_MINOR 1
#define OPENPMD_STANDARD_MAJOR 2
#define OPENPMD_STANDARD_MINOR 0
#define OPENPMD_STANDARD_PATCH 0
/** @} */

/** maximum supported version of the openPMD standard (read & write,
* compile-time)
* @{
*/
#define OPENPMD_STANDARD_DEFAULT_MAJOR 1
#define OPENPMD_STANDARD_DEFAULT_MINOR 1
#define OPENPMD_STANDARD_DEFAULT_PATCH 0
/** @} */

/** minimum supported version of the openPMD standard (read, compile-time)
* @{
*/
Expand Down Expand Up @@ -79,6 +88,13 @@ std::string getVersion();
*/
std::string getStandard();

/** Return the default used version of the openPMD standard (read & write,
* run-time)
*
* @return std::string openPMD standard version (dot separated)
*/
std::string getStandardDefault();

/** Return the minimum supported version of the openPMD standard (read,
* run-time)
*
Expand Down
6 changes: 6 additions & 0 deletions src/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ namespace error
, description(std::move(description_in))
{}

IllegalInOpenPMDStandard::IllegalInOpenPMDStandard(std::string what_in)
: Error(
"Operation leads to illegal use of the openPMD standard:\n" +
std::move(what_in))
{}

void throwReadError(
AffectedObject affectedObject,
Reason reason,
Expand Down
13 changes: 8 additions & 5 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ std::string Series::basePath() const
Series &Series::setBasePath(std::string const &bp)
{
std::string version = openPMD();
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0")
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" ||
version == "2.0.0")
throw std::runtime_error(
"Custom basePath not allowed in openPMD <=1.1.0");
"Custom basePath not allowed in openPMD <=2.0");

setAttribute("basePath", bp);
return *this;
Expand Down Expand Up @@ -684,7 +685,7 @@ void Series::initDefaults(IterationEncoding ie, bool initAll)
}
}
if (!containsAttribute("openPMD"))
setOpenPMD(getStandard());
setOpenPMD(getStandardDefault());
/*
* In Append mode, only init the rest of the defaults after checking that
* the file does not yet exist to avoid overriding more than needed.
Expand Down Expand Up @@ -1274,7 +1275,8 @@ void Series::readOneIterationFileBased(std::string const &filePath)

Parameter<Operation::OPEN_PATH> pOpen;
std::string version = openPMD();
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0")
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" ||
version == "2.0.0")
pOpen.path = auxiliary::replace_first(basePath(), "/%T/", "");
else
throw error::ReadError(
Expand Down Expand Up @@ -1427,7 +1429,8 @@ creating new iterations.

Parameter<Operation::OPEN_PATH> pOpen;
std::string version = openPMD();
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0")
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" ||
version == "2.0.0")
pOpen.path = auxiliary::replace_first(basePath(), "/%T/", "");
else
throw error::ReadError(
Expand Down
3 changes: 3 additions & 0 deletions src/binding/python/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "openPMD/Error.hpp"

#include "openPMD/binding/python/Common.hpp"
#include <pybind11/pybind11.h>

void init_Error(py::module &m)
{
Expand All @@ -22,6 +23,8 @@ void init_Error(py::module &m)
py::register_exception<error::Internal>(m, "ErrorInternal", baseError);
py::register_exception<error::NoSuchAttribute>(
m, "ErrorNoSuchAttribute", baseError);
py::register_exception<error::IllegalInOpenPMDStandard>(
m, "ErrorIllegalInOpenPMDStandard", baseError);

#ifndef NDEBUG
m.def("test_throw", [](std::string description) {
Expand Down
10 changes: 10 additions & 0 deletions src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ std::string openPMD::getStandard()
return standard.str();
}

std::string openPMD::getStandardDefault()
{
std::stringstream standard;
standard << OPENPMD_STANDARD_DEFAULT_MAJOR << "."
<< OPENPMD_STANDARD_DEFAULT_MINOR << "."
<< OPENPMD_STANDARD_DEFAULT_PATCH;
std::string const standardstr = standard.str();
return standardstr;
}

std::string openPMD::getStandardMinimum()
{
std::stringstream standardMin;
Expand Down
5 changes: 4 additions & 1 deletion test/CoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ TEST_CASE("versions_test", "[core]")
auto const is_dot = [](char const c) { return c == '.'; };
REQUIRE(2u == std::count_if(apiVersion.begin(), apiVersion.end(), is_dot));

auto const standardDefault = getStandardDefault();
REQUIRE(standardDefault == "1.1.0");

auto const standard = getStandard();
REQUIRE(standard == "1.1.0");
REQUIRE(standard == "2.0.0");

auto const standardMin = getStandardMinimum();
REQUIRE(standardMin == "1.0.0");
Expand Down
1 change: 1 addition & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,7 @@ inline void constant_scalar(std::string const &file_ending)
// constant scalar
Series s =
Series("../samples/constant_scalar." + file_ending, Access::CREATE);
s.setOpenPMD("2.0.0");
auto rho = s.iterations[1].meshes["rho"][MeshRecordComponent::SCALAR];
REQUIRE(s.iterations[1].meshes["rho"].scalar());
rho.resetDataset(Dataset(Datatype::CHAR, {1, 2, 3}));
Expand Down

0 comments on commit c7e86d4

Please sign in to comment.