artdaq  v3_02_00
artdaqapp.hh
1 #ifndef ARTDAQ_PROTO_ARTDAQAPP_HH
2 #define ARTDAQ_PROTO_ARTDAQAPP_HH
3 
4 #include "artdaq/DAQdata/Globals.hh"
5 
6 #include "artdaq/Application/TaskType.hh"
7 #include "artdaq-core/Utilities/configureMessageFacility.hh"
8 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
9 #include "artdaq/Application/BoardReaderApp.hh"
10 #include "artdaq/Application/EventBuilderApp.hh"
11 #include "artdaq/Application/DataLoggerApp.hh"
12 #include "artdaq/Application/DispatcherApp.hh"
13 #include "artdaq/Application/RoutingMasterApp.hh"
14 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
15 
16 #include <sys/prctl.h>
17 
18 namespace artdaq {
19 
20  class artdaqapp
21  {
22  public:
23  struct Config
24  {
25  fhicl::Atom<std::string> application_name{ fhicl::Name{ "application_name" }, fhicl::Comment{ "Name to use for metrics and logging" }, "BoardReader" };
26  fhicl::Atom<bool> replace_image_name{ fhicl::Name{ "replace_image_name" }, fhicl::Comment{ "Replace the application image name with application_name" }, false };
27  fhicl::Atom<int> rank{ fhicl::Name{ "rank" }, fhicl::Comment{ "The \"rank\" of the application, used for configuring data transfers" } };
28  fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
29  fhicl::Atom<bool> auto_run{ fhicl::Name{"auto_run"}, fhicl::Comment{"Whether to automatically start a run"}, false };
30  fhicl::Atom<int> run_number{ fhicl::Name{"run_number"}, fhicl::Comment{"Run number to use for automatic run"}, 101 };
31  fhicl::Atom<uint64_t> transition_timeout{ fhicl::Name{"trantition_timeout"}, fhicl::Comment{"Timeout to use for automatic transitions"}, 30 };
32  };
33 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
34  using Parameters = fhicl::WrappedTable<Config>;
35 #endif
36 
37  static void runArtdaqApp(detail::TaskType task, fhicl::ParameterSet const& config_ps)
38  {
39  app_name = config_ps.get<std::string>("application_name", detail::TaskTypeToString(task));
40 
41  if (config_ps.get<bool>("replace_image_name", config_ps.get<bool>("rin", false)))
42  {
43  int s;
44  s = prctl(PR_SET_NAME, app_name.c_str(), NULL, NULL, NULL);
45  if (s != 0)
46  {
47  std::cerr << "Could not replace process image name with " << app_name << "!" << std::endl;
48  exit(1);
49  }
50  }
51 
52  std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
53  artdaq::configureMessageFacility(mf_app_name.c_str());
54 
55  if (config_ps.has_key("rank"))
56  {
57  my_rank = config_ps.get<int>("rank");
58  }
59  TLOG_DEBUG(app_name + "Main") << "Setting application name to " << app_name;
60 
61  TLOG_DEBUG(app_name + "Main") << "artdaq version " <<
63  << ", built " <<
65 
66  artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
67 
68  std::unique_ptr<artdaq::Commandable> comm(nullptr);
69  switch (task)
70  {
71  case(detail::BoardReaderTask):
72  comm.reset(new BoardReaderApp());
73  break;
74  case(detail::EventBuilderTask):
75  comm.reset(new EventBuilderApp());
76  break;
77  case(detail::DataLoggerTask):
78  comm.reset(new DataLoggerApp());
79  break;
80  case(detail::DispatcherTask):
81  comm.reset(new DispatcherApp());
82  break;
83  case(detail::RoutingMasterTask):
84  comm.reset(new RoutingMasterApp());
85  break;
86  default:
87  return;
88  }
89 
90  auto auto_run = config_ps.get<bool>("auto_run", false);
91  if (auto_run)
92  {
93  int run = config_ps.get<int>("run_number", 101);
94  uint64_t timeout = config_ps.get<uint64_t>("transition_timeout", 30);
95  uint64_t timestamp = 0;
96 
97  comm->do_initialize(config_ps, timeout, timestamp);
98  comm->do_start(art::RunID(run), timeout, timestamp);
99 
100  TLOG_INFO(app_name + "Main") << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl
101  << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.stop" << std::endl
102  << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.shutdown";
103  }
104 
105  auto commander = artdaq::MakeCommanderPlugin(config_ps, *comm.get());
106  commander->run_server();
107  }
108  };
109 }
110 
111 #endif // ARTDAQ_PROTO_ARTDAQAPP_HH
static artdaq::PackageBuildInfo getPackageBuildInfo()
Gets the version number and build timestmap for artdaq.
std::unique_ptr< artdaq::CommanderInterface > MakeCommanderPlugin(const fhicl::ParameterSet &commander_pset, artdaq::Commandable &commandable)
Load a CommanderInterface plugin.
TaskType
The types of applications in artdaq.
Definition: TaskType.hh:17