Line data Source code
1 : /************************************************************
2 : * create_config_plot.cpp
3 : *
4 : * JCF, May-7-2024
5 : *
6 : * Main file of create_config_plot used to generate GraphViz dot
7 : * files of DUNE DAQ configurations. The latter can
8 : * be used to generate graphs that visualize the database
9 : * patterns
10 : *
11 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
12 : * Licensing/copyright details are in the COPYING file that you should have
13 : * received with this code.
14 : *
15 : *************************************************************/
16 : #include "GraphBuilder.hpp"
17 :
18 : #include "appmodel/appmodelIssues.hpp"
19 : #include "logging/Logging.hpp"
20 :
21 : #include <boost/program_options.hpp>
22 :
23 : #include <map>
24 : #include <numeric>
25 : #include <sstream>
26 : #include <stdexcept>
27 : #include <string>
28 :
29 : namespace bpo = boost::program_options;
30 :
31 : int
32 0 : main(int argc, char* argv[])
33 : {
34 :
35 0 : std::string oksfilename{ "" };
36 0 : std::string outputfilename{ "" };
37 0 : std::string object_uid{ "" };
38 0 : std::string sessionname{ "" };
39 :
40 0 : bpo::options_description options_description("Allowed options", 128);
41 :
42 0 : options_description.add_options()
43 :
44 0 : ("help,h", "Provide help message")
45 :
46 0 : ("file,f", bpo::value<std::string>(&oksfilename), "OKS database file name")
47 :
48 0 : ("root-object,r",
49 0 : bpo::value<std::string>(&object_uid)->default_value(""),
50 0 : "OKS object UID of root vertex; must be session, segment or application")(
51 : "session,s",
52 0 : bpo::value<std::string>(&sessionname)->default_value(""),
53 0 : "Name of the session associated with the root object (only needed if >1 session in the database)")(
54 : "output,o",
55 0 : bpo::value<std::string>(&outputfilename)->default_value("config.dot"),
56 : "Output DOT file which can be used as input to GraphViz");
57 :
58 0 : bpo::variables_map args;
59 :
60 0 : auto display_help_message = [&options_description]() {
61 0 : TLOG() << "create_config_plot : Generate dot graphs from database files" << std::endl
62 0 : << std::endl
63 : << "Usage: create_config_plot -f/--file <input OKS file> -r/--root-object <object UID for session, segment "
64 : "or application> (-s/--session <session containing root-object>) (-o/--output <output DOT file, default "
65 0 : "is config.dot>)"
66 0 : << std::endl
67 0 : << std::endl
68 0 : << options_description << std::endl;
69 0 : };
70 :
71 0 : try {
72 0 : bpo::store(bpo::command_line_parser(argc, argv).options(options_description).run(), args);
73 0 : bpo::notify(args);
74 :
75 0 : if (args.count("help") || !args.count("file")) {
76 0 : display_help_message();
77 0 : return EXIT_FAILURE;
78 : }
79 :
80 0 : daqconf::GraphBuilder graphbuilder(oksfilename, sessionname);
81 0 : graphbuilder.construct_graph(object_uid);
82 0 : graphbuilder.write_graph(outputfilename);
83 :
84 0 : } catch (const bpo::error& e) {
85 :
86 0 : display_help_message();
87 :
88 0 : std::stringstream errmsgstr;
89 0 : errmsgstr << "Incorrect command line argument: " << e.what();
90 0 : ers::fatal(daqconf::GeneralGraphToolError(ERS_HERE, errmsgstr.str()));
91 :
92 0 : } catch (const dunedaq::appmodel::BadConf& exc) {
93 0 : std::stringstream errmsgstr;
94 0 : errmsgstr << "Caught BadConf exception: " << exc;
95 0 : ers::fatal(daqconf::GeneralGraphToolError(ERS_HERE, errmsgstr.str()));
96 :
97 0 : } catch (const daqconf::GeneralGraphToolError& e) {
98 :
99 0 : ers::fatal(e);
100 0 : }
101 :
102 : return 0;
103 0 : }
|