diff --git a/include/picongpu/plugins/openPMD/openPMDWriter.hpp b/include/picongpu/plugins/openPMD/openPMDWriter.hpp index 4e70403733..2971dac100 100644 --- a/include/picongpu/plugins/openPMD/openPMDWriter.hpp +++ b/include/picongpu/plugins/openPMD/openPMDWriter.hpp @@ -399,13 +399,10 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1. fileExtension = help.fileNameExtension.get(id); fileInfix = help.fileNameInfix.get(id); /* if file name is relative, prepend with common directory */ - fileName = boost::filesystem::path(file).has_root_path() ? file : dir + "/" + file; - + fileName = file; // avoid deadlock between not finished pmacc tasks and mpi blocking collectives __getTransactionEvent().waitForFinished(); - log("openPMD: setting file pattern: %1%%2%.%3%") % fileName % fileInfix - % fileExtension; strategyString = help.dataPreparationStrategy.get(id); jsonString = help.jsonConfig.get(id); @@ -413,6 +410,10 @@ make sure that environment variable OPENPMD_BP_BACKEND is not set to ADIOS1. } } + fileName = boost::filesystem::path(file).has_root_path() ? fileName : dir + "/" + fileName; + log("openPMD: setting file pattern: %1%%2%.%3%") % fileName % fileInfix + % fileExtension; + /* * Enforce group-based iteration layout for streaming backends */ diff --git a/include/picongpu/plugins/openPMD/toml.cpp b/include/picongpu/plugins/openPMD/toml.cpp index 660d6d4f6a..09f164ef77 100644 --- a/include/picongpu/plugins/openPMD/toml.cpp +++ b/include/picongpu/plugins/openPMD/toml.cpp @@ -133,7 +133,35 @@ namespace return res; } - Period_t parseTomlFile(std::string const& content, std::string const& file = "unknown file") + void parsePluginOptions(picongpu::toml::PluginOptions & options, toml::value tomlConfig) + { + auto parseOption = [&tomlConfig](std::string& target, std::string const& key) { + if(not tomlConfig.contains(key)) + { + return; // leave the default option + } + try + { + target = toml::find(tomlConfig, key); + } + catch(toml::type_error const& e) + { + throw std::runtime_error( + "[openPMD plugin] Global key '" + key + "' must point to a value of string type."); + } + }; + + parseOption( options.fileName, "file" ); + parseOption( options.fileInfix, "infix" ); + parseOption( options.fileExtension, "ext" ); + parseOption( options.jsonConfig, "backend_config" ); + parseOption( options.dataPreparationStrategy, "data_preparation_strategy" ); + } + + void parseTomlFile( + picongpu::toml::DataSources& dataSources, + std::string const& content, + std::string const& file = "unknown file") { auto data = [&content, &file]() { std::istringstream istream(content.c_str()); @@ -141,9 +169,8 @@ namespace }(); if(not data.contains("sink")) { - return {}; + return; } - Period_t res; auto& sinkTable = [&data]() -> toml::value::table_type const& { try { @@ -175,13 +202,17 @@ namespace "[openPMD plugin] Key 'period' in TOML file must be a table (" + std::string(e.what()) + ")"); } }(); - mergePeriodTable(res, parseSinglePeriodTable(periodTable)); + mergePeriodTable(dataSources.m_period, parseSinglePeriodTable(periodTable)); } - return res; + parsePluginOptions( dataSources.openPMDPluginOptions, data ); } template - Period_t waitForParseAndMergeTomlFiles(std::string const path, ChronoDuration&& sleepInterval, MPI_Comm comm) + void waitForParseAndMergeTomlFiles( + picongpu::toml::DataSources& dataSources, + std::string const path, + ChronoDuration&& sleepInterval, + MPI_Comm comm) { int rank; MPI_Comm_rank(comm, &rank); @@ -206,7 +237,7 @@ namespace picongpu::toml::writeLog("openPMD: Reading TOML file collectively"); std::string fileContents = picongpu::collective_file_read(path, comm); - return parseTomlFile(fileContents, path); + parseTomlFile(dataSources, fileContents, path); } } // namespace @@ -219,8 +250,8 @@ namespace picongpu constexpr std::chrono::seconds const WAIT_TIME = 5s; DataSources::DataSources(std::string const& tomlFile, MPI_Comm comm) - : m_period{waitForParseAndMergeTomlFiles(tomlFile, WAIT_TIME, comm)} { + waitForParseAndMergeTomlFiles(*this, tomlFile, WAIT_TIME, comm); // todo: read from toml files // verify that a step will always be available m_upcomingSteps[0].reserve(m_period.size()); diff --git a/include/picongpu/plugins/openPMD/toml.hpp b/include/picongpu/plugins/openPMD/toml.hpp index b5b7deea7b..e58f1476fa 100644 --- a/include/picongpu/plugins/openPMD/toml.hpp +++ b/include/picongpu/plugins/openPMD/toml.hpp @@ -54,8 +54,6 @@ namespace picongpu using Period_t = std::map>; private: - Period_t m_period; - /* * For each period p, let s be the upcoming step divisible by p. * Then m_nextActiveAt[s] contains p. @@ -63,6 +61,8 @@ namespace picongpu std::map> m_upcomingSteps; public: + Period_t m_period; + PluginOptions openPMDPluginOptions; // @todo read these from TOML DataSources(std::string const& tomlFile, MPI_Comm);