00001 #ifndef ARTDAQ_PROTO_ARTDAQAPP_HH
00002 #define ARTDAQ_PROTO_ARTDAQAPP_HH
00003
00004 #include "artdaq/DAQdata/Globals.hh"
00005
00006 #include "artdaq/Application/TaskType.hh"
00007 #include "artdaq-core/Utilities/configureMessageFacility.hh"
00008 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
00009 #include "artdaq/Application/BoardReaderApp.hh"
00010 #include "artdaq/Application/EventBuilderApp.hh"
00011 #include "artdaq/Application/DataLoggerApp.hh"
00012 #include "artdaq/Application/DispatcherApp.hh"
00013 #include "artdaq/Application/RoutingMasterApp.hh"
00014 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh"
00015
00016 #include <sys/prctl.h>
00017
00018 namespace artdaq {
00022 class artdaqapp
00023 {
00024 public:
00028 struct Config
00029 {
00031 fhicl::Atom<std::string> application_name{ fhicl::Name{ "application_name" }, fhicl::Comment{ "Name to use for metrics and logging" }, "BoardReader" };
00033 fhicl::Atom<bool> replace_image_name{ fhicl::Name{ "replace_image_name" }, fhicl::Comment{ "Replace the application image name with application_name" }, false };
00035 fhicl::Atom<int> rank{ fhicl::Name{ "rank" }, fhicl::Comment{ "The \"rank\" of the application, used for configuring data transfers" } };
00036 fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig;
00037
00038 fhicl::Atom<bool> auto_run{ fhicl::Name{"auto_run"}, fhicl::Comment{"Whether to automatically start a run"}, false };
00040 fhicl::Atom<int> run_number{ fhicl::Name{"run_number"}, fhicl::Comment{"Run number to use for automatic run"}, 101 };
00042 fhicl::Atom<uint64_t> transition_timeout{ fhicl::Name{"transition_timeout"}, fhicl::Comment{"Timeout to use for automatic transitions"}, 30 };
00043 };
00044 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103
00045 using Parameters = fhicl::WrappedTable<Config>;
00046 #endif
00047
00053 static void runArtdaqApp(detail::TaskType task, fhicl::ParameterSet const& config_ps)
00054 {
00055 app_name = config_ps.get<std::string>("application_name", detail::TaskTypeToString(task));
00056
00057 if (config_ps.get<bool>("replace_image_name", config_ps.get<bool>("rin", false)))
00058 {
00059 int s;
00060 s = prctl(PR_SET_NAME, app_name.c_str(), NULL, NULL, NULL);
00061 if (s != 0)
00062 {
00063 std::cerr << "Could not replace process image name with " << app_name << "!" << std::endl;
00064 exit(1);
00065 }
00066 }
00067
00068 std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
00069 artdaq::configureMessageFacility(mf_app_name.c_str());
00070
00071 if (config_ps.has_key("rank"))
00072 {
00073 my_rank = config_ps.get<int>("rank");
00074 }
00075 TLOG_DEBUG(app_name + "Main") << "Setting application name to " << app_name;
00076
00077
00078 if (config_ps.has_key("partition_number"))
00079 {
00080 artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number");
00081 }
00082 TLOG_DEBUG(app_name + "Main") << "Setting partition number to " << artdaq::Globals::partition_number_;
00083
00084 TLOG_DEBUG(app_name + "Main") << "artdaq version " <<
00085 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion()
00086 << ", built " <<
00087 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp();
00088
00089 artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id"));
00090
00091 std::unique_ptr<artdaq::Commandable> comm(nullptr);
00092 switch (task)
00093 {
00094 case(detail::BoardReaderTask):
00095 comm.reset(new BoardReaderApp());
00096 break;
00097 case(detail::EventBuilderTask):
00098 comm.reset(new EventBuilderApp());
00099 break;
00100 case(detail::DataLoggerTask):
00101 comm.reset(new DataLoggerApp());
00102 break;
00103 case(detail::DispatcherTask):
00104 comm.reset(new DispatcherApp());
00105 break;
00106 case(detail::RoutingMasterTask):
00107 comm.reset(new RoutingMasterApp());
00108 break;
00109 default:
00110 return;
00111 }
00112
00113 auto auto_run = config_ps.get<bool>("auto_run", false);
00114 if (auto_run)
00115 {
00116 int run = config_ps.get<int>("run_number", 101);
00117 uint64_t timeout = config_ps.get<uint64_t>("transition_timeout", 30);
00118 uint64_t timestamp = 0;
00119
00120 comm->do_initialize(config_ps, timeout, timestamp);
00121 comm->do_start(art::RunID(run), timeout, timestamp);
00122
00123 TLOG_INFO(app_name + "Main") << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl
00124 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.stop" << std::endl
00125 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.shutdown";
00126 }
00127
00128 auto commander = artdaq::MakeCommanderPlugin(config_ps, *comm.get());
00129 commander->run_server();
00130 }
00131 };
00132 }
00133
00134 #endif // ARTDAQ_PROTO_ARTDAQAPP_HH