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