DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
config_api_info.cpp
Go to the documentation of this file.
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
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 */
26namespace dbe
27{
28namespace config
29{
30namespace api
31{
32namespace info
33{
34//------------------------------------------------------------------------------------------
35template<>
36std::vector<dbe::tref> onclass::objects<true> ( std::string const & cname,
37 bool const keep_inherited )
38{
39 std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets ( cname );
40
41 if ( not keep_inherited )
42 {
43 objectrefs.erase (
44 std::remove_if ( objectrefs.begin(), objectrefs.end(),
45 [&cname] ( dbe::tref anobject )
46 {
47 return ( anobject.class_name() != cname );
48 } ),
49 objectrefs.end() );
50 }
51
52 std::sort ( objectrefs.begin(), objectrefs.end(), SortObjects() );
53
54 return objectrefs;
55}
56template std::vector<dbe::tref> onclass::objects<true> ( std::string const &, bool const );
57
58template<>
59std::vector<dbe::tref> onclass::objects<false> ( std::string const & cname,
60 bool const keep_inherited )
61{
62 std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets ( cname );
63
64 if ( not keep_inherited )
65 {
66 objectrefs.erase (
67 std::remove_if ( objectrefs.begin(), objectrefs.end(),
68 [&cname] ( dbe::tref anobject )
69 {
70 return ( anobject.class_name() != cname );
71 } ),
72 objectrefs.end() );
73 }
74
75 return objectrefs;
76}
77template std::vector<dbe::tref> onclass::objects<false> ( std::string const &, bool const );
78//------------------------------------------------------------------------------------------
79
80//------------------------------------------------------------------------------------------
81bool onclass::derived ( std::string const & fromclass, std::string const & aclass )
82{
85
86 for ( std::string const & x : aclassdef.p_superclasses )
87 {
88 if ( fromclass == x )
89 {
90 return true;
91 }
92 }
93
94 return false;
95}
96//------------------------------------------------------------------------------------------
97
98//------------------------------------------------------------------------------------------
99bool has_obj ( std::string const & classname, std::string const & object_uid )
100{
101 try
102 {
103 return not inner::dbcontroller::get (
104 { object_uid, classname} ).is_null();
105 }
106 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
107 {
108 return false;
109 }
110
111 return true;
112}
113//------------------------------------------------------------------------------------------
114
115//------------------------------------------------------------------------------------------
116dunedaq::conffwk::class_t onclass::definition ( const std::string & cn, bool direct_only )
117{
118 try
119 {
120 return dbaccessor::dbptr()->get_class_info ( cn, direct_only );
121 }
122 catch ( dunedaq::conffwk::NotFound const & Ex )
123 {
125 }
126}
127//------------------------------------------------------------------------------------------
128
129//------------------------------------------------------------------------------------------
130dunedaq::conffwk::attribute_t attributematch ( QString const & AttributeName,
131 QString const & ClassName )
132{
134 ClassName.toStdString(), false );
135 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.p_attributes;
136
137 for ( auto & Attribute : AttributeList )
138 {
139 if ( Attribute.p_name == AttributeName.toStdString() )
140 {
141 return Attribute;
142 }
143 }
144
146}
147//------------------------------------------------------------------------------------------
148
149//------------------------------------------------------------------------------------------
151{
152 return ( relation.p_cardinality == dunedaq::conffwk::only_one )
153 or ( relation.p_cardinality == dunedaq::conffwk::zero_or_one );
154}
155//------------------------------------------------------------------------------------------
156
157//------------------------------------------------------------------------------------------
159 std::string const & arelation,
160 std::string const & aclass )
161{
162 dunedaq::conffwk::class_t const & aninfo_for_class =
164 std::vector<dunedaq::conffwk::relationship_t> const relations =
165 aninfo_for_class.p_relationships;
166
167 for ( auto & r : relations )
168 {
169 if ( r.p_name == arelation )
170 {
171 return r;
172 }
173 }
175}
177 std::string const & ,
178 std::string const & );
179//------------------------------------------------------------------------------------------
180
181//------------------------------------------------------------------------------------------
183 QString const & arelation,
184 QString const & aclass )
185{
186 return match(aclass.toStdString(), arelation.toStdString());
187}
189 QString const & ,
190 QString const & );
191//------------------------------------------------------------------------------------------
192}
193}
194}
195}
196//------------------------------------------------------------------------------------------
static bool derived(std::string const &fromclass, std::string const &aclass)
static std::vector< dbe::inner::configobject::tref > objects(std::string const &cname, bool const keep_inherited=true)
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
static cptr< dunedaq::conffwk::Configuration > dbptr()
static std::vector< configobject::tref > gets(std::string const &cname, std::string const &query="")
static configobject::tref get(dbe::cokey const &desc)
dunedaq::conffwk::relationship_t match< QString >(QString const &, QString const &)
dunedaq::conffwk::relationship_t match< std::string >(std::string const &, std::string const &)
bool is_simple(dunedaq::conffwk::relationship_t const &)
bool has_obj(std::string const &classname, std::string const &object_uid)
dunedaq::conffwk::attribute_t attributematch(QString const &, QString const &)
Include QT Headers.
inner::configobject::tref tref
Definition tref.hpp:35
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:170
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:171
const std::vector< std::string > p_superclasses
Definition Schema.hpp:168