DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
daqconf::GraphBuilder Class Reference

#include <GraphBuilder.hpp>

Collaboration diagram for daqconf::GraphBuilder:
[legend]

Classes

struct  EdgeLabel
 
struct  EnhancedObject
 
struct  VertexLabel
 

Public Types

enum class  ObjectKind {
  kUndefined , kSession , kSegment , kApplication ,
  kModule , kIncomingExternal , kOutgoingExternal
}
 
using ConfigObject = dunedaq::conffwk::ConfigObject
 
using Graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VertexLabel, EdgeLabel>
 
using Edge_t = boost::graph_traits<Graph_t>::edge_descriptor
 
using Vertex_t = boost::graph_traits<Graph_t>::vertex_descriptor
 

Public Member Functions

 GraphBuilder (const std::string &oksfilename, const std::string &sessionname)
 
void construct_graph (std::string root_obj_uid)
 
void write_graph (const std::string &outputfilename) const
 
 GraphBuilder (const GraphBuilder &)=delete
 
 GraphBuilder (GraphBuilder &&)=delete
 
GraphBuilderoperator= (const GraphBuilder &)=delete
 
GraphBuilderoperator= (GraphBuilder &&)=delete
 

Private Member Functions

void find_candidate_objects ()
 
std::vector< dunedaq::conffwk::ConfigObjectfind_child_objects (const ConfigObject &parent_obj)
 
void calculate_graph (const std::string &root_obj_uid)
 
void find_objects_and_connections (const ConfigObject &object)
 
void calculate_network_connections ()
 

Private Attributes

const std::string m_oksfilename
 
dunedaq::conffwk::Configurationm_confdb
 
const std::unordered_map< ObjectKind, std::vector< std::string > > m_included_classes
 
std::unordered_map< std::string, EnhancedObjectm_objects_for_graph
 
std::unordered_map< std::string, std::vector< std::string > > m_incoming_connections
 
std::unordered_map< std::string, std::vector< std::string > > m_outgoing_connections
 
Graph_t m_graph
 
ObjectKind m_root_object_kind
 
dunedaq::confmodel::Sessionm_session
 
std::string m_session_name
 
std::vector< std::string > m_ignored_application_uids
 
std::vector< ConfigObjectm_all_objects
 
std::vector< ConfigObjectm_candidate_objects
 

Detailed Description

Definition at line 43 of file GraphBuilder.hpp.

Member Typedef Documentation

◆ ConfigObject

◆ Edge_t

using daqconf::GraphBuilder::Edge_t = boost::graph_traits<Graph_t>::edge_descriptor

Definition at line 55 of file GraphBuilder.hpp.

◆ Graph_t

using daqconf::GraphBuilder::Graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VertexLabel, EdgeLabel>

Definition at line 54 of file GraphBuilder.hpp.

◆ Vertex_t

using daqconf::GraphBuilder::Vertex_t = boost::graph_traits<Graph_t>::vertex_descriptor

Definition at line 56 of file GraphBuilder.hpp.

Member Enumeration Documentation

◆ ObjectKind

Enumerator
kUndefined 
kSession 
kSegment 
kApplication 
kModule 
kIncomingExternal 
kOutgoingExternal 

Definition at line 58 of file GraphBuilder.hpp.

Constructor & Destructor Documentation

◆ GraphBuilder() [1/3]

daqconf::GraphBuilder::GraphBuilder ( const std::string & oksfilename,
const std::string & sessionname )
explicit

Definition at line 49 of file GraphBuilder.cpp.

50 : m_oksfilename{ oksfilename }
51 , m_confdb{ nullptr }
52 , m_included_classes{ { ObjectKind::kSession, { "Session", "Segment", "Application" } },
53 { ObjectKind::kSegment, { "Segment", "Application" } },
54 { ObjectKind::kApplication, { "Application", "Module" } },
55 { ObjectKind::kModule, { "Module" } } }
57 , m_session{ nullptr }
58 , m_session_name{ sessionname }
59{
60
61 // Open the database represented by the OKS XML file
62
63 try {
65 } catch (dunedaq::conffwk::Generic& exc) {
66 TLOG() << "Failed to load OKS database: " << exc << "\n";
67 throw exc;
68 }
69
70 // Get the session in the database
71 std::vector<ConfigObject> session_objects{};
72
73 m_confdb->get("Session", session_objects);
74
75 if (m_session_name == "") { // If no session name given, use the one-and-only session expected in the database
76 if (session_objects.size() == 1) {
77 m_session_name = session_objects[0].UID();
78 } else {
79 std::stringstream errmsg;
80 errmsg << "No Session instance name was provided, and since " << session_objects.size()
81 << " session instances were found in \"" << m_oksfilename << "\" this is an error";
82
83 throw daqconf::GeneralGraphToolError(ERS_HERE, errmsg.str());
84 }
85 } else { // session name provided by the user, let's make sure it's there
86 auto it =
87 std::ranges::find_if(session_objects, [&](const ConfigObject& obj) { return obj.UID() == m_session_name; });
88
89 if (it == session_objects.end()) {
90 std::stringstream errmsg;
91 errmsg << "Did not find Session instance \"" << m_session_name << "\" in \"" << m_oksfilename
92 << "\" and its includes";
93 throw daqconf::GeneralGraphToolError(ERS_HERE, errmsg.str());
94 }
95 }
96
97 // The following not-brief section of code is dedicated to
98 // determining which applications in the configuration are
99 // disabled
100
101 // First, we need the session object to check if an application
102 // has been disabled
103
104 // Note the "const_cast" is needed since "m_confdb->get"
105 // returns a const pointer, but since m_session is a member needed
106 // by multiple functions and can't be determined until after we've
107 // opened the database and found the session, we need to change
108 // its initial value here. Once this is done, it shouldn't be
109 // changed again.
110
111 m_session = const_cast<dunedaq::confmodel::Session*>( // NOLINT
113
114 if (!m_session) {
115 std::stringstream errmsg;
116 errmsg << "Unable to get session with UID \"" << m_session_name << "\"";
117 throw daqconf::GeneralGraphToolError(ERS_HERE, errmsg.str());
118 }
119
120 std::vector<ConfigObject> every_object_deriving_from_class{}; // Includes objects of the class itself
121 std::vector<ConfigObject> objects_of_class{}; // A subset of every_object_deriving_from_class
122
123 // m_confdb->superclasses() returns a conffwk::fmap; see the conffwk package for details
124
125 auto classnames = m_confdb->superclasses() | std::views::keys |
126 std::views::transform([](const auto& ptr_to_class_name) { return *ptr_to_class_name; });
127
128 for (const auto& classname : classnames) {
129
130 every_object_deriving_from_class.clear();
131 objects_of_class.clear();
132
133 m_confdb->get(classname, every_object_deriving_from_class);
134
135 std::ranges::copy_if(every_object_deriving_from_class,
136 std::back_inserter(objects_of_class),
137 [&classname](const ConfigObject& obj) { return obj.class_name() == classname; });
138
139 std::ranges::copy(objects_of_class, std::back_inserter(m_all_objects));
140
141 if (classname.find("Application") != std::string::npos) { // DFApplication, ReadoutApplication, etc.
142 for (const auto& appobj : objects_of_class) {
143
144 auto daqapp = m_confdb->get<dunedaq::appmodel::SmartDaqApplication>(appobj.UID());
145
146 if (daqapp) {
147
148 auto res = daqapp->cast<dunedaq::confmodel::Resource>();
149
150 if (res && res->is_disabled(*m_session)) {
151 m_ignored_application_uids.push_back(appobj.UID());
152 TLOG() << "Skipping disabled application " << appobj.UID() << "@" << daqapp->class_name();
153 continue;
154 }
155 } else {
156 TLOG(TLVL_DEBUG) << "Skipping non-SmartDaqApplication " << appobj.UID() << "@" << appobj.class_name();
157 m_ignored_application_uids.push_back(appobj.UID());
158 }
159 }
160 }
161 }
162}
#define ERS_HERE
dunedaq::confmodel::Session * m_session
std::vector< ConfigObject > m_all_objects
const std::unordered_map< ObjectKind, std::vector< std::string > > m_included_classes
dunedaq::conffwk::Configuration * m_confdb
std::vector< std::string > m_ignored_application_uids
const std::string m_oksfilename
dunedaq::conffwk::ConfigObject ConfigObject
Defines base class for cache of template objects.
const conffwk::fmap< conffwk::fset > & superclasses() const noexcept
void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get object by class name and object id (multi-thread safe).
Generic configuration exception.
#define TLOG(...)
Definition macro.hpp:22

◆ GraphBuilder() [2/3]

daqconf::GraphBuilder::GraphBuilder ( const GraphBuilder & )
delete

◆ GraphBuilder() [3/3]

daqconf::GraphBuilder::GraphBuilder ( GraphBuilder && )
delete

Member Function Documentation

◆ calculate_graph()

void daqconf::GraphBuilder::calculate_graph ( const std::string & root_obj_uid)
private

Definition at line 182 of file GraphBuilder.cpp.

183{
184
185 // To start, get the session / segments / applications in the
186 // session by setting up a temporary graph with the session as its
187 // root. This way we can check to see if the actual requested root
188 // object lies within the session in question.
189
190 auto true_root_object_kind = m_root_object_kind;
193
194 auto it_session =
195 std::ranges::find_if(m_all_objects, [&](const ConfigObject& obj) { return obj.UID() == m_session_name; });
196
197 find_objects_and_connections(*it_session);
198
199 if (!m_objects_for_graph.contains(root_obj_uid)) {
200 std::stringstream errmsg;
201 errmsg << "Unable to find requested object \"" << root_obj_uid << "\" in session \"" << m_session_name << "\"";
202 throw daqconf::GeneralGraphToolError(ERS_HERE, errmsg.str());
203 }
204
205 // Since we used our first call to find_objects_and_connections
206 // only as a fact-finding mission, reset the containers it filled
207
208 m_objects_for_graph.clear();
211
212 m_candidate_objects.clear();
213
214 m_root_object_kind = true_root_object_kind;
216
217 bool found = false;
218 for (auto& obj : m_candidate_objects) {
219 if (obj.UID() == root_obj_uid) {
220 found = true;
221 find_objects_and_connections(obj); // Put differently, "find what will make up the vertices and edges"
222 break;
223 }
224 }
225
226 assert(found);
227
228 calculate_network_connections(); // Put differently, "find the edges between the vertices"
229}
void find_objects_and_connections(const ConfigObject &object)
std::unordered_map< std::string, std::vector< std::string > > m_incoming_connections
std::unordered_map< std::string, std::vector< std::string > > m_outgoing_connections
std::unordered_map< std::string, EnhancedObject > m_objects_for_graph
std::vector< ConfigObject > m_candidate_objects

◆ calculate_network_connections()

void daqconf::GraphBuilder::calculate_network_connections ( )
private

Definition at line 232 of file GraphBuilder.cpp.

233{
234
235 // Will use "incoming_matched" and "outgoing_matched" to keep
236 // track of incoming and outgoing connections which don't get
237 // matched, i.e. would terminate external to the graph
238
239 std::vector<std::string> incoming_matched;
240 std::vector<std::string> outgoing_matched;
241
242 for (auto& incoming : m_incoming_connections) {
243
244 std::regex incoming_pattern(incoming.first);
245
246 for (auto& outgoing : m_outgoing_connections) {
247
248 std::regex outgoing_pattern(outgoing.first);
249
250 bool match = false;
251
252 if (incoming.first == outgoing.first) {
253 match = true;
254 } else if (incoming.first.find(".*") != std::string::npos) {
255 if (std::regex_match(outgoing.first, incoming_pattern)) {
256 match = true;
257 }
258 } else if (outgoing.first.find(".*") != std::string::npos) {
259 if (std::regex_match(incoming.first, outgoing_pattern)) {
260 match = true;
261 }
262 }
263
264 if (match) {
265
266 bool low_level_plot =
268
269 for (auto& receiver : incoming.second) {
270 for (auto& sender : outgoing.second) {
271
272 // We just want to plot applications sending to other
273 // applications and queues sending to other
274 // queues. Showing, e.g., a queue directly sending to
275 // some other application via a network connection makes
276 // the plot too busy.
277
278 if (!m_objects_for_graph.contains(sender) || !m_objects_for_graph.contains(receiver)) {
279 continue;
280 } else if (m_objects_for_graph.at(sender).kind != m_objects_for_graph.at(receiver).kind) {
281 continue;
282 } else if (low_level_plot && incoming.first.find("NetworkConnection") != std::string::npos) {
283
284 // Don't want to directly link modules in an
285 // application if the data is transferred over network
286 continue;
287 }
288
289 if (!low_level_plot || incoming.first.find(".*") == std::string::npos) {
290 if (std::ranges::find(incoming_matched, incoming.first) == incoming_matched.end()) {
291 incoming_matched.push_back(incoming.first);
292 }
293 }
294
295 if (!low_level_plot || outgoing.first.find(".*") == std::string::npos) {
296 if (std::ranges::find(outgoing_matched, outgoing.first) == outgoing_matched.end()) {
297 outgoing_matched.push_back(outgoing.first);
298 }
299 }
300
301 const EnhancedObject::ReceivingInfo receiving_info{ incoming.first, receiver };
302
303 auto res = std::ranges::find(m_objects_for_graph.at(sender).receiving_object_infos, receiving_info);
304 if (res == m_objects_for_graph.at(sender).receiving_object_infos.end()) {
305 m_objects_for_graph.at(sender).receiving_object_infos.push_back(receiving_info);
306 }
307 }
308 }
309 }
310 }
311 }
312
313 auto incoming_unmatched =
314 m_incoming_connections | std::views::keys | std::views::filter([&incoming_matched](auto& connection) {
315 return std::ranges::find(incoming_matched, connection) == incoming_matched.end();
316 });
317
318 auto included_classes = m_included_classes.at(m_root_object_kind);
319
320 for (auto& incoming_conn : incoming_unmatched) {
321
322 EnhancedObject external_obj{ ConfigObject{}, ObjectKind::kIncomingExternal };
323 const std::string incoming_vertex_name = incoming_conn;
324
325 // Find the connections appropriate to the granularity level of this graph
326 for (auto& receiving_object_name : m_incoming_connections[incoming_conn]) {
327
328 if (!m_objects_for_graph.contains(receiving_object_name)) {
329 continue;
330 }
331
332 if (std::ranges::find(included_classes, "Module") != included_classes.end()) {
333 if (m_objects_for_graph.at(receiving_object_name).kind == ObjectKind::kModule) {
334 external_obj.receiving_object_infos.push_back({ incoming_conn, receiving_object_name });
335 }
336 } else if (std::ranges::find(included_classes, "Application") != included_classes.end()) {
337 if (m_objects_for_graph.at(receiving_object_name).kind == ObjectKind::kApplication) {
338 external_obj.receiving_object_infos.push_back({ incoming_conn, receiving_object_name });
339 }
340 }
341 }
342
343 m_objects_for_graph.insert({ incoming_vertex_name, external_obj });
344 }
345
346 auto outgoing_unmatched =
347 m_outgoing_connections | std::views::keys | std::views::filter([&outgoing_matched](auto& connection) {
348 return std::ranges::find(outgoing_matched, connection) == outgoing_matched.end();
349 });
350
351 for (auto& outgoing_conn : outgoing_unmatched) {
352
353 EnhancedObject external_obj{ ConfigObject{}, ObjectKind::kOutgoingExternal };
354 const std::string outgoing_vertex_name = outgoing_conn;
355
356 // Find the connections appropriate to the granularity level of this graph
357 for (auto& sending_object_name : m_outgoing_connections[outgoing_conn]) {
358
359 if (!m_objects_for_graph.contains(sending_object_name)) {
360 continue;
361 }
362
363 if (std::ranges::find(included_classes, "Module") != included_classes.end()) {
364 if (m_objects_for_graph.at(sending_object_name).kind == ObjectKind::kModule) {
365 m_objects_for_graph.at(sending_object_name)
366 .receiving_object_infos.push_back({ outgoing_conn, outgoing_vertex_name });
367 }
368 } else if (std::ranges::find(included_classes, "Application") != included_classes.end()) {
369 if (m_objects_for_graph.at(sending_object_name).kind == ObjectKind::kApplication) {
370 m_objects_for_graph.at(sending_object_name)
371 .receiving_object_infos.push_back({ outgoing_conn, outgoing_vertex_name });
372 }
373 }
374 }
375
376 m_objects_for_graph.insert({ outgoing_vertex_name, external_obj });
377 }
378}
dunedaq::conffwk::relationship_t match(T const &, T const &)

◆ construct_graph()

void daqconf::GraphBuilder::construct_graph ( std::string root_obj_uid)

Definition at line 472 of file GraphBuilder.cpp.

473{
474
475 if (root_obj_uid == "") {
476 root_obj_uid = m_session_name;
477 }
478
479 // Next several lines just mean "tell me the class type of the root object in the config plot's graph"
480
481 auto class_names_view =
482 m_all_objects | std::views::filter([root_obj_uid](const ConfigObject& obj) { return obj.UID() == root_obj_uid; }) |
483 std::views::transform([](const ConfigObject& obj) { return obj.class_name(); });
484
485 if (std::ranges::distance(class_names_view) != 1) {
486 std::stringstream errmsg;
487 errmsg << "Failed to find instance of desired root object \"" << root_obj_uid << "\"";
488 throw daqconf::GeneralGraphToolError(ERS_HERE, errmsg.str());
489 }
490
491 const std::string& root_obj_class_name = *class_names_view.begin();
492
493 m_root_object_kind = get_object_kind(root_obj_class_name);
494
495 calculate_graph(root_obj_uid);
496
497 for (auto& enhanced_object : m_objects_for_graph | std::views::values) {
498
499 if (enhanced_object.kind == ObjectKind::kIncomingExternal) {
500 enhanced_object.vertex_in_graph = boost::add_vertex(VertexLabel("O", ""), m_graph);
501 } else if (enhanced_object.kind == ObjectKind::kOutgoingExternal) {
502 enhanced_object.vertex_in_graph = boost::add_vertex(VertexLabel("X", ""), m_graph);
503 } else {
504 auto& obj = enhanced_object.config_object;
505 enhanced_object.vertex_in_graph = boost::add_vertex(VertexLabel(obj.UID(), obj.class_name()), m_graph);
506 }
507 }
508
509 for (auto& parent_obj : m_objects_for_graph | std::views::values) {
510 for (auto& child_obj_name : parent_obj.child_object_names) {
511 boost::add_edge(parent_obj.vertex_in_graph,
512 m_objects_for_graph.at(child_obj_name).vertex_in_graph,
513 { "" }, // No label for an edge which just describes "ownership" rather than dataflow
514 m_graph);
515 }
516 }
517
518 for (auto& possible_sender_object : m_objects_for_graph | std::views::values) {
519 for (auto& receiver_info : possible_sender_object.receiving_object_infos) {
520
521 auto at_pos = receiver_info.connection_name.find("@");
522 const std::string connection_label = receiver_info.connection_name.substr(0, at_pos);
523
524 // If we're plotting at the level of a session or segment,
525 // show the connections as between applications; if we're
526 // doing this for a single application, show them entering and
527 // exiting the individual modules
528
530 if (m_objects_for_graph.at(receiver_info.receiver_label).kind == ObjectKind::kModule) {
531 continue;
532 }
533 }
534
536 if (m_objects_for_graph.at(receiver_info.receiver_label).kind == ObjectKind::kApplication) {
537 continue;
538 }
539 }
540
541 boost::add_edge(possible_sender_object.vertex_in_graph,
542 m_objects_for_graph.at(receiver_info.receiver_label).vertex_in_graph,
543 { connection_label },
544 m_graph)
545 .first;
546 }
547 }
548}
void calculate_graph(const std::string &root_obj_uid)
constexpr GraphBuilder::ObjectKind get_object_kind(const std::string &class_name)

◆ find_candidate_objects()

void daqconf::GraphBuilder::find_candidate_objects ( )
private

Definition at line 165 of file GraphBuilder.cpp.

166{
167
168 m_candidate_objects.clear();
169
170 for (const auto& obj : m_all_objects) {
171 for (const auto& classname : this->m_included_classes.at(m_root_object_kind)) {
172
173 if (obj.class_name().find(classname) != std::string::npos &&
174 std::ranges::find(m_ignored_application_uids, obj.UID()) == m_ignored_application_uids.end()) {
175 m_candidate_objects.emplace_back(obj);
176 }
177 }
178 }
179}

◆ find_child_objects()

std::vector< dunedaq::conffwk::ConfigObject > daqconf::GraphBuilder::find_child_objects ( const ConfigObject & parent_obj)
nodiscardprivate

Definition at line 551 of file GraphBuilder.cpp.

552{
553
554 std::vector<ConfigObject> connected_objects{};
555
556 dunedaq::conffwk::class_t classdef = m_confdb->get_class_info(parent_obj.class_name(), false);
557
558 for (const dunedaq::conffwk::relationship_t& relationship : classdef.p_relationships) {
559
560 // The ConfigObject::get(...) function doesn't have a
561 // const-qualifier on it for no apparent good reason; we need
562 // this cast in order to call it
563
564 auto parent_obj_casted = const_cast<ConfigObject&>(parent_obj); // NOLINT
565
566 if (relationship.p_cardinality == dunedaq::conffwk::only_one ||
568 ConfigObject connected_obj{};
569 parent_obj_casted.get(relationship.p_name, connected_obj);
570 connected_objects.push_back(connected_obj);
571 } else {
572 std::vector<ConfigObject> connected_objects_in_relationship{};
573 parent_obj_casted.get(relationship.p_name, connected_objects_in_relationship);
574 connected_objects.insert(
575 connected_objects.end(), connected_objects_in_relationship.begin(), connected_objects_in_relationship.end());
576 }
577 }
578
579 return connected_objects;
580}
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
const dunedaq::conffwk::class_t & get_class_info(const std::string &class_name, bool direct_only=false)
The method provides access to description of class.
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:164

◆ find_objects_and_connections()

void daqconf::GraphBuilder::find_objects_and_connections ( const ConfigObject & object)
private

Definition at line 381 of file GraphBuilder.cpp.

382{
383
384 EnhancedObject starting_object{ object, get_object_kind(object.class_name()) };
385
386 // If we've got a session or a segment, look at its OKS-relations,
387 // and recursively process those relation objects which are on the
388 // candidates list and haven't already been processed
389
390 if (starting_object.kind == ObjectKind::kSession || starting_object.kind == ObjectKind::kSegment) {
391
392 for (auto& child_object : find_child_objects(starting_object.config_object)) {
393
394 if (std::ranges::find(m_candidate_objects, child_object) != m_candidate_objects.end()) {
395 find_objects_and_connections(child_object);
396 starting_object.child_object_names.push_back(child_object.UID());
397 }
398 }
399 } else if (starting_object.kind == ObjectKind::kApplication) {
400
401 // If we've got an application object, try to determine what
402 // modules are in it and what their connections are. Recursively
403 // process the modules, and then add connection info to class-wide
404 // member maps to calculate edges corresponding to the connections
405 // for the plotted graph later
406
407 dunedaq::conffwk::Configuration* local_database{ nullptr };
408
409 try {
410 local_database = new dunedaq::conffwk::Configuration("oksconflibs:" + m_oksfilename);
411 } catch (dunedaq::conffwk::Generic& exc) {
412 TLOG() << "Failed to load OKS database: " << exc << "\n";
413 throw exc;
414 }
415
416 auto daqapp = local_database->get<dunedaq::appmodel::SmartDaqApplication>(object.UID());
417 if (daqapp) {
418 auto local_session = const_cast<dunedaq::confmodel::Session*>( // NOLINT
419 local_database->get<dunedaq::confmodel::Session>(m_session_name));
420 daqapp->generate_modules(local_session);
421 auto modules = daqapp->get_modules();
422
423 std::vector<std::string> allowed_conns{};
424
426 allowed_conns = { "NetworkConnection" };
428 allowed_conns = { "NetworkConnection", "Queue", "QueueWithSourceId" };
429 }
430
431 for (const auto& module : modules) {
432
433 for (auto in : module->get_inputs()) {
434
435 // Elsewhere in the code it'll be useful to know if the
436 // connection is a network or a queue, so include the
437 // class name in the std::string key
438
439 const std::string key = in->config_object().UID() + "@" + in->config_object().class_name();
440
441 if (std::ranges::find(allowed_conns, in->config_object().class_name()) != allowed_conns.end()) {
442 m_incoming_connections[key].push_back(object.UID());
443 m_incoming_connections[key].push_back(module->UID());
444 }
445 }
446
447 for (auto out : module->get_outputs()) {
448
449 const std::string key = out->config_object().UID() + "@" + out->config_object().class_name();
450
451 if (std::ranges::find(allowed_conns, out->config_object().class_name()) != allowed_conns.end()) {
452 m_outgoing_connections[key].push_back(object.UID());
453 m_outgoing_connections[key].push_back(module->UID());
454 }
455 }
456
457 if (std::ranges::find(m_included_classes.at(m_root_object_kind), "Module") !=
459 find_objects_and_connections(module->config_object());
460 starting_object.child_object_names.push_back(module->UID());
461 }
462 }
463 }
464 }
465
466 assert(!m_objects_for_graph.contains(object.UID()));
467
468 m_objects_for_graph.insert({ object.UID(), starting_object });
469}
std::vector< dunedaq::conffwk::ConfigObject > find_child_objects(const ConfigObject &parent_obj)
module(name, schema, other_dals=[], backend='oksconflibs', db=None)
Definition dal.py:673
FELIX Initialization std::string initerror FELIX queue timed out

◆ operator=() [1/2]

GraphBuilder & daqconf::GraphBuilder::operator= ( const GraphBuilder & )
delete

◆ operator=() [2/2]

GraphBuilder & daqconf::GraphBuilder::operator= ( GraphBuilder && )
delete

◆ write_graph()

void daqconf::GraphBuilder::write_graph ( const std::string & outputfilename) const

Definition at line 583 of file GraphBuilder.cpp.

584{
585
586 std::stringstream outputstream;
587
588 boost::write_graphviz(outputstream,
589 m_graph,
590 boost::make_label_writer(boost::get(&GraphBuilder::VertexLabel::displaylabel, m_graph)),
591 boost::make_label_writer(boost::get(&GraphBuilder::EdgeLabel::displaylabel, m_graph)));
592
593 // It's arguably hacky to edit the DOT code generated by
594 // boost::write_graphviz after the fact to give vertices colors,
595 // but the fact is that the color-assigning logic in Boost's graph
596 // library is so messy and clumsy that this is a worthwhile
597 // tradeoff
598
599 struct VertexStyle
600 {
601 const std::string shape;
602 const std::string color;
603 };
604
605 const std::unordered_map<ObjectKind, VertexStyle> vertex_styles{ { ObjectKind::kSession, { "octagon", "black" } },
606 { ObjectKind::kSegment, { "hexagon", "brown" } },
607 { ObjectKind::kApplication, { "pentagon", "blue" } },
608 { ObjectKind::kModule, { "rectangle", "red" } } };
609
610 std::string dotfile_slurped = outputstream.str();
611 std::vector<std::string> legend_entries{};
612 std::vector<std::string> legend_ordering_code{};
613
614 for (auto& eo : m_objects_for_graph | std::views::values) {
615
616 std::stringstream vertexstr{};
617 std::stringstream legendstr{};
618 std::stringstream labelstringstr{};
619 size_t insertion_location{ 0 };
620
621 auto calculate_insertion_location = [&]() {
622 labelstringstr << "label=\"" << eo.config_object.UID() << "\n";
623 insertion_location = dotfile_slurped.find(labelstringstr.str());
624 assert(insertion_location != std::string::npos);
625 return insertion_location;
626 };
627
628 // TODO: John Freeman (jcfree@fnal.gov), Sep-17-2024
629
630 // Switch to std::format for line construction rather than
631 // std::stringstream when we switch to a gcc version which
632 // supports it
633
634 auto add_vertex_info = [&]() {
635 vertexstr << "shape=" << vertex_styles.at(eo.kind).shape << ", color=" << vertex_styles.at(eo.kind).color
636 << ", fontcolor=" << vertex_styles.at(eo.kind).color << ", ";
637 dotfile_slurped.insert(calculate_insertion_location(), vertexstr.str());
638 };
639
640 auto add_legend_entry = [&](char letter, const std::string objkind) {
641 legendstr << "legend" << letter << " [label=<<font color=\"" << vertex_styles.at(eo.kind).color << "\"><b><i>"
642 << vertex_styles.at(eo.kind).color << ": " << objkind
643 << "</i></b></font>>, shape=plaintext, color=" << vertex_styles.at(eo.kind).color
644 << ", fontcolor=" << vertex_styles.at(eo.kind).color << "];";
645 };
646
647 // Note that the seemingly arbitrary single characters added
648 // after "legend" aren't just to uniquely identify each entry in
649 // the legend, it's also so that when the entries are sorted
650 // alphabetically they'll appear in the correct order
651
652 switch (eo.kind) {
654 add_vertex_info();
655 add_legend_entry('A', "session");
656 break;
658 add_vertex_info();
659 add_legend_entry('B', "segment");
660 break;
662 add_vertex_info();
663 add_legend_entry('C', "application");
664 break;
666 add_vertex_info();
667 add_legend_entry('D', "DAQModule");
668 break;
670 legendstr
671 << "legendE [label=<<font color=\"black\">O:<b><i> External Data Source</i></b></font>>, shape=plaintext];";
672 break;
674 legendstr
675 << "legendF [label=<<font color=\"black\">X:<b><i> External Data Sink</i></b></font>>, shape=plaintext];";
676 break;
677 default:
678 assert(false);
679 }
680
681 if (std::ranges::find(legend_entries, legendstr.str()) == legend_entries.end()) {
682 legend_entries.emplace_back(legendstr.str());
683 }
684 }
685
686 std::ranges::sort(legend_entries);
687
688 // We have the line-by-line entries containing the labels in our
689 // legend and their colors, but more DOT code is needed in order
690 // to show the labels in order. E.g., if we have:
691
692 // legendA [label=<<font color="blue">Blue: Segment</font>>, shape=box, color=blue, fontcolor=blue];
693 // legendB [label=<<font color="red">Red: Application</font>>, shape=box, color=red, fontcolor=red];
694 //
695 // Then we'll also need
696 //
697 // legendA -> legendB [style=invis];
698
699 auto legend_tokens = legend_entries | std::views::transform([](const std::string& line) {
700 return line.substr(0, line.find(' ')); // i.e., grab the first word on the line
701 });
702
703 auto it = legend_tokens.begin();
704 for (auto next_it = std::next(it); next_it != legend_tokens.end(); ++it, ++next_it) {
705 std::stringstream astr{};
706 astr << " " << *it << " -> " << *next_it << " [style=invis];";
707 legend_ordering_code.push_back(astr.str());
708 }
709
710 constexpr int chars_to_last_brace = 2;
711 auto last_brace_iter = dotfile_slurped.end() - chars_to_last_brace;
712 assert(*last_brace_iter == '}');
713 size_t last_brace_loc = last_brace_iter - dotfile_slurped.begin();
714
715 std::string legend_code{};
716 legend_code += "\n\n\n";
717
718 for (const auto& l : legend_entries) {
719 legend_code += l + "\n";
720 }
721
722 legend_code += "\n\n\n";
723
724 for (const auto& l : legend_ordering_code) {
725 legend_code += l + "\n";
726 }
727
728 dotfile_slurped.insert(last_brace_loc, legend_code);
729
730 // Take advantage of the fact that the edges describing ownership
731 // rather than data flow (e.g., hsi-segment owning hsi-01, the
732 // FakeHSIApplication) have null labels in order to turn them into
733 // arrow-free dotted lines
734
735 const std::string unlabeled_edge = "label=\"\"";
736 const std::string edge_modifier = ", style=\"dotted\", arrowhead=\"none\"";
737
738 size_t pos = 0;
739 while ((pos = dotfile_slurped.find(unlabeled_edge, pos)) != std::string::npos) {
740 dotfile_slurped.replace(pos, unlabeled_edge.length(), unlabeled_edge + edge_modifier);
741 pos += (unlabeled_edge + edge_modifier).length();
742 }
743
744 // And now with all the edits made to the contents of the DOT code, write it to file
745
746 std::ofstream outputfile;
747 outputfile.open(outputfilename);
748
749 if (outputfile.is_open()) {
750 outputfile << dotfile_slurped.c_str();
751 } else {
752 std::stringstream errmsg;
753 errmsg << "Unable to open requested file \"" << outputfilename << "\" for writing";
754 throw daqconf::GeneralGraphToolError(ERS_HERE, errmsg.str());
755 }
756}

Member Data Documentation

◆ m_all_objects

std::vector<ConfigObject> daqconf::GraphBuilder::m_all_objects
private

Definition at line 155 of file GraphBuilder.hpp.

◆ m_candidate_objects

std::vector<ConfigObject> daqconf::GraphBuilder::m_candidate_objects
private

Definition at line 156 of file GraphBuilder.hpp.

◆ m_confdb

dunedaq::conffwk::Configuration* daqconf::GraphBuilder::m_confdb
private

Definition at line 138 of file GraphBuilder.hpp.

◆ m_graph

Graph_t daqconf::GraphBuilder::m_graph
private

Definition at line 147 of file GraphBuilder.hpp.

◆ m_ignored_application_uids

std::vector<std::string> daqconf::GraphBuilder::m_ignored_application_uids
private

Definition at line 153 of file GraphBuilder.hpp.

◆ m_included_classes

const std::unordered_map<ObjectKind, std::vector<std::string> > daqconf::GraphBuilder::m_included_classes
private

Definition at line 140 of file GraphBuilder.hpp.

◆ m_incoming_connections

std::unordered_map<std::string, std::vector<std::string> > daqconf::GraphBuilder::m_incoming_connections
private

Definition at line 144 of file GraphBuilder.hpp.

◆ m_objects_for_graph

std::unordered_map<std::string, EnhancedObject> daqconf::GraphBuilder::m_objects_for_graph
private

Definition at line 142 of file GraphBuilder.hpp.

◆ m_oksfilename

const std::string daqconf::GraphBuilder::m_oksfilename
private

Definition at line 137 of file GraphBuilder.hpp.

◆ m_outgoing_connections

std::unordered_map<std::string, std::vector<std::string> > daqconf::GraphBuilder::m_outgoing_connections
private

Definition at line 145 of file GraphBuilder.hpp.

◆ m_root_object_kind

ObjectKind daqconf::GraphBuilder::m_root_object_kind
private

Definition at line 148 of file GraphBuilder.hpp.

◆ m_session

dunedaq::confmodel::Session* daqconf::GraphBuilder::m_session
private

Definition at line 150 of file GraphBuilder.hpp.

◆ m_session_name

std::string daqconf::GraphBuilder::m_session_name
private

Definition at line 151 of file GraphBuilder.hpp.


The documentation for this class was generated from the following files: