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 : * configuration.cpp
8 : *
9 : * Created on: Mar 22, 2016
10 : * Author: Leonidas Georgopoulos
11 : */
12 :
13 : #include "dbe/config_ui_info.hpp"
14 : #include "dbe/config_api_info.hpp"
15 : #include "dbe/GraphicalClass.hpp"
16 : #include "dbe/messenger.hpp"
17 : #include "dbe/Conversion.hpp"
18 :
19 : #include "dbe/config_api_get.hpp"
20 : #include "dbe/config_api_graph.hpp"
21 :
22 : #include <QStringList>
23 :
24 : #include <map>
25 : #include <vector>
26 :
27 : using namespace dunedaq::conffwk;
28 :
29 0 : dbe::ui::config::info::info ( std::vector<std::string> const & full_file_name )
30 0 : : this_full_filenames ( full_file_name )
31 : {
32 0 : parse();
33 0 : }
34 :
35 0 : dbe::GraphicalClass dbe::ui::config::info::graphical ( std::string const & name ) const
36 : {
37 0 : std::map<std::string, GraphicalClass>::const_iterator it = this_graphical.find ( name );
38 :
39 0 : if ( it != this_graphical.end() )
40 : {
41 0 : return it->second;
42 : }
43 : else
44 : {
45 0 : return
46 0 : {};
47 : }
48 0 : }
49 :
50 0 : dbe::ViewConfiguration dbe::ui::config::info::view ( std::string const & name ) const
51 : {
52 0 : std::map<std::string, ViewConfiguration>::const_iterator it = this_views.find ( name );
53 :
54 0 : if ( it != this_views.end() )
55 : {
56 0 : return it->second;
57 : }
58 : else
59 : {
60 0 : return
61 0 : {};
62 : }
63 0 : }
64 :
65 0 : dbe::Window dbe::ui::config::info::window ( std::string const & name ) const
66 : {
67 0 : std::map<std::string, Window>::const_iterator it = this_windows.find ( name );
68 :
69 0 : if ( it != this_windows.end() )
70 : {
71 0 : return it->second;
72 : }
73 : else
74 : {
75 0 : return
76 0 : {};
77 : }
78 0 : }
79 :
80 0 : void dbe::ui::config::info::parse()
81 : {
82 0 : for ( std::string const & fname : this_full_filenames )
83 : {
84 0 : std::string Implementation = "oksconflibs:" + fname;
85 :
86 0 : try
87 : {
88 0 : std::shared_ptr<Configuration> ConfigFile ( new Configuration ( Implementation ) );
89 0 : std::vector<ConfigObject> objects;
90 :
91 0 : ConfigFile->get ( "Class", objects );
92 :
93 0 : for ( ConfigObject & aclass : objects )
94 : {
95 0 : parse_graphical ( ConfigFile, aclass );
96 : }
97 :
98 0 : objects.clear();
99 0 : ConfigFile->get ( "Window", objects );
100 :
101 0 : for ( ConfigObject & awindow : objects )
102 : {
103 0 : parse_window ( ConfigFile, awindow );
104 : }
105 0 : }
106 0 : catch ( dunedaq::conffwk::Exception const & ex )
107 : {
108 0 : ERROR ( "Configuration database load did not succeed",
109 0 : dbe::config::errors::parse ( ex ).c_str() );
110 0 : }
111 0 : }
112 0 : }
113 :
114 0 : void dbe::ui::config::info::parse_graphical ( std::shared_ptr<Configuration> ConfigFile,
115 : ConfigObject & Object )
116 : {
117 0 : GraphicalClass GraphicalClassObject;
118 :
119 0 : GraphicalClassObject.GraphicalUID = QString ( Object.UID().c_str() );
120 0 : dunedaq::conffwk::class_t cinfo = ConfigFile->get_class_info ( Object.class_name(), false );
121 :
122 0 : std::vector<dunedaq::conffwk::attribute_t> const & attributes = cinfo.p_attributes;
123 0 : std::vector<dunedaq::conffwk::relationship_t> const & relations = cinfo.p_relationships;
124 :
125 0 : for ( dunedaq::conffwk::attribute_t const & attr : attributes )
126 : {
127 0 : QStringList data = dbe::config::api::get::direct::attribute<QStringList> ( Object, attr );
128 :
129 0 : if ( attr.p_name == "Name" )
130 : {
131 0 : GraphicalClassObject.DatabaseClassName = data.at ( 0 );
132 : }
133 0 : else if ( attr.p_name == "Generic Pixmap File" )
134 : {
135 0 : GraphicalClassObject.GenericPixmapFile = data.at ( 0 );
136 : }
137 0 : else if ( attr.p_name == "Used Pixmap File" )
138 : {
139 0 : GraphicalClassObject.UsedPixmapFile = data.at ( 0 );
140 : }
141 0 : else if ( attr.p_name == "Icon Bitmap File" )
142 : {
143 0 : GraphicalClassObject.BitmapFile = data.at ( 0 );
144 : }
145 0 : else if ( attr.p_name == "Icon Mask Bitmap File" )
146 : {
147 0 : GraphicalClassObject.BitmapMaskFile = data.at ( 0 );
148 : }
149 0 : else if ( attr.p_name == "Show All Attributes" )
150 : {
151 0 : GraphicalClassObject.ShowAllAttributes = convert::to<bool> (
152 0 : data, attr.p_int_format );
153 : }
154 0 : else if ( attr.p_name == "Attributes" )
155 : {
156 0 : GraphicalClassObject.Attributes = data;
157 : }
158 0 : else if ( attr.p_name == "Show All Relationships" )
159 : {
160 0 : GraphicalClassObject.ShowAllRelationships = convert::to<bool> (
161 0 : data, attr.p_int_format );
162 : }
163 0 : else if ( attr.p_name == "Relationships" )
164 : {
165 0 : GraphicalClassObject.Relationships = data;
166 :
167 : }
168 0 : else if ( attr.p_name == "Icon Title" )
169 : {
170 0 : GraphicalClassObject.IconTitle = data.at ( 0 );
171 : }
172 0 : }
173 :
174 0 : for ( dunedaq::conffwk::relationship_t const & relation : relations )
175 : {
176 0 : QStringList data;
177 0 : std::vector<ConfigObject> neighboring
178 : { };
179 :
180 0 : if ( dbe::config::api::info::relation::is_simple ( relation ) )
181 : {
182 0 : neighboring.push_back (
183 0 : dbe::config::api::graph::direct::linked<ConfigObject> ( Object, relation ) );
184 : }
185 : else
186 : {
187 0 : std::vector<ConfigObject> objects = dbe::config::api::graph::direct::linked <
188 0 : std::vector<ConfigObject >> ( Object, relation );
189 0 : neighboring.insert ( std::end ( neighboring ), std::begin ( objects ),
190 : std::end ( objects ) );
191 0 : }
192 :
193 0 : for ( ConfigObject & RelObject : neighboring )
194 : {
195 0 : dunedaq::conffwk::class_t RelClassInfo = ConfigFile->get_class_info ( RelObject.class_name(),
196 0 : false );
197 0 : std::vector<dunedaq::conffwk::attribute_t> AttributeRelList = RelClassInfo.p_attributes;
198 :
199 0 : if ( RelObject.class_name() == "Dual Relationship" )
200 : {
201 0 : DualRelationship DRel;
202 :
203 0 : for ( dunedaq::conffwk::attribute_t & Attribute : AttributeRelList )
204 : {
205 0 : data = dbe::config::api::get::direct::attribute<QStringList> ( RelObject,
206 0 : Attribute );
207 :
208 0 : if ( Attribute.p_name == "Direct" )
209 : {
210 0 : DRel.Direct = data.at ( 0 );
211 : }
212 0 : else if ( Attribute.p_name == "Reverse" )
213 : {
214 0 : DRel.Reverse = data.at ( 0 );
215 : }
216 : }
217 :
218 0 : GraphicalClassObject.DualRelationships.push_back ( DRel );
219 0 : }
220 0 : else if ( RelObject.class_name() == "Init Attribute Value" )
221 : {
222 0 : InitAttributeFromEnv IRel;
223 :
224 0 : for ( dunedaq::conffwk::attribute_t & Attribute : AttributeRelList )
225 : {
226 0 : data = dbe::config::api::get::direct::attribute<QStringList> ( RelObject,
227 0 : Attribute );
228 :
229 0 : if ( Attribute.p_name == "Attribute Name" )
230 : {
231 0 : IRel.AttributeName = data.at ( 0 );
232 : }
233 0 : else if ( Attribute.p_name == "Environment Variables" )
234 : {
235 0 : IRel.EnvNames = data;
236 : }
237 : }
238 :
239 0 : GraphicalClassObject.NeedToInitialize.push_back ( IRel );
240 0 : }
241 0 : }
242 0 : }
243 :
244 0 : this_graphical.emplace ( GraphicalClassObject.GraphicalUID.toStdString(),
245 : GraphicalClassObject );
246 :
247 0 : }
248 :
249 0 : void dbe::ui::config::info::parse_window ( std::shared_ptr<Configuration> database,
250 : ConfigObject & object )
251 : {
252 0 : Window WindowObject;
253 0 : dunedaq::conffwk::class_t ClassInfo = database->get_class_info ( object.class_name(), false );
254 0 : std::vector<dunedaq::conffwk::attribute_t> const & attributes = ClassInfo.p_attributes;
255 0 : std::vector<dunedaq::conffwk::relationship_t> const & relations = ClassInfo.p_relationships;
256 :
257 0 : for ( dunedaq::conffwk::attribute_t const & attribute : attributes )
258 : {
259 0 : if ( attribute.p_name == "Title" )
260 : {
261 0 : WindowObject.Title = dbe::config::api::get::direct::attribute<QStringList> ( object,
262 : attribute ).at (
263 0 : 0 );
264 : }
265 : }
266 :
267 0 : for ( dunedaq::conffwk::relationship_t const & relation : relations )
268 : {
269 0 : std::vector<ConfigObject> linkedobjects;
270 :
271 0 : if ( dbe::config::api::info::relation::is_simple ( relation ) )
272 : {
273 0 : linkedobjects.push_back (
274 0 : dbe::config::api::graph::direct::linked<ConfigObject> ( object, relation ) );
275 : }
276 : else
277 : {
278 0 : std::vector<ConfigObject> voisins = dbe::config::api::graph::direct::linked <
279 0 : std::vector<ConfigObject >> ( object, relation );
280 :
281 0 : if ( not voisins.empty() )
282 : {
283 0 : linkedobjects.insert ( std::end ( linkedobjects ), std::begin ( voisins ),
284 : std::end ( voisins ) );
285 : }
286 0 : }
287 :
288 0 : for ( ConfigObject & neighbor : linkedobjects )
289 : {
290 0 : dunedaq::conffwk::class_t classinfo = database->get_class_info ( neighbor.class_name(),
291 0 : false );
292 0 : std::vector<dunedaq::conffwk::attribute_t> const & AttributeRelList = classinfo
293 : .p_attributes;
294 0 : std::vector<dunedaq::conffwk::relationship_t> const & RelationshipRelList = classinfo
295 : .p_relationships;
296 :
297 0 : if ( neighbor.class_name() != "Window Separator" )
298 : {
299 0 : for ( dunedaq::conffwk::attribute_t const & Attribute : AttributeRelList )
300 : {
301 0 : if ( Attribute.p_name == "Shown with children" )
302 : {
303 0 : QStringList neighbor_names
304 0 : { dbe::config::api::get::direct::attribute<QStringList> ( neighbor, Attribute ) };
305 :
306 0 : if ( neighbor_names.at ( 0 ) != "none" )
307 : {
308 0 : WindowObject.ShowChildren = true;
309 : }
310 : else
311 : {
312 0 : WindowObject.ShowChildren = false;
313 : }
314 0 : }
315 : }
316 :
317 0 : for ( dunedaq::conffwk::relationship_t const & RelationshipRel : RelationshipRelList )
318 : {
319 0 : QStringList RelDataList;
320 0 : std::vector<ConfigObject> neighboring_nodes;
321 :
322 0 : if ( dbe::config::api::info::relation::is_simple ( RelationshipRel ) )
323 : {
324 0 : neighboring_nodes.push_back (
325 0 : dbe::config::api::graph::direct::linked<ConfigObject> ( neighbor,
326 : RelationshipRel ) );
327 : }
328 : else
329 : {
330 :
331 0 : std::vector<ConfigObject> neighbors = dbe::config::api::graph::direct::linked <
332 0 : std::vector<ConfigObject >> ( neighbor, RelationshipRel );
333 :
334 0 : neighboring_nodes.insert ( std::end ( neighboring_nodes ), std::begin ( neighbors ),
335 : std::end ( neighbors ) );
336 0 : }
337 :
338 0 : for ( ConfigObject & RelDataObject : neighboring_nodes )
339 : {
340 0 : RelDataList.push_back ( QString ( RelDataObject.UID().c_str() ) );
341 : }
342 :
343 0 : WindowObject.GraphicalClassesList.push_back ( RelDataList.at ( 0 ) );
344 0 : }
345 : }
346 0 : }
347 0 : }
348 :
349 0 : this_windows.emplace ( WindowObject.Title.toStdString(), WindowObject );
350 0 : }
351 :
352 0 : std::vector<dbe::Window> dbe::ui::config::info::windows() const
353 : {
354 0 : std::vector<dbe::Window> windows;
355 :
356 0 : for ( auto const & x : this_windows )
357 : {
358 0 : windows.push_back ( x.second );
359 : }
360 :
361 0 : return windows;
362 0 : }
363 :
364 0 : std::vector<dbe::ViewConfiguration> dbe::ui::config::info::views() const
365 : {
366 0 : std::vector<dbe::ViewConfiguration> views;
367 :
368 0 : for ( auto const & x : this_views )
369 : {
370 0 : views.push_back ( x.second );
371 : }
372 :
373 0 : return views;
374 0 : }
375 :
376 0 : std::vector<dbe::GraphicalClass> dbe::ui::config::info::graphicals() const
377 : {
378 0 : std::vector<dbe::GraphicalClass> the_graphicals;
379 :
380 0 : for ( auto const & x : this_graphical )
381 : {
382 0 : the_graphicals.push_back ( x.second );
383 : }
384 :
385 0 : return the_graphicals;
386 0 : }
387 :
|