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"
12 int main(
int argc,
char** argv)
17 fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
19 fhicl::Atom<std::string> partition_number{fhicl::Name{
"partition_number"}, fhicl::Comment{
"Partition to run in"},
""};
21 artdaq::configureMessageFacility(
"commander_test",
true,
true);
22 fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv,
"commander_test",
"A test driver for CommanderInterface plugins");
26 auto id_rand = seedAndRandom();
27 if (config_ps.has_key(
"id"))
29 TLOG(TLVL_DEBUG) <<
"Ignoring set id and using random!";
30 config_ps.erase(
"id");
32 config_ps.put(
"id", artdaq::Globals::partition_number_ * 1000 + (id_rand % 1000));
39 boost::thread commanderThread([&] { commander->run_server(); });
40 while (!commander->GetStatus())
47 fhicl::ParameterSet pset;
49 TLOG(TLVL_INFO) <<
"START";
51 TLOG(TLVL_DEBUG) <<
"Sending init";
52 std::string sts = commander->send_init(pset, arg, arg);
53 TLOG(TLVL_DEBUG) <<
"init res=" << sts;
56 TLOG(TLVL_ERROR) <<
"init returned " << sts <<
", exiting with error";
60 TLOG(TLVL_DEBUG) <<
"Sending soft_init";
61 sts = commander->send_soft_init(pset, arg, arg);
62 TLOG(TLVL_DEBUG) <<
"soft_init res=" << sts;
65 TLOG(TLVL_ERROR) <<
"soft_init returned " << sts <<
", exiting with error";
69 TLOG(TLVL_DEBUG) <<
"Sending legal_commands";
70 sts = commander->send_legal_commands();
71 TLOG(TLVL_DEBUG) <<
"legal_commands res=" << sts;
72 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
74 TLOG(TLVL_ERROR) <<
"legal_commands returned " << sts <<
", exiting with error";
78 TLOG(TLVL_DEBUG) <<
"Sending meta_command";
79 sts = commander->send_meta_command(
"test",
"test");
80 TLOG(TLVL_DEBUG) <<
"meta_command res=" << sts;
83 TLOG(TLVL_ERROR) <<
"meta_command returned " << sts <<
", exiting with error";
87 TLOG(TLVL_DEBUG) <<
"Sending report";
88 sts = commander->send_report(
"test");
89 TLOG(TLVL_DEBUG) <<
"report res=" << sts;
90 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
92 TLOG(TLVL_ERROR) <<
"report returned " << sts <<
", exiting with error";
96 TLOG(TLVL_DEBUG) <<
"Sending start";
97 sts = commander->send_start(art::RunID(0x7357), arg, arg);
98 TLOG(TLVL_DEBUG) <<
"start res=" << sts;
101 TLOG(TLVL_ERROR) <<
"start returned " << sts <<
", exiting with error";
105 TLOG(TLVL_DEBUG) <<
"Sending status";
106 sts = commander->send_status();
107 TLOG(TLVL_DEBUG) <<
"status res=" << sts;
108 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
110 TLOG(TLVL_ERROR) <<
"status returned " << sts <<
", exiting with error";
114 TLOG(TLVL_DEBUG) <<
"Sending pause";
115 sts = commander->send_pause(arg, arg);
116 TLOG(TLVL_DEBUG) <<
"pause res=" << sts;
117 if (sts !=
"Success")
119 TLOG(TLVL_ERROR) <<
"pause returned " << sts <<
", exiting with error";
123 TLOG(TLVL_DEBUG) <<
"Sending resume";
124 sts = commander->send_resume(arg, arg);
125 TLOG(TLVL_DEBUG) <<
"resume res=" << sts;
126 if (sts !=
"Success")
128 TLOG(TLVL_ERROR) <<
"resume returned " << sts <<
", exiting with error";
132 TLOG(TLVL_DEBUG) <<
"Sending rollover_subrun";
133 sts = commander->send_rollover_subrun(arg, static_cast<uint32_t>(arg));
134 TLOG(TLVL_DEBUG) <<
"rollover_subrun res=" << sts;
135 if (sts !=
"Success")
137 TLOG(TLVL_ERROR) <<
"rollover_subrun returned " << sts <<
", exiting with error";
141 TLOG(TLVL_DEBUG) <<
"Sending stop";
142 sts = commander->send_stop(arg, arg);
143 TLOG(TLVL_DEBUG) <<
"stop res=" << sts;
144 if (sts !=
"Success")
146 TLOG(TLVL_ERROR) <<
"stop returned " << sts <<
", exiting with error";
150 TLOG(TLVL_DEBUG) <<
"Sending reinit";
151 sts = commander->send_reinit(pset, arg, arg);
152 TLOG(TLVL_DEBUG) <<
"reinit res=" << sts;
153 if (sts !=
"Success")
155 TLOG(TLVL_ERROR) <<
"reinit returned " << sts <<
", exiting with error";
159 TLOG(TLVL_DEBUG) <<
"Sending trace_set";
160 sts = commander->send_trace_set(
"TRACE",
"M",
"0x7357AAAABBBBCCCC");
161 TLOG(TLVL_DEBUG) <<
"trace_set res=" << sts;
162 if (sts !=
"Success")
164 TLOG(TLVL_ERROR) <<
"trace_set returned " << sts <<
", exiting with error";
168 TLOG(TLVL_DEBUG) <<
"Sending trace_get";
169 sts = commander->send_trace_get(
"TRACE");
170 TLOG(TLVL_DEBUG) <<
"trace_get res=" << sts;
171 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
173 TLOG(TLVL_ERROR) <<
"trace_get returned " << sts <<
", exiting with error";
177 TLOG(TLVL_DEBUG) <<
"Sending register_monitor";
178 sts = commander->send_register_monitor(
"unqiue_label: test");
179 TLOG(TLVL_DEBUG) <<
"register_monitor res=" << sts;
180 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
182 TLOG(TLVL_ERROR) <<
"register_monitor returned " << sts <<
", exiting with error";
186 TLOG(TLVL_DEBUG) <<
"Sending unregister_monitor";
187 sts = commander->send_unregister_monitor(
"test");
188 TLOG(TLVL_DEBUG) <<
"unregister_monitor res=" << sts;
189 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
191 TLOG(TLVL_ERROR) <<
"unregister_monitor returned " << sts <<
", exiting with error";
195 TLOG(TLVL_DEBUG) <<
"Sending shutdown";
196 sts = commander->send_shutdown(arg);
197 TLOG(TLVL_DEBUG) <<
"shutdown res=" << sts;
198 if (sts !=
"Success")
200 TLOG(TLVL_ERROR) <<
"shutdown returned " << sts <<
", exiting with error";
204 TLOG(TLVL_INFO) <<
"DONE";
206 if (commanderThread.joinable())
208 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.
Configuration for simple_metric_sender.
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.