Skip to content

Commit

Permalink
TOML: Use short modes by default
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Oct 12, 2023
1 parent 23bff34 commit 544923b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
2 changes: 2 additions & 0 deletions include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
std::string originalExtension);
#endif

void init(openPMD::json::TracingJSON config);

~JSONIOHandlerImpl() override;

void
Expand Down
34 changes: 21 additions & 13 deletions src/IO/JSON/JSONIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -425,7 +434,6 @@ JSONIOHandlerImpl::JSONIOHandlerImpl(
warnUnusedJson(backendConfig.value());
}
}
#endif

JSONIOHandlerImpl::~JSONIOHandlerImpl() = default;

Expand Down
25 changes: 20 additions & 5 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,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';
Expand Down Expand Up @@ -1836,7 +1841,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"];

Expand Down Expand Up @@ -7397,7 +7403,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);
Expand All @@ -7410,7 +7419,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);
Expand Down Expand Up @@ -7450,7 +7462,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);
Expand Down
3 changes: 2 additions & 1 deletion test/python/unittest/API/APITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]


Expand Down

0 comments on commit 544923b

Please sign in to comment.