DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
GraphBuilder.hpp
Go to the documentation of this file.
1/************************************************************
2 *
3 * GraphBuilder.hpp
4 *
5 * JCF, Sep-11-2024
6 *
7 * GraphBuilder is the tool we can use to plot configurations. A quick overview:
8 *
9 * - Constructed from an OKS database file (XML) and the name of a session contained within it
10 * - GraphBuilder::construct_graph will take a "root object" from the session and
11 * construct a graph accordingly
12 * - GraphBuilder::write_graph will take the name of an output DOT
13 * file and write the graph to it
14 *
15 * The resulting DOT file can then be processed by, e.g., Graphviz in
16 * order to generate a viewable graphic of the configuration
17 *
18 * This is part of the DUNE DAQ Application Framework, copyright 2020.
19 * Licensing/copyright details are in the COPYING file that you should have
20 * received with this code.
21 *
22 *************************************************************/
23
24#ifndef DAQCONF_APPS_GRAPHBUILDER_HPP_
25#define DAQCONF_APPS_GRAPHBUILDER_HPP_
26
28
29#include "confmodel/Session.hpp"
30#include "ers/ers.hpp"
31#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
32
33#include "boost/graph/adjacency_list.hpp"
34#include "boost/graph/graph_traits.hpp"
35#include "boost/graph/labeled_graph.hpp"
36
37#include <string>
38#include <unordered_map>
39#include <vector>
40
41namespace daqconf {
42
44{
45
46public:
48
49 struct VertexLabel;
50 struct EdgeLabel;
51
52 // Switching container type to boost::listS seems to cause
53 // compilation problems with the boost::write_graphviz function...
54 using Graph_t = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VertexLabel, EdgeLabel>;
55 using Edge_t = boost::graph_traits<Graph_t>::edge_descriptor;
56 using Vertex_t = boost::graph_traits<Graph_t>::vertex_descriptor;
57
58 enum class ObjectKind
59 {
64 kModule,
65 kIncomingExternal, // Object is meant to represent the outside world, not an actual component of the DAQ
67 };
68
70 {
71
72 VertexLabel() = default;
73
74 VertexLabel(const std::string& uid, const std::string& classname)
75 : displaylabel(uid + "\n" + classname)
76 {
77 }
78
79 const std::string displaylabel{ "undefined" };
80 };
81
82 struct EdgeLabel
83 {
84 const std::string displaylabel{ "undefined" };
85 };
86
87 explicit GraphBuilder(const std::string& oksfilename, const std::string& sessionname);
88
89 void construct_graph(std::string root_obj_uid);
90 void write_graph(const std::string& outputfilename) const;
91
92 GraphBuilder(const GraphBuilder&) = delete;
96
97private:
99 {
100
102 {
103 std::string connection_name;
104 std::string receiver_label;
105
106 bool operator==(const ReceivingInfo& other) const = default;
107 };
108
109 EnhancedObject(const ConfigObject& config_object_arg, ObjectKind kind_arg)
110 : config_object{ config_object_arg }
111 , kind{ kind_arg }
112 {
113 }
114
117
119
120 // What objects is this one the parent of? E.g., a parent session with child segments
121 std::vector<std::string> child_object_names;
122
123 // What objects does this one send data to, and what are their connections called?
124 std::vector<ReceivingInfo> receiving_object_infos;
125 };
126
128 [[nodiscard]] std::vector<dunedaq::conffwk::ConfigObject> find_child_objects(const ConfigObject& parent_obj);
129 void calculate_graph(const std::string& root_obj_uid);
130
131 // find_objects_and_connections fills m_objects_for_graph as well
132 // as m_incoming_connections and m_outgoing_connections
133
134 void find_objects_and_connections(const ConfigObject& object);
136
137 const std::string m_oksfilename;
139
140 const std::unordered_map<ObjectKind, std::vector<std::string>> m_included_classes;
141
142 std::unordered_map<std::string, EnhancedObject> m_objects_for_graph;
143
144 std::unordered_map<std::string, std::vector<std::string>> m_incoming_connections;
145 std::unordered_map<std::string, std::vector<std::string>> m_outgoing_connections;
146
149
151 std::string m_session_name;
152
153 std::vector<std::string> m_ignored_application_uids;
154
155 std::vector<ConfigObject> m_all_objects;
156 std::vector<ConfigObject> m_candidate_objects;
157};
158
159[[nodiscard]] constexpr GraphBuilder::ObjectKind
160get_object_kind(const std::string& class_name);
161
162} // namespace daqconf
163
164ERS_DECLARE_ISSUE(daqconf, GeneralGraphToolError, "A graph tool error occured: " << errmsg, ((std::string)errmsg))
165
166#endif // DAQCONF_APPS_GRAPHBUILDER_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
GraphBuilder & operator=(GraphBuilder &&)=delete
dunedaq::confmodel::Session * m_session
boost::graph_traits< Graph_t >::vertex_descriptor Vertex_t
GraphBuilder(const GraphBuilder &)=delete
void find_objects_and_connections(const ConfigObject &object)
std::unordered_map< std::string, std::vector< std::string > > m_incoming_connections
std::vector< ConfigObject > m_all_objects
std::unordered_map< std::string, std::vector< std::string > > m_outgoing_connections
void construct_graph(std::string root_obj_uid)
const std::unordered_map< ObjectKind, std::vector< std::string > > m_included_classes
std::unordered_map< std::string, EnhancedObject > m_objects_for_graph
void write_graph(const std::string &outputfilename) const
dunedaq::conffwk::Configuration * m_confdb
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VertexLabel, EdgeLabel > Graph_t
std::vector< ConfigObject > m_candidate_objects
std::vector< std::string > m_ignored_application_uids
void calculate_graph(const std::string &root_obj_uid)
std::vector< dunedaq::conffwk::ConfigObject > find_child_objects(const ConfigObject &parent_obj)
const std::string m_oksfilename
boost::graph_traits< Graph_t >::edge_descriptor Edge_t
GraphBuilder(const std::string &oksfilename, const std::string &sessionname)
GraphBuilder(GraphBuilder &&)=delete
GraphBuilder & operator=(const GraphBuilder &)=delete
Represents database objects.
Defines base class for cache of template objects.
constexpr GraphBuilder::ObjectKind get_object_kind(const std::string &class_name)
bool operator==(const ReceivingInfo &other) const =default
std::vector< std::string > child_object_names
std::vector< ReceivingInfo > receiving_object_infos
EnhancedObject(const ConfigObject &config_object_arg, ObjectKind kind_arg)
VertexLabel(const std::string &uid, const std::string &classname)