$treeview $search $mathjax $extrastylesheet
artdaq
v3_04_01
$projectbrief
|
$projectbrief
|
$searchbox |
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 fhicl::TableFragment<artdaq::PortManager::Config> portsConfig; 00044 }; 00046 using Parameters = fhicl::WrappedTable<Config>; 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 portMan->UpdateConfiguration(config_ps); 00057 00058 if (config_ps.get<bool>("replace_image_name", config_ps.get<bool>("rin", false))) 00059 { 00060 int s; 00061 s = prctl(PR_SET_NAME, app_name.c_str(), NULL, NULL, NULL); 00062 if (s != 0) 00063 { 00064 std::cerr << "Could not replace process image name with " << app_name << "!" << std::endl; 00065 exit(1); 00066 } 00067 } 00068 00069 std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id")); 00070 artdaq::configureMessageFacility(mf_app_name.c_str()); 00071 00072 if (config_ps.has_key("rank")) 00073 { 00074 my_rank = config_ps.get<int>("rank"); 00075 } 00076 TLOG_DEBUG(app_name + "Main") << "Setting application name to " << app_name; 00077 00078 // 23-May-2018, KAB: added lookup of the partition number from the command line arguments. 00079 if (config_ps.has_key("partition_number")) 00080 { 00081 artdaq::Globals::partition_number_ = config_ps.get<int>("partition_number"); 00082 } 00083 TLOG_DEBUG(app_name + "Main") << "Setting partition number to " << artdaq::Globals::partition_number_; 00084 00085 TLOG_DEBUG(app_name + "Main") << "artdaq version " << 00086 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion() 00087 << ", built " << 00088 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp(); 00089 00090 artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id")); 00091 00092 std::unique_ptr<artdaq::Commandable> comm(nullptr); 00093 switch (task) 00094 { 00095 case(detail::BoardReaderTask): 00096 comm.reset(new BoardReaderApp()); 00097 break; 00098 case(detail::EventBuilderTask): 00099 comm.reset(new EventBuilderApp()); 00100 break; 00101 case(detail::DataLoggerTask): 00102 comm.reset(new DataLoggerApp()); 00103 break; 00104 case(detail::DispatcherTask): 00105 comm.reset(new DispatcherApp()); 00106 break; 00107 case(detail::RoutingMasterTask): 00108 comm.reset(new RoutingMasterApp()); 00109 break; 00110 default: 00111 return; 00112 } 00113 00114 auto auto_run = config_ps.get<bool>("auto_run", false); 00115 if (auto_run) 00116 { 00117 int run = config_ps.get<int>("run_number", 101); 00118 uint64_t timeout = config_ps.get<uint64_t>("transition_timeout", 30); 00119 uint64_t timestamp = 0; 00120 00121 comm->do_initialize(config_ps, timeout, timestamp); 00122 comm->do_start(art::RunID(run), timeout, timestamp); 00123 00124 TLOG_INFO(app_name + "Main") << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl 00125 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.stop" << std::endl 00126 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.shutdown"; 00127 } 00128 00129 auto commander = artdaq::MakeCommanderPlugin(config_ps, *comm.get()); 00130 commander->run_server(); 00131 artdaq::Globals::CleanUpGlobals(); 00132 } 00133 00134 }; 00135 } 00136 00137 #endif // ARTDAQ_PROTO_ARTDAQAPP_HH