artdaq  v3_07_01
commander_test.cc
1 #define TRACE_NAME "commander_test"
2 
3 #include "artdaq/ExternalComms/CommanderInterface.hh"
4 
5 #include "artdaq/Application/LoadParameterSet.hh"
6 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
7 
8 #include <boost/thread.hpp>
9 #include "artdaq/DAQdata/Globals.hh"
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  artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number", 1);
23 
24  auto id_rand = seedAndRandom();
25  if (config_ps.has_key("id"))
26  {
27  TLOG(TLVL_DEBUG) << "Ignoring set id and using random!";
28  config_ps.erase("id");
29  }
30  config_ps.put("id", artdaq::Globals::partition_number_ * 1000 + (id_rand % 1000));
31 
32  std::unique_ptr<artdaq::Commandable> cmdble(new artdaq::Commandable());
33 
34  auto commander = artdaq::MakeCommanderPlugin(config_ps, *cmdble.get());
35 
36  // Start server thread
37  boost::thread commanderThread([&] { commander->run_server(); });
38  while (!commander->GetStatus()) usleep(10000);
39  sleep(1);
40 
41  uint64_t arg = 0;
42  fhicl::ParameterSet pset;
43 
44  TLOG(TLVL_DEBUG) << "Sending init";
45  std::string sts = commander->send_init(pset, arg, arg);
46  TLOG(TLVL_DEBUG) << "init res=" << sts << ", sending soft_init";
47  sts = commander->send_soft_init(pset, arg, arg);
48  TLOG(TLVL_DEBUG) << "soft_init res=" << sts << ", sending legal_commands";
49 
50  sts = commander->send_legal_commands();
51  TLOG(TLVL_DEBUG) << "legal_commands res=" << sts << ", sending meta_command";
52  sts = commander->send_meta_command("test", "test");
53  TLOG(TLVL_DEBUG) << "meta_command res=" << sts << ", sending report";
54  sts = commander->send_report("test");
55  TLOG(TLVL_DEBUG) << "report res=" << sts << ", sending start";
56 
57  sts = commander->send_start(art::RunID(0x7357), arg, arg);
58  TLOG(TLVL_DEBUG) << "start res=" << sts << ", sending status";
59  sts = commander->send_status();
60  TLOG(TLVL_DEBUG) << "status res=" << sts << ", sending pause";
61  sts = commander->send_pause(arg, arg);
62  TLOG(TLVL_DEBUG) << "pause res=" << sts << ", sending resume";
63  sts = commander->send_resume(arg, arg);
64  TLOG(TLVL_DEBUG) << "resume res=" << sts << ", sending rollover_subrun";
65  sts = commander->send_rollover_subrun(arg, arg);
66  TLOG(TLVL_DEBUG) << "rollover_subrun res=" << sts << ", sending stop";
67  sts = commander->send_stop(arg, arg);
68  TLOG(TLVL_DEBUG) << "stop res=" << sts << ", sending reinit";
69  sts = commander->send_reinit(pset, arg, arg);
70  TLOG(TLVL_DEBUG) << "reinit res=" << sts << ", sending trace_set";
71 
72  sts = commander->send_trace_set("TRACE", "M", 0x7357);
73  TLOG(TLVL_DEBUG) << "trace_set res=" << sts << ", sending trace_get";
74  sts = commander->send_trace_get("TRACE");
75  TLOG(TLVL_DEBUG) << "trace_get res=" << sts << ", sending register_monitor";
76 
77  sts = commander->send_register_monitor("test");
78  TLOG(TLVL_DEBUG) << "register_monitor res=" << sts << ", sending unregister_monitor";
79  sts = commander->send_unregister_monitor("test");
80  TLOG(TLVL_DEBUG) << "unregister_monitor res=" << sts << ", sending shutdown";
81 
82  sts = commander->send_shutdown(arg);
83  TLOG(TLVL_DEBUG) << "shutdown res=" << sts << ", DONE";
84 
85  if (commanderThread.joinable()) commanderThread.join();
86 }
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:39