Skip to content

Commit

Permalink
Logging, fix waiting for late files
Browse files Browse the repository at this point in the history
Also make WAITING_TIME a constant
  • Loading branch information
franzpoeschel committed Aug 16, 2021
1 parent 80b337e commit db3d8bb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
13 changes: 13 additions & 0 deletions include/picongpu/plugins/openPMD/openPMDWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
#include <algorithm>
#include <cstdint>
#include <cstdlib> // getenv
#include <iostream>
#include <list>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -1318,4 +1319,16 @@ Please pick either of the following:
}

} // namespace openPMD

namespace toml
{
void writeLog(char const* message, size_t argsc, char const** argsv)
{
auto logg = log<picLog::INPUT_OUTPUT>(message);
for(size_t i = 0; i < argsc; ++i)
{
logg = logg % argsv[i];
}
}
} // namespace toml
} // namespace picongpu
32 changes: 30 additions & 2 deletions include/picongpu/plugins/openPMD/toml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# include "picongpu/plugins/misc/splitString.hpp"

# include <chrono>
# include <sstream>
# include <thread> // std::this_thread::sleep_for
# include <utility> // std::forward

Expand Down Expand Up @@ -142,6 +143,26 @@ namespace
template<typename ChronoDuration>
Period_t waitForParseAndMergeTomlFiles(std::vector<std::string> paths, ChronoDuration&& sleepInterval)
{
auto formatVectorOfStrings = [](std::vector<std::string> const& paths) -> std::string {
if(paths.empty())
{
return "[]";
}
std::stringstream res;
res << "[";
for(size_t i = 0; i < paths.size() - 1; ++i)
{
res << paths[i] << ", ";
}
res << *paths.rbegin() << "]";
return res.str();
};
{
auto pathsFormatted = formatVectorOfStrings(paths);
char const*(argsv[]) = {pathsFormatted.c_str()};
picongpu::toml::writeLog("openPMD: Reading data requirements from TOML files:\n\t%1%", 1, argsv);
}

Period_t res;
std::vector<decltype(paths)::iterator> toRemove;
toRemove.reserve(paths.size());
Expand All @@ -153,8 +174,8 @@ namespace
if(file_exists(path))
{
mergePeriodTable(res, parseSingleTomlFile(path));
toRemove.push_back(it);
}
toRemove.push_back(it);
}
// std::vector<>::erase
// "Invalidates iterators and references at or after the point of the erase, including the end() iterator."
Expand All @@ -169,6 +190,11 @@ namespace
{
break;
}
{
auto pathsFormatted = formatVectorOfStrings(paths);
char const*(argsv[]) = {pathsFormatted.c_str()};
picongpu::toml::writeLog("openPMD: Still waiting for TOML files:\n\t%1%", 1, argsv);
}
std::this_thread::sleep_for(sleepInterval);
}
return res;
Expand All @@ -190,7 +216,9 @@ namespace picongpu
namespace toml
{
using namespace std::literals::chrono_literals;
DataSources::DataSources(std::string const& tomlFiles) : m_period{waitForParseAndMergeTomlFiles(tomlFiles, 5s)}
constexpr std::chrono::seconds const WAIT_TIME = 5s;

DataSources::DataSources(std::string const& tomlFiles) : m_period{waitForParseAndMergeTomlFiles(tomlFiles, WAIT_TIME)}
{
// todo: read from toml files
// verify that a step will always be available
Expand Down
4 changes: 4 additions & 0 deletions include/picongpu/plugins/openPMD/toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ namespace picongpu

DataSources& operator++();
};

// Definition of this needs to go in NVCC-compiled files
// (openPMDWriter.hpp) due to include structure of PIConGPU
void writeLog(char const* message, size_t argsn, char const** argsv);
} // namespace toml
} // namespace picongpu

0 comments on commit db3d8bb

Please sign in to comment.