LCOV - code coverage report
Current view: top level - dbe/src/internal - config_api_info.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 59.1 % 66 39
Test Date: 2025-12-21 13:07:08 Functions: 63.6 % 11 7

            Line data    Source code
       1              : /*
       2              :  * config_api_info.cpp
       3              :  *
       4              :  *  Created on: Apr 20, 2016
       5              :  *      Author: Leonidas Georgopoulos
       6              :  */
       7              : 
       8              : #include "dbe/config_api_info.hpp"
       9              : #include "dbe/config_api.hpp"
      10              : #include "dbe/treenode.hpp"
      11              : #include "dbe/Sorting.hpp"
      12              : #include "conffwk/Schema.hpp"
      13              : #include <QString>
      14              : //------------------------------------------------------------------------------------------
      15              : //                                    DBE::CONFIG::API::INFO NAMESPACE
      16              : //------------------------------------------------------------------------------------------
      17              : /*
      18              :  * This namespace groups methods for providing information about config related
      19              :  * structures and objects
      20              :  */
      21              : namespace dbe
      22              : {
      23              : namespace config
      24              : {
      25              : namespace api
      26              : {
      27              : namespace info
      28              : {
      29              : //------------------------------------------------------------------------------------------
      30              : template<>
      31            2 : std::vector<dbe::tref> onclass::objects<true> ( std::string const & cname,
      32              :                                                 bool const keep_inherited )
      33              : {
      34            2 :   std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets ( cname );
      35              : 
      36            2 :   if ( not keep_inherited )
      37              :   {
      38            1 :     objectrefs.erase (
      39            1 :       std::remove_if ( objectrefs.begin(), objectrefs.end(),
      40            3 :                        [&cname] ( dbe::tref anobject )
      41              :     {
      42            3 :       return ( anobject.class_name() != cname );
      43              :     } ),
      44            2 :     objectrefs.end() );
      45              :   }
      46              : 
      47            2 :   std::sort ( objectrefs.begin(), objectrefs.end(), SortObjects() );
      48              : 
      49            2 :   return objectrefs;
      50            0 : }
      51              : template std::vector<dbe::tref> onclass::objects<true> ( std::string const &, bool const );
      52              : 
      53              : template<>
      54            0 : std::vector<dbe::tref> onclass::objects<false> ( std::string const & cname,
      55              :                                                  bool const keep_inherited )
      56              : {
      57            0 :   std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets ( cname );
      58              : 
      59            0 :   if ( not keep_inherited )
      60              :   {
      61            0 :     objectrefs.erase (
      62            0 :       std::remove_if ( objectrefs.begin(), objectrefs.end(),
      63            0 :                        [&cname] ( dbe::tref anobject )
      64              :     {
      65            0 :       return ( anobject.class_name() != cname );
      66              :     } ),
      67            0 :     objectrefs.end() );
      68              :   }
      69              : 
      70            0 :   return objectrefs;
      71            0 : }
      72              : template std::vector<dbe::tref> onclass::objects<false> ( std::string const &, bool const );
      73              : //------------------------------------------------------------------------------------------
      74              : 
      75              : //------------------------------------------------------------------------------------------
      76            3 : bool onclass::derived ( std::string const & fromclass, std::string const & aclass )
      77              : {
      78            3 :   dunedaq::conffwk::class_t aclassdef
      79            3 :   { dbe::config::api::info::onclass::definition ( aclass, false ) };
      80              : 
      81           10 :   for ( std::string const & x : aclassdef.p_superclasses )
      82              :   {
      83           10 :     if ( fromclass == x )
      84              :     {
      85            3 :       return true;
      86              :     }
      87              :   }
      88              : 
      89            0 :   return false;
      90            3 : }
      91              : //------------------------------------------------------------------------------------------
      92              : 
      93              : //------------------------------------------------------------------------------------------
      94            1 : bool has_obj ( std::string const & classname, std::string const & object_uid )
      95              : {
      96            1 :   try
      97              :   {
      98            2 :     return not inner::dbcontroller::get (
      99            1 :     { object_uid, classname} ).is_null();
     100              :   }
     101            0 :   catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
     102              :   {
     103            0 :     return false;
     104            0 :   }
     105              : 
     106              :   return true;
     107              : }
     108              : //------------------------------------------------------------------------------------------
     109              : 
     110              : //------------------------------------------------------------------------------------------
     111           15 : dunedaq::conffwk::class_t onclass::definition ( const std::string & cn, bool direct_only )
     112              : {
     113           15 :   try
     114              :   {
     115           17 :     return dbaccessor::dbptr()->get_class_info ( cn, direct_only );
     116              :   }
     117            2 :   catch ( dunedaq::conffwk::NotFound const & Ex )
     118              :   {
     119            2 :     return dunedaq::conffwk::class_t();
     120            2 :   }
     121              : }
     122              : //------------------------------------------------------------------------------------------
     123              : 
     124              : //------------------------------------------------------------------------------------------
     125            0 : dunedaq::conffwk::attribute_t attributematch ( QString const & AttributeName,
     126              :                                           QString const & ClassName )
     127              : {
     128            0 :   const dunedaq::conffwk::class_t & ClassInfo = dbe::config::api::info::onclass::definition (
     129            0 :                                              ClassName.toStdString(), false );
     130            0 :   const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.p_attributes;
     131              : 
     132            0 :   for ( auto & Attribute : AttributeList )
     133              :   {
     134            0 :     if ( Attribute.p_name == AttributeName.toStdString() )
     135              :     {
     136            0 :       return Attribute;
     137              :     }
     138              :   }
     139              : 
     140            0 :   return dunedaq::conffwk::attribute_t();
     141            0 : }
     142              : //------------------------------------------------------------------------------------------
     143              : 
     144              : //------------------------------------------------------------------------------------------
     145            1 : bool relation::is_simple ( dunedaq::conffwk::relationship_t const & relation )
     146              : {
     147            1 :   return ( relation.p_cardinality == dunedaq::conffwk::only_one )
     148            1 :          or ( relation.p_cardinality == dunedaq::conffwk::zero_or_one );
     149              : }
     150              : //------------------------------------------------------------------------------------------
     151              : 
     152              : //------------------------------------------------------------------------------------------
     153            1 : template<> dunedaq::conffwk::relationship_t info::relation::match<std::string> (
     154              :         std::string const & arelation,
     155              :         std::string const & aclass )
     156              : {
     157            1 :   dunedaq::conffwk::class_t const & aninfo_for_class =
     158            1 :                 dbe::config::api::info::onclass::definition ( aclass, false );
     159            1 :   std::vector<dunedaq::conffwk::relationship_t> const relations =
     160            1 :                 aninfo_for_class.p_relationships;
     161              : 
     162            1 :   for ( auto & r : relations )
     163              :   {
     164            1 :     if ( r.p_name == arelation )
     165              :     {
     166            1 :       return r;
     167              :     }
     168              :   }
     169            0 :   return dunedaq::conffwk::relationship_t();
     170            1 : }
     171              : template dunedaq::conffwk::relationship_t info::relation::match<std::string> (
     172              :         std::string const & ,
     173              :         std::string const & );
     174              : //------------------------------------------------------------------------------------------
     175              : 
     176              : //------------------------------------------------------------------------------------------
     177            0 : template<> dunedaq::conffwk::relationship_t info::relation::match<QString>(
     178              :         QString const & arelation,
     179              :         QString const & aclass )
     180              : {
     181            0 :         return match(aclass.toStdString(), arelation.toStdString());
     182              : }
     183              : template dunedaq::conffwk::relationship_t info::relation::match<QString>(
     184              :         QString const & ,
     185              :         QString const & );
     186              : //------------------------------------------------------------------------------------------
     187              : }
     188              : }
     189              : }
     190              : }
     191              : //------------------------------------------------------------------------------------------
        

Generated by: LCOV version 2.0-1