artdaq  v3_05_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 {
22  class artdaqapp
23  {
24  public:
28  struct Config
29  {
31  fhicl::Atom<std::string> application_name{ fhicl::Name{ "application_name" }, fhicl::Comment{ "Name to use for metrics and logging" }, "BoardReader" };
33  fhicl::Atom<bool> replace_image_name{ fhicl::Name{ "replace_image_name" }, fhicl::Comment{ "Replace the application image name with application_name" }, false };
35  fhicl::Atom<int> rank{ fhicl::Name{ "rank" }, fhicl::Comment{ "The \"rank\" of the application, used for configuring data transfers" } };
36  fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
37  fhicl::Atom<bool> auto_run{ fhicl::Name{"auto_run"}, fhicl::Comment{"Whether to automatically start a run"}, false };
40  fhicl::Atom<int> run_number{ fhicl::Name{"run_number"}, fhicl::Comment{"Run number to use for automatic run"}, 101 };
42  fhicl::Atom<uint64_t> transition_timeout{ fhicl::Name{"transition_timeout"}, fhicl::Comment{"Timeout to use for automatic transitions"}, 30 };
43  fhicl::TableFragment<artdaq::PortManager::Config> portsConfig;
44  };
46  using Parameters = fhicl::WrappedTable<Config>;
47 
53  static void runArtdaqApp(detail::TaskType task, fhicl::ParameterSet const& config_ps)
54  {
55  app_name = config_ps.get<std::string>("application_name", detail::TaskTypeToString(task));
56  portMan->UpdateConfiguration(config_ps);
57 
58  if (config_ps.get<bool>("replace_image_name", config_ps.get<bool>("rin", false)))
59  {
60  int s;
61  s = prctl(PR_SET_NAME, app_name.c_str(), NULL, NULL, NULL);
62  if (s != 0)
63  {
64  std::cerr << "Could not replace process image name with " << app_name << "!" << std::endl;
65  exit(1);
66  }
67  }
68 
69  std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
70  artdaq::configureMessageFacility(mf_app_name.c_str());
71 
72  if (config_ps.has_key("rank"))
73  {
74  my_rank = config_ps.get<int>("rank");
75  }
76  TLOG_DEBUG(app_name + "Main") << "Setting application name to " << app_name;
77 
78  // 23-May-2018, KAB: added lookup of the partition number from the command line arguments.
79  if (config_ps.has_key("partition_number"))
80  {
81  artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number");
82  }
83  TLOG_DEBUG(app_name + "Main") << "Setting partition number to " << artdaq::Globals::partition_number_;
84 
85  TLOG_DEBUG(app_name + "Main") << "artdaq version " <<
87  << ", built " <<
89 
90  artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
91 
92  std::unique_ptr<artdaq::Commandable> comm(nullptr);
93  switch (task)
94  {
95  case(detail::BoardReaderTask):
96  comm.reset(new BoardReaderApp());
97  break;
98  case(detail::EventBuilderTask):
99  comm.reset(new EventBuilderApp());
100  break;
101  case(detail::DataLoggerTask):
102  comm.reset(new DataLoggerApp());
103  break;
104  case(detail::DispatcherTask):
105  comm.reset(new DispatcherApp());
106  break;
107  case(detail::RoutingMasterTask):
108  comm.reset(new RoutingMasterApp());
109  break;
110  default:
111  return;
112  }
113 
114  auto auto_run = config_ps.get<bool>("auto_run", false);
115  if (auto_run)
116  {
117  int run = config_ps.get<int>("run_number", 101);
118  uint64_t timeout = config_ps.get<uint64_t>("transition_timeout", 30);
119  uint64_t timestamp = 0;
120 
121  comm->do_initialize(config_ps, timeout, timestamp);
122  comm->do_start(art::RunID(run), timeout, timestamp);
123 
124  TLOG_INFO(app_name + "Main") << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl
125  << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.stop" << std::endl
126  << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.shutdown";
127  }
128 
129  auto commander = artdaq::MakeCommanderPlugin(config_ps, *comm.get());
130  commander->run_server();
132  }
133 
134  };
135 }
136 
137 #endif // ARTDAQ_PROTO_ARTDAQAPP_HH
virtual bool do_start(art::RunID, uint64_t, uint64_t)
Perform the start transition.
Definition: Commandable.cc:326
fhicl::Atom< int > run_number
&quot;run_number&quot; (Default: 101): Run number to use for automatic run
Definition: artdaqapp.hh:40
DispatcherApp is an artdaq::Commandable derived class which controls the DispatcherCore.
BoardReaderApp is an artdaq::Commandable derived class which controls the BoardReaderCore state machi...
fhicl::Atom< bool > auto_run
&quot;auto_run&quot; (Default: false): Whether to automatically start a run
Definition: artdaqapp.hh:38
static void CleanUpGlobals()
Clean up statically-allocated Manager class instances.
Definition: Globals.hh:150
static artdaq::PackageBuildInfo getPackageBuildInfo()
Gets the version number and build timestmap for artdaq.
Class representing an artdaq application. Used by all &quot;main&quot; functions to start artdaq.
Definition: artdaqapp.hh:22
DataLoggerApp is an artdaq::Commandable derived class which controls the DataLoggerCore.
fhicl::TableFragment< artdaq::PortManager::Config > portsConfig
Configuration for artdaq Ports.
Definition: artdaqapp.hh:43
EventBuilderApp is an artdaq::Commandable derived class which controls the EventBuilderCore.
fhicl::Atom< uint64_t > transition_timeout
&quot;transition_timeout&quot; (Default: 30): Timeout to use for automatic transitions
Definition: artdaqapp.hh:42
fhicl::Atom< std::string > application_name
&quot;application_name&quot; (Default: artdaq::detail::TaskTypeToString(task)): Name to use for metrics and log...
Definition: artdaqapp.hh:31
std::unique_ptr< artdaq::CommanderInterface > MakeCommanderPlugin(const fhicl::ParameterSet &commander_pset, artdaq::Commandable &commandable)
Load a CommanderInterface plugin.
std::string TaskTypeToString(TaskType const &task)
Convert a TaskType to string representation
Definition: TaskType.hh:67
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation (if desired)
Definition: artdaqapp.hh:46
RoutingMasterApp is an artdaq::Commandable derived class which controls the RoutingMasterCore state m...
fhicl::TableFragment< artdaq::CommanderInterface::Config > commanderPluginConfig
Definition: artdaqapp.hh:36
fhicl::Atom< int > rank
&quot;rank&quot;: The &quot;rank&quot; of the application, used for configuring data transfers
Definition: artdaqapp.hh:35
static void runArtdaqApp(detail::TaskType task, fhicl::ParameterSet const &config_ps)
Run an artdaq Application
Definition: artdaqapp.hh:53
static int partition_number_
The partition number of the current application.
Definition: Globals.hh:41
fhicl::Atom< bool > replace_image_name
&quot;replace_image_name&quot; (Default: false): Replace the application image name with application_name ...
Definition: artdaqapp.hh:33
Configuration of artdaqapp. May be used for parameter validation
Definition: artdaqapp.hh:28
virtual bool do_initialize(fhicl::ParameterSet const &, uint64_t, uint64_t)
Perform the initialize transition.
Definition: Commandable.cc:319
TaskType
The types of applications in artdaq.
Definition: TaskType.hh:19