artdaq  v3_01_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 "fhiclcpp/ParameterSet.h"
8 #include "artdaq-core/Utilities/configureMessageFacility.hh"
9 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
10 #include "artdaq/Application/BoardReaderApp.hh"
11 #include "artdaq/Application/EventBuilderApp.hh"
12 #include "artdaq/Application/DataLoggerApp.hh"
13 #include "artdaq/Application/DispatcherApp.hh"
14 #include "artdaq/Application/RoutingMasterApp.hh"
15 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
16 
17 #include <sys/prctl.h>
18 
19 namespace artdaq {
20  class artdaqapp {
21  public:
22  static void runArtdaqApp(detail::TaskType task, fhicl::ParameterSet const& config_ps)
23  {
24  app_name = config_ps.get<std::string>("application_name", detail::TaskTypeToString(task));
25 
26  if (config_ps.get<bool>("replace_image_name", config_ps.get<bool>("rin", false)))
27  {
28  int s;
29  s = prctl(PR_SET_NAME, app_name.c_str(), NULL, NULL, NULL);
30  if (s != 0)
31  {
32  std::cerr << "Could not replace process image name with " << app_name << "!" << std::endl;
33  exit(1);
34  }
35  }
36 
37  std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
38  artdaq::configureMessageFacility(mf_app_name.c_str());
39 
40  if (config_ps.has_key("rank")) {
41  my_rank = config_ps.get<int>("rank");
42  }
43  TLOG_DEBUG(app_name + "Main") << "Setting application name to " << app_name ;
44 
45  TLOG_DEBUG(app_name + "Main") << "artdaq version " <<
47  << ", built " <<
49 
50  artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
51 
52  std::unique_ptr<artdaq::Commandable> comm(nullptr);
53  switch (task)
54  {
55  case(detail::BoardReaderTask):
56  comm.reset(new BoardReaderApp());
57  break;
58  case(detail::EventBuilderTask):
59  comm.reset(new EventBuilderApp());
60  break;
61  case(detail::DataLoggerTask):
62  comm.reset(new DataLoggerApp());
63  break;
64  case(detail::DispatcherTask):
65  comm.reset(new DispatcherApp());
66  break;
67  case(detail::RoutingMasterTask):
68  comm.reset(new RoutingMasterApp());
69  break;
70  default:
71  return;
72  }
73 
74  auto auto_run = config_ps.get<bool>("auto_run", false);
75  if (auto_run) {
76  int run = config_ps.get<int>("run_number", 101);
77  uint64_t timeout = config_ps.get<uint64_t>("transition_timeout", 30);
78  uint64_t timestamp = 0;
79 
80  comm->do_initialize(config_ps, timeout, timestamp);
81  comm->do_start(art::RunID(run), timeout, timestamp);
82 
83  TLOG_INFO(app_name + "Main") << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl
84  << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.stop" << std::endl
85  << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.shutdown" ;
86  }
87 
88  auto commander = artdaq::MakeCommanderPlugin(config_ps, *comm.get());
89  commander->run_server();
90  }
91  };
92 }
93 
94 #endif // ARTDAQ_PROTO_ARTDAQAPP_HH
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Definition: Commandable.cc:345
DispatcherApp is an artdaq::Commandable derived class which controls the DispatcherCore.
BoardReaderApp is an artdaq::Commandable derived class which controls the BoardReaderCore state machi...
static artdaq::PackageBuildInfo getPackageBuildInfo()
Gets the version number and build timestmap for artdaq.
DataLoggerApp is an artdaq::Commandable derived class which controls the DataLoggerCore.
EventBuilderApp is an artdaq::Commandable derived class which controls the EventBuilderCore.
std::unique_ptr< artdaq::CommanderInterface > MakeCommanderPlugin(const fhicl::ParameterSet &commander_pset, artdaq::Commandable &commandable)
Load a CommanderInterface plugin.
RoutingMasterApp is an artdaq::Commandable derived class which controls the RoutingMasterCore state m...
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
Definition: Commandable.cc:338
TaskType
The types of applications in artdaq.
Definition: TaskType.hh:17