34 #include <boost/property_tree/xml_parser.hpp> 44 ControlHelper::ControlHelper()
45 : m_config(), m_name(), m_output_prefix(), m_run_clock(
"run"), m_stride_logger(nullptr), m_use_install_dirs()
67 auto log = [](
const string& s) ->
void { cerr << s << endl; };
69 throw runtime_error(
"ControlHelper::CheckEnv> Install dirs not OK.");
87 if (
m_name ==
"TestController") {
96 const auto logLevel =
m_config.get<
string>(
"run.stride_log_level");
107 spdlog::drop(
"stride_logger");
124 m_stride_logger->info(
"Max number OpenMP threads in this environment: {}",
127 m_config.get<
unsigned int>(
"run.num_threads"));
132 write_xml(ss,
m_config, xml_writer_make_settings<ptree::key_type>(
' ', 8));
133 const auto s = ss.str();
134 stringstream spretty;
135 std::regex_replace(std::ostreambuf_iterator<char>(spretty), s.begin(), s.end(), std::regex(
"(\\n+)"),
"\n");
143 const auto cli_v = make_shared<viewers::CliViewer>(runner,
m_stride_logger);
147 if (
m_config.get<
bool>(
"run.output_cases",
false)) {
149 const auto v = make_shared<viewers::InfectedFileViewer>(runner,
m_output_prefix);
154 if (
m_config.get<
bool>(
"run.output_persons",
false)) {
156 const auto v = make_shared<viewers::PersonsFileViewer>(runner,
m_output_prefix);
161 if (
m_config.get<
bool>(
"run.output_summary",
false)) {
163 const auto v = make_shared<viewers::SummaryFileViewer>(runner,
m_output_prefix);
static unsigned int NumberAvailableThreads()
Return number of threads (in case of OpenMP).
static filesys::path GetDataDir()
/// Return data dir (only relevant when use_install_dirs mode is active)
void Update(sim_event::Id id)
Let viewer perform update.
void RegisterViewers(std::shared_ptr< SimRunner > runner)
Register the viewers of the SimRunner.
static filesys::path GetCurrentDir()
Get path to the current directory.
Stopwatch & Start()
Starts stopwatch if it was stopped.
static filesys::path GetExecPath()
Get path of the executable.
Observer for SimEvents for commandline interface usage.
void Update(sim_event::Id id)
Let viewer perform update.
~ControlHelper()
Simple destructor.
boost::property_tree::ptree m_config
Main configuration for run and sim.
std::string m_output_prefix
Prefix to output (name prefix or prefix dir)
void CheckEnv()
Check install environment.
Utilities for the project.
string ToString(Id l)
Converts a LogMode value to corresponding name.
bool m_use_install_dirs
Working dir or install dir mode.
std::shared_ptr< spdlog::logger > m_stride_logger
General logger.
Stopwatch & Stop()
Stops the stopwatch if it was running.
static std::string GitRevision()
Return git revision string.
void LogStartup()
Logs info on setup for cli environment to stride_logger.
Observer for Persons output.
ControlHelper()
Empty controller: used as target for delegation.
Observer for Persons output.
void Update(sim_event::Id id)
Let viewer perform update.
static bool CreateDirectory(std::string s)
Create a directory relative to the current directory with the given path, returns if it was succesful...
static std::shared_ptr< spdlog::logger > CreateCliLogger(const std::string &logger_name, const std::string &file_name)
Return a (not-yet-registered) commandline and file logger, without registering it.
Provides wall-clock time stamp using the time call.
std::string ToString() const
Returns string representation of readout.
static filesys::path GetConfigDir()
Return config dir (only relevant when use_install_dirs mode is active)
static filesys::path GetRootDir()
Return install root dir (only relevant when use_install_dirs mode is active)
static bool CheckInstallEnv(std::function< void(const std::string &)> logger=std::function< void(const std::string &)>())
Verify that current dir is root dir and all install dirs are present.
Logging (spdlog) utilities.
util::Stopwatch m_run_clock
Stopwatch for timing the computation.
static filesys::path BuildPath(const std::string &output_prefix, const std::string &filename)
Interpret prefix (directory or filename prefix) and return appropriate path.
std::string m_name
Contoller's name.
void Shutdown()
Logs info on setup for cli environment to stride_logger.
static unsigned int ProcessorCount()
Return processor count for system.
Observer for Infected output.
Header file for the core Population class.
static std::shared_ptr< spdlog::logger > CreateFileLogger(const std::string &logger_name, const std::string &file_name)
Return a (not-yet-registered) file logger, without registering it.
static constexpr bool HaveOpenMP()
True if OpenMP in executable, false otherwise.
static bool IsDirectoryString(const std::string &s)
String represents a directory path (relative or absolute) iff it contains at least one / (may be a tr...
Interface for install directory queries.
Namespace for the simulator and related classes.
void Update(sim_event::Id id)
Let viewer perform update.
void InstallLogger()
Make the appropriate logger for cli environment and register as stride_logger.
Header for the command line controller.
Header for the SimRunner class.