LCOV - code coverage report
Current view: top level - dbe/apps - graphtool.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 76 0
Test Date: 2026-10-11 15:05:20 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/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              : 
      27              : namespace bop = boost::program_options;
      28              : 
      29              : int
      30            0 : main(int argc, char* argv[])
      31              : {
      32              : 
      33              :   /// Setting language variable to english(otherwise , is interpreted as . in numbers)
      34            0 :   setenv("LC_ALL", "C", 1);
      35              : 
      36            0 :   std::string oksfn, rdbrl, roksrl, outfn, sepfnbase, stats, logfile, msglevel("ERROR");
      37              : 
      38            0 :   size_t min_component_size = 0;
      39            0 :   size_t max_component_size = std::numeric_limits<size_t>::max();
      40              : 
      41            0 :   bop::options_description options_description("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), "RDB String (e.g. partition::rdbServerName)")
      50              : 
      51            0 :           ("roks,o",
      52            0 :            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), "Output file which can be used as input to graphviz")
      56              : 
      57            0 :               ("separate,s", bop::value<std::string>(&sepfnbase), "Output pathnames to prepend to subgraph files")
      58              : 
      59            0 :                 ("stats,S",
      60            0 :                  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            0 :                   ("minc,m",
      64            0 :                    bop::value<size_t>(&min_component_size)->default_value(min_component_size),
      65              :                    "The minimum component size to output")
      66              : 
      67            0 :                     ("maxc,M",
      68            0 :                      bop::value<size_t>(&max_component_size)->default_value(max_component_size),
      69              :                      "The maximum component size to output")
      70              : 
      71            0 :                       ("msglevel,L",
      72            0 :                        bop::value<std::string>(&msglevel)->default_value(msglevel),
      73              :                        "The minimum level of error messages to report (INFO,WARN,ERROR,FAIL)")
      74              : 
      75            0 :                         ("log,l",
      76            0 :                          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            0 :     std::cout << "DBE gtool : Generate dot graphs from database files" << std::endl
      85            0 :               << std::endl
      86              :               << "Usage: dbe_gtool [options] , only the first option is taken into account "
      87            0 :               << "and the output file. If no output file is specified the result is sent to stdout" << std::endl
      88            0 :               << std::endl
      89            0 :               << options_description << std::endl;
      90            0 :   };
      91              : 
      92            0 :   try {
      93            0 :     bop::store(bop::command_line_parser(argc, argv).options(options_description).run(), args);
      94            0 :     bop::notify(args);
      95              : 
      96              :     // Set the message level to output
      97            0 :     t_msghandler::ref().setlevel(msglevel, t_messenger::all_levels);
      98              : 
      99              :     // Send output to the specified file
     100            0 :     if (args.count("log")) {
     101            0 :       t_msghandler::ref().set(logfile);
     102              :     }
     103              : 
     104              :     // Initialize access to configuration backend
     105            0 :     dbe::confaccessor::init();
     106              : 
     107              :     // Select input source
     108            0 :     if (args.count("help") or argc == 1) {
     109            0 :       display_help_message();
     110              :       return EXIT_FAILURE;
     111            0 :     } else if (args.count("file")) {
     112            0 :       proc = std::unique_ptr<dbe::tool::graph::gtool>(new dbe::tool::graph::gtool(oksfn, dbe::dbinfo::oks));
     113            0 :     } else if (args.count("rdb")) {
     114            0 :       proc = std::unique_ptr<dbe::tool::graph::gtool>(new dbe::tool::graph::gtool(rdbrl, dbe::dbinfo::rdb));
     115            0 :     } else if (args.count("roks")) {
     116            0 :       proc = std::unique_ptr<dbe::tool::graph::gtool>(new dbe::tool::graph::gtool(roksrl, dbe::dbinfo::roks));
     117              :     } else {
     118            0 :       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            0 :     if (not args.count("result") and not args.count("separate")) {
     124            0 :       WARN("Output file not specified ", "User input warning", "Output will be sent to standard output");
     125            0 :       display_help_message();
     126              :     }
     127              : 
     128            0 :   } catch (std::string const& e) {
     129            0 :     ERROR("Program execution failure", e);
     130            0 :     return EXIT_FAILURE;
     131            0 :   } catch (std::exception const& e) {
     132            0 :     ERROR("Incorrect command line argument", e.what());
     133            0 :     display_help_message();
     134            0 :     return EXIT_FAILURE;
     135            0 :   }
     136              : 
     137            0 :   try {
     138            0 :     if (args.count("separate")) {
     139            0 :       INFO("Graph will be separated to its components", "Program execution control");
     140            0 :       dbe::tool::graph::segregated_graph_write sgw(sepfnbase, min_component_size, max_component_size);
     141            0 :       return proc->load_and_run(sgw);
     142            0 :     } else {
     143            0 :       INFO("One large output file to be created", "Program execution control");
     144            0 :       dbe::tool::graph::writegraph w(outfn);
     145            0 :       return proc->load_and_run(w);
     146            0 :     }
     147            0 :   } catch (std::exception const& e) {
     148            0 :     std::cerr << "Exception: " << e.what() << std::endl;
     149            0 :   } catch (...) {
     150            0 :     std::cerr << "Unknown Exception" << std::endl;
     151            0 :   }
     152              : 
     153              :   return EXIT_FAILURE;
     154            0 : }
        

Generated by: LCOV version 2.0-1