The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::SimulationInfo Class Reference

Contains information describing the simulation instance for the purpose of identifying the simulation and possible recreating it. This information should be written to all log files, reports, cmdline, etc. More...

#include <SimulationInfo.hpp>

Public Member Functions

 ~SimulationInfo ()=default
 Destruction.
 
 SimulationInfo ()
 Default Constructor.
 
 SimulationInfo (const SimulationInfo &rhp)
 Copy-constructor.
 
 SimulationInfo (SimulationInfo &&)=delete
 Not move-constructable.
 
SimulationInfooperator= (const SimulationInfo &rhp)
 Assignable.
 
 SimulationInfo (const std::string &_sim_name, const std::string &_command_line, const std::string &_working_dir, const std::string &_executable, const std::string &_simulator_version, const std::string &_reproduction_info, const std::vector< std::string > &_other)
 SimulationInfo constructor.
 
 SimulationInfo (const std::string &_sim_name, int argc, char **argv, const std::string &_simulator_version, const std::string &_reproduction_info, const std::vector< std::string > &_other)
 SimulationInfo constructor with automatic command-line reconstruction.
 
 SimulationInfo (std::ifstream &json_fin, std::map< std::string, std::string > *json_kvpairs=nullptr)
 Instantiate a SimulationInfo object from a json, json_reduced, json_detail, or js_json report file.
 
std::string getSpartaVersion () const
 Get the SPARTA version string for this SimulationInfo object. Most of the time, this will be SimulationInfo::sparta_version (const / global).
 
void setCommandLine (int argc, char **argv)
 Assign command_line_ and executable_ from args.
 
void setCommandLine (const std::string &cmdline)
 Assign command line from string.
 
void addOtherInfo (const std::string &_other)
 Add other information to the simulation.
 
template<typename StreamType = std::ostream>
void write (StreamType &o, const std::string &line_start="# ", const std::string &line_end="\n", bool show_field_names=true) const
 Write this information to an ostream.
 
template<typename ... Args>
std::string stringize (const Args &...args) const
 Generate a string using the write function without needing to construct a temporary stringstream.
 
template<typename ... Args>
std::vector< std::string > stringizeToLines (const Args &...args) const
 Generate a vector of lines.
 
std::vector< std::pair< std::string, std::string > > getHeaderPairs () const
 Gets (name, value) pairs for each header entry.
 
void postSim ()
 Called once after simulation in saveReports()
 

Static Public Member Functions

static SimulationInfogetInstance ()
 Gets the SimulationInfo singleton instance.
 

Public Attributes

const std::string & sim_name
 Simulator application name. Note that multiple simulators could exist in the same process space, so this should be the application containing those simulations. If there is only one simulation, this should usually match the simulation name.
 
const std::string & command_line
 Simulator application instance command-line.
 
const std::string & working_dir
 Simulator application instance working dir.
 
const std::string & executable
 Executable being run.
 
const std::string & simulator_version
 Simulator Version of the simulator itself.
 
const std::string & reproduction_info
 versions/buildnums/tags of simulator and dependencies necessary for reproducing the build from a version control system
 
const std::string & start_time
 Time at which the simulation started (roughly)
 
const std::vector< std::string > & other
 other simulator information
 

Static Public Attributes

static const char sparta_version []
 The version of SPARTA.
 

Detailed Description

Contains information describing the simulation instance for the purpose of identifying the simulation and possible recreating it. This information should be written to all log files, reports, cmdline, etc.

Note
Since this is just useful information and does not change the function of a simulator, it does not protect itself from run-time changes.

Definition at line 105 of file SimulationInfo.hpp.

Constructor & Destructor Documentation

◆ SimulationInfo() [1/5]

sparta::SimulationInfo::SimulationInfo ( )
inline

Default Constructor.

Definition at line 186 of file SimulationInfo.hpp.

◆ SimulationInfo() [2/5]

sparta::SimulationInfo::SimulationInfo ( const SimulationInfo & rhp)
inline

Copy-constructor.

Definition at line 201 of file SimulationInfo.hpp.

◆ SimulationInfo() [3/5]

sparta::SimulationInfo::SimulationInfo ( const std::string & _sim_name,
const std::string & _command_line,
const std::string & _working_dir,
const std::string & _executable,
const std::string & _simulator_version,
const std::string & _reproduction_info,
const std::vector< std::string > & _other )
inline

SimulationInfo constructor.

Definition at line 237 of file SimulationInfo.hpp.

◆ SimulationInfo() [4/5]

sparta::SimulationInfo::SimulationInfo ( const std::string & _sim_name,
int argc,
char ** argv,
const std::string & _simulator_version,
const std::string & _reproduction_info,
const std::vector< std::string > & _other )
inline

SimulationInfo constructor with automatic command-line reconstruction.

Note
Automatically determine working directory using getcwd. Consider this when deciding where to call this method.

Definition at line 261 of file SimulationInfo.hpp.

Here is the call graph for this function:

◆ SimulationInfo() [5/5]

sparta::SimulationInfo::SimulationInfo ( std::ifstream & json_fin,
std::map< std::string, std::string > * json_kvpairs = nullptr )

Instantiate a SimulationInfo object from a json, json_reduced, json_detail, or js_json report file.

Parameters
json_finInput file stream for the JSON report file
json_kvpairsOptional output argument to get all the name-value pairs of SimulationInfo properties found in the file.

Member Function Documentation

◆ addOtherInfo()

void sparta::SimulationInfo::addOtherInfo ( const std::string & _other)
inline

Add other information to the simulation.

Definition at line 345 of file SimulationInfo.hpp.

◆ getHeaderPairs()

std::vector< std::pair< std::string, std::string > > sparta::SimulationInfo::getHeaderPairs ( ) const
inline

Gets (name, value) pairs for each header entry.

Definition at line 407 of file SimulationInfo.hpp.

Here is the call graph for this function:

◆ getInstance()

static SimulationInfo & sparta::SimulationInfo::getInstance ( )
inlinestatic

Gets the SimulationInfo singleton instance.

Definition at line 174 of file SimulationInfo.hpp.

◆ getSpartaVersion()

std::string sparta::SimulationInfo::getSpartaVersion ( ) const
inline

Get the SPARTA version string for this SimulationInfo object. Most of the time, this will be SimulationInfo::sparta_version (const / global).

Definition at line 302 of file SimulationInfo.hpp.

◆ operator=()

SimulationInfo & sparta::SimulationInfo::operator= ( const SimulationInfo & rhp)
inline

Assignable.

Definition at line 221 of file SimulationInfo.hpp.

◆ postSim()

void sparta::SimulationInfo::postSim ( )
inline

Called once after simulation in saveReports()

Definition at line 430 of file SimulationInfo.hpp.

Here is the call graph for this function:

◆ setCommandLine() [1/2]

void sparta::SimulationInfo::setCommandLine ( const std::string & cmdline)
inline

Assign command line from string.

Definition at line 338 of file SimulationInfo.hpp.

◆ setCommandLine() [2/2]

void sparta::SimulationInfo::setCommandLine ( int argc,
char ** argv )
inline

Assign command_line_ and executable_ from args.

Todo
Re-escape quotes or remove need for quotes by escaping everything

Definition at line 313 of file SimulationInfo.hpp.

◆ stringize()

template<typename ... Args>
std::string sparta::SimulationInfo::stringize ( const Args &... args) const
inline

Generate a string using the write function without needing to construct a temporary stringstream.

Definition at line 385 of file SimulationInfo.hpp.

Here is the call graph for this function:

◆ stringizeToLines()

template<typename ... Args>
std::vector< std::string > sparta::SimulationInfo::stringizeToLines ( const Args &... args) const
inline

Generate a vector of lines.

Note
line_end is ignored
Warning
This is too expensive to call in the critical path \warnign The output of this function may be subject to change

Definition at line 398 of file SimulationInfo.hpp.

Here is the call graph for this function:

◆ write()

template<typename StreamType = std::ostream>
void sparta::SimulationInfo::write ( StreamType & o,
const std::string & line_start = "# ",
const std::string & line_end = "\n",
bool show_field_names = true ) const
inline

Write this information to an ostream.

Parameters
line_startString to write at the start of each line (per field)
line_endString to write at the end of each line (per field). This is typically "\n", but can be anything.
show_field_namesShow the names of each field before printing the values

Definition at line 358 of file SimulationInfo.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ command_line

const std::string& sparta::SimulationInfo::command_line

Simulator application instance command-line.

Definition at line 132 of file SimulationInfo.hpp.

◆ executable

const std::string& sparta::SimulationInfo::executable

Executable being run.

Definition at line 142 of file SimulationInfo.hpp.

◆ other

const std::vector<std::string>& sparta::SimulationInfo::other

other simulator information

Definition at line 169 of file SimulationInfo.hpp.

◆ reproduction_info

const std::string& sparta::SimulationInfo::reproduction_info

versions/buildnums/tags of simulator and dependencies necessary for reproducing the build from a version control system

Definition at line 159 of file SimulationInfo.hpp.

◆ sim_name

const std::string& sparta::SimulationInfo::sim_name

Simulator application name. Note that multiple simulators could exist in the same process space, so this should be the application containing those simulations. If there is only one simulation, this should usually match the simulation name.

Definition at line 127 of file SimulationInfo.hpp.

◆ simulator_version

const std::string& sparta::SimulationInfo::simulator_version

Simulator Version of the simulator itself.

Definition at line 147 of file SimulationInfo.hpp.

◆ sparta_version

const char sparta::SimulationInfo::sparta_version[]
static

The version of SPARTA.

Definition at line 152 of file SimulationInfo.hpp.

◆ start_time

const std::string& sparta::SimulationInfo::start_time

Time at which the simulation started (roughly)

Definition at line 164 of file SimulationInfo.hpp.

◆ working_dir

const std::string& sparta::SimulationInfo::working_dir

Simulator application instance working dir.

Definition at line 137 of file SimulationInfo.hpp.


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