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