Skip to content

Commit

Permalink
Less intrusive warnings, allow disabling them
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Oct 12, 2023
1 parent 25385a2 commit 23bff34
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,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}
)
Expand Down
17 changes: 15 additions & 2 deletions include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,22 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl

IOMode m_mode = IOMode::Dataset;
SpecificationVia m_IOModeSpecificationVia = SpecificationVia::DefaultValue;
bool m_printedSkippedWriteWarningAlready = false;

std::pair<IOMode, SpecificationVia>
retrieveDatasetMode(openPMD::json::TracingJSON &config) const;
struct DatasetMode
{
IOMode m_IOMode;
SpecificationVia m_specificationVia;
bool m_skipWarnings;

template <typename A, typename B, typename C>
operator std::tuple<A, B, C>()
{
return std::tuple<A, B, C>{
m_IOMode, m_specificationVia, m_skipWarnings};
}
};
DatasetMode retrieveDatasetMode(openPMD::json::TracingJSON &config) const;

///////////////////////
// Attribute IO mode //
Expand Down
52 changes: 37 additions & 15 deletions src/IO/JSON/JSONIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,12 @@ namespace
}
} // namespace

auto JSONIOHandlerImpl::retrieveDatasetMode(openPMD::json::TracingJSON &config)
const -> std::pair<IOMode, SpecificationVia>
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())
{
Expand All @@ -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
{
Expand All @@ -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(
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 23bff34

Please sign in to comment.