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 "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 */
26namespace dbe {
27namespace config {
28namespace api {
29namespace info {
30//------------------------------------------------------------------------------------------
31template<>
32std::vector<dbe::tref>
33onclass::objects<true>(std::string const& cname, bool const keep_inherited)
34{
35 std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets(cname);
36
37 if (not keep_inherited) {
38 objectrefs.erase(std::remove_if(objectrefs.begin(),
39 objectrefs.end(),
40 [&cname](dbe::tref anobject) { return (anobject.class_name() != cname); }),
41 objectrefs.end());
42 }
43
44 std::sort(objectrefs.begin(), objectrefs.end(), SortObjects());
45
46 return objectrefs;
47}
48template std::vector<dbe::tref>
49onclass::objects<true>(std::string const&, bool const);
50
51template<>
52std::vector<dbe::tref>
53onclass::objects<false>(std::string const& cname, bool const keep_inherited)
54{
55 std::vector<dbe::tref> objectrefs = inner::dbcontroller::gets(cname);
56
57 if (not keep_inherited) {
58 objectrefs.erase(std::remove_if(objectrefs.begin(),
59 objectrefs.end(),
60 [&cname](dbe::tref anobject) { return (anobject.class_name() != cname); }),
61 objectrefs.end());
62 }
63
64 return objectrefs;
65}
66template std::vector<dbe::tref>
67onclass::objects<false>(std::string const&, bool const);
68//------------------------------------------------------------------------------------------
69
70//------------------------------------------------------------------------------------------
71bool
72onclass::derived(std::string const& fromclass, std::string const& aclass)
73{
75
76 for (std::string const& x : aclassdef.p_superclasses) {
77 if (fromclass == x) {
78 return true;
79 }
80 }
81
82 return false;
83}
84//------------------------------------------------------------------------------------------
85
86//------------------------------------------------------------------------------------------
87bool
88has_obj(std::string const& classname, std::string const& object_uid)
89{
90 try {
91 return not inner::dbcontroller::get({ object_uid, classname }).is_null();
92 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
93 return false;
94 }
95
96 return true;
97}
98//------------------------------------------------------------------------------------------
99
100//------------------------------------------------------------------------------------------
102onclass::definition(const std::string& cn, bool direct_only)
103{
104 try {
105 return dbaccessor::dbptr()->get_class_info(cn, direct_only);
106 } catch (dunedaq::conffwk::NotFound const& Ex) {
108 }
109}
110//------------------------------------------------------------------------------------------
111
112//------------------------------------------------------------------------------------------
114attributematch(QString const& AttributeName, QString const& ClassName)
115{
116 const dunedaq::conffwk::class_t& ClassInfo =
117 dbe::config::api::info::onclass::definition(ClassName.toStdString(), false);
118 const std::vector<dunedaq::conffwk::attribute_t> AttributeList = ClassInfo.p_attributes;
119
120 for (auto& Attribute : AttributeList) {
121 if (Attribute.p_name == AttributeName.toStdString()) {
122 return Attribute;
123 }
124 }
125
127}
128//------------------------------------------------------------------------------------------
129
130//------------------------------------------------------------------------------------------
131bool
137//------------------------------------------------------------------------------------------
138
139//------------------------------------------------------------------------------------------
140template<>
142info::relation::match<std::string>(std::string const& arelation, std::string const& aclass)
143{
144 dunedaq::conffwk::class_t const& aninfo_for_class = dbe::config::api::info::onclass::definition(aclass, false);
145 std::vector<dunedaq::conffwk::relationship_t> const relations = aninfo_for_class.p_relationships;
146
147 for (auto& r : relations) {
148 if (r.p_name == arelation) {
149 return r;
150 }
151 }
153}
155info::relation::match<std::string>(std::string const&, std::string const&);
156//------------------------------------------------------------------------------------------
157
158//------------------------------------------------------------------------------------------
159template<>
161info::relation::match<QString>(QString const& arelation, QString const& aclass)
162{
163 return match(aclass.toStdString(), arelation.toStdString());
164}
166info::relation::match<QString>(QString const&, QString const&);
167//------------------------------------------------------------------------------------------
168}
169}
170}
171}
172//------------------------------------------------------------------------------------------
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:36
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:161
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:162
const std::vector< std::string > p_superclasses
Definition Schema.hpp:159