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 { 00019 00020 class artdaqapp 00021 { 00022 public: 00023 struct Config 00024 { 00025 fhicl::Atom<std::string> application_name{ fhicl::Name{ "application_name" }, fhicl::Comment{ "Name to use for metrics and logging" }, "BoardReader" }; 00026 fhicl::Atom<bool> replace_image_name{ fhicl::Name{ "replace_image_name" }, fhicl::Comment{ "Replace the application image name with application_name" }, false }; 00027 fhicl::Atom<int> rank{ fhicl::Name{ "rank" }, fhicl::Comment{ "The \"rank\" of the application, used for configuring data transfers" } }; 00028 fhicl::TableFragment<artdaq::CommanderInterface::Config> commanderPluginConfig; 00029 fhicl::Atom<bool> auto_run{ fhicl::Name{"auto_run"}, fhicl::Comment{"Whether to automatically start a run"}, false }; 00030 fhicl::Atom<int> run_number{ fhicl::Name{"run_number"}, fhicl::Comment{"Run number to use for automatic run"}, 101 }; 00031 fhicl::Atom<uint64_t> transition_timeout{ fhicl::Name{"trantition_timeout"}, fhicl::Comment{"Timeout to use for automatic transitions"}, 30 }; 00032 }; 00033 #if MESSAGEFACILITY_HEX_VERSION >= 0x20103 00034 using Parameters = fhicl::WrappedTable<Config>; 00035 #endif 00036 00037 static void runArtdaqApp(detail::TaskType task, fhicl::ParameterSet const& config_ps) 00038 { 00039 app_name = config_ps.get<std::string>("application_name", detail::TaskTypeToString(task)); 00040 00041 if (config_ps.get<bool>("replace_image_name", config_ps.get<bool>("rin", false))) 00042 { 00043 int s; 00044 s = prctl(PR_SET_NAME, app_name.c_str(), NULL, NULL, NULL); 00045 if (s != 0) 00046 { 00047 std::cerr << "Could not replace process image name with " << app_name << "!" << std::endl; 00048 exit(1); 00049 } 00050 } 00051 00052 std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id")); 00053 artdaq::configureMessageFacility(mf_app_name.c_str()); 00054 00055 if (config_ps.has_key("rank")) 00056 { 00057 my_rank = config_ps.get<int>("rank"); 00058 } 00059 TLOG_DEBUG(app_name + "Main") << "Setting application name to " << app_name; 00060 00061 TLOG_DEBUG(app_name + "Main") << "artdaq version " << 00062 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion() 00063 << ", built " << 00064 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp(); 00065 00066 artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id")); 00067 00068 std::unique_ptr<artdaq::Commandable> comm(nullptr); 00069 switch (task) 00070 { 00071 case(detail::BoardReaderTask): 00072 comm.reset(new BoardReaderApp()); 00073 break; 00074 case(detail::EventBuilderTask): 00075 comm.reset(new EventBuilderApp()); 00076 break; 00077 case(detail::DataLoggerTask): 00078 comm.reset(new DataLoggerApp()); 00079 break; 00080 case(detail::DispatcherTask): 00081 comm.reset(new DispatcherApp()); 00082 break; 00083 case(detail::RoutingMasterTask): 00084 comm.reset(new RoutingMasterApp()); 00085 break; 00086 default: 00087 return; 00088 } 00089 00090 auto auto_run = config_ps.get<bool>("auto_run", false); 00091 if (auto_run) 00092 { 00093 int run = config_ps.get<int>("run_number", 101); 00094 uint64_t timeout = config_ps.get<uint64_t>("transition_timeout", 30); 00095 uint64_t timestamp = 0; 00096 00097 comm->do_initialize(config_ps, timeout, timestamp); 00098 comm->do_start(art::RunID(run), timeout, timestamp); 00099 00100 TLOG_INFO(app_name + "Main") << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl 00101 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.stop" << std::endl 00102 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.shutdown"; 00103 } 00104 00105 auto commander = artdaq::MakeCommanderPlugin(config_ps, *comm.get()); 00106 commander->run_server(); 00107 } 00108 }; 00109 } 00110 00111 #endif // ARTDAQ_PROTO_ARTDAQAPP_HH