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