DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
graphtool.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: yes (from src/graphtool.cpp to apps/graphtool.cpp).
5
6/************************************************************
7 * graphtool.cpp
8 *
9 * Main file of graphtool ( aka gtool ) used to generate dot
10 * files of the ATLAS configuration database. The latter can
11 * be used to generate graphs that visualize the database
12 * patterns
13 *
14 * Created on: Jun 10, 2016
15 * Author: Leonidas Georgopoulos
16 ************************************************************/
17#include "dbe/graphtool.hpp"
18#include "dbe/confaccessor.hpp"
19#include "dbe/gtool.hpp"
20#include "dbe/messenger.hpp"
21#include "dbe/segregate.hpp"
22
23#include <boost/program_options.hpp>
24
25#include <numeric>
26
27namespace bop = boost::program_options;
28
29int
30main(int argc, char* argv[])
31{
32
34 setenv("LC_ALL", "C", 1);
35
36 std::string oksfn, rdbrl, roksrl, outfn, sepfnbase, stats, logfile, msglevel("ERROR");
37
38 size_t min_component_size = 0;
39 size_t max_component_size = std::numeric_limits<size_t>::max();
40
41 bop::options_description options_description("Allowed options ( warning : almost no sanity checks performed )", 128);
42
43 options_description.add_options()
44
45 ("help,h", "Provide help message")
46
47 ("file,f", bop::value<std::string>(&oksfn), "OKS database file name")
48
49 ("rdb,r", bop::value<std::string>(&rdbrl), "RDB String (e.g. partition::rdbServerName)")
50
51 ("roks,o",
52 bop::value<std::string>(&roksrl),
53 "ROKS String (e.g. oracle://atlas_oksprod/r:atlas_oks_tdaq:24:77)")
54
55 ("result,u", bop::value<std::string>(&outfn), "Output file which can be used as input to graphviz")
56
57 ("separate,s", bop::value<std::string>(&sepfnbase), "Output pathnames to prepend to subgraph files")
58
59 ("stats,S",
60 bop::value<std::string>(&stats)->default_value(stats),
61 "The statistic to compute can be a comma sperated list \" e.g. min_dist,num_of_component \"...")
62
63 ("minc,m",
64 bop::value<size_t>(&min_component_size)->default_value(min_component_size),
65 "The minimum component size to output")
66
67 ("maxc,M",
68 bop::value<size_t>(&max_component_size)->default_value(max_component_size),
69 "The maximum component size to output")
70
71 ("msglevel,L",
72 bop::value<std::string>(&msglevel)->default_value(msglevel),
73 "The minimum level of error messages to report (INFO,WARN,ERROR,FAIL)")
74
75 ("log,l",
76 bop::value<std::string>(&logfile),
77 "Redirect error messages to logfile instead of cerr");
78
79 bop::variables_map args;
80
81 std::unique_ptr<dbe::tool::graph::gtool> proc;
82
83 auto display_help_message = [&options_description]() {
84 std::cout << "DBE gtool : Generate dot graphs from database files" << std::endl
85 << std::endl
86 << "Usage: dbe_gtool [options] , only the first option is taken into account "
87 << "and the output file. If no output file is specified the result is sent to stdout" << std::endl
88 << std::endl
89 << options_description << std::endl;
90 };
91
92 try {
93 bop::store(bop::command_line_parser(argc, argv).options(options_description).run(), args);
94 bop::notify(args);
95
96 // Set the message level to output
97 t_msghandler::ref().setlevel(msglevel, t_messenger::all_levels);
98
99 // Send output to the specified file
100 if (args.count("log")) {
101 t_msghandler::ref().set(logfile);
102 }
103
104 // Initialize access to configuration backend
106
107 // Select input source
108 if (args.count("help") or argc == 1) {
109 display_help_message();
110 return EXIT_FAILURE;
111 } else if (args.count("file")) {
112 proc = std::unique_ptr<dbe::tool::graph::gtool>(new dbe::tool::graph::gtool(oksfn, dbe::dbinfo::oks));
113 } else if (args.count("rdb")) {
114 proc = std::unique_ptr<dbe::tool::graph::gtool>(new dbe::tool::graph::gtool(rdbrl, dbe::dbinfo::rdb));
115 } else if (args.count("roks")) {
116 proc = std::unique_ptr<dbe::tool::graph::gtool>(new dbe::tool::graph::gtool(roksrl, dbe::dbinfo::roks));
117 } else {
118 display_help_message();
119 return EXIT_FAILURE;
120 }
121
122 // If neither separate or result have been provided , output the help message and a warning
123 if (not args.count("result") and not args.count("separate")) {
124 WARN("Output file not specified ", "User input warning", "Output will be sent to standard output");
125 display_help_message();
126 }
127
128 } catch (std::string const& e) {
129 ERROR("Program execution failure", e);
130 return EXIT_FAILURE;
131 } catch (std::exception const& e) {
132 ERROR("Incorrect command line argument", e.what());
133 display_help_message();
134 return EXIT_FAILURE;
135 }
136
137 try {
138 if (args.count("separate")) {
139 INFO("Graph will be separated to its components", "Program execution control");
140 dbe::tool::graph::segregated_graph_write sgw(sepfnbase, min_component_size, max_component_size);
141 return proc->load_and_run(sgw);
142 } else {
143 INFO("One large output file to be created", "Program execution control");
145 return proc->load_and_run(w);
146 }
147 } catch (std::exception const& e) {
148 std::cerr << "Exception: " << e.what() << std::endl;
149 } catch (...) {
150 std::cerr << "Unknown Exception" << std::endl;
151 }
152
153 return EXIT_FAILURE;
154}
static void init()
int main(int argc, char *argv[])
#define ERROR(...)
Definition messenger.hpp:90
#define WARN(...)
Definition messenger.hpp:82
#define INFO(...)
Definition messenger.hpp:98