Skip to content

Commit 544923b

Browse files
committed
TOML: Use short modes by default
1 parent 23bff34 commit 544923b

4 files changed

Lines changed: 45 additions & 19 deletions

File tree

include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
180180
std::string originalExtension);
181181
#endif
182182

183+
void init(openPMD::json::TracingJSON config);
184+
183185
~JSONIOHandlerImpl() override;
184186

185187
void

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,7 @@ JSONIOHandlerImpl::JSONIOHandlerImpl(
386386
, m_fileFormat{format}
387387
, m_originalExtension{std::move(originalExtension)}
388388
{
389-
std::tie(
390-
m_mode, m_IOModeSpecificationVia, m_printedSkippedWriteWarningAlready) =
391-
retrieveDatasetMode(config);
392-
std::tie(m_attributeMode, m_attributeModeSpecificationVia) =
393-
retrieveAttributeMode(config);
394-
395-
if (auto [_, backendConfig] = getBackendConfig(config);
396-
backendConfig.has_value())
397-
{
398-
(void)_;
399-
warnUnusedJson(backendConfig.value());
400-
}
389+
init(std::move(config));
401390
}
402391

403392
#if openPMD_HAVE_MPI
@@ -412,6 +401,26 @@ JSONIOHandlerImpl::JSONIOHandlerImpl(
412401
, m_fileFormat{format}
413402
, m_originalExtension{std::move(originalExtension)}
414403
{
404+
init(std::move(config));
405+
}
406+
#endif
407+
408+
void JSONIOHandlerImpl::init(openPMD::json::TracingJSON config)
409+
{
410+
// set the defaults
411+
switch (m_fileFormat)
412+
{
413+
case FileFormat::Json:
414+
// @todo take the switch to openPMD 2.0 as a chance to switch to
415+
// short attribute mode as a default here
416+
m_attributeMode = AttributeMode::Long;
417+
m_mode = IOMode::Dataset;
418+
break;
419+
case FileFormat::Toml:
420+
m_attributeMode = AttributeMode::Short;
421+
m_mode = IOMode::Template;
422+
break;
423+
}
415424
std::tie(
416425
m_mode, m_IOModeSpecificationVia, m_printedSkippedWriteWarningAlready) =
417426
retrieveDatasetMode(config);
@@ -425,7 +434,6 @@ JSONIOHandlerImpl::JSONIOHandlerImpl(
425434
warnUnusedJson(backendConfig.value());
426435
}
427436
}
428-
#endif
429437

430438
JSONIOHandlerImpl::~JSONIOHandlerImpl() = default;
431439

test/SerialIOTest.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,12 @@ inline void dtype_test(
12411241
"../samples/dtype_test." + backend,
12421242
Access::CREATE,
12431243
activateTemplateMode.value())
1244-
: Series("../samples/dtype_test." + backend, Access::CREATE);
1244+
:
1245+
// test TOML long attribute mode by default
1246+
Series(
1247+
"../samples/dtype_test." + backend,
1248+
Access::CREATE,
1249+
R"({"toml":{"attribute":{"mode":"long"}}})");
12451250
bool adios1 = s.backend() == "ADIOS1" || s.backend() == "MPI_ADIOS1";
12461251

12471252
char c = 'c';
@@ -1836,7 +1841,8 @@ inline void fileBased_write_test(const std::string &backend)
18361841
{
18371842
Series o = Series(
18381843
"../samples/subdir/serial_fileBased_write%03T." + backend,
1839-
Access::CREATE);
1844+
Access::CREATE,
1845+
R"({"toml":{"dataset":{"mode":"dataset"}}})");
18401846

18411847
ParticleSpecies &e_1 = o.iterations[1].particles["e"];
18421848

@@ -7397,7 +7403,10 @@ void groupbased_read_write(std::string const &ext)
73977403
std::string filename = "../samples/groupbased_read_write." + ext;
73987404

73997405
{
7400-
Series write(filename, Access::CREATE);
7406+
Series write(
7407+
filename,
7408+
Access::CREATE,
7409+
R"({"toml":{"dataset":{"mode":"dataset"}}})");
74017410
auto E_x = write.iterations[0].meshes["E"]["x"];
74027411
auto E_y = write.iterations[0].meshes["E"]["y"];
74037412
E_x.resetDataset(ds);
@@ -7410,7 +7419,10 @@ void groupbased_read_write(std::string const &ext)
74107419
}
74117420

74127421
{
7413-
Series write(filename, Access::READ_WRITE);
7422+
Series write(
7423+
filename,
7424+
Access::READ_WRITE,
7425+
R"({"toml":{"dataset":{"mode":"dataset"}}})");
74147426
// create a new iteration
74157427
auto E_x = write.iterations[1].meshes["E"]["x"];
74167428
E_x.resetDataset(ds);
@@ -7450,7 +7462,10 @@ void groupbased_read_write(std::string const &ext)
74507462

74517463
// check that truncation works correctly
74527464
{
7453-
Series write(filename, Access::CREATE);
7465+
Series write(
7466+
filename,
7467+
Access::CREATE,
7468+
R"({"toml":{"dataset":{"mode":"dataset"}}})");
74547469
// create a new iteration
74557470
auto E_x = write.iterations[2].meshes["E"]["x"];
74567471
E_x.resetDataset(ds);

test/python/unittest/API/APITest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
from TestUtilities.TestUtilities import generateTestFilePath
2626

2727
tested_file_extensions = [
28-
ext for ext in io.file_extensions if ext != 'sst' and ext != 'ssc'
28+
ext for ext in io.file_extensions
29+
if ext != 'sst' and ext != 'ssc' and ext != 'toml'
2930
]
3031

3132

0 commit comments

Comments
 (0)