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