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: 2026-07-12 15:23:06 Functions: 63.6 % 11 7

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

Generated by: LCOV version 2.0-1