LCOV - code coverage report
Current view: top level - dbe/src/internal - config_api_info.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 56.9 % 58 33
Test Date: 2026-10-11 15:05:20 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 "conffwk/Schema.hpp"
      15              : #include "dbe/Sorting.hpp"
      16              : #include "dbe/config_api.hpp"
      17              : #include "dbe/treenode.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              : namespace config {
      28              : namespace api {
      29              : namespace info {
      30              : //------------------------------------------------------------------------------------------
      31              : template<>
      32              : std::vector<dbe::tref>
      33            2 : onclass::objects<true>(std::string const& cname, bool const keep_inherited)
      34              : {
      35            2 :   std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets(cname);
      36              : 
      37            2 :   if (not keep_inherited) {
      38            1 :     objectrefs.erase(std::remove_if(objectrefs.begin(),
      39              :                                     objectrefs.end(),
      40            3 :                                     [&cname](dbe::tref anobject) { return (anobject.class_name() != cname); }),
      41            2 :                      objectrefs.end());
      42              :   }
      43              : 
      44            2 :   std::sort(objectrefs.begin(), objectrefs.end(), SortObjects());
      45              : 
      46            2 :   return objectrefs;
      47            0 : }
      48              : template std::vector<dbe::tref>
      49              : onclass::objects<true>(std::string const&, bool const);
      50              : 
      51              : template<>
      52              : std::vector<dbe::tref>
      53            0 : onclass::objects<false>(std::string const& cname, bool const keep_inherited)
      54              : {
      55            0 :   std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets(cname);
      56              : 
      57            0 :   if (not keep_inherited) {
      58            0 :     objectrefs.erase(std::remove_if(objectrefs.begin(),
      59              :                                     objectrefs.end(),
      60            0 :                                     [&cname](dbe::tref anobject) { return (anobject.class_name() != cname); }),
      61            0 :                      objectrefs.end());
      62              :   }
      63              : 
      64            0 :   return objectrefs;
      65            0 : }
      66              : template std::vector<dbe::tref>
      67              : onclass::objects<false>(std::string const&, bool const);
      68              : //------------------------------------------------------------------------------------------
      69              : 
      70              : //------------------------------------------------------------------------------------------
      71              : bool
      72            3 : onclass::derived(std::string const& fromclass, std::string const& aclass)
      73              : {
      74            3 :   dunedaq::conffwk::class_t aclassdef{ dbe::config::api::info::onclass::definition(aclass, false) };
      75              : 
      76           10 :   for (std::string const& x : aclassdef.p_superclasses) {
      77           10 :     if (fromclass == x) {
      78            3 :       return true;
      79              :     }
      80              :   }
      81              : 
      82            0 :   return false;
      83            3 : }
      84              : //------------------------------------------------------------------------------------------
      85              : 
      86              : //------------------------------------------------------------------------------------------
      87              : bool
      88            1 : has_obj(std::string const& classname, std::string const& object_uid)
      89              : {
      90            1 :   try {
      91            1 :     return not inner::dbcontroller::get({ object_uid, classname }).is_null();
      92            0 :   } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
      93            0 :     return false;
      94            0 :   }
      95              : 
      96              :   return true;
      97              : }
      98              : //------------------------------------------------------------------------------------------
      99              : 
     100              : //------------------------------------------------------------------------------------------
     101              : dunedaq::conffwk::class_t
     102           15 : onclass::definition(const std::string& cn, bool direct_only)
     103              : {
     104           15 :   try {
     105           17 :     return dbaccessor::dbptr()->get_class_info(cn, direct_only);
     106            2 :   } catch (dunedaq::conffwk::NotFound const& Ex) {
     107            2 :     return dunedaq::conffwk::class_t();
     108            2 :   }
     109              : }
     110              : //------------------------------------------------------------------------------------------
     111              : 
     112              : //------------------------------------------------------------------------------------------
     113              : dunedaq::conffwk::attribute_t
     114            0 : attributematch(QString const& AttributeName, QString const& ClassName)
     115              : {
     116            0 :   const dunedaq::conffwk::class_t& ClassInfo =
     117            0 :     dbe::config::api::info::onclass::definition(ClassName.toStdString(), false);
     118            0 :   const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.p_attributes;
     119              : 
     120            0 :   for (auto& Attribute : AttributeList) {
     121            0 :     if (Attribute.p_name == AttributeName.toStdString()) {
     122            0 :       return Attribute;
     123              :     }
     124              :   }
     125              : 
     126            0 :   return dunedaq::conffwk::attribute_t();
     127            0 : }
     128              : //------------------------------------------------------------------------------------------
     129              : 
     130              : //------------------------------------------------------------------------------------------
     131              : bool
     132            1 : relation::is_simple(dunedaq::conffwk::relationship_t const& relation)
     133              : {
     134            1 :   return (relation.p_cardinality == dunedaq::conffwk::only_one) or
     135            1 :          (relation.p_cardinality == dunedaq::conffwk::zero_or_one);
     136              : }
     137              : //------------------------------------------------------------------------------------------
     138              : 
     139              : //------------------------------------------------------------------------------------------
     140              : template<>
     141              : dunedaq::conffwk::relationship_t
     142            1 : info::relation::match<std::string>(std::string const& arelation, std::string const& aclass)
     143              : {
     144            1 :   dunedaq::conffwk::class_t const& aninfo_for_class = dbe::config::api::info::onclass::definition(aclass, false);
     145            1 :   std::vector<dunedaq::conffwk::relationship_t> const relations = aninfo_for_class.p_relationships;
     146              : 
     147            1 :   for (auto& r : relations) {
     148            1 :     if (r.p_name == arelation) {
     149            1 :       return r;
     150              :     }
     151              :   }
     152            0 :   return dunedaq::conffwk::relationship_t();
     153            1 : }
     154              : template dunedaq::conffwk::relationship_t
     155              : info::relation::match<std::string>(std::string const&, std::string const&);
     156              : //------------------------------------------------------------------------------------------
     157              : 
     158              : //------------------------------------------------------------------------------------------
     159              : template<>
     160              : dunedaq::conffwk::relationship_t
     161            0 : info::relation::match<QString>(QString const& arelation, QString const& aclass)
     162              : {
     163            0 :   return match(aclass.toStdString(), arelation.toStdString());
     164              : }
     165              : template dunedaq::conffwk::relationship_t
     166              : info::relation::match<QString>(QString const&, QString const&);
     167              : //------------------------------------------------------------------------------------------
     168              : }
     169              : }
     170              : }
     171              : }
     172              : //------------------------------------------------------------------------------------------
        

Generated by: LCOV version 2.0-1