artdaq  v2_02_03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
EventBuilderMain.cc
1 #include <iostream>
2 #include <memory>
3 #include <boost/program_options.hpp>
4 #include <boost/lexical_cast.hpp>
5 #include "artdaq/DAQdata/Globals.hh"
6 #include "artdaq/Application/TaskType.hh"
7 #include "artdaq/Application/EventBuilderApp.hh"
8 #include "artdaq/ExternalComms/xmlrpc_commander.hh"
9 #include "artdaq/Application/MPI2/MPISentry.hh"
11 #include "artdaq/BuildInfo/GetPackageBuildInfo.hh"
12 #include "cetlib/exception.h"
13 
14 int main(int argc, char* argv[])
15 {
16  artdaq::configureMessageFacility("eventbuilder");
17 
18  // initialization
19 
20  int const wanted_threading_level{MPI_THREAD_MULTIPLE};
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::EventBuilderTask, local_group_comm));
27  }
28  catch (cet::exception& errormsg)
29  {
30  TLOG_ERROR("EventBuilderMain") << errormsg << TLOG_ENDL;
31  TLOG_ERROR("EventBuilderMain") << "MPISentry error encountered in EventBuilderMain; exiting..." << TLOG_ENDL;
32  throw errormsg;
33  }
34 
35  // handle the command-line arguments
36  std::string usage = std::string(argv[0]) + " -p port_number -n name <other-options>";
37  boost::program_options::options_description desc(usage);
38 
39  desc.add_options()
40  ("port,p", boost::program_options::value<unsigned short>(), "Port number")
41  ("name,n", boost::program_options::value<std::string>(), "Application Nickname")
42  ("help,h", "produce help message");
43 
44  boost::program_options::variables_map vm;
45  try
46  {
47  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).run(), vm);
48  boost::program_options::notify(vm);
49  }
50  catch (boost::program_options::error const& e)
51  {
52  TLOG_ERROR("Option") << "exception from command line processing in " << argv[0] << ": " << e.what() << TLOG_ENDL;
53  return 1;
54  }
55 
56  if (vm.count("help"))
57  {
58  std::cout << desc << std::endl;
59  return 0;
60  }
61 
62  if (!vm.count("port"))
63  {
64  TLOG_ERROR("Option") << argv[0] << " port number not suplied" << std::endl << "For usage and an options list, please do '" << argv[0] << " --help'" << TLOG_ENDL;
65  return 1;
66  }
67 
68  std::string name = "EventBuilder";
69  if (vm.count("name"))
70  {
71  name = vm["name"].as<std::string>();
72  TLOG_DEBUG(name + "Main") << "Setting application name to " << name << TLOG_ENDL;
73  }
74 
75  artdaq::setMsgFacAppName(name, vm["port"].as<unsigned short>());
76  TLOG_DEBUG(name + "Main") << "artdaq version " <<
78  << ", built " <<
79  artdaq::GetPackageBuildInfo::getPackageBuildInfo().getBuildTimestamp() << TLOG_ENDL;
80 
81  // create the EventBuilderApp
82  artdaq::EventBuilderApp evb_app(mpiSentry->rank(), name);
83 
84  // create the xmlrpc_commander and run it
85  artdaq::xmlrpc_commander commander(vm["port"].as<unsigned short>(), evb_app);
86  commander.run();
87 }
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.
EventBuilderApp is an artdaq::Commandable derived class which controls the EventBuilderCore.
void setMsgFacAppName(const std::string &appType, unsigned short port)
Set the message facility application name using the specified application type and port number...