From 54a1907035f531558e5402eef40e0da081acfa3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Thu, 12 Oct 2023 11:29:09 +0200 Subject: [PATCH] TOML: Use short modes by default --- include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp | 2 ++ src/IO/JSON/JSONIOHandlerImpl.cpp | 34 ++++++++++++------- test/SerialIOTest.cpp | 25 +++++++++++--- test/python/unittest/API/APITest.py | 3 +- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp b/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp index 7fe1d6438e..e114d5da45 100644 --- a/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp +++ b/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp @@ -180,6 +180,8 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl std::string originalExtension); #endif + void init(openPMD::json::TracingJSON config); + ~JSONIOHandlerImpl() override; void diff --git a/src/IO/JSON/JSONIOHandlerImpl.cpp b/src/IO/JSON/JSONIOHandlerImpl.cpp index e5db1ef2c6..0ed7616860 100644 --- a/src/IO/JSON/JSONIOHandlerImpl.cpp +++ b/src/IO/JSON/JSONIOHandlerImpl.cpp @@ -386,18 +386,7 @@ JSONIOHandlerImpl::JSONIOHandlerImpl( , m_fileFormat{format} , m_originalExtension{std::move(originalExtension)} { - std::tie( - m_mode, m_IOModeSpecificationVia, m_printedSkippedWriteWarningAlready) = - retrieveDatasetMode(config); - std::tie(m_attributeMode, m_attributeModeSpecificationVia) = - retrieveAttributeMode(config); - - if (auto [_, backendConfig] = getBackendConfig(config); - backendConfig.has_value()) - { - (void)_; - warnUnusedJson(backendConfig.value()); - } + init(std::move(config)); } #if openPMD_HAVE_MPI @@ -412,6 +401,26 @@ JSONIOHandlerImpl::JSONIOHandlerImpl( , m_fileFormat{format} , m_originalExtension{std::move(originalExtension)} { + init(std::move(config)); +} +#endif + +void JSONIOHandlerImpl::init(openPMD::json::TracingJSON config) +{ + // set the defaults + switch (m_fileFormat) + { + case FileFormat::Json: + // @todo take the switch to openPMD 2.0 as a chance to switch to + // short attribute mode as a default here + m_attributeMode = AttributeMode::Long; + m_mode = IOMode::Dataset; + break; + case FileFormat::Toml: + m_attributeMode = AttributeMode::Short; + m_mode = IOMode::Template; + break; + } std::tie( m_mode, m_IOModeSpecificationVia, m_printedSkippedWriteWarningAlready) = retrieveDatasetMode(config); @@ -425,7 +434,6 @@ JSONIOHandlerImpl::JSONIOHandlerImpl( warnUnusedJson(backendConfig.value()); } } -#endif JSONIOHandlerImpl::~JSONIOHandlerImpl() = default; diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index f87d5c05d7..e21bc8a3fa 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -1285,7 +1285,12 @@ inline void dtype_test( "../samples/dtype_test." + backend, Access::CREATE, activateTemplateMode.value()) - : Series("../samples/dtype_test." + backend, Access::CREATE); + : + // test TOML long attribute mode by default + Series( + "../samples/dtype_test." + backend, + Access::CREATE, + R"({"toml":{"attribute":{"mode":"long"}}})"); bool adios1 = s.backend() == "ADIOS1" || s.backend() == "MPI_ADIOS1"; char c = 'c'; @@ -1880,7 +1885,8 @@ inline void fileBased_write_test(const std::string &backend) { Series o = Series( "../samples/subdir/serial_fileBased_write%03T." + backend, - Access::CREATE); + Access::CREATE, + R"({"toml":{"dataset":{"mode":"dataset"}}})"); ParticleSpecies &e_1 = o.iterations[1].particles["e"]; @@ -7441,7 +7447,10 @@ void groupbased_read_write(std::string const &ext) std::string filename = "../samples/groupbased_read_write." + ext; { - Series write(filename, Access::CREATE); + Series write( + filename, + Access::CREATE, + R"({"toml":{"dataset":{"mode":"dataset"}}})"); auto E_x = write.iterations[0].meshes["E"]["x"]; auto E_y = write.iterations[0].meshes["E"]["y"]; E_x.resetDataset(ds); @@ -7454,7 +7463,10 @@ void groupbased_read_write(std::string const &ext) } { - Series write(filename, Access::READ_WRITE); + Series write( + filename, + Access::READ_WRITE, + R"({"toml":{"dataset":{"mode":"dataset"}}})"); // create a new iteration auto E_x = write.iterations[1].meshes["E"]["x"]; E_x.resetDataset(ds); @@ -7494,7 +7506,10 @@ void groupbased_read_write(std::string const &ext) // check that truncation works correctly { - Series write(filename, Access::CREATE); + Series write( + filename, + Access::CREATE, + R"({"toml":{"dataset":{"mode":"dataset"}}})"); // create a new iteration auto E_x = write.iterations[2].meshes["E"]["x"]; E_x.resetDataset(ds); diff --git a/test/python/unittest/API/APITest.py b/test/python/unittest/API/APITest.py index a510098c8d..5068bd08d8 100644 --- a/test/python/unittest/API/APITest.py +++ b/test/python/unittest/API/APITest.py @@ -25,7 +25,8 @@ from TestUtilities.TestUtilities import generateTestFilePath tested_file_extensions = [ - ext for ext in io.file_extensions if ext != 'sst' and ext != 'ssc' + ext for ext in io.file_extensions + if ext != 'sst' and ext != 'ssc' and ext != 'toml' ]