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