00001 #include "otsdaq-core/GatewaySupervisor/ARTDAQCommandable.h"
00002 #include "otsdaq-core/GatewaySupervisor/GatewaySupervisor.h"
00003 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
00004
00005 ots::ARTDAQCommandable::ARTDAQCommandable(GatewaySupervisor * super)
00006 : artdaq::Commandable()
00007 , theSupervisor_(super)
00008 , theCommander_(nullptr)
00009 {}
00010
00011 ots::ARTDAQCommandable::~ARTDAQCommandable()
00012 {
00013 if (theCommander_ != nullptr)
00014 {
00015 theCommander_->send_shutdown(0);
00016 if (commanderThread_.joinable()) commanderThread_.join();
00017 }
00018 }
00019
00020 void ots::ARTDAQCommandable::init(int commanderId, std::string commanderType)
00021 {
00022 fhicl::ParameterSet ps;
00023 ps.put<int>("id", commanderId);
00024 ps.put<std::string>("commanderPluginType", commanderType);
00025
00026 theCommander_ = artdaq::MakeCommanderPlugin(ps, *this);
00027 boost::thread::attributes attrs;
00028 attrs.set_stack_size(4096 * 2000);
00029 commanderThread_ = boost::thread(attrs, boost::bind(&artdaq::CommanderInterface::run_server, theCommander_.get()));
00030 }
00031
00032 bool ots::ARTDAQCommandable::do_initialize(fhicl::ParameterSet const & ps, uint64_t, uint64_t)
00033 {
00034 std::vector<std::string> parameters;
00035 parameters.push_back(ps.get<std::string>("config_name"));
00036
00037 auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Initialize",
00038 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00039 "ARTDAQCommandable", parameters);
00040 if (ret == "")
00041 ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Configure",
00042 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00043 "ARTDAQCommandable", parameters);
00044 report_string_ = ret;
00045 return ret == "";
00046 }
00047
00048 bool ots::ARTDAQCommandable::do_start(art::RunID, uint64_t, uint64_t)
00049 {
00050 std::vector<std::string> parameters;
00051 auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Start",
00052 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00053 "ARTDAQCommandable", parameters);
00054 report_string_ = ret;
00055 return ret == "";
00056 }
00057
00058 bool ots::ARTDAQCommandable::do_stop(uint64_t, uint64_t)
00059 {
00060 std::vector<std::string> parameters;
00061 auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Stop",
00062 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00063 "ARTDAQCommandable", parameters);
00064 report_string_ = ret;
00065 return ret == "";
00066 }
00067
00068 bool ots::ARTDAQCommandable::do_pause(uint64_t, uint64_t)
00069 {
00070 std::vector<std::string> parameters;
00071 auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Pause",
00072 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00073 "ARTDAQCommandable", parameters);
00074 report_string_ = ret;
00075 return ret == "";
00076 }
00077
00078 bool ots::ARTDAQCommandable::do_resume(uint64_t, uint64_t)
00079 {
00080 std::vector<std::string> parameters;
00081 auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Resume",
00082 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00083 "ARTDAQCommandable", parameters);
00084 report_string_ = ret;
00085 return ret == "";
00086 }
00087
00088 bool ots::ARTDAQCommandable::do_shutdown(uint64_t)
00089 {
00090 std::vector<std::string> parameters;
00091 auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Halt",
00092 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00093 "ARTDAQCommandable", parameters);
00094 if (ret == "")
00095 ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, "Shutdown",
00096 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00097 "ARTDAQCommandable", parameters);
00098 report_string_ = ret;
00099 return ret == "";
00100 }
00101
00102 bool ots::ARTDAQCommandable::do_meta_command(std::string const & command, std::string const & args)
00103 {
00104 std::vector<std::string> parameters;
00105 parameters.push_back(args);
00106 auto ret = theSupervisor_->attemptStateMachineTransition(nullptr, nullptr, command,
00107 theSupervisor_->activeStateMachineName_, theSupervisor_->activeStateMachineWindowName_,
00108 "ARTDAQCommandable", parameters);
00109 report_string_ = ret;
00110 return ret == "";
00111 }
00112