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: 2026-07-12 15:23:06 Functions: 0.0 % 2 0

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

Generated by: LCOV version 2.0-1