1 #include "TRACE/tracemf.h"
2 #define TRACE_NAME "commander_test"
4 #include "artdaq-core/Utilities/configureMessageFacility.hh"
5 #include "artdaq/Application/LoadParameterSet.hh"
6 #include "artdaq/DAQdata/Globals.hh"
7 #include "artdaq/ExternalComms/CommanderInterface.hh"
8 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
10 #include "fhiclcpp/types/Atom.h"
11 #include "fhiclcpp/types/Comment.h"
12 #include "fhiclcpp/types/Name.h"
13 #include "fhiclcpp/types/TableFragment.h"
15 #include <boost/thread.hpp>
18 int main(
int argc,
char** argv)
23 fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
25 fhicl::Atom<std::string> partition_number{fhicl::Name{
"partition_number"}, fhicl::Comment{
"Partition to run in"},
""};
27 artdaq::configureMessageFacility(
"commander_test",
true,
true);
28 fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv,
"commander_test",
"A test driver for CommanderInterface plugins");
32 auto id_rand = seedAndRandom();
33 if (config_ps.has_key(
"id"))
35 TLOG(TLVL_DEBUG) <<
"Ignoring set id and using random!";
36 config_ps.erase(
"id");
38 config_ps.put(
"id", artdaq::Globals::partition_number_ * 1000 + (id_rand % 1000));
45 boost::thread commanderThread([&] { commander->run_server(); });
46 while (!commander->GetStatus())
53 fhicl::ParameterSet pset;
55 TLOG(TLVL_INFO) <<
"START";
57 TLOG(TLVL_DEBUG) <<
"Sending init";
58 std::string sts = commander->send_init(pset, arg, arg);
59 TLOG(TLVL_DEBUG) <<
"init res=" << sts;
62 TLOG(TLVL_ERROR) <<
"init returned " << sts <<
", exiting with error";
66 TLOG(TLVL_DEBUG) <<
"Sending soft_init";
67 sts = commander->send_soft_init(pset, arg, arg);
68 TLOG(TLVL_DEBUG) <<
"soft_init res=" << sts;
71 TLOG(TLVL_ERROR) <<
"soft_init returned " << sts <<
", exiting with error";
75 TLOG(TLVL_DEBUG) <<
"Sending legal_commands";
76 sts = commander->send_legal_commands();
77 TLOG(TLVL_DEBUG) <<
"legal_commands res=" << sts;
78 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
80 TLOG(TLVL_ERROR) <<
"legal_commands returned " << sts <<
", exiting with error";
84 TLOG(TLVL_DEBUG) <<
"Sending meta_command";
85 sts = commander->send_meta_command(
"test",
"test");
86 TLOG(TLVL_DEBUG) <<
"meta_command res=" << sts;
89 TLOG(TLVL_ERROR) <<
"meta_command returned " << sts <<
", exiting with error";
93 TLOG(TLVL_DEBUG) <<
"Sending report";
94 sts = commander->send_report(
"test");
95 TLOG(TLVL_DEBUG) <<
"report res=" << sts;
96 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
98 TLOG(TLVL_ERROR) <<
"report returned " << sts <<
", exiting with error";
102 TLOG(TLVL_DEBUG) <<
"Sending start";
103 sts = commander->send_start(art::RunID(0x7357), arg, arg);
104 TLOG(TLVL_DEBUG) <<
"start res=" << sts;
105 if (sts !=
"Success")
107 TLOG(TLVL_ERROR) <<
"start returned " << sts <<
", exiting with error";
111 TLOG(TLVL_DEBUG) <<
"Sending status";
112 sts = commander->send_status();
113 TLOG(TLVL_DEBUG) <<
"status res=" << sts;
114 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
116 TLOG(TLVL_ERROR) <<
"status returned " << sts <<
", exiting with error";
120 TLOG(TLVL_DEBUG) <<
"Sending pause";
121 sts = commander->send_pause(arg, arg);
122 TLOG(TLVL_DEBUG) <<
"pause res=" << sts;
123 if (sts !=
"Success")
125 TLOG(TLVL_ERROR) <<
"pause returned " << sts <<
", exiting with error";
129 TLOG(TLVL_DEBUG) <<
"Sending resume";
130 sts = commander->send_resume(arg, arg);
131 TLOG(TLVL_DEBUG) <<
"resume res=" << sts;
132 if (sts !=
"Success")
134 TLOG(TLVL_ERROR) <<
"resume returned " << sts <<
", exiting with error";
138 TLOG(TLVL_DEBUG) <<
"Sending rollover_subrun";
139 sts = commander->send_rollover_subrun(arg, static_cast<uint32_t>(arg));
140 TLOG(TLVL_DEBUG) <<
"rollover_subrun res=" << sts;
141 if (sts !=
"Success")
143 TLOG(TLVL_ERROR) <<
"rollover_subrun returned " << sts <<
", exiting with error";
147 TLOG(TLVL_DEBUG) <<
"Sending stop";
148 sts = commander->send_stop(arg, arg);
149 TLOG(TLVL_DEBUG) <<
"stop res=" << sts;
150 if (sts !=
"Success")
152 TLOG(TLVL_ERROR) <<
"stop returned " << sts <<
", exiting with error";
156 TLOG(TLVL_DEBUG) <<
"Sending reinit";
157 sts = commander->send_reinit(pset, arg, arg);
158 TLOG(TLVL_DEBUG) <<
"reinit res=" << sts;
159 if (sts !=
"Success")
161 TLOG(TLVL_ERROR) <<
"reinit returned " << sts <<
", exiting with error";
165 TLOG(TLVL_DEBUG) <<
"Sending trace_set";
166 sts = commander->send_trace_set(
"TRACE",
"M",
"0x7357AAAABBBBCCCC");
167 TLOG(TLVL_DEBUG) <<
"trace_set res=" << sts;
168 if (sts !=
"Success")
170 TLOG(TLVL_ERROR) <<
"trace_set returned " << sts <<
", exiting with error";
174 TLOG(TLVL_DEBUG) <<
"Sending trace_get";
175 sts = commander->send_trace_get(
"TRACE");
176 TLOG(TLVL_DEBUG) <<
"trace_get res=" << sts;
177 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
179 TLOG(TLVL_ERROR) <<
"trace_get returned " << sts <<
", exiting with error";
183 TLOG(TLVL_DEBUG) <<
"Sending register_monitor";
184 sts = commander->send_register_monitor(
"unqiue_label: test");
185 TLOG(TLVL_DEBUG) <<
"register_monitor res=" << sts;
186 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
188 TLOG(TLVL_ERROR) <<
"register_monitor returned " << sts <<
", exiting with error";
192 TLOG(TLVL_DEBUG) <<
"Sending unregister_monitor";
193 sts = commander->send_unregister_monitor(
"test");
194 TLOG(TLVL_DEBUG) <<
"unregister_monitor res=" << sts;
195 if (sts.empty() || sts.find(
"Exception", 0) != std::string::npos || sts.find(
"Error", 0) != std::string::npos)
197 TLOG(TLVL_ERROR) <<
"unregister_monitor returned " << sts <<
", exiting with error";
201 TLOG(TLVL_DEBUG) <<
"Sending shutdown";
202 sts = commander->send_shutdown(arg);
203 TLOG(TLVL_DEBUG) <<
"shutdown res=" << sts;
204 if (sts !=
"Success")
206 TLOG(TLVL_ERROR) <<
"shutdown returned " << sts <<
", exiting with error";
210 TLOG(TLVL_INFO) <<
"DONE";
212 if (commanderThread.joinable())
214 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.