Line data Source code
1 : /**
2 : * @file daq_application.cxx Main Application for the DAQ Framework, loads
3 : * DAQModules based on json configuration file
4 : *
5 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
6 : * Licensing/copyright details are in the COPYING file that you should have
7 : * received with this code.
8 : */
9 :
10 : #include "Application.hpp"
11 : #include "CommandLineInterpreter.hpp"
12 :
13 : #include "logging/Logging.hpp"
14 :
15 : #include <csignal>
16 : #include <fstream>
17 : #include <list>
18 : #include <map>
19 : #include <memory>
20 : #include <string>
21 : #include <vector>
22 :
23 : /**
24 : * @brief Global atomic for process lifetime
25 : */
26 : std::atomic<bool> run_marker{ true };
27 :
28 : /**
29 : * @brief Signal handler for graceful stop
30 : */
31 : static void
32 0 : signal_handler(int signal)
33 : {
34 0 : TLOG() << "Signal received: " << signal;
35 0 : run_marker.store(false);
36 0 : }
37 :
38 : int
39 0 : main(int argc, char* argv[])
40 : {
41 :
42 : // Setup signals
43 0 : std::signal(SIGINT, signal_handler);
44 0 : std::signal(SIGQUIT, signal_handler);
45 :
46 0 : using namespace dunedaq;
47 :
48 0 : appfwk::CommandLineInterpreter args;
49 0 : try {
50 0 : args = appfwk::CommandLineInterpreter::parse(argc, argv);
51 0 : } catch (bpo::error const& e) {
52 : // Die but do it gracefully gracefully.
53 0 : std::cerr << "Failed to interpret command line: " << e.what(); // NOLINT
54 0 : exit(1);
55 0 : }
56 :
57 0 : if (args.help_requested) {
58 0 : exit(0);
59 : }
60 :
61 : // Enable DUNE-DAQ logging, including TLOG and ERS messages
62 0 : dunedaq::logging::Logging().setup(args.session_name, args.app_name);
63 :
64 : // Create the Application
65 0 : appfwk::Application app(args.app_name,
66 : args.session_name,
67 : args.command_facility_plugin_name,
68 : args.conf_service_plugin_name,
69 0 : args.configuration_id);
70 :
71 0 : try {
72 :
73 0 : app.init();
74 0 : app.run(run_marker);
75 0 : } catch (ers::Issue& e) {
76 0 : ers::fatal(appfwk::ApplicationFailure(ERS_HERE, args.session_name, args.app_name, e));
77 0 : }
78 :
79 0 : TLOG() << "Application " << args.session_name << '.' << args.app_name << " exiting.";
80 0 : return 0;
81 0 : }
|