artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
StateResponder.cc
1 #include "artdaq/Application/Commandable.hh"
2 #include "artdaq/Application/MPI2/MPISentry.hh"
3 #include "artdaq/DAQdata/configureMessageFacility.hh"
5 #include "artdaq/DAQdata/Globals.hh"
6 #include "artdaq/ExternalComms/xmlrpc_commander.hh"
7 
8 #include "boost/program_options.hpp"
9 #include "boost/lexical_cast.hpp"
10 
11 #include <iostream>
12 
13 int main(int argc, char* argv[])
14 {
15  // initialization
16  int const wanted_threading_level{MPI_THREAD_FUNNELED};
17  artdaq::MPISentry mpiSentry(&argc, &argv, wanted_threading_level);
18  artdaq::configureMessageFacility("commandable");
19  TLOG_DEBUG("Commandable::main")
20  << "MPI initialized with requested thread support level of "
21  << wanted_threading_level << ", actual support level = "
22  << mpiSentry.threading_level() << "." << TLOG_ENDL;
23  TLOG_DEBUG("Commandable::main")
24  << "size = "
25  << mpiSentry.procs()
26  << ", rank = "
27  << mpiSentry.rank() << TLOG_ENDL;
28 
29  // handle the command-line arguments
30  std::string usage = std::string(argv[0]) + " -p port_number <other-options>";
31  boost::program_options::options_description desc(usage);
32 
33  desc.add_options()
34  ("port,p", boost::program_options::value<unsigned short>(), "Port number")
35  ("help,h", "produce help message");
36 
37  boost::program_options::variables_map vm;
38  try
39  {
40  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).run(), vm);
41  boost::program_options::notify(vm);
42  }
43  catch (boost::program_options::error const& e)
44  {
45  TLOG_ERROR("Option") << "exception from command line processing in " << argv[0] << ": " << e.what() << TLOG_ENDL;
46  return 1;
47  }
48 
49  if (vm.count("help"))
50  {
51  std::cout << desc << std::endl;
52  return 0;
53  }
54 
55  if (!vm.count("port"))
56  {
57  TLOG_ERROR("Option") << argv[0] << " port number not suplied" << std::endl << "For usage and an options list, please do '" << argv[0] << " --help'" << TLOG_ENDL;
58  return 1;
59  }
60 
61  artdaq::setMsgFacAppName("Commandable", vm["port"].as<unsigned short>());
62 
63  // create the Commandable object
64  artdaq::Commandable commandable;
65 
66  // create the xmlrpc_commander and run it
67  artdaq::xmlrpc_commander commander(vm["port"].as<unsigned short>(), commandable);
68  commander.run();
69 }
Commandable is the base class for all artdaq components which implement the artdaq state machine...
Definition: Commandable.hh:20
The MPISentry class initializes and finalizes the MPI context that the artdaq applciations run in...
Definition: MPISentry.hh:15
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...