LCOV - code coverage report
Current view: top level - conffwk/test/apps - conffwk_check_inheritance.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 56 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 2 0

            Line data    Source code
       1              : #include "CLI/CLI.hpp"
       2              : #include <fmt/core.h>
       3              : #include <fmt/ranges.h>
       4              : 
       5              : #include "conffwk/Configuration.hpp"
       6              : #include "conffwk/DalFactory.hpp"
       7              : #include "conffwk/Schema.hpp"
       8              : 
       9              : std::deque<std::set<std::string>>
      10            0 : construct_class_domains(dunedaq::conffwk::Configuration& cfg_db)
      11              : {
      12              : 
      13            0 :   std::deque<std::set<std::string>> domains;
      14              : 
      15            0 :   std::deque<dunedaq::conffwk::class_t> progenitors;
      16            0 :   for (const auto& c : cfg_db.get_class_list()) {
      17            0 :     auto ci = cfg_db.get_class_info(c);
      18            0 :     if (ci.p_superclasses.empty())
      19            0 :       progenitors.push_back(ci);
      20              :     // fmt::print("   - {} {}\n", c, ci.p_superclasses.size(), ci.p_superclasses.size());
      21            0 :   }
      22              : 
      23            0 :   for (const auto& ci : progenitors) {
      24              :     // Make a candidate cluster based using the seed subclasses
      25            0 :     std::set<std::string> class_cluster;
      26            0 :     class_cluster.insert(ci.p_name);
      27            0 :     class_cluster.insert(ci.p_subclasses.begin(), ci.p_subclasses.end());
      28              : 
      29              :     // Look for overlaps with other domains
      30            0 :     std::deque<std::set<std::string>> overlapping;
      31            0 :     for (auto& dom : domains) {
      32            0 :       std::set<std::string> intersection;
      33            0 :       std::set_intersection(dom.begin(), dom.end(), class_cluster.begin(), class_cluster.end(), std::inserter(intersection, intersection.begin()));
      34              :       // non-zero intersection, overlap found
      35            0 :       if (intersection.size() > 0) {
      36            0 :         overlapping.push_back(dom);
      37              :       }
      38            0 :     }
      39              : 
      40              :     // If overlapping are found, merge all overlapping domains
      41            0 :     if ( !overlapping.empty() ) {
      42            0 :       for( auto& dom : overlapping ) {
      43              :         // merge the existing cluster in class_cluster
      44            0 :         class_cluster.insert(dom.begin(), dom.end());
      45              :         // Remove the old cluster from the list
      46            0 :         auto it = std::find(domains.begin(), domains.end(), dom);
      47            0 :         if (it!= domains.end()) {
      48            0 :             domains.erase(it);
      49              :         }
      50              :       }
      51              :     }
      52              : 
      53              : 
      54            0 :     domains.push_back(class_cluster);
      55            0 :   }
      56              : 
      57            0 :   return domains;
      58            0 : }
      59              : 
      60              : int
      61            0 : main(int argc, char const* argv[])
      62              : {
      63            0 :   using namespace dunedaq;
      64              : 
      65            0 :   CLI::App app{ "App description" };
      66              : 
      67            0 :   std::string file;
      68            0 :   app.add_option("-f,--file", file, "Schema file")->required()->check(CLI::ExistingFile);
      69              : 
      70            0 :   CLI11_PARSE(app, argc, argv);
      71              : 
      72            0 :   fmt::print("Configuration database file: {}\n", file);
      73              : 
      74            0 :   conffwk::Configuration db("oksconflibs:" + file);
      75              : 
      76            0 :   std::deque<std::set<std::string>> domains = construct_class_domains(db);
      77              : 
      78              : 
      79            0 :   std::map<std::string, uint> class_domain_map;
      80            0 :   conffwk::fmap<uint> class_domain_map_2;
      81              :   // Print the clustered domains
      82            0 :   fmt::print("Found {} inheritance domains\n", domains.size());
      83            0 :   for( size_t i(0); i<domains.size(); ++i ) {
      84            0 :     const auto& dom = domains[i];
      85            0 :     fmt::print("   - {} : {}", i, fmt::join(dom, ","));
      86              :     // fmt::print("   - {} : {}", i, dom);
      87            0 :     for( const auto& class_name : dom ) {
      88            0 :       class_domain_map[class_name] = i;
      89            0 :       class_domain_map_2[&conffwk::DalFactory::instance().get_known_class_name_ref(class_name)] = i;
      90              :     }
      91            0 :     fmt::print("\n");
      92              :   }
      93              : 
      94            0 :   for( const auto& [name, id] : class_domain_map ) {
      95            0 :     fmt::print("- {} : {}\n", name, id);
      96              :   }
      97              : 
      98            0 :   fmt::print("-------------------\n");
      99            0 :   fmt::print("cdm2 {}\n", class_domain_map_2.size());
     100              :   
     101              : 
     102              : 
     103            0 :   for( const auto& [name, id] : class_domain_map_2 ) {
     104            0 :     fmt::print("+ {} : {}\n", *name, id);
     105              :   }
     106              : 
     107              :   /* code */
     108            0 :   return 0;
     109            0 : }
        

Generated by: LCOV version 2.0-1