DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
graphtool.cpp File Reference
#include "dbe/graphtool.hpp"
#include "dbe/messenger.hpp"
#include "dbe/confaccessor.hpp"
#include "dbe/gtool.hpp"
#include "dbe/segregate.hpp"
#include <boost/program_options.hpp>
#include <numeric>
Include dependency graph for graphtool.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Setting language variable to english(otherwise , is interpreted as . in numbers)

Definition at line 29 of file graphtool.cpp.

30{
31
33 setenv ( "LC_ALL", "C", 1 );
34
35 std::string oksfn, rdbrl, roksrl, outfn, sepfnbase, stats, logfile, msglevel ( "ERROR" );
36
37 size_t min_component_size = 0;
38 size_t max_component_size = std::numeric_limits<size_t>::max();
39
40 bop::options_description options_description (
41 "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 ),
50 "RDB String (e.g. partition::rdbServerName)" )
51
52 ( "roks,o", 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 ),
56 "Output file which can be used as input to graphviz" )
57
58 ( "separate,s", bop::value<std::string> ( &sepfnbase ),
59 "Output pathnames to prepend to subgraph files" )
60
61 ( "stats,S",
62 bop::value<std::string> ( &stats )->default_value ( stats ),
63 "The statistic to compute can be a comma sperated list \" e.g. min_dist,num_of_component \"..." )
64
65 ( "minc,m", bop::value<size_t> ( &min_component_size )->default_value (
66 min_component_size ),
67 "The minimum component size to output" )
68
69 ( "maxc,M", bop::value<size_t> ( &max_component_size )->default_value (
70 max_component_size ),
71 "The maximum component size to output" )
72
73 ( "msglevel,L", bop::value<std::string> ( &msglevel )->default_value ( msglevel ),
74 "The minimum level of error messages to report (INFO,WARN,ERROR,FAIL)" )
75
76 ( "log,l", 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 {
85 std::cout
86 << "DBE gtool : Generate dot graphs from database files"
87 << std::endl
88 << std::endl
89 << "Usage: dbe_gtool [options] , only the first option is taken into account "
90 << "and the output file. If no output file is specified the result is sent to stdout"
91 << std::endl
92 << std::endl
93 << options_description
94 << std::endl;
95 };
96
97 try
98 {
99 bop::store ( bop::command_line_parser ( argc, argv ).options ( options_description ).run(),
100 args );
101 bop::notify ( args );
102
103 // Set the message level to output
104 t_msghandler::ref().setlevel ( msglevel, t_messenger::all_levels );
105
106 // Send output to the specified file
107 if ( args.count ( "log" ) )
108 {
109 t_msghandler::ref().set ( logfile );
110 }
111
112 // Initialize access to configuration backend
114
115 // Select input source
116 if ( args.count ( "help" ) or argc == 1 )
117 {
118 display_help_message();
119 return EXIT_FAILURE;
120 }
121 else if ( args.count ( "file" ) )
122 {
123 proc = std::unique_ptr<dbe::tool::graph::gtool> (
125 }
126 else if ( args.count ( "rdb" ) )
127 {
128 proc = std::unique_ptr<dbe::tool::graph::gtool> (
130 }
131 else if ( args.count ( "roks" ) )
132 {
133 proc = std::unique_ptr<dbe::tool::graph::gtool> (
135 }
136 else
137 {
138 display_help_message();
139 return EXIT_FAILURE;
140 }
141
142 // If neither separate or result have been provided , output the help message and a warning
143 if ( not args.count ( "result" ) and not args.count ( "separate" ) )
144 {
145 WARN ( "Output file not specified ", "User input warning",
146 "Output will be sent to standard output" );
147 display_help_message();
148 }
149
150 }
151 catch ( std::string const & e )
152 {
153 ERROR ( "Program execution failure", e );
154 return EXIT_FAILURE;
155 }
156 catch ( std::exception const & e )
157 {
158 ERROR ( "Incorrect command line argument", e.what() );
159 display_help_message();
160 return EXIT_FAILURE;
161 }
162
163 try
164 {
165 if ( args.count ( "separate" ) )
166 {
167 INFO ( "Graph will be separated to its components", "Program execution control" );
168 dbe::tool::graph::segregated_graph_write sgw ( sepfnbase, min_component_size,
169 max_component_size );
170 return proc->load_and_run ( sgw );
171 }
172 else
173 {
174 INFO ( "One large output file to be created", "Program execution control" );
176 return proc->load_and_run ( w );
177 }
178 }
179 catch ( std::exception const & e )
180 {
181 std::cerr << "Exception: " << e.what() << std::endl;
182 }
183 catch ( ... )
184 {
185 std::cerr << "Unknown Exception" << std::endl;
186 }
187
188 return EXIT_FAILURE;
189
190}
static void init()
static volatile sig_atomic_t run
#define ERROR(...)
Definition messenger.hpp:93
#define WARN(...)
Definition messenger.hpp:85
#define INFO(...)
stats(obj, sel_links, seconds, show_udp, show_buf)