artdaq  v2_03_02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
AggregatorMain.cc
1 #include <iostream>
2 #include <boost/program_options.hpp>
3 #include <boost/lexical_cast.hpp>
4 #include "artdaq/Application/TaskType.hh"
5 #include "artdaq/DAQdata/Globals.hh"
6 #include "artdaq/Application/AggregatorApp.hh"
7 #include "artdaq/ExternalComms/xmlrpc_commander.hh"
8 #include "artdaq/Application/MPI2/MPISentry.hh"
10 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
11 #include "cetlib/exception.h"
12 
13 int main(int argc, char* argv[])
14 {
16 
17  // initialization
18 
19  int const wanted_threading_level{MPI_THREAD_FUNNELED};
20 
21  MPI_Comm local_group_comm;
22  std::unique_ptr<artdaq::MPISentry> mpiSentry;
23 
24  try
25  {
26  mpiSentry.reset(new artdaq::MPISentry(&argc, &argv, wanted_threading_level, artdaq::TaskType::AggregatorTask, local_group_comm));
27  }
28  catch (cet::exception& errormsg)
29  {
30  TLOG_ERROR("AggregatorMain") << errormsg << TLOG_ENDL;
31  TLOG_ERROR("AggregatorMain") << "MPISentry error encountered in AggregatorMain; exiting..." << TLOG_ENDL;
32  throw errormsg;
33  }
34 
35 
36  // handle the command-line arguments
37  std::string usage = std::string(argv[0]) + " -p port_number -n name <other-options>";
38  boost::program_options::options_description desc(usage);
39 
40  desc.add_options()
41  ("port,p", boost::program_options::value<unsigned short>(), "Port number")
42  ("name,n", boost::program_options::value<std::string>(), "Application Nickname")
43  ("help,h", "produce help message");
44 
45  boost::program_options::variables_map vm;
46  try
47  {
48  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).run(), vm);
49  boost::program_options::notify(vm);
50  }
51  catch (boost::program_options::error const& e)
52  {
53  TLOG_ERROR("Option") << "exception from command line processing in " << argv[0] << ": " << e.what() << TLOG_ENDL;
54  return 1;
55  }
56 
57  if (vm.count("help"))
58  {
59  std::cout << desc << std::endl;
60  return 0;
61  }
62 
63  if (!vm.count("port"))
64  {
65  TLOG_ERROR("Option") << argv[0] << " port number not supplied" << std::endl << "For usage and an options list, please do '" << argv[0] << " --help'" << TLOG_ENDL;
66  return 1;
67  }
68 
69  std::string name = "Aggregator";
70  if (vm.count("name"))
71  {
72  name = vm["name"].as<std::string>();
73  TLOG_DEBUG(name + "Main") << "Setting application name to " << name << TLOG_ENDL;
74  }
75 
76  artdaq::setMsgFacAppName(name, vm["port"].as<unsigned short>());
77  TLOG_DEBUG(name + "Main") << "artdaq version " <<
79  << ", built " <<
80  artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp() << TLOG_ENDL;
81 
82  // create the AggregatorApp
83  artdaq::AggregatorApp agg_app(mpiSentry->rank(), name);
84 
85  // create the xmlrpc_commander and run it
86  artdaq::xmlrpc_commander commander(vm["port"].as<unsigned short>(), agg_app);
87  commander.run();
88 }
AggregatorApp is an artdaq::Commandable derived class which controls the AggregatorCore.
The MPISentry class initializes and finalizes the MPI context that the artdaq applciations run in...
Definition: MPISentry.hh:15
int rank() const
Get the MPI rank of the application.
Definition: MPISentry.cc:113
static artdaq::PackageBuildInfo getPackageBuildInfo()
Gets the version number and build timestmap for artdaq.
void configureMessageFacility(char const *progname, bool useConsole=true)
Configure and start the message facility. Provide the program name so that messages will be appropria...
The xmlrpc_commander class serves as the XMLRPC server run in each artdaq application.
void setMsgFacAppName(const std::string &appType, unsigned short port)
Set the message facility application name using the specified application type and port number...