From 84f67ef79ffa5dc3e1cfb751b14221a7bb612a50 Mon Sep 17 00:00:00 2001 From: jmpenn Date: Wed, 25 Jul 2018 13:05:10 -0500 Subject: [PATCH] Update all enums in MonteCarlo with prefixes, so as to not conflict with other enums. (#650) --- include/trick/MonteCarlo.hh | 36 +++++------ .../sim_services/MonteCarlo/MonteCarlo.cpp | 2 +- .../MonteCarlo_dispatch_run_to_slave.cpp | 12 ++-- .../MonteCarlo/MonteCarlo_funcs.cpp | 62 +++++++++---------- .../MonteCarlo_initialize_sockets.cpp | 4 +- .../MonteCarlo/MonteCarlo_master_file_io.cpp | 6 +- .../MonteCarlo/MonteCarlo_master_shutdown.cpp | 6 +- .../MonteCarlo/MonteCarlo_receive_results.cpp | 38 ++++++------ .../MonteCarlo/MonteCarlo_slave.cpp | 22 +++---- .../MonteCarlo/MonteCarlo_slave_init.cpp | 6 +- .../MonteCarlo_slave_process_run.cpp | 14 ++--- .../MonteCarlo/MonteCarlo_spawn_slaves.cpp | 10 +-- 12 files changed, 109 insertions(+), 109 deletions(-) diff --git a/include/trick/MonteCarlo.hh b/include/trick/MonteCarlo.hh index 2edce3ba..5cd56172 100644 --- a/include/trick/MonteCarlo.hh +++ b/include/trick/MonteCarlo.hh @@ -93,23 +93,23 @@ namespace Trick { public: /** Operational state. */ enum State { - UNINITIALIZED, /**< newly created */ - INITIALIZING, /**< starting up */ - READY, /**< awaiting new run */ - RUNNING, /**< processing a run */ - STOPPING, /**< stopping after current run */ - STOPPED, /**< not accepting new runs */ - FINISHED, /**< completed all runs */ - UNRESPONSIVE_RUNNING, /**< timed out and in a running state */ - UNRESPONSIVE_STOPPING, /**< timed out and in a stopping state */ - DISCONNECTED /**< lost connection */ + MC_UNINITIALIZED, /**< newly created */ + MC_INITIALIZING, /**< starting up */ + MC_READY, /**< awaiting new run */ + MC_RUNNING, /**< processing a run */ + MC_STOPPING, /**< stopping after current run */ + MC_STOPPED, /**< not accepting new runs */ + MC_FINISHED, /**< completed all runs */ + MC_UNRESPONSIVE_RUNNING, /**< timed out and in a running state */ + MC_UNRESPONSIVE_STOPPING, /**< timed out and in a stopping state */ + MC_DISCONNECTED /**< lost connection */ }; /** Master-to-slave commands. */ enum Command { - PROCESS_RUN, /**< process a new run */ - SHUTDOWN, /**< kill any executing run, call shutdown jobs, and shutdown cleanly */ - DIE /**< kill any executing run, do not call shutdown jobs, and exit */ + MC_PROCESS_RUN, /**< process a new run */ + MC_SHUTDOWN, /**< kill any executing run, call shutdown jobs, and shutdown cleanly */ + MC_DIE /**< kill any executing run, do not call shutdown jobs, and exit */ }; /** Unique identifier assigned by the master. */ @@ -166,7 +166,7 @@ namespace Trick { */ MonteSlave(std::string name = "localhost") : id(0), - state(UNINITIALIZED), + state(MC_UNINITIALIZED), port(0), current_run(NULL), num_dispatches(0), @@ -248,10 +248,10 @@ namespace Trick { public: /** Verbosity of message reporting. */ enum Verbosity { - NONE, /**< report no messages */ - ERROR, /**< report error messages */ - INFORMATIONAL, /**< report error and informational messages, no warning messages */ - ALL /**< report all messages (error, informational & warning) */ + MC_NONE, /**< report no messages */ + MC_ERROR, /**< report error messages */ + MC_INFORMATIONAL, /**< report error and informational messages, no warning messages */ + MC_ALL /**< report all messages (error, informational & warning) */ }; /** Options to be passed to the slave sim. */ diff --git a/trick_source/sim_services/MonteCarlo/MonteCarlo.cpp b/trick_source/sim_services/MonteCarlo/MonteCarlo.cpp index 688e040c..0cc791d5 100644 --- a/trick_source/sim_services/MonteCarlo/MonteCarlo.cpp +++ b/trick_source/sim_services/MonteCarlo/MonteCarlo.cpp @@ -10,7 +10,7 @@ Trick::MonteCarlo::MonteCarlo() : custom_slave_dispatch(false), timeout(120), max_tries(2), - verbosity(INFORMATIONAL), + verbosity(MC_INFORMATIONAL), num_runs(0), actual_num_runs(0), num_results(0), diff --git a/trick_source/sim_services/MonteCarlo/MonteCarlo_dispatch_run_to_slave.cpp b/trick_source/sim_services/MonteCarlo/MonteCarlo_dispatch_run_to_slave.cpp index 5132ab82..feeb19bb 100644 --- a/trick_source/sim_services/MonteCarlo/MonteCarlo_dispatch_run_to_slave.cpp +++ b/trick_source/sim_services/MonteCarlo/MonteCarlo_dispatch_run_to_slave.cpp @@ -14,7 +14,7 @@ void Trick::MonteCarlo::dispatch_run_to_slave(MonteRun *run, MonteSlave *slave) if (prepare_run(run) == -1) { return; } - slave->state = MonteSlave::RUNNING; + slave->state = MonteSlave::MC_RUNNING; connection_device.hostname = (char*)slave->machine_name.c_str(); connection_device.port = slave->port; if (tc_connect(&connection_device) == TC_SUCCESS) { @@ -29,18 +29,18 @@ void Trick::MonteCarlo::dispatch_run_to_slave(MonteRun *run, MonteSlave *slave) buffer_stream << run->id ; buffer += std::string("trick.mc_set_current_run(") + buffer_stream.str() + std::string(")\n"); - if (verbosity >= INFORMATIONAL) { + if (verbosity >= MC_INFORMATIONAL) { message_publish(MSG_INFO, "Monte [Master] Dispatching run %d to %s:%d.\n", run->id, slave->machine_name.c_str(), slave->id) ; } - int command = htonl(MonteSlave::PROCESS_RUN); + int command = htonl(MonteSlave::MC_PROCESS_RUN); tc_write(&connection_device, (char *)&command, (int)sizeof(command)); int num_bytes = htonl(buffer.length()); tc_write(&connection_device, (char*)&num_bytes, (int)sizeof(num_bytes)); tc_write(&connection_device, (char*)buffer.c_str(), (int)buffer.length()); - if (verbosity >= ALL) { + if (verbosity >= MC_ALL) { message_publish(MSG_INFO, "Parameterization of run %d :\n%s\n", run->id, buffer.c_str()) ; } @@ -54,8 +54,8 @@ void Trick::MonteCarlo::dispatch_run_to_slave(MonteRun *run, MonteSlave *slave) run->start_time = time_val.tv_sec + (double)time_val.tv_usec / 1000000; ++run->num_tries; } else { - slave->state = Trick::MonteSlave::DISCONNECTED; - if (verbosity >= ERROR) { + slave->state = Trick::MonteSlave::MC_DISCONNECTED; + if (verbosity >= MC_ERROR) { message_publish(MSG_ERROR, "Monte [Master] Failed to connect to %s:%d to dispatch run.\n", slave->machine_name.c_str(), slave->id) ; } diff --git a/trick_source/sim_services/MonteCarlo/MonteCarlo_funcs.cpp b/trick_source/sim_services/MonteCarlo/MonteCarlo_funcs.cpp index 0f31f02e..c6786863 100644 --- a/trick_source/sim_services/MonteCarlo/MonteCarlo_funcs.cpp +++ b/trick_source/sim_services/MonteCarlo/MonteCarlo_funcs.cpp @@ -201,38 +201,38 @@ void Trick::MonteCarlo::add_slave(Trick::MonteSlave *in_slave) { /** * @par Detailed Design: - * This function has an effect only if the slave exists and is in the STOPPING, UNRESPONSIVE_STOPPING, or STOPPED state. + * This function has an effect only if the slave exists and is in the MC_STOPPING, MC_UNRESPONSIVE_STOPPING, or MC_STOPPED state. */ void Trick::MonteCarlo::start_slave(unsigned int id) { if (MonteSlave *slave = get_slave(id)) { - if (verbosity >= ALL) { + if (verbosity >= MC_ALL) { message_publish(MSG_INFO, "Monte [Master] Starting %s:%d.\n", slave->machine_name.c_str(), slave->id) ; } - if (slave->state == Trick::MonteSlave::STOPPING) { - slave->state = Trick::MonteSlave::RUNNING; - } else if (slave->state == Trick::MonteSlave::UNRESPONSIVE_STOPPING) { - slave->state = Trick::MonteSlave::UNRESPONSIVE_RUNNING; - } else if (slave->state == Trick::MonteSlave::STOPPED) { - slave->state = Trick::MonteSlave::READY; + if (slave->state == Trick::MonteSlave::MC_STOPPING) { + slave->state = Trick::MonteSlave::MC_RUNNING; + } else if (slave->state == Trick::MonteSlave::MC_UNRESPONSIVE_STOPPING) { + slave->state = Trick::MonteSlave::MC_UNRESPONSIVE_RUNNING; + } else if (slave->state == Trick::MonteSlave::MC_STOPPED) { + slave->state = Trick::MonteSlave::MC_READY; } } } /** * @par Detailed Design: - * This function has an effect only if the slave exists and is in the READY, RUNNING, or UNRESPONSIVE_RUNNING state. + * This function has an effect only if the slave exists and is in the MC_READY, MC_RUNNING, or MC_UNRESPONSIVE_RUNNING state. */ void Trick::MonteCarlo::stop_slave(unsigned int id) { if (MonteSlave *slave = get_slave(id)) { - if (verbosity >= ALL) { + if (verbosity >= MC_ALL) { message_publish(MSG_INFO, "Monte [Master] Stopping %s:%d.\n", slave->machine_name.c_str(), slave->id) ; } - if (slave->state == Trick::MonteSlave::READY) { - slave->state = Trick::MonteSlave::STOPPED; - } else if (slave->state == Trick::MonteSlave::RUNNING) { - slave->state = Trick::MonteSlave::STOPPING; - } else if (slave->state == Trick::MonteSlave::UNRESPONSIVE_RUNNING) { - slave->state = Trick::MonteSlave::UNRESPONSIVE_STOPPING; + if (slave->state == Trick::MonteSlave::MC_READY) { + slave->state = Trick::MonteSlave::MC_STOPPED; + } else if (slave->state == Trick::MonteSlave::MC_RUNNING) { + slave->state = Trick::MonteSlave::MC_STOPPING; + } else if (slave->state == Trick::MonteSlave::MC_UNRESPONSIVE_RUNNING) { + slave->state = Trick::MonteSlave::MC_UNRESPONSIVE_STOPPING; } } } @@ -245,9 +245,9 @@ void Trick::MonteCarlo::disable_slave(std::string name, bool disabled){ for (std::vector::size_type i = 0; i < slaves.size(); ++i) { if (equals_ignore_case(slaves[i]->machine_name, name)) { if (disabled) { - slaves[i]->state = Trick::MonteSlave::STOPPED; + slaves[i]->state = Trick::MonteSlave::MC_STOPPED; } else { - slaves[i]->state = Trick::MonteSlave::UNINITIALIZED; + slaves[i]->state = Trick::MonteSlave::MC_UNINITIALIZED; } return; } @@ -279,7 +279,7 @@ int Trick::MonteCarlo::shutdown() { connection_device.port = master_port; if (tc_connect(&connection_device) == TC_SUCCESS) { int exit_status = MonteRun::MC_RUN_COMPLETE; - if (verbosity >= ALL) { + if (verbosity >= MC_ALL) { message_publish(MSG_INFO, "Monte [%s:%d] Sending run exit status to master: %d\n", machine_name.c_str(), slave_id, exit_status) ; } @@ -290,7 +290,7 @@ int Trick::MonteCarlo::shutdown() { run_queue(&slave_post_queue, "in slave_post queue"); tc_disconnect(&connection_device); } else { - if (verbosity >= ERROR) + if (verbosity >= MC_ERROR) message_publish( MSG_ERROR, "Monte [%s:%d] Failed to connect to master.\n", @@ -303,12 +303,12 @@ int Trick::MonteCarlo::shutdown() { void Trick::MonteCarlo::handle_retry(MonteSlave& slave, MonteRun::ExitStatus exit_status) { if (max_tries <= 0 || slave.current_run->num_tries < max_tries) { // Add the run to the retry queue. - if (verbosity >= ERROR) { + if (verbosity >= MC_ERROR) { message_publish(MSG_ERROR, "Monte [Master] Queueing run %d for retry.\n", slave.current_run->id) ; } runs.push_back(slave.current_run); } else { - if (verbosity >= ERROR) { + if (verbosity >= MC_ERROR) { message_publish(MSG_ERROR, "Monte [Master] Run %d has reached its maximum allowed tries and has been skipped.\n", slave.current_run->id) ; } @@ -333,7 +333,7 @@ void Trick::MonteCarlo::resolve_run(MonteSlave& slave, MonteRun::ExitStatus exit ++num_results; - if (verbosity >= ALL) { + if (verbosity >= MC_ALL) { message_publish(MSG_INFO, "Monte [Master] Run %d has been resolved as: %d.\n",slave.current_run->id, exit_status) ; } } @@ -345,7 +345,7 @@ void Trick::MonteCarlo::check_timeouts() { /**