Class csv_sink

Inheritance Relationships

Base Types

Derived Types

Class Documentation

class csv_sink : public rcppsw::metrics::file_sink, public rcppsw::er::client<csv_sink>

Metrics sink so that collectors can output their metrics to a .csv file. Metrics are written out in .csv format at whatever frequency derived classes choose.

Subclassed by rcppsw::ds::metrics::grid2D_metrics_csv_sink< TCellOp >, rcppsw::ds::metrics::grid3D_metrics_csv_sink< TCellOp >

Public Functions

csv_sink(fs::path fpath, const rmetrics::output_mode &mode, const rtypes::timestep &interval)
Parameters:
  • fpath – Full path to output file, sans the .csv extension.

  • mode – The output mode. See output_mode for possible values.

virtual ~csv_sink(void) = default
virtual void finalize(void) override

Finalize metrics and flush files in preparation for program exit.

virtual write_status flush(const rmetrics::base_data *data, const rtypes::timestep &t) override

Flush gathered metrics data to file; might do nothing if the internal conditions for writing metrics (e.g., the configured interval) are not met.

virtual void initialize(const rmetrics::base_data *data) override

Initialize any required files for the metrics sink (i.e., .csv headers).

Protected Functions

template<class T, class U>
inline std::string csv_entry_domavg(const T &sum, const U &count, bool last = false) const

Return a string of the average value of a sum of SOMETHING divided by a COUNT + separator (if the csv entry is not the last one in a line). If the count is 0, then “0” + separator (if the csv entry is not the last one in a line) is returned.

Parameters:
  • sum – The sum of SOMETHING.

  • count – The divisor for the SOMETHING.

  • last – Is this the last column in the .csv row?

template<class T>
inline std::string csv_entry_intavg(const T &sum, bool last = false) const

Return a string of the average value of a sum of SOMETHING over an interval (using the value of interval()) + separator() (if the csv entry is not the last one in a line).

Parameters:
  • sum – The sum of SOMETHING.

  • last – Is this the last column in the .csv row?

template<class T>
inline std::string csv_entry_tsavg(const T &sum, const rtypes::timestep &t, bool last = false) const

Return a string of the average value of a sum of SOMETHING over the elapsed simulation time so far (using the value of timestep()) + separator() (if the csv entry is not the last one in a line).

Parameters:
  • sum – The count of SOMETHING.

  • last – Is this the last column in the .csv row?

virtual std::list<std::string> csv_header_cols(const rmetrics::base_data *data) const = 0

Return a list of additional columns that should be in the emitted .csv file for the sink.

Returns:

a list of the names of the columns for the .csv.

void csv_header_write(const rmetrics::base_data *data)

Construct and write out the .csv header.

virtual boost::optional<std::string> csv_line_build(const rmetrics::base_data *data, const rtypes::timestep &t) = 0

Build the next line of metrics.

Returns:

The line that should be added to the .csv file, or empty if the necessary conditions are not met. This allows metrics to be gathered across multiple timesteps, but only written out once an interesting event has occurred.

inline std::list<std::string> dflt_csv_header_cols(void) const

Return a list of default columns that should be include in (almost) all emitted .csv files for the sink.

Returns:

A list of the names of the default header columns for the .csv, which is: [clock].

inline const std::string &separator(void) const

Return the separator used to separate .csv entries from each other.

Protected Attributes

const std::string mc_separator = {";"}