DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
config_api_graph.cpp
Go to the documentation of this file.
1/*
2 * config_api_graph.cpp
3 *
4 * Created on: Apr 20, 2016
5 * Author: Leonidas Georgopoulos
6 */
7
11#include "dbe/dbcontroller.hpp"
12#include "dbe/messenger.hpp"
13
14#include "conffwk/Schema.hpp"
15
16#include <algorithm>
17
18using namespace dunedaq::conffwk;
19
20//------------------------------------------------------------------------------------------
21// DBE::CONFIG::API::GRAPH NAMESPACE
22//------------------------------------------------------------------------------------------
23namespace dbe
24{
25namespace config
26{
27namespace api
28{
29namespace graph
30{
31
32
33//------------------------------------------------------------------------------------------
34namespace linked
35{
36namespace through
37{
38//------------------------------------------------------------------------------------------
39//------------------------------------------------------------------------------------------
40/*
41 * Objects referenced by the given object through a specific attribute
42 */
43template<>
45{
46 return object.get<tref> ( attr.p_name );
47}
48
49template<>
50std::vector<tref> attribute<std::vector<tref>> (
51 tref item, dunedaq::conffwk::attribute_t const & attr )
52{
53 if ( attr.p_type == dunedaq::conffwk::class_type )
54 {
55 if ( attr.p_is_multi_value )
56 {
57 std::vector<tref> adj;
58 item.get ( attr.p_name, adj );
59 return adj;
60 }
61 else if ( attr.p_is_not_null )
62 {
63 try
64 {
65 return
66 { attribute<tref> ( item, attr ) };
67 }
68 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
69 {
70 if ( attr.p_is_not_null )
71 {
72 WARN (
73 "Query returned null value for an attr that has p_is_not_null set true",
74 "Program parsing data validation failure", item.full_name(),
75 " for attribute ", attr.p_name );
76 }
77 else
78 {
79 DEBUG ( "Query returned null value", "Program parsing data validation" );
80 }
81 }
82 }
83 }
84
85 return
86 {};
87}
88//------------------------------------------------------------------------------------------
89
90//------------------------------------------------------------------------------------------
91/*
92 * Objects referenced by the given object through a specific relation
93 */
94template<>
96{
97 return object.get<tref> ( r.p_name );
98}
99
100template<>
101std::vector<tref> relation<std::vector<tref>> (
102 tref item, dunedaq::conffwk::relationship_t const & r )
103{
105 {
106 try
107 {
108 return
109 { through::relation<tref> ( item, r ) };
110 }
111 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
112 {
113 return
114 {};
115 }
116 }
117 else
118 {
119 std::vector<tref> adjacent;
120 item.get ( r.p_name, adjacent );
121 return adjacent;
122 }
123}
124
125template<>
127 tref item, dunedaq::conffwk::relationship_t const & r )
128{
129 QStringList result;
130 std::vector<tref> adjacent = relation<std::vector<tref>> ( item, r );
131
132 for ( auto const & x : adjacent )
133 {
134 result.push_back ( x.UID().c_str() );
135 }
136
137 return result;
138}
139
140template<>
141std::vector<dbe::config_object_description<std::string>> relation <
142 std::vector<dbe::config_object_description<std::string> > > (
144{
145 std::vector<dbe::config_object_description<std::string>> result;
146
147 std::vector<tref> adjacent = linked::through::relation<std::vector<tref>> ( object,
148 relation );
149
150 for ( auto const & x : adjacent )
151 {
152 result.push_back ( x );
153 }
154
155 return result;
156}
157
158//------------------------------------------------------------------------------------------
159} // end namespace through
160} // end namespace link
161
162//------------------------------------------------------------------------------------------
163template<typename T>
164inline T direct::linked ( ConfigObject & input,
165 dunedaq::conffwk::relationship_t const & relation )
166{
167 T value;
168 input.get ( relation.p_name, value );
169 return value;
170}
171
172template
175
176template
177std::vector<ConfigObject>
180//------------------------------------------------------------------------------------------
181
182//------------------------------------------------------------------------------------------
183/*
184 * Retrieve objects referenced by an object through any of its relations
185 */
186template<typename T>
188{
190 { info::onclass::definition ( o.class_name(), false ) };
191
192 std::vector<T> voisins;
193
194 for ( dunedaq::conffwk::relationship_t const & r : classdef.p_relationships )
195 {
196 std::vector<T> a = relation<std::vector<T>> ( o, r );
197 voisins.insert ( voisins.end(), a.begin(), a.end() );
198 }
199
200 voisins.erase ( std::unique ( std::begin ( voisins ), std::end ( voisins ) ),
201 std::end ( voisins ) );
202 return voisins;
203}
204template std::vector<tref> linked::through::relations<tref> ( tref const & );
205
206/*
207 * Retrieve objects linked by an object through any of its attributes
208 */
209template<typename T>
211{
213 { info::onclass::definition ( o.class_name(), true ) };
214
215 std::vector<T> voisins;
216
217 for ( dunedaq::conffwk::attribute_t const & attr : classdef.p_attributes )
218 {
219 std::vector<tref> a = attribute<std::vector<T>> ( o, attr );
220 voisins.insert ( voisins.end(), a.begin(), a.end() );
221 }
222
223 voisins.erase ( std::unique ( std::begin ( voisins ), std::end ( voisins ) ),
224 std::end ( voisins ) );
225 return voisins;
226}
227template std::vector<tref> linked::through::attributes<tref> ( tref const & );
228//------------------------------------------------------------------------------------------
229
230//------------------------------------------------------------------------------------------
231/*
232 * Retrieve links by operating directly on a ConfigObject
233 */
234template<typename T>
235inline T direct::linked ( ConfigObject & input, dunedaq::conffwk::attribute_t const & relation )
236{
237 T value;
238 input.get ( relation.p_name, value );
239 return value;
240}
241
242template<>
243inline QStringList direct::linked<QStringList> (
244 ConfigObject & input, dunedaq::conffwk::relationship_t const & relation )
245{
246 QStringList result;
247 std::vector<ConfigObject> adjacent;
248
249 if ( info::relation::is_simple ( relation ) )
250 {
251 adjacent =
252 { direct::linked<ConfigObject> ( input, relation ) };
253 }
254 else
255 {
256 adjacent = direct::linked<std::vector<ConfigObject>> ( input, relation );
257 }
258
259 for ( auto const & x : adjacent )
260 {
261 result.push_back ( x.UID().c_str() );
262 }
263
264 return result;
265}
266
267template
270template
271std::vector<ConfigObject>
274template
275QStringList direct::linked<QStringList> (
277//------------------------------------------------------------------------------------------
278
279
280template
283template
286template
288template
289std::vector<tref>
291template
294template
295std::vector<dbe::config_object_description<std::string>> linked::through::relation <
296std::vector<dbe::config_object_description<std::string> > > (
298//------------------------------------------------------------------------------------------
299
300//------------------------------------------------------------------------------------------
301namespace linked
302{
303namespace by
304{
305/*
306 * Get objects that are linked by a given object
307 */
308template<typename T> std::vector<T> object ( inner::configobject::tref const & o )
309{
310 std::vector<T> links = through::attributes<T> ( o );
311 std::vector<T> rlinks = through::relations<T> ( o );
312
313 if ( not rlinks.empty() )
314 {
315 links.insert ( links.end(), rlinks.begin(), rlinks.end() );
316 }
317
318 links.erase ( std::unique ( links.begin(), links.end() ), links.end() );
319
320 return links;
321}
322
323} // end namespace by
324} // end namespace link
325template
326std::vector<inner::configobject::tref>
327linked::by::object<inner::configobject::tref> ( inner::configobject::tref const & );
328//------------------------------------------------------------------------------------------
329
330//------------------------------------------------------------------------------------------
331namespace linked
332{
333namespace to
334{
335
336/*
337 * Get objects which link to a given object
338 */
339template<>
340std::vector<inner::configobject::tref> object<inner::configobject::tref> (
341 inner::configobject::tref const & o )
342{
343 // Use with caution ... takes for ever to complete due to the underlying
344 // ConfigObject implementation
345 return o.referenced_by ( "*", false );
346}
347
348} // end namespace to
349} // end namespace link
350template
351std::vector<inner::configobject::tref>
353//------------------------------------------------------------------------------------------
354}
355}
356}
357}
358//------------------------------------------------------------------------------------------
359
static T linked(dunedaq::conffwk::ConfigObject &item, dunedaq::conffwk::relationship_t const &relation)
static dunedaq::conffwk::class_t definition(std::string const &cn, bool direct_only)
std::vector< T > referenced_by(std::string const &name="*", bool check_composite_only=true) const
Represents database objects.
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
#define WARN(...)
Definition messenger.hpp:80
#define DEBUG(...)
std::vector< T > object(tref const &item)
QStringList relation< QStringList >(tref item, dunedaq::conffwk::relationship_t const &r)
std::vector< T > attributes(tref const &item)
T attribute(tref item, dunedaq::conffwk::attribute_t const &attr)
tref relation< tref >(tref object, dunedaq::conffwk::relationship_t const &r)
tref attribute< tref >(tref object, dunedaq::conffwk::attribute_t const &attr)
T relation(tref item, dunedaq::conffwk::relationship_t const &relation)
std::vector< T > relations(tref const &item)
std::vector< inner::configobject::tref > object< inner::configobject::tref >(inner::configobject::tref const &o)
template std::vector< inner::configobject::tref > linked::by::object< inner::configobject::tref >(inner::configobject::tref const &)
bool is_simple(dunedaq::conffwk::relationship_t const &)
Include QT Headers.
inner::configobject::tref tref
Definition tref.hpp:30