1 #define TRACE_NAME "commander_test"
3 #include "artdaq/ExternalComms/CommanderInterface.hh"
5 #include "artdaq/Application/LoadParameterSet.hh"
6 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
8 #include <boost/thread.hpp>
9 #include "artdaq/DAQdata/Globals.hh"
11 int main(
int argc,
char** argv)
15 fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
17 fhicl::Atom<std::string> partition_number{fhicl::Name{
"partition_number"}, fhicl::Comment{
"Partition to run in"},
""};
19 artdaq::configureMessageFacility(
"commander_test",
true,
true);
20 fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv,
"commander_test",
"A test driver for CommanderInterface plugins");
24 auto id_rand = seedAndRandom();
25 if (config_ps.has_key(
"id"))
27 TLOG(TLVL_DEBUG) <<
"Ignoring set id and using random!";
28 config_ps.erase(
"id");
30 config_ps.put(
"id", artdaq::Globals::partition_number_ * 1000 + (id_rand % 1000));
37 boost::thread commanderThread([&] { commander->run_server(); });
38 while (!commander->GetStatus()) usleep(10000);
42 fhicl::ParameterSet pset;
44 TLOG(TLVL_INFO) <<
"START";
46 TLOG(TLVL_DEBUG) <<
"Sending init";
47 std::string sts = commander->send_init(pset, arg, arg);
48 TLOG(TLVL_DEBUG) <<
"init res=" << sts;
51 TLOG(TLVL_ERROR) <<
"init returned " << sts <<
", exiting with error";
55 TLOG(TLVL_DEBUG) <<
"Sending soft_init";
56 sts = commander->send_soft_init(pset, arg, arg);
57 TLOG(TLVL_DEBUG) <<
"soft_init res=" << sts;
60 TLOG(TLVL_ERROR) <<
"soft_init returned " << sts <<
", exiting with error";
64 TLOG(TLVL_DEBUG) <<
"Sending legal_commands";
65 sts = commander->send_legal_commands();
66 TLOG(TLVL_DEBUG) <<
"legal_commands res=" << sts;
67 if (sts.size() == 0 || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
69 TLOG(TLVL_ERROR) <<
"legal_commands returned " << sts <<
", exiting with error";
73 TLOG(TLVL_DEBUG) <<
"Sending meta_command";
74 sts = commander->send_meta_command(
"test",
"test");
75 TLOG(TLVL_DEBUG) <<
"meta_command res=" << sts;
78 TLOG(TLVL_ERROR) <<
"meta_command returned " << sts <<
", exiting with error";
82 TLOG(TLVL_DEBUG) <<
"Sending report";
83 sts = commander->send_report(
"test");
84 TLOG(TLVL_DEBUG) <<
"report res=" << sts;
85 if (sts.size() == 0 || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
87 TLOG(TLVL_ERROR) <<
"report returned " << sts <<
", exiting with error";
91 TLOG(TLVL_DEBUG) <<
"Sending start";
92 sts = commander->send_start(art::RunID(0x7357), arg, arg);
93 TLOG(TLVL_DEBUG) <<
"start res=" << sts;
96 TLOG(TLVL_ERROR) <<
"start returned " << sts <<
", exiting with error";
100 TLOG(TLVL_DEBUG) <<
"Sending status";
101 sts = commander->send_status();
102 TLOG(TLVL_DEBUG) <<
"status res=" << sts;
103 if (sts.size() == 0 || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
105 TLOG(TLVL_ERROR) <<
"status returned " << sts <<
", exiting with error";
109 TLOG(TLVL_DEBUG) <<
"Sending pause";
110 sts = commander->send_pause(arg, arg);
111 TLOG(TLVL_DEBUG) <<
"pause res=" << sts;
112 if (sts !=
"Success")
114 TLOG(TLVL_ERROR) <<
"pause returned " << sts <<
", exiting with error";
118 TLOG(TLVL_DEBUG) <<
"Sending resume";
119 sts = commander->send_resume(arg, arg);
120 TLOG(TLVL_DEBUG) <<
"resume res=" << sts;
121 if (sts !=
"Success")
123 TLOG(TLVL_ERROR) <<
"resume returned " << sts <<
", exiting with error";
127 TLOG(TLVL_DEBUG) <<
"Sending rollover_subrun";
128 sts = commander->send_rollover_subrun(arg, static_cast<uint32_t>(arg));
129 TLOG(TLVL_DEBUG) <<
"rollover_subrun res=" << sts;
130 if (sts !=
"Success")
132 TLOG(TLVL_ERROR) <<
"rollover_subrun returned " << sts <<
", exiting with error";
136 TLOG(TLVL_DEBUG) <<
"Sending stop";
137 sts = commander->send_stop(arg, arg);
138 TLOG(TLVL_DEBUG) <<
"stop res=" << sts;
139 if (sts !=
"Success")
141 TLOG(TLVL_ERROR) <<
"stop returned " << sts <<
", exiting with error";
145 TLOG(TLVL_DEBUG) <<
"Sending reinit";
146 sts = commander->send_reinit(pset, arg, arg);
147 TLOG(TLVL_DEBUG) <<
"reinit res=" << sts;
148 if (sts !=
"Success")
150 TLOG(TLVL_ERROR) <<
"reinit returned " << sts <<
", exiting with error";
154 TLOG(TLVL_DEBUG) <<
"Sending trace_set";
155 sts = commander->send_trace_set(
"TRACE",
"M",
"0x7357AAAABBBBCCCC");
156 TLOG(TLVL_DEBUG) <<
"trace_set res=" << sts;
157 if (sts !=
"Success")
159 TLOG(TLVL_ERROR) <<
"trace_set returned " << sts <<
", exiting with error";
163 TLOG(TLVL_DEBUG) <<
"Sending trace_get";
164 sts = commander->send_trace_get(
"TRACE");
165 TLOG(TLVL_DEBUG) <<
"trace_get res=" << sts;
166 if (sts.size() == 0 || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
168 TLOG(TLVL_ERROR) <<
"trace_get returned " << sts <<
", exiting with error";
172 TLOG(TLVL_DEBUG) <<
"Sending register_monitor";
173 sts = commander->send_register_monitor(
"unqiue_label: test");
174 TLOG(TLVL_DEBUG) <<
"register_monitor res=" << sts;
175 if (sts.size() == 0 || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
177 TLOG(TLVL_ERROR) <<
"register_monitor returned " << sts <<
", exiting with error";
181 TLOG(TLVL_DEBUG) <<
"Sending unregister_monitor";
182 sts = commander->send_unregister_monitor(
"test");
183 TLOG(TLVL_DEBUG) <<
"unregister_monitor res=" << sts;
184 if (sts.size() == 0 || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
186 TLOG(TLVL_ERROR) <<
"unregister_monitor returned " << sts <<
", exiting with error";
190 TLOG(TLVL_DEBUG) <<
"Sending shutdown";
191 sts = commander->send_shutdown(arg);
192 TLOG(TLVL_DEBUG) <<
"shutdown res=" << sts;
193 if (sts !=
"Success")
195 TLOG(TLVL_ERROR) <<
"shutdown returned " << sts <<
", exiting with error";
199 TLOG(TLVL_INFO) <<
"DONE";
201 if (commanderThread.joinable()) commanderThread.join();
Commandable is the base class for all artdaq components which implement the artdaq state machine...
static void CleanUpGlobals()
Clean up statically-allocated Manager class instances.
std::unique_ptr< artdaq::CommanderInterface > MakeCommanderPlugin(const fhicl::ParameterSet &commander_pset, artdaq::Commandable &commandable)
Load a CommanderInterface plugin.
static int partition_number_
The partition number of the current application.