diff --git a/CMakeLists.txt b/CMakeLists.txt index 85836010f6..eabf3a6918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1376,7 +1376,7 @@ if(openPMD_BUILD_TESTING) --outfile ../samples/git-sample/thetaMode/data%T.json \ --outconfig ' \ json.attribute.mode = \"short\" \n\ - json.dataset.mode = \"template\"' \ + json.dataset.mode = \"template_no_warn\"' \ " WORKING_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY} ) diff --git a/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp b/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp index ba7a3d719d..7fe1d6438e 100644 --- a/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp +++ b/include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp @@ -292,9 +292,22 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl IOMode m_mode = IOMode::Dataset; SpecificationVia m_IOModeSpecificationVia = SpecificationVia::DefaultValue; + bool m_printedSkippedWriteWarningAlready = false; - std::pair - retrieveDatasetMode(openPMD::json::TracingJSON &config) const; + struct DatasetMode + { + IOMode m_IOMode; + SpecificationVia m_specificationVia; + bool m_skipWarnings; + + template + operator std::tuple() + { + return std::tuple{ + m_IOMode, m_specificationVia, m_skipWarnings}; + } + }; + DatasetMode retrieveDatasetMode(openPMD::json::TracingJSON &config) const; /////////////////////// // Attribute IO mode // diff --git a/src/IO/JSON/JSONIOHandlerImpl.cpp b/src/IO/JSON/JSONIOHandlerImpl.cpp index 3b9152355a..e5db1ef2c6 100644 --- a/src/IO/JSON/JSONIOHandlerImpl.cpp +++ b/src/IO/JSON/JSONIOHandlerImpl.cpp @@ -248,11 +248,12 @@ namespace } } // namespace -auto JSONIOHandlerImpl::retrieveDatasetMode(openPMD::json::TracingJSON &config) - const -> std::pair +auto JSONIOHandlerImpl::retrieveDatasetMode( + openPMD::json::TracingJSON &config) const -> DatasetMode { - IOMode res = m_mode; - SpecificationVia res_2 = SpecificationVia::DefaultValue; + IOMode ioMode = m_mode; + SpecificationVia specificationVia = SpecificationVia::DefaultValue; + bool skipWarnings = false; if (auto [configLocation, maybeConfig] = getBackendConfig(config); maybeConfig.has_value()) { @@ -274,13 +275,19 @@ auto JSONIOHandlerImpl::retrieveDatasetMode(openPMD::json::TracingJSON &config) auto mode = modeOption.value(); if (mode == "dataset") { - res = IOMode::Dataset; - res_2 = SpecificationVia::Manually; + ioMode = IOMode::Dataset; + specificationVia = SpecificationVia::Manually; } else if (mode == "template") { - res = IOMode::Template; - res_2 = SpecificationVia::Manually; + ioMode = IOMode::Template; + specificationVia = SpecificationVia::Manually; + } + else if (mode == "template_no_warn") + { + ioMode = IOMode::Template; + specificationVia = SpecificationVia::Manually; + skipWarnings = true; } else { @@ -292,7 +299,7 @@ auto JSONIOHandlerImpl::retrieveDatasetMode(openPMD::json::TracingJSON &config) } } } - return std::make_pair(res, res_2); + return DatasetMode{ioMode, specificationVia, skipWarnings}; } auto JSONIOHandlerImpl::retrieveAttributeMode( @@ -379,7 +386,9 @@ JSONIOHandlerImpl::JSONIOHandlerImpl( , m_fileFormat{format} , m_originalExtension{std::move(originalExtension)} { - std::tie(m_mode, m_IOModeSpecificationVia) = retrieveDatasetMode(config); + std::tie( + m_mode, m_IOModeSpecificationVia, m_printedSkippedWriteWarningAlready) = + retrieveDatasetMode(config); std::tie(m_attributeMode, m_attributeModeSpecificationVia) = retrieveAttributeMode(config); @@ -403,7 +412,9 @@ JSONIOHandlerImpl::JSONIOHandlerImpl( , m_fileFormat{format} , m_originalExtension{std::move(originalExtension)} { - std::tie(m_mode, m_IOModeSpecificationVia) = retrieveDatasetMode(config); + std::tie( + m_mode, m_IOModeSpecificationVia, m_printedSkippedWriteWarningAlready) = + retrieveDatasetMode(config); std::tie(m_attributeMode, m_attributeModeSpecificationVia) = retrieveAttributeMode(config); @@ -548,7 +559,13 @@ void JSONIOHandlerImpl::createDataset( parameter.options, /* considerFiles = */ false); // Retrieves mode from dataset-specific configuration, falls back to global // value if not defined - IOMode localMode = retrieveDatasetMode(config).first; + auto [localMode, _, skipWarnings] = retrieveDatasetMode(config); + (void)_; + // No use in introducing logic to skip warnings only for one particular + // dataset. If warnings are skipped, then they are skipped consistently. + // Use |= since `false` is the default value and we don't wish to reset + // the flag. + m_printedSkippedWriteWarningAlready |= skipWarnings; parameter.warnUnusedParameters( config, @@ -1183,9 +1200,14 @@ void JSONIOHandlerImpl::writeDataset( case IOMode::Dataset: break; case IOMode::Template: - std::cerr << "[JSON/TOML backend: Warning] Trying to write data to a " - "template dataset. Will skip." - << std::endl; + if (!m_printedSkippedWriteWarningAlready) + { + std::cerr + << "[JSON/TOML backend: Warning] Trying to write data to a " + "template dataset. Will skip." + << std::endl; + m_printedSkippedWriteWarningAlready = true; + } return; }