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)
try
16 fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
18 fhicl::Atom<std::string> partition_number{fhicl::Name{
"partition_number"}, fhicl::Comment{
"Partition to run in"},
""};
20 artdaq::configureMessageFacility(
"commander_test",
true,
true);
21 fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv,
"commander_test",
"A test driver for CommanderInterface plugins");
25 auto id_rand = seedAndRandom();
26 if (config_ps.has_key(
"id"))
28 TLOG(TLVL_DEBUG) <<
"Ignoring set id and using random!";
29 config_ps.erase(
"id");
31 config_ps.put(
"id", artdaq::Globals::partition_number_ * 1000 + (id_rand % 1000));
38 boost::thread commanderThread([&] { commander->run_server(); });
39 while (!commander->GetStatus())
46 fhicl::ParameterSet pset;
48 TLOG(TLVL_INFO) <<
"START";
50 TLOG(TLVL_DEBUG) <<
"Sending init";
51 std::string sts = commander->send_init(pset, arg, arg);
52 TLOG(TLVL_DEBUG) <<
"init res=" << sts;
55 TLOG(TLVL_ERROR) <<
"init returned " << sts <<
", exiting with error";
59 TLOG(TLVL_DEBUG) <<
"Sending soft_init";
60 sts = commander->send_soft_init(pset, arg, arg);
61 TLOG(TLVL_DEBUG) <<
"soft_init res=" << sts;
64 TLOG(TLVL_ERROR) <<
"soft_init returned " << sts <<
", exiting with error";
68 TLOG(TLVL_DEBUG) <<
"Sending legal_commands";
69 sts = commander->send_legal_commands();
70 TLOG(TLVL_DEBUG) <<
"legal_commands res=" << sts;
71 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
73 TLOG(TLVL_ERROR) <<
"legal_commands returned " << sts <<
", exiting with error";
77 TLOG(TLVL_DEBUG) <<
"Sending meta_command";
78 sts = commander->send_meta_command(
"test",
"test");
79 TLOG(TLVL_DEBUG) <<
"meta_command res=" << sts;
82 TLOG(TLVL_ERROR) <<
"meta_command returned " << sts <<
", exiting with error";
86 TLOG(TLVL_DEBUG) <<
"Sending report";
87 sts = commander->send_report(
"test");
88 TLOG(TLVL_DEBUG) <<
"report res=" << sts;
89 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
91 TLOG(TLVL_ERROR) <<
"report returned " << sts <<
", exiting with error";
95 TLOG(TLVL_DEBUG) <<
"Sending start";
96 sts = commander->send_start(art::RunID(0x7357), arg, arg);
97 TLOG(TLVL_DEBUG) <<
"start res=" << sts;
100 TLOG(TLVL_ERROR) <<
"start returned " << sts <<
", exiting with error";
104 TLOG(TLVL_DEBUG) <<
"Sending status";
105 sts = commander->send_status();
106 TLOG(TLVL_DEBUG) <<
"status res=" << sts;
107 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
109 TLOG(TLVL_ERROR) <<
"status returned " << sts <<
", exiting with error";
113 TLOG(TLVL_DEBUG) <<
"Sending pause";
114 sts = commander->send_pause(arg, arg);
115 TLOG(TLVL_DEBUG) <<
"pause res=" << sts;
116 if (sts !=
"Success")
118 TLOG(TLVL_ERROR) <<
"pause returned " << sts <<
", exiting with error";
122 TLOG(TLVL_DEBUG) <<
"Sending resume";
123 sts = commander->send_resume(arg, arg);
124 TLOG(TLVL_DEBUG) <<
"resume res=" << sts;
125 if (sts !=
"Success")
127 TLOG(TLVL_ERROR) <<
"resume returned " << sts <<
", exiting with error";
131 TLOG(TLVL_DEBUG) <<
"Sending rollover_subrun";
132 sts = commander->send_rollover_subrun(arg, static_cast<uint32_t>(arg));
133 TLOG(TLVL_DEBUG) <<
"rollover_subrun res=" << sts;
134 if (sts !=
"Success")
136 TLOG(TLVL_ERROR) <<
"rollover_subrun returned " << sts <<
", exiting with error";
140 TLOG(TLVL_DEBUG) <<
"Sending stop";
141 sts = commander->send_stop(arg, arg);
142 TLOG(TLVL_DEBUG) <<
"stop res=" << sts;
143 if (sts !=
"Success")
145 TLOG(TLVL_ERROR) <<
"stop returned " << sts <<
", exiting with error";
149 TLOG(TLVL_DEBUG) <<
"Sending reinit";
150 sts = commander->send_reinit(pset, arg, arg);
151 TLOG(TLVL_DEBUG) <<
"reinit res=" << sts;
152 if (sts !=
"Success")
154 TLOG(TLVL_ERROR) <<
"reinit returned " << sts <<
", exiting with error";
158 TLOG(TLVL_DEBUG) <<
"Sending trace_set";
159 sts = commander->send_trace_set(
"TRACE",
"M",
"0x7357AAAABBBBCCCC");
160 TLOG(TLVL_DEBUG) <<
"trace_set res=" << sts;
161 if (sts !=
"Success")
163 TLOG(TLVL_ERROR) <<
"trace_set returned " << sts <<
", exiting with error";
167 TLOG(TLVL_DEBUG) <<
"Sending trace_get";
168 sts = commander->send_trace_get(
"TRACE");
169 TLOG(TLVL_DEBUG) <<
"trace_get res=" << sts;
170 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
172 TLOG(TLVL_ERROR) <<
"trace_get returned " << sts <<
", exiting with error";
176 TLOG(TLVL_DEBUG) <<
"Sending register_monitor";
177 sts = commander->send_register_monitor(
"unqiue_label: test");
178 TLOG(TLVL_DEBUG) <<
"register_monitor res=" << sts;
179 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
181 TLOG(TLVL_ERROR) <<
"register_monitor returned " << sts <<
", exiting with error";
185 TLOG(TLVL_DEBUG) <<
"Sending unregister_monitor";
186 sts = commander->send_unregister_monitor(
"test");
187 TLOG(TLVL_DEBUG) <<
"unregister_monitor res=" << sts;
188 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
190 TLOG(TLVL_ERROR) <<
"unregister_monitor returned " << sts <<
", exiting with error";
194 TLOG(TLVL_DEBUG) <<
"Sending shutdown";
195 sts = commander->send_shutdown(arg);
196 TLOG(TLVL_DEBUG) <<
"shutdown res=" << sts;
197 if (sts !=
"Success")
199 TLOG(TLVL_ERROR) <<
"shutdown returned " << sts <<
", exiting with error";
203 TLOG(TLVL_INFO) <<
"DONE";
205 if (commanderThread.joinable())
207 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.