trick/trick_source/sim_services/MonteCarlo/MonteCarlo_dryrun.cpp

50 lines
2.0 KiB
C++
Raw Normal View History

2015-02-26 15:02:31 +00:00
#include <sstream>
#include <iomanip>
#include <fstream>
#include <sys/stat.h>
#include <unistd.h>
#include "trick/MonteCarlo.hh"
#include "trick/message_proto.h"
#include "trick/message_type.h"
#include "trick/command_line_protos.h"
2015-02-26 15:02:31 +00:00
/** @par Detailed Design: */
void Trick::MonteCarlo::dryrun() {
/** <ul><li> For all runs: run the pre run jobs. */
MonteRun * curr_run;
while ((curr_run = get_next_dispatch())) {
prepare_run(curr_run);
// Write out the input file for this run.
std::stringstream buffer_stream;
buffer_stream << run_directory << "/RUN_" << std::setw(5) << std::setfill('0') << curr_run->id;
std::ofstream of ;
if ( (access(buffer_stream.str().c_str(), F_OK) == 0) or (mkdir(buffer_stream.str().c_str(), 0755) == 0) ) {
of.open(std::string(buffer_stream.str() + "/monte_input").c_str()) ;
of << "# This run can be executed in stand alone (non-Monte Carlo) mode by running\n"
"# the S_main executable with this file specified as the input file.\n\n" ;
of << "if (sys.version_info > (3, 0)):" << std::endl ;
of << " exec(open(\"" << command_line_args_get_input_file() << "\").read())" << std::endl ;
of << "else:" << std::endl ;
of << " execfile(\"" << command_line_args_get_input_file() << "\")" << std::endl << std::endl ;
of << "trick.mc_set_enabled(0)" << std::endl ;
for (std::vector<std::string>::size_type j = 0; j < curr_run->variables.size(); ++j) {
of << curr_run->variables[j] << std::endl ;
}
of << "trick.set_output_dir(\"" << buffer_stream.str() << "\")" << std::endl ;
of << "trick.mc_set_current_run(" << curr_run->id << ")" << std::endl ;
of.close() ;
}
2015-02-26 15:02:31 +00:00
}
/** <ul><li> Run the master shutdown jobs */
run_queue(&master_shutdown_queue, "in master_shutdown queue") ;
message_publish(MSG_INFO, "Monte [Master] Dry run complete.\n") ;
exit(0) ;
}