LCOV - code coverage report
Current view: top level - dbe/apps - graphtool.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 83 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 2 0

            Line data    Source code
       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              : 
      22              : namespace bop = boost::program_options;
      23              : 
      24            0 : int main ( int argc, char * argv[] )
      25              : {
      26              : 
      27              :   /// Setting language variable to english(otherwise , is interpreted as . in numbers)
      28            0 :   setenv ( "LC_ALL", "C", 1 );
      29              : 
      30            0 :   std::string oksfn, rdbrl, roksrl, outfn, sepfnbase, stats, logfile, msglevel ( "ERROR" );
      31              : 
      32            0 :   size_t min_component_size = 0;
      33            0 :   size_t max_component_size = std::numeric_limits<size_t>::max();
      34              : 
      35            0 :   bop::options_description options_description (
      36            0 :     "Allowed options ( warning : almost no sanity checks performed )", 128 );
      37              : 
      38            0 :   options_description.add_options()
      39              : 
      40            0 :   ( "help,h", "Provide help message" )
      41              : 
      42            0 :   ( "file,f", bop::value<std::string> ( &oksfn ), "OKS database file name" )
      43              : 
      44            0 :   ( "rdb,r", bop::value<std::string> ( &rdbrl ),
      45              :     "RDB String (e.g. partition::rdbServerName)" )
      46              : 
      47            0 :   ( "roks,o", bop::value<std::string> ( &roksrl ),
      48              :     "ROKS String (e.g. oracle://atlas_oksprod/r:atlas_oks_tdaq:24:77)" )
      49              : 
      50            0 :   ( "result,u", bop::value<std::string> ( &outfn ),
      51              :     "Output file which can be used as input to graphviz" )
      52              : 
      53            0 :   ( "separate,s", bop::value<std::string> ( &sepfnbase ),
      54              :     "Output pathnames to prepend to subgraph files" )
      55              : 
      56            0 :   ( "stats,S",
      57            0 :     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            0 :   ( "minc,m", bop::value<size_t> ( &min_component_size )->default_value (
      61              :       min_component_size ),
      62              :     "The minimum component size to output" )
      63              : 
      64            0 :   ( "maxc,M", bop::value<size_t> ( &max_component_size )->default_value (
      65              :       max_component_size ),
      66              :     "The maximum component size to output" )
      67              : 
      68            0 :   ( "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            0 :   ( "log,l", bop::value<std::string> ( &logfile ),
      72              :     "Redirect error messages to logfile instead of cerr" );
      73              : 
      74            0 :   bop::variables_map args;
      75              : 
      76            0 :   std::unique_ptr<dbe::tool::graph::gtool> proc;
      77              : 
      78            0 :   auto display_help_message = [&options_description]()
      79              :   {
      80            0 :     std::cout
      81            0 :         << "DBE gtool : Generate dot graphs from database files"
      82            0 :         << std::endl
      83            0 :         << std::endl
      84              :         << "Usage: dbe_gtool [options] , only the first option is taken into account "
      85            0 :         << "and the output file. If no output file is specified the result is sent to stdout"
      86            0 :         << std::endl
      87            0 :         << std::endl
      88            0 :         << options_description
      89            0 :         << std::endl;
      90            0 :   };
      91              : 
      92            0 :   try
      93              :   {
      94            0 :     bop::store ( bop::command_line_parser ( argc, argv ).options ( options_description ).run(),
      95              :                  args );
      96            0 :     bop::notify ( args );
      97              : 
      98              :     // Set the message level to output
      99            0 :     t_msghandler::ref().setlevel ( msglevel, t_messenger::all_levels );
     100              : 
     101              :     // Send output to the specified file
     102            0 :     if ( args.count ( "log" ) )
     103              :     {
     104            0 :       t_msghandler::ref().set ( logfile );
     105              :     }
     106              : 
     107              :     // Initialize access to configuration backend
     108            0 :     dbe::confaccessor::init();
     109              : 
     110              :     // Select input source
     111            0 :     if ( args.count ( "help" ) or argc == 1 )
     112              :     {
     113            0 :       display_help_message();
     114              :       return EXIT_FAILURE;
     115              :     }
     116            0 :     else if ( args.count ( "file" ) )
     117              :     {
     118            0 :       proc = std::unique_ptr<dbe::tool::graph::gtool> (
     119            0 :                new dbe::tool::graph::gtool ( oksfn, dbe::dbinfo::oks ) );
     120              :     }
     121            0 :     else if ( args.count ( "rdb" ) )
     122              :     {
     123            0 :       proc = std::unique_ptr<dbe::tool::graph::gtool> (
     124            0 :                new dbe::tool::graph::gtool ( rdbrl, dbe::dbinfo::rdb ) );
     125              :     }
     126            0 :     else if ( args.count ( "roks" ) )
     127              :     {
     128            0 :       proc = std::unique_ptr<dbe::tool::graph::gtool> (
     129            0 :                new dbe::tool::graph::gtool ( roksrl, dbe::dbinfo::roks ) );
     130              :     }
     131              :     else
     132              :     {
     133            0 :       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            0 :     if ( not args.count ( "result" ) and not args.count ( "separate" ) )
     139              :     {
     140            0 :       WARN ( "Output file not specified ", "User input warning",
     141            0 :              "Output will be sent to standard output" );
     142            0 :       display_help_message();
     143              :     }
     144              : 
     145              :   }
     146            0 :   catch ( std::string const & e )
     147              :   {
     148            0 :     ERROR ( "Program execution failure", e );
     149            0 :     return EXIT_FAILURE;
     150            0 :   }
     151            0 :   catch ( std::exception const & e )
     152              :   {
     153            0 :     ERROR ( "Incorrect command line argument", e.what() );
     154            0 :     display_help_message();
     155            0 :     return EXIT_FAILURE;
     156            0 :   }
     157              : 
     158            0 :   try
     159              :   {
     160            0 :     if ( args.count ( "separate" ) )
     161              :     {
     162            0 :       INFO ( "Graph will be separated to its components", "Program execution control" );
     163            0 :       dbe::tool::graph::segregated_graph_write sgw ( sepfnbase, min_component_size,
     164            0 :                                                      max_component_size );
     165            0 :       return proc->load_and_run ( sgw );
     166            0 :     }
     167              :     else
     168              :     {
     169            0 :       INFO ( "One large output file to be created", "Program execution control" );
     170            0 :       dbe::tool::graph::writegraph w ( outfn );
     171            0 :       return proc->load_and_run ( w );
     172            0 :     }
     173              :   }
     174            0 :   catch ( std::exception const & e )
     175              :   {
     176            0 :     std::cerr << "Exception: " << e.what() << std::endl;
     177            0 :   }
     178            0 :   catch ( ... )
     179              :   {
     180            0 :     std::cerr << "Unknown Exception" << std::endl;
     181            0 :   }
     182              : 
     183              :   return EXIT_FAILURE;
     184              : 
     185            0 : }
        

Generated by: LCOV version 2.0-1