artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
aggregator.cc
1 //
2 // artdaqDriver is a program for testing the behavior of the generic
3 // RawInput source. Run 'artdaqDriver --help' to get a description of the
4 // expected command-line parameters.
5 //
6 //
7 // The current version generates simple data fragments, for testing
8 // that data are transmitted without corruption from the
9 // artdaq::EventStore through to the artdaq::RawInput source.
10 //
11 
12 #include "artdaq-core/Data/Fragment.hh"
13 #include "artdaq-core/Utilities/ExceptionHandler.hh"
14 
15 #include "artdaq/DAQdata/Globals.hh"
16 #include "artdaq-utilities/Plugins/MetricManager.hh"
17 #include "cetlib/container_algorithms.h"
18 #include "cetlib/filepath_maker.h"
19 #include "fhiclcpp/ParameterSet.h"
20 #include "fhiclcpp/make_ParameterSet.h"
21 #include "boost/program_options.hpp"
22 
23 #include <signal.h>
24 #include <iostream>
25 #include <memory>
26 #include <utility>
27 #include <artdaq/Application/AggregatorApp.hh>
28 #include <artdaq/ExternalComms/xmlrpc_commander.hh>
29 #include <artdaq/BuildInfo/GetPackageBuildInfo.hh>
30 
31 int main(int argc, char * argv[])
32 {
33  std::ostringstream descstr;
34  descstr << argv[0]
35  << " <-p <port-number>> <-r <rank>> [-n <name>] [-c <config-file>]";
36  boost::program_options::options_description desc(descstr.str());
37  desc.add_options()
38  ("config,c", boost::program_options::value<std::string>(), "Configuration file.")
39  ("rank,r", boost::program_options::value<int>(), "Process Rank")
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  boost::program_options::variables_map vm;
44  try {
45  boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(desc).run(), vm);
46  boost::program_options::notify(vm);
47  }
48  catch (boost::program_options::error const & e) {
49  std::cerr << "Exception from command line processing in " << argv[0]
50  << ": " << e.what() << "\n";
51  return -1;
52  }
53  if (vm.count("help")) {
54  std::cout << desc << std::endl;
55  return 1;
56  }
57 
58  if (!vm.count("port"))
59  {
60  TLOG_ERROR("Option") << argv[0] << " port number not supplied" << std::endl << "For usage and an options list, please do '" << argv[0] << " --help'" << TLOG_ENDL;
61  return 1;
62  }
63 
64  if (!vm.count("rank"))
65  {
66  TLOG_ERROR("Option") << argv[0] << " rank not supplied" << std::endl << "For usage and an options list, please do '" << argv[0] << " --help'" << TLOG_ENDL;
67  return 2;
68  }
69  auto rank = vm["rank"].as<int>();
70 
71  std::string name = "Aggregator";
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 AggregatorApp
85  artdaq::AggregatorApp agg_app(rank, name);
86 
87  if (vm.count("config")) {
88  fhicl::ParameterSet pset;
89  if (getenv("FHICL_FILE_PATH") == nullptr) {
90  std::cerr
91  << "INFO: environment variable FHICL_FILE_PATH was not set. Using \".\"\n";
92  setenv("FHICL_FILE_PATH", ".", 0);
93  }
94  cet::filepath_lookup_after1 lookup_policy("FHICL_FILE_PATH");
95  make_ParameterSet(vm["config"].as<std::string>(), lookup_policy, pset);
96 
97  int run = pset.get<int>("run_number", 101);
98  uint64_t timeout = pset.get<uint64_t>("transition_timeout", 30);
99  uint64_t timestamp = 0;
100 
101  agg_app.do_initialize(pset, timeout, timestamp);
102  agg_app.do_start(art::RunID(run), timeout, timestamp);
103 
104  TLOG_INFO(name) << "Running XMLRPC Commander. To stop, either Control-C or " << std::endl
105  << "xmlrpc http://`hostname`:" << vm["port"].as<unsigned short>() << "/RPC2 daq.stop" << std::endl
106  << "xmlrpc http://`hostname`:" << vm["port"].as<unsigned short>() << "/RPC2 daq.shutdown" << TLOG_ENDL;
107  }
108 
109  // create the xmlrpc_commander and run it
110  artdaq::xmlrpc_commander commander(vm["port"].as<unsigned short>(), agg_app);
111  commander.run();
112 
113 }
AggregatorApp is an artdaq::Commandable derived class which controls the AggregatorCore.
static artdaq::PackageBuildInfo getPackageBuildInfo()
Gets the version number and build timestmap for artdaq.
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...