artdaq_mfextensions  v1_03_01
msgserver.cc
1 #include "messagefacility/MessageLogger/MessageLogger.h"
2 #include "messagefacility/Utilities/ErrorObj.h"
3 
4 #include <boost/program_options.hpp>
5 #include <boost/bind.hpp>
6 
7 #include <iostream>
8 #include <string>
9 #include "mfextensions/Binaries/ReceiverManager.hh"
10 #include "fhiclcpp/make_ParameterSet.h"
11 
12 namespace po = boost::program_options;
13 
14 bool cmdline = false;
15 int z = 0;
16 
17 int main(int argc, char* argv[])
18 {
19  // checking options
20  std::string filename;
21  std::string configFile;
22 
23  try
24  {
25  po::options_description cmdopt("Allowed options");
26  cmdopt.add_options()
27  ("help,h", "display help message")
28  ("config,c", po::value<std::string>(&configFile)->default_value(""), "Specify the FHiCL configuration file to use")
29  ("filename,f",
30  po::value<std::string>(&filename)->default_value("msg_archive"),
31  "specify the message archive file name");
32 
33  po::options_description desc;
34  desc.add(cmdopt);
35 
36  po::variables_map vm;
37  po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
38  po::notify(vm);
39 
40  if (vm.count("help"))
41  {
42  std::cout << "Usage: msglogger [options] <message text>\n";
43  std::cout << cmdopt;
44  return 0;
45  }
46  }
47  catch (std::exception& e)
48  {
49  std::cerr << "error: " << e.what() << "\n";
50  return 1;
51  }
52  catch (...)
53  {
54  std::cerr << "Exception of unknown type!\n";
55  return 1;
56  }
57 
58 
59  // Start MessageFacility Service
60  std::ostringstream descstr;
61  descstr << "";
62  fhicl::ParameterSet main_pset;
63  mf::StartMessageFacility(main_pset);
64 
65  fhicl::ParameterSet pset;
66  auto maker = cet::filepath_maker();
67  fhicl::make_ParameterSet(configFile, maker, pset);
69 
70 
71  // Welcome message
72  std::cout << "Message Facility MsgServer is up and listening to configured Receivers" << std::endl;
73 
74  // Command line message loop
75  std::string cmd;
76 
77  while (true)
78  {
79  if (cmdline) std::cout << "> ";
80  getline(std::cin, cmd);
81 
82  if (cmd.empty())
83  {
84  cmdline = true;
85  }
86  else if (cmdline && (cmd == "r" || cmd == "resume"))
87  {
88  cmdline = false;;
89  }
90  else if (cmdline && (cmd == "q" || cmd == "quit"))
91  {
92  //dds.stop();
93  return 0;
94  }
95  else if (cmdline && (cmd == "h" || cmd == "help"))
96  {
97  std::cout << "MessageFacility DDS server available commands:\n"
98  << " (h)elp display this help message\n"
99  << " (s)tat summary of received messages\n"
100  << " (r)esume resume to message listening mode\n"
101  //<< " (p)artition listen to a new partition\n"
102  << " (q)uit exit MessageFacility DDS server\n"
103  << " ... more interactive commands on the way.\n";
104  }
105  else if (cmdline && (cmd == "s" || cmd == "stat"))
106  {
107  std::cout << "Currently listening, " << z << " messages have been received." << std::endl;
108  }
109  else if (cmdline)
110  {
111  std::cout << "Command " << cmd << " not found. "
112  << "Type \"help\" or \"h\" for a list of available commands.\n";
113  }
114  } // end of command line message loop
115 
116 
117  return 0;
118 }
The ReceiverManager loads one or more receiver plugins and displays messages received by those plugin...