diff --git a/include/picongpu/plugins/openPMD/toml.cpp b/include/picongpu/plugins/openPMD/toml.cpp index b3d387645e..132f6b2ab6 100644 --- a/include/picongpu/plugins/openPMD/toml.cpp +++ b/include/picongpu/plugins/openPMD/toml.cpp @@ -28,6 +28,45 @@ namespace picongpu { namespace toml { + DataSources::DataSources(std::string tomlFiles) : m_period{{100, {std::string("fields_all"), "species_all"}}} + { + // todo: read from toml files + // verify that a step will always be available + m_upcomingSteps[0].reserve(m_period.size()); + for(auto pair : m_period) + { + m_upcomingSteps[0].push_back(pair.first); + } + } + + std::vector DataSources::currentDataSources() const + { + std::set result; + for(SimulationStep_t period : m_upcomingSteps.begin()->second) + { + for(std::string const& source : m_period.at(period)) + { + result.insert(source); + } + } + return {result.begin(), result.end()}; + } + + auto DataSources::currentStep() const -> SimulationStep_t + { + return m_upcomingSteps.begin()->first; + } + + DataSources& DataSources::operator++() + { + SimulationStep_t current = currentStep(); + for(auto period : m_upcomingSteps.begin()->second) + { + m_upcomingSteps[current + period].push_back(period); + } + m_upcomingSteps.erase(m_upcomingSteps.begin()); + return *this; + } } // namespace toml } // namespace picongpu diff --git a/include/picongpu/plugins/openPMD/toml.hpp b/include/picongpu/plugins/openPMD/toml.hpp index e2e27d0281..92d36e7d97 100644 --- a/include/picongpu/plugins/openPMD/toml.hpp +++ b/include/picongpu/plugins/openPMD/toml.hpp @@ -19,8 +19,10 @@ #pragma once +#include #include #include +#include #include namespace picongpu @@ -29,37 +31,27 @@ namespace picongpu { class DataSources { - using Period_t = std::map>; + public: + using SimulationStep_t = uint32_t; + + private: + using Period_t = std::map>; Period_t m_period; /* * For each period p, let s be the upcoming step divisible by p. * Then m_nextActiveAt[s] contains p. */ - std::map> m_nextActiveAt; + std::map> m_upcomingSteps; public: - DataSources(std::string tomlFiles) - { - // todo: read from toml files - } + DataSources(std::string tomlFiles); - std::vector currentDataSources() const - { - // todo - return {std::string("fields_all"), "species_all"}; - } + std::vector currentDataSources() const; - uint32_t currentStep() const - { - return m_period.begin()->first; - } + SimulationStep_t currentStep() const; - DataSources& operator++() - { - // todo - return *this; - } + DataSources& operator++(); }; } // namespace toml } // namespace picongpu