artdaq  v3_03_00
commander_test.cc
1 #define TRACE_NAME "commander_test"
2 
3 #include "artdaq/ExternalComms/CommanderInterface.hh"
4 
5 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
6 #include "artdaq/Application/LoadParameterSet.hh"
7 
8 #include "artdaq/DAQdata/Globals.hh"
9 #include <boost/thread.hpp>
10 
11 int main(int argc, char** argv)
12 {
13  struct Config
14  {
15  fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
16 
17  fhicl::Atom<std::string> partition_number{ fhicl::Name{ "partition_number" }, fhicl::Comment{ "Partition to run in" }, "" };
18  };
19  artdaq::configureMessageFacility("transfer_driver");
20  fhicl::ParameterSet config_ps = LoadParameterSet<Config>(argc, argv, "commander_test", "A test driver for CommanderInterface plugins");
21 
22 
23  if (config_ps.has_key("partition_number")) artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number");
24 
25  std::unique_ptr<artdaq::Commandable> cmdble(new artdaq::Commandable());
26 
27  auto commander = artdaq::MakeCommanderPlugin(config_ps, *cmdble.get());
28 
29  // Start server thread
30  boost::thread commanderThread([&] { commander->run_server(); });
31  while (!commander->GetStatus()) usleep(10000);
32 
33  uint64_t arg = 0;
34  fhicl::ParameterSet pset;
35 
36  TLOG(TLVL_DEBUG) << "Sending init";
37  std::string sts = commander->send_init(pset, arg, arg);
38  TLOG(TLVL_DEBUG) << "init res=" << sts << ", sending soft_init";
39  sts = commander->send_soft_init(pset,arg,arg);
40  TLOG(TLVL_DEBUG) << "soft_init res=" << sts << ", sending legal_commands";
41 
42  sts = commander->send_legal_commands();
43  TLOG(TLVL_DEBUG) << "legal_commands res=" << sts << ", sending meta_command";
44  sts = commander->send_meta_command("test","test");
45  TLOG(TLVL_DEBUG) << "meta_command res=" << sts << ", sending report";
46  sts = commander->send_report("test");
47  TLOG(TLVL_DEBUG) << "report res=" << sts << ", sending start";
48 
49  sts = commander->send_start(art::RunID(0x7357),arg,arg);
50  TLOG(TLVL_DEBUG) << "start res=" << sts << ", sending status";
51  sts = commander->send_status();
52  TLOG(TLVL_DEBUG) << "status res=" << sts << ", sending pause";
53  sts = commander->send_pause(arg,arg);
54  TLOG(TLVL_DEBUG) << "pause res=" << sts << ", sending resume";
55  sts = commander->send_resume(arg,arg);
56  TLOG(TLVL_DEBUG) << "resume res=" << sts << ", sending rollover_subrun";
57  sts = commander->send_rollover_subrun(arg);
58  TLOG(TLVL_DEBUG) << "rollover_subrun res=" << sts << ", sending stop";
59  sts = commander->send_stop(arg,arg);
60  TLOG(TLVL_DEBUG) << "stop res=" << sts << ", sending reinit";
61  sts = commander->send_reinit(pset, arg, arg);
62  TLOG(TLVL_DEBUG) << "reinit res=" << sts << ", sending trace_set";
63 
64  sts = commander->send_trace_set("TRACE", "M", 0x7357);
65  TLOG(TLVL_DEBUG) << "trace_set res=" << sts << ", sending trace_get";
66  sts = commander->send_trace_get("TRACE");
67  TLOG(TLVL_DEBUG) << "trace_get res=" << sts << ", sending register_monitor";
68 
69  sts = commander->send_register_monitor("test");
70  TLOG(TLVL_DEBUG) << "register_monitor res=" << sts << ", sending unregister_monitor";
71  sts = commander->send_unregister_monitor("test");
72  TLOG(TLVL_DEBUG) << "unregister_monitor res=" << sts << ", sending shutdown";
73 
74  sts = commander->send_shutdown(arg);
75  TLOG(TLVL_DEBUG) << "shutdown res=" << sts << ", DONE";
76 
77  if(commanderThread.joinable()) commanderThread.join();
78 }
Commandable is the base class for all artdaq components which implement the artdaq state machine...
Definition: Commandable.hh:20
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.
Definition: Globals.hh:41