Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Attributes | List of all members
Utopia::DataIO::MonitorManager Class Reference

The MonitorManager manages the monitor entries and MonitorTimer. More...

#include <monitor.hh>

Public Member Functions

 MonitorManager (const double emit_interval, const std::string emit_prefix="!!map ", const std::string emit_suffix="")
 Constructor.
 
void emit_if_enabled ()
 Perform an emission of the data to the terminal, if the flag was set.
 
void check_timer ()
 Checks with the timer whether the time to emit has come.
 
bool emit_enabled () const
 Returns true if the emission is enabled.
 
template<typename Value >
void set_entry (const std::string &path, const std::string &key, const Value value)
 Set an entry in the tree of monitor entries.
 
template<typename Time >
void set_time_entries (const Time time, const Time time_max)
 Set time- and progress-related top level entries.
 
Timerget_timer ()
 Get a shared pointer to the MonitorTimer object.
 
auto get_emit_interval ()
 Return the emit interval.
 
auto get_emit_counter ()
 Return the emit interval.
 
YAML::Node & get_entries ()
 Get the reference to the monitor entries object.
 

Private Types

using Timer = std::shared_ptr< MonitorTimer >
 Type of the timer.
 

Private Attributes

Timer _timer
 The monitor timer.
 
YAML::Node _entries
 The monitor entries.
 
bool _emit_enabled
 The flag that determines whether to collect data.
 
std::size_t _emit_counter
 Counts the number of emit operations.
 
const std::string _emit_prefix
 A prefix to the emitted string.
 
const std::string _emit_suffix
 A suffix to the emitted string.
 

Detailed Description

The MonitorManager manages the monitor entries and MonitorTimer.

The manager performs an emission of the stored monitor data if the monitor timer asserts that enough time has passed since the last emit.

Member Typedef Documentation

◆ Timer

Type of the timer.

Constructor & Destructor Documentation

◆ MonitorManager()

Utopia::DataIO::MonitorManager::MonitorManager ( const double  emit_interval,
const std::string  emit_prefix = "!!map ",
const std::string  emit_suffix = "" 
)
inline

Constructor.

Parameters
emit_intervalThe emit interval that specifies after how much time to emit the monitor data.
emit_prefixA prefix to the emitted string, default: "!!map "
emit_suffixA suffix to the emitted string, default: "". Note that std::endl is always appended.
195 :
196 // Create a new MonitorTimer object
197 _timer(std::make_shared< MonitorTimer >(emit_interval)),
198 // Create an empty MonitorEntries object for the data to be emitted
199 _entries(YAML::Node()),
200 // Initialially set the collect data flag to true
201 _emit_enabled(true),
202 _emit_counter(0),
205 {};
Timer _timer
The monitor timer.
Definition monitor.hh:166
std::size_t _emit_counter
Counts the number of emit operations.
Definition monitor.hh:175
const std::string _emit_suffix
A suffix to the emitted string.
Definition monitor.hh:181
const std::string _emit_prefix
A prefix to the emitted string.
Definition monitor.hh:178
YAML::Node _entries
The monitor entries.
Definition monitor.hh:169
bool _emit_enabled
The flag that determines whether to collect data.
Definition monitor.hh:172
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

Member Function Documentation

◆ check_timer()

void Utopia::DataIO::MonitorManager::check_timer ( )
inline

Checks with the timer whether the time to emit has come.

231 {
232 if (_timer->time_has_come())
233 {
234 _emit_enabled = true;
235 }
236 }

◆ emit_enabled()

bool Utopia::DataIO::MonitorManager::emit_enabled ( ) const
inline

Returns true if the emission is enabled.

246 {
247 return _emit_enabled;
248 }

◆ emit_if_enabled()

void Utopia::DataIO::MonitorManager::emit_if_enabled ( )
inline

Perform an emission of the data to the terminal, if the flag was set.

210 {
211 if (not _emit_enabled) return;
212
213 // Calling recursive_setitem may remove the emitter style, requiring
214 // to reset it here each time. This will only set some flags in the
215 // to-be-created YAML::Emitter and has negligible performance impact.
216 _entries.SetStyle(YAML::EmitterStyle::Flow);
217
218 std::cout << _emit_prefix
219 << _entries
220 << _emit_suffix
221 << std::endl;
222
224 _timer->reset();
225 _emit_enabled = false;
226 }

◆ get_emit_counter()

auto Utopia::DataIO::MonitorManager::get_emit_counter ( )
inline

Return the emit interval.

309 {
310 return _emit_counter;
311 }

◆ get_emit_interval()

auto Utopia::DataIO::MonitorManager::get_emit_interval ( )
inline

Return the emit interval.

302 {
303 return _timer->get_emit_interval();
304 }

◆ get_entries()

YAML::Node & Utopia::DataIO::MonitorManager::get_entries ( )
inline

Get the reference to the monitor entries object.

316 {
317 return _entries;
318 }

◆ get_timer()

Timer & Utopia::DataIO::MonitorManager::get_timer ( )
inline

Get a shared pointer to the MonitorTimer object.

295 {
296 return _timer;
297 }

◆ set_entry()

template<typename Value >
void Utopia::DataIO::MonitorManager::set_entry ( const std::string &  path,
const std::string &  key,
const Value  value 
)
inline

Set an entry in the tree of monitor entries.

Sets an element at <path>.<key> to value, creating intermediate nodes within the monitor entries tree.

Template Parameters
ValueThe type of the value that should be monitored
Parameters
pathThe path at which to add the key. This can be used to traverse the entries tree. To separate the path segments, the . character is used.
keyThe key of the new entry. It is suffixed onto the path with the . delimiter in between, becoming the last segment of the path.
valueThe value of the new entry
269 {
271 recursive_setitem(_entries, path + "." + key, value, ".");
272 }
void recursive_setitem(Config &d, std::list< std::string > key_sequence, const T val)
Recursively sets an element in a configuration tree.
Definition cfg_utils.hh:422

◆ set_time_entries()

template<typename Time >
void Utopia::DataIO::MonitorManager::set_time_entries ( const Time  time,
const Time  time_max 
)
inline

Set time- and progress-related top level entries.

Using the given parameters, this method sets the top-level entries 'time' and 'progress'

Template Parameters
TimeThe data type of the time
Parameters
timeThe current time
time_maxThe maximum time of the simulation
285 {
286 _entries["time"] = time;
287
288 // Add the progress indicator and the elapsed time
289 _entries["progress"] = float(time) / float(time_max);
290 }

Member Data Documentation

◆ _emit_counter

std::size_t Utopia::DataIO::MonitorManager::_emit_counter
private

Counts the number of emit operations.

◆ _emit_enabled

bool Utopia::DataIO::MonitorManager::_emit_enabled
private

The flag that determines whether to collect data.

◆ _emit_prefix

const std::string Utopia::DataIO::MonitorManager::_emit_prefix
private

A prefix to the emitted string.

◆ _emit_suffix

const std::string Utopia::DataIO::MonitorManager::_emit_suffix
private

A suffix to the emitted string.

◆ _entries

YAML::Node Utopia::DataIO::MonitorManager::_entries
private

The monitor entries.

◆ _timer

Timer Utopia::DataIO::MonitorManager::_timer
private

The monitor timer.


The documentation for this class was generated from the following file: