Skip to content

Commit c7e86d4

Browse files
committed
Add openPMD 2.0 standard setting
1 parent 71aa0e9 commit c7e86d4

File tree

8 files changed

+56
-8
lines changed

8 files changed

+56
-8
lines changed

include/openPMD/Error.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ namespace error
109109
public:
110110
NoSuchAttribute(std::string attributeName);
111111
};
112+
113+
class IllegalInOpenPMDStandard : public Error
114+
{
115+
public:
116+
IllegalInOpenPMDStandard(std::string what);
117+
};
112118
} // namespace error
113119

114120
/**

include/openPMD/version.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@
3737
* compile-time)
3838
* @{
3939
*/
40-
#define OPENPMD_STANDARD_MAJOR 1
41-
#define OPENPMD_STANDARD_MINOR 1
40+
#define OPENPMD_STANDARD_MAJOR 2
41+
#define OPENPMD_STANDARD_MINOR 0
4242
#define OPENPMD_STANDARD_PATCH 0
4343
/** @} */
4444

45+
/** maximum supported version of the openPMD standard (read & write,
46+
* compile-time)
47+
* @{
48+
*/
49+
#define OPENPMD_STANDARD_DEFAULT_MAJOR 1
50+
#define OPENPMD_STANDARD_DEFAULT_MINOR 1
51+
#define OPENPMD_STANDARD_DEFAULT_PATCH 0
52+
/** @} */
53+
4554
/** minimum supported version of the openPMD standard (read, compile-time)
4655
* @{
4756
*/
@@ -79,6 +88,13 @@ std::string getVersion();
7988
*/
8089
std::string getStandard();
8190

91+
/** Return the default used version of the openPMD standard (read & write,
92+
* run-time)
93+
*
94+
* @return std::string openPMD standard version (dot separated)
95+
*/
96+
std::string getStandardDefault();
97+
8298
/** Return the minimum supported version of the openPMD standard (read,
8399
* run-time)
84100
*

src/Error.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ namespace error
122122
, description(std::move(description_in))
123123
{}
124124

125+
IllegalInOpenPMDStandard::IllegalInOpenPMDStandard(std::string what_in)
126+
: Error(
127+
"Operation leads to illegal use of the openPMD standard:\n" +
128+
std::move(what_in))
129+
{}
130+
125131
void throwReadError(
126132
AffectedObject affectedObject,
127133
Reason reason,

src/Series.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ std::string Series::basePath() const
147147
Series &Series::setBasePath(std::string const &bp)
148148
{
149149
std::string version = openPMD();
150-
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0")
150+
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" ||
151+
version == "2.0.0")
151152
throw std::runtime_error(
152-
"Custom basePath not allowed in openPMD <=1.1.0");
153+
"Custom basePath not allowed in openPMD <=2.0");
153154

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

12751276
Parameter<Operation::OPEN_PATH> pOpen;
12761277
std::string version = openPMD();
1277-
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0")
1278+
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" ||
1279+
version == "2.0.0")
12781280
pOpen.path = auxiliary::replace_first(basePath(), "/%T/", "");
12791281
else
12801282
throw error::ReadError(
@@ -1427,7 +1429,8 @@ creating new iterations.
14271429

14281430
Parameter<Operation::OPEN_PATH> pOpen;
14291431
std::string version = openPMD();
1430-
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0")
1432+
if (version == "1.0.0" || version == "1.0.1" || version == "1.1.0" ||
1433+
version == "2.0.0")
14311434
pOpen.path = auxiliary::replace_first(basePath(), "/%T/", "");
14321435
else
14331436
throw error::ReadError(

src/binding/python/Error.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "openPMD/Error.hpp"
1010

1111
#include "openPMD/binding/python/Common.hpp"
12+
#include <pybind11/pybind11.h>
1213

1314
void init_Error(py::module &m)
1415
{
@@ -22,6 +23,8 @@ void init_Error(py::module &m)
2223
py::register_exception<error::Internal>(m, "ErrorInternal", baseError);
2324
py::register_exception<error::NoSuchAttribute>(
2425
m, "ErrorNoSuchAttribute", baseError);
26+
py::register_exception<error::IllegalInOpenPMDStandard>(
27+
m, "ErrorIllegalInOpenPMDStandard", baseError);
2528

2629
#ifndef NDEBUG
2730
m.def("test_throw", [](std::string description) {

src/version.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ std::string openPMD::getStandard()
4141
return standard.str();
4242
}
4343

44+
std::string openPMD::getStandardDefault()
45+
{
46+
std::stringstream standard;
47+
standard << OPENPMD_STANDARD_DEFAULT_MAJOR << "."
48+
<< OPENPMD_STANDARD_DEFAULT_MINOR << "."
49+
<< OPENPMD_STANDARD_DEFAULT_PATCH;
50+
std::string const standardstr = standard.str();
51+
return standardstr;
52+
}
53+
4454
std::string openPMD::getStandardMinimum()
4555
{
4656
std::stringstream standardMin;

test/CoreTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ TEST_CASE("versions_test", "[core]")
3333
auto const is_dot = [](char const c) { return c == '.'; };
3434
REQUIRE(2u == std::count_if(apiVersion.begin(), apiVersion.end(), is_dot));
3535

36+
auto const standardDefault = getStandardDefault();
37+
REQUIRE(standardDefault == "1.1.0");
38+
3639
auto const standard = getStandard();
37-
REQUIRE(standard == "1.1.0");
40+
REQUIRE(standard == "2.0.0");
3841

3942
auto const standardMin = getStandardMinimum();
4043
REQUIRE(standardMin == "1.0.0");

test/SerialIOTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,7 @@ inline void constant_scalar(std::string const &file_ending)
920920
// constant scalar
921921
Series s =
922922
Series("../samples/constant_scalar." + file_ending, Access::CREATE);
923+
s.setOpenPMD("2.0.0");
923924
auto rho = s.iterations[1].meshes["rho"][MeshRecordComponent::SCALAR];
924925
REQUIRE(s.iterations[1].meshes["rho"].scalar());
925926
rho.resetDataset(Dataset(Datatype::CHAR, {1, 2, 3}));

0 commit comments

Comments
 (0)