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 {
29namespace config {
30namespace api {
31namespace graph {
32
33//------------------------------------------------------------------------------------------
34namespace linked {
35namespace through {
36//------------------------------------------------------------------------------------------
37//------------------------------------------------------------------------------------------
38/*
39 * Objects referenced by the given object through a specific attribute
40 */
41template<>
44{
45 return object.get<tref>(attr.p_name);
46}
47
48template<>
49std::vector<tref>
51{
52 if (attr.p_type == dunedaq::conffwk::class_type) {
53 if (attr.p_is_multi_value) {
54 std::vector<tref> adj;
55 item.get(attr.p_name, adj);
56 return adj;
57 } else if (attr.p_is_not_null) {
58 try {
59 return { attribute<tref>(item, attr) };
60 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
61 if (attr.p_is_not_null) {
62 WARN("Query returned null value for an attr that has p_is_not_null set true",
63 "Program parsing data validation failure",
64 item.full_name(),
65 " for attribute ",
66 attr.p_name);
67 } else {
68 DEBUG("Query returned null value", "Program parsing data validation");
69 }
70 }
71 }
72 }
73
74 return {};
75}
76//------------------------------------------------------------------------------------------
77
78//------------------------------------------------------------------------------------------
79/*
80 * Objects referenced by the given object through a specific relation
81 */
82template<>
85{
86 return object.get<tref>(r.p_name);
87}
88
89template<>
90std::vector<tref>
92{
94 try {
95 return { through::relation<tref>(item, r) };
96 } catch (daq::dbe::config_object_retrieval_result_is_null const& e) {
97 return {};
98 }
99 } else {
100 std::vector<tref> adjacent;
101 item.get(r.p_name, adjacent);
102 return adjacent;
103 }
104}
105
106template<>
107QStringList
109{
110 QStringList result;
111 std::vector<tref> adjacent = relation<std::vector<tref>>(item, r);
112
113 for (auto const& x : adjacent) {
114 result.push_back(x.UID().c_str());
115 }
116
117 return result;
118}
119
120template<>
121std::vector<dbe::config_object_description<std::string>>
124{
125 std::vector<dbe::config_object_description<std::string>> result;
126
127 std::vector<tref> adjacent = linked::through::relation<std::vector<tref>>(object, relation);
128
129 for (auto const& x : adjacent) {
130 result.push_back(x);
131 }
132
133 return result;
134}
135
136//------------------------------------------------------------------------------------------
137} // end namespace through
138} // end namespace link
139
140//------------------------------------------------------------------------------------------
141template<typename T>
142inline T
144{
145 T value;
146 input.get(relation.p_name, value);
147 return value;
148}
149
150template ConfigObject
152
153template std::vector<ConfigObject>
155//------------------------------------------------------------------------------------------
156
157//------------------------------------------------------------------------------------------
158/*
159 * Retrieve objects referenced by an object through any of its relations
160 */
161template<typename T>
162std::vector<T>
164{
166
167 std::vector<T> voisins;
168
169 for (dunedaq::conffwk::relationship_t const& r : classdef.p_relationships) {
170 std::vector<T> a = relation<std::vector<T>>(o, r);
171 voisins.insert(voisins.end(), a.begin(), a.end());
172 }
173
174 voisins.erase(std::unique(std::begin(voisins), std::end(voisins)), std::end(voisins));
175 return voisins;
176}
177template std::vector<tref>
179
180/*
181 * Retrieve objects linked by an object through any of its attributes
182 */
183template<typename T>
184std::vector<T>
186{
188
189 std::vector<T> voisins;
190
191 for (dunedaq::conffwk::attribute_t const& attr : classdef.p_attributes) {
192 std::vector<tref> a = attribute<std::vector<T>>(o, attr);
193 voisins.insert(voisins.end(), a.begin(), a.end());
194 }
195
196 voisins.erase(std::unique(std::begin(voisins), std::end(voisins)), std::end(voisins));
197 return voisins;
198}
199template std::vector<tref>
201//------------------------------------------------------------------------------------------
202
203//------------------------------------------------------------------------------------------
204/*
205 * Retrieve links by operating directly on a ConfigObject
206 */
207template<typename T>
208inline T
210{
211 T value;
212 input.get(relation.p_name, value);
213 return value;
214}
215
216template<>
217inline QStringList
219{
220 QStringList result;
221 std::vector<ConfigObject> adjacent;
222
223 if (info::relation::is_simple(relation)) {
224 adjacent = { direct::linked<ConfigObject>(input, relation) };
225 } else {
226 adjacent = direct::linked<std::vector<ConfigObject>>(input, relation);
227 }
228
229 for (auto const& x : adjacent) {
230 result.push_back(x.UID().c_str());
231 }
232
233 return result;
234}
235
236template ConfigObject
238template std::vector<ConfigObject>
240template QStringList
242//------------------------------------------------------------------------------------------
243
244template tref
246template std::vector<tref>
248template tref
250template std::vector<tref>
252template QStringList
254template std::vector<dbe::config_object_description<std::string>>
258//------------------------------------------------------------------------------------------
259
260//------------------------------------------------------------------------------------------
261namespace linked {
262namespace by {
263/*
264 * Get objects that are linked by a given object
265 */
266template<typename T>
267std::vector<T>
269{
270 std::vector<T> links = through::attributes<T>(o);
271 std::vector<T> rlinks = through::relations<T>(o);
272
273 if (not rlinks.empty()) {
274 links.insert(links.end(), rlinks.begin(), rlinks.end());
275 }
276
277 links.erase(std::unique(links.begin(), links.end()), links.end());
278
279 return links;
280}
281
282} // end namespace by
283} // end namespace link
284template std::vector<inner::configobject::tref>
286//------------------------------------------------------------------------------------------
287
288//------------------------------------------------------------------------------------------
289namespace linked {
290namespace to {
291
292/*
293 * Get objects which link to a given object
294 */
295template<>
296std::vector<inner::configobject::tref>
298{
299 // Use with caution ... takes for ever to complete due to the underlying
300 // ConfigObject implementation
301 return o.referenced_by("*", false);
302}
303
304} // end namespace to
305} // end namespace link
306template std::vector<inner::configobject::tref>
308//------------------------------------------------------------------------------------------
309}
310}
311}
312}
313//------------------------------------------------------------------------------------------
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:82
#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:36
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:161
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:162