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 ()
 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 (const simdb::ObjectManager &sim_db, const simdb::DatabaseID obj_mgr_db_id, const simdb::DatabaseID report_node_id=0)
 Recreate a SimulationInfo object from the provided SimInfo record with the given ObjMgrID.
 
 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). But there are some SimDB/report workflows that need to create or recreate SimulationInfo objects with a different SPARTA version string.
 
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.
 
const utils::ValidValue< std::string > & getLastCapturedElapsedTime () const
 Return the very last 'Elapsed' time that this object got from the TimeManager. This is reset with each call to getHeaderPairs().
 

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 108 of file SimulationInfo.hpp.

Constructor & Destructor Documentation

◆ ~SimulationInfo()

sparta::SimulationInfo::~SimulationInfo ( )
inline

Destruction.

Definition at line 201 of file SimulationInfo.hpp.

◆ SimulationInfo() [1/6]

sparta::SimulationInfo::SimulationInfo ( )
inline

Default Constructor.

Definition at line 210 of file SimulationInfo.hpp.

◆ SimulationInfo() [2/6]

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

Copy-constructor.

Definition at line 225 of file SimulationInfo.hpp.

◆ SimulationInfo() [3/6]

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 261 of file SimulationInfo.hpp.

◆ SimulationInfo() [4/6]

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 285 of file SimulationInfo.hpp.

Here is the call graph for this function:

◆ SimulationInfo() [5/6]

sparta::SimulationInfo::SimulationInfo ( const simdb::ObjectManager &  sim_db,
const simdb::DatabaseID  obj_mgr_db_id,
const simdb::DatabaseID  report_node_id = 0 
)

Recreate a SimulationInfo object from the provided SimInfo record with the given ObjMgrID.

Note
While this SimDB-created SimulationInfo object is in scope, calls to SimulationInfo::getInstance() will not return the singleton. It will return the object that you recreated using this "SimDB constructor". It is not recommended to use this constructor during an actual SPARTA simulation!

◆ SimulationInfo() [6/6]

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 385 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 447 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 191 of file SimulationInfo.hpp.

◆ getLastCapturedElapsedTime()

const utils::ValidValue< std::string > & sparta::SimulationInfo::getLastCapturedElapsedTime ( ) const
inline

Return the very last 'Elapsed' time that this object got from the TimeManager. This is reset with each call to getHeaderPairs().

Definition at line 480 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). But there are some SimDB/report workflows that need to create or recreate SimulationInfo objects with a different SPARTA version string.

Definition at line 342 of file SimulationInfo.hpp.

◆ operator=()

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

Assignable.

Definition at line 245 of file SimulationInfo.hpp.

◆ setCommandLine() [1/2]

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

Assign command line from string.

Definition at line 378 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 353 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 425 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 438 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 398 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 149 of file SimulationInfo.hpp.

◆ executable

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

Executable being run.

Definition at line 159 of file SimulationInfo.hpp.

◆ other

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

other simulator information

Definition at line 186 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 176 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 144 of file SimulationInfo.hpp.

◆ simulator_version

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

Simulator Version of the simulator itself.

Definition at line 164 of file SimulationInfo.hpp.

◆ sparta_version

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

The version of SPARTA.

Definition at line 169 of file SimulationInfo.hpp.

◆ start_time

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

Time at which the simulation started (roughly)

Definition at line 181 of file SimulationInfo.hpp.

◆ working_dir

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

Simulator application instance working dir.

Definition at line 154 of file SimulationInfo.hpp.


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