Skip to content

Commit bdda98b

Browse files
committed
Use more reliable logic for specifying overridable dataset config
Copied from HDF5 backend
1 parent c2e0e83 commit bdda98b

2 files changed

Lines changed: 65 additions & 13 deletions

File tree

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,12 @@ class ADIOS2IOHandlerImpl
270270
adios2::Params params;
271271
};
272272

273-
std::vector<ParameterizedOperator> defaultOperators;
273+
// read operators can (currently) not be specified per dataset, so parse
274+
// them once and then buffer them
275+
std::vector<ParameterizedOperator> readOperators;
274276

275277
json::TracingJSON m_config;
278+
std::optional<nlohmann::json> m_buffered_dataset_config;
276279
static json::TracingJSON nullvalue;
277280

278281
template <typename Callback>

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ void ADIOS2IOHandlerImpl::init(
208208
groupTableViaEnv == 0 ? UseGroupTable::No : UseGroupTable::Yes;
209209
}
210210

211+
{
212+
constexpr char const *const init_json_shadow_str = R"(
213+
{
214+
"adios2": {
215+
"dataset": {
216+
"operators": null
217+
}
218+
}
219+
})";
220+
auto init_json_shadow = nlohmann::json::parse(init_json_shadow_str);
221+
json::merge(cfg.getShadow(), init_json_shadow);
222+
}
223+
211224
if (cfg.json().contains("adios2"))
212225
{
213226
m_config = cfg["adios2"];
@@ -266,7 +279,7 @@ void ADIOS2IOHandlerImpl::init(
266279
auto operators = getOperators();
267280
if (operators)
268281
{
269-
defaultOperators = std::move(operators.value());
282+
readOperators = std::move(operators.value());
270283
}
271284
}
272285
#if !openPMD_HAS_ADIOS_2_9
@@ -753,23 +766,59 @@ void ADIOS2IOHandlerImpl::createDataset(
753766
filePos->gd = GroupOrDataset::DATASET;
754767
auto const varName = nameOfVariable(writable);
755768

769+
json::TracingJSON config = [&]() {
770+
if (!m_buffered_dataset_config.has_value())
771+
{
772+
// we are only interested in these values from the global config
773+
constexpr char const *const mask_for_global_conf = R"(
774+
{
775+
"dataset": {
776+
"operators": null,
777+
"shape": null
778+
}
779+
})";
780+
m_buffered_dataset_config = m_config.json();
781+
json::filterByTemplate(
782+
*m_buffered_dataset_config,
783+
nlohmann::json::parse(mask_for_global_conf));
784+
}
785+
auto parsed_config = json::parseOptions(
786+
parameters.options, /* considerFiles = */ false);
787+
if (auto adios2_config_it = parsed_config.config.find("adios2");
788+
adios2_config_it != parsed_config.config.end())
789+
{
790+
adios2_config_it.value() = json::merge(
791+
*m_buffered_dataset_config, adios2_config_it.value());
792+
}
793+
else
794+
{
795+
parsed_config.config["adios2"] = *m_buffered_dataset_config;
796+
}
797+
return parsed_config;
798+
}();
799+
756800
std::vector<ParameterizedOperator> operators;
757-
json::TracingJSON options =
758-
json::parseOptions(parameters.options, /* considerFiles = */ false);
759-
if (options.json().contains("adios2"))
801+
if (config.json().contains("adios2"))
760802
{
761-
json::TracingJSON datasetConfig(options["adios2"]);
803+
json::TracingJSON datasetConfig(config["adios2"]);
762804
auto datasetOperators = getOperators(datasetConfig);
763-
764-
operators = datasetOperators ? std::move(datasetOperators.value())
765-
: defaultOperators;
805+
if (datasetOperators.has_value())
806+
{
807+
operators = std::move(*datasetOperators);
808+
}
766809
}
767-
else
810+
811+
#if 0
812+
std::cout << "Operations for '" << varName << "':";
813+
for(auto const & op: operators)
768814
{
769-
operators = defaultOperators;
815+
std::cout << " '" << op.op.Type() << "'";
770816
}
817+
std::cout << std::endl;
818+
#endif
819+
771820
parameters.warnUnusedParameters(
772-
options,
821+
config,
773822
"adios2",
774823
"Warning: parts of the backend configuration for ADIOS2 dataset '" +
775824
varName + "' remain unused:\n");
@@ -1936,7 +1985,7 @@ namespace detail
19361985
}
19371986

19381987
// Operators in reading needed e.g. for setting decompression threads
1939-
for (auto const &operation : impl->defaultOperators)
1988+
for (auto const &operation : impl->readOperators)
19401989
{
19411990
if (operation.op)
19421991
{

0 commit comments

Comments
 (0)