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 "fhiclcpp/ParameterSet.h" 00008 #include "artdaq-core/Utilities/configureMessageFacility.hh" 00009 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh" 00010 #include "artdaq/Application/BoardReaderApp.hh" 00011 #include "artdaq/Application/EventBuilderApp.hh" 00012 #include "artdaq/Application/DataLoggerApp.hh" 00013 #include "artdaq/Application/DispatcherApp.hh" 00014 #include "artdaq/Application/RoutingMasterApp.hh" 00015 #include "artdaq/ExternalComms/MakeCommanderPlugin.hh" 00016 00017 #include <sys/prctl.h> 00018 00019 namespace artdaq { 00020 class artdaqapp { 00021 public: 00022 static void runArtdaqApp(detail::TaskType task, fhicl::ParameterSet const& config_ps) 00023 { 00024 app_name = config_ps.get<std::string>("application_name", detail::TaskTypeToString(task)); 00025 00026 if (config_ps.get<bool>("replace_image_name", config_ps.get<bool>("rin", false))) 00027 { 00028 int s; 00029 s = prctl(PR_SET_NAME, app_name.c_str(), NULL, NULL, NULL); 00030 if (s != 0) 00031 { 00032 std::cerr << "Could not replace process image name with " << app_name << "!" << std::endl; 00033 exit(1); 00034 } 00035 } 00036 00037 std::string mf_app_name = artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id")); 00038 artdaq::configureMessageFacility(mf_app_name.c_str()); 00039 00040 if (config_ps.has_key("rank")) { 00041 my_rank = config_ps.get<int>("rank"); 00042 } 00043 TLOG_DEBUG(app_name + "Main") << "Setting application name to " << app_name ; 00044 00045 TLOG_DEBUG(app_name + "Main") << "artdaq version " << 00046 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion() 00047 << ", built " << 00048 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp() ; 00049 00050 artdaq::setMsgFacAppName(app_name, config_ps.get<int>("id")); 00051 00052 std::unique_ptr<artdaq::Commandable> comm(nullptr); 00053 switch (task) 00054 { 00055 case(detail::BoardReaderTask): 00056 comm.reset(new BoardReaderApp()); 00057 break; 00058 case(detail::EventBuilderTask): 00059 comm.reset(new EventBuilderApp()); 00060 break; 00061 case(detail::DataLoggerTask): 00062 comm.reset(new DataLoggerApp()); 00063 break; 00064 case(detail::DispatcherTask): 00065 comm.reset(new DispatcherApp()); 00066 break; 00067 case(detail::RoutingMasterTask): 00068 comm.reset(new RoutingMasterApp()); 00069 break; 00070 default: 00071 return; 00072 } 00073 00074 auto auto_run = config_ps.get<bool>("auto_run", false); 00075 if (auto_run) { 00076 int run = config_ps.get<int>("run_number", 101); 00077 uint64_t timeout = config_ps.get<uint64_t>("transition_timeout", 30); 00078 uint64_t timestamp = 0; 00079 00080 comm->do_initialize(config_ps, timeout, timestamp); 00081 comm->do_start(art::RunID(run), timeout, timestamp); 00082 00083 TLOG_INFO(app_name + "Main") << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl 00084 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.stop" << std::endl 00085 << "xmlrpc http://`hostname`:" << config_ps.get<int>("id") << "/RPC2 daq.shutdown" ; 00086 } 00087 00088 auto commander = artdaq::MakeCommanderPlugin(config_ps, *comm.get()); 00089 commander->run_server(); 00090 } 00091 }; 00092 } 00093 00094 #endif // ARTDAQ_PROTO_ARTDAQAPP_HH