00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "artdaq-core/Data/Fragment.hh"
00013 #include "artdaq-core/Utilities/ExceptionHandler.hh"
00014
00015 #include "artdaq/DAQdata/Globals.hh"
00016 #include "artdaq-utilities/Plugins/MetricManager.hh"
00017 #include "cetlib/container_algorithms.h"
00018 #include "cetlib/filepath_maker.h"
00019 #include "fhiclcpp/ParameterSet.h"
00020 #include "fhiclcpp/make_ParameterSet.h"
00021 #include "boost/program_options.hpp"
00022
00023 #include <signal.h>
00024 #include <iostream>
00025 #include <memory>
00026 #include <utility>
00027 #include <artdaq/Application/AggregatorApp.hh>
00028 #include <artdaq/ExternalComms/xmlrpc_commander.hh>
00029 #include <artdaq/BuildInfo/GetPackageBuildInfo.hh>
00030
00031 int main(int argc, char * argv[])
00032 {
00033 std::ostringstream descstr;
00034 descstr << argv[0]
00035 << " <-p <port-number>> <-r <rank>> [-n <name>] [-c <config-file>]";
00036 boost::program_options::options_description desc(descstr.str());
00037 desc.add_options()
00038 ("config,c", boost::program_options::value<std::string>(), "Configuration file.")
00039 ("rank,r", boost::program_options::value<int>(), "Process Rank")
00040 ("port,p", boost::program_options::value<unsigned short>(), "Port number")
00041 ("name,n", boost::program_options::value<std::string>(), "Application Nickname")
00042 ("help,h", "produce help message");
00043 boost::program_options::variables_map vm;
00044 try {
00045 boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).run(), vm);
00046 boost::program_options::notify(vm);
00047 }
00048 catch (boost::program_options::error const & e) {
00049 std::cerr << "Exception from command line processing in " << argv[0]
00050 << ": " << e.what() << "\n";
00051 return -1;
00052 }
00053 if (vm.count("help")) {
00054 std::cout << desc << std::endl;
00055 return 1;
00056 }
00057
00058 if (!vm.count("port"))
00059 {
00060 TLOG_ERROR("Option") << argv[0] << " port number not supplied" << std::endl << "For usage and an options list, please do '" << argv[0] << " --help'" << TLOG_ENDL;
00061 return 1;
00062 }
00063
00064 if (!vm.count("rank"))
00065 {
00066 TLOG_ERROR("Option") << argv[0] << " rank not supplied" << std::endl << "For usage and an options list, please do '" << argv[0] << " --help'" << TLOG_ENDL;
00067 return 2;
00068 }
00069 auto rank = vm["rank"].as<int>();
00070
00071 std::string name = "Aggregator";
00072 if (vm.count("name"))
00073 {
00074 name = vm["name"].as<std::string>();
00075 TLOG_DEBUG(name + "Main") << "Setting application name to " << name << TLOG_ENDL;
00076 }
00077
00078 artdaq::setMsgFacAppName(name, vm["port"].as<unsigned short>());
00079 TLOG_DEBUG(name + "Main") << "artdaq version " <<
00080 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getPackageVersion()
00081 << ", built " <<
00082 artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp() << TLOG_ENDL;
00083
00084
00085 artdaq::AggregatorApp agg_app(rank, name);
00086
00087 if (vm.count("config")) {
00088 fhicl::ParameterSet pset;
00089 if (getenv("FHICL_FILE_PATH") == nullptr) {
00090 std::cerr
00091 << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
00092 setenv("FHICL_FILE_PATH", ".", 0);
00093 }
00094 cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
00095 make_ParameterSet(vm["config"].as<std::string>(), lookup_policy, pset);
00096
00097 int run = pset.get<int>("run_number", 101);
00098 uint64_t timeout = pset.get<uint64_t>("transition_timeout", 30);
00099 uint64_t timestamp = 0;
00100
00101 agg_app.do_initialize(pset, timeout, timestamp);
00102 agg_app.do_start(art::RunID(run), timeout, timestamp);
00103
00104 TLOG_INFO(name) << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl
00105 << "xmlrpc http://`hostname`:" << vm["port"].as<unsigned short>() << "/RPC2 daq.stop" << std::endl
00106 << "xmlrpc http://`hostname`:" << vm["port"].as<unsigned short>() << "/RPC2 daq.shutdown" << TLOG_ENDL;
00107 }
00108
00109
00110 artdaq::xmlrpc_commander commander(vm["port"].as<unsigned short>(), agg_app);
00111 commander.run();
00112
00113 }