The Gaudi Framework  master (bef125d4)
Loading...
Searching...
No Matches
Gaudi::Hive::Graph Class Reference

utilities to dump graphs in different formats More...

#include </builds/gaudi/Gaudi/GaudiHive/src/GraphDumper.h>

Collaboration diagram for Gaudi::Hive::Graph:

Public Member Functions

 Graph (std::string_view fileName, FileType type=FileType::UNKNOWN)
 Creates a graph with given type and given file name.
 
 ~Graph ()
 
std::string const & fileName ()
 
void addNode (std::string_view id, std::string_view name)
 
void addEdge (std::string_view srcId, std::string_view tgtId, std::string_view label="")
 

Private Member Functions

void writeHeader ()
 
void writeTrailer ()
 

Private Attributes

std::string m_fileName
 name of the filed used for storing the graph
 
std::ofstream m_stream
 stream to the graph file
 
FileType m_type { FileType::UNKNOWN }
 type of file used
 

Detailed Description

utilities to dump graphs in different formats

supported right now : .dot, mermaid and graphml

Usage :

  • create a Graph calling the constructor with type and name of the output file
  • use then addNode and addEdge to specify the graph
  • on destruction, the Graph will be written to file

Definition at line 30 of file GraphDumper.h.

Constructor & Destructor Documentation

◆ Graph()

Gaudi::Hive::Graph::Graph ( std::string_view fileName,
FileType type = FileType::UNKNOWN )

Creates a graph with given type and given file name.

by default (and if UNKNOWN is provided) type is deduced from the file extension in case extension is not recognized, dot format is used and filename gets an extra ".dot" at the end

Definition at line 45 of file GraphDumper.cpp.

46 // find out type of file if not given
47 if ( type == FileType::UNKNOWN ) {
48 // Check file extension
49 if ( m_fileName.ends_with( ".dot" ) ) {
51 } else if ( m_fileName.ends_with( ".md" ) ) {
53 } else if ( m_fileName.ends_with( ".graphml" ) ) {
55 } else {
57 m_fileName += ".dot";
58 }
59 }
60 // open file
61 m_stream = std::ofstream{ m_fileName, std::ofstream::out };
63 }
FileType m_type
type of file used
Definition GraphDumper.h:60
std::string m_fileName
name of the filed used for storing the graph
Definition GraphDumper.h:56
std::string const & fileName()
std::ofstream m_stream
stream to the graph file
Definition GraphDumper.h:58

◆ ~Graph()

Gaudi::Hive::Graph::~Graph ( )

Definition at line 65 of file GraphDumper.cpp.

65 {
67 m_stream.close();
68 }

Member Function Documentation

◆ addEdge()

void Gaudi::Hive::Graph::addEdge ( std::string_view srcId,
std::string_view tgtId,
std::string_view label = "" )

Definition at line 93 of file GraphDumper.cpp.

93 {
94 switch ( m_type ) {
95 case FileType::DOT:
96 m_stream << " " << srcId << " -> " << tgtId;
97 if ( label != "" ) m_stream << " [label=\"" << label << "\"]";
98 m_stream << ";\n";
99 break;
100 case FileType::MD:
101 m_stream << " " << srcId << " --> " << tgtId;
102 if ( label != "" ) m_stream << " : " << label;
103 m_stream << "\n";
104 break;
105 case FileType::ML:
106 if ( label != "" ) {
107 m_stream << " <edge source=\"" << srcId << "\" target=\"" << tgtId
108 << "\">\n"
109 " <data key=\"d1\">"
110 << escapeSpecialCharactersForMl( label )
111 << "</data>\n"
112 " </edge>\n";
113 } else {
114 m_stream << " <edge source=\"" << srcId << "\" target=\"" << tgtId << "\"/>\n";
115 }
116 break;
118 break;
119 }
120 };

◆ addNode()

void Gaudi::Hive::Graph::addNode ( std::string_view id,
std::string_view name )

Definition at line 72 of file GraphDumper.cpp.

72 {
73 switch ( m_type ) {
74 case FileType::DOT:
75 m_stream << " " << id << " [label=\"" << name << "\";shape=box];\n";
76 break;
77 case FileType::MD:
78 m_stream << " " << id << "{{" << name << "}}\n";
79 break;
80 case FileType::ML:
81 m_stream << " <node id=\"" << id
82 << "\">\n"
83 " <data key=\"d0\">"
84 << escapeSpecialCharactersForMl( name )
85 << "</data>\n"
86 " </node>\n";
87 break;
89 break;
90 }
91 };

◆ fileName()

std::string const & Gaudi::Hive::Graph::fileName ( )

Definition at line 70 of file GraphDumper.cpp.

70{ return m_fileName; }

◆ writeHeader()

void Gaudi::Hive::Graph::writeHeader ( )
private

Definition at line 124 of file GraphDumper.cpp.

124 {
125 switch ( m_type ) {
126 case FileType::DOT:
127 m_stream << "digraph datadeps {\n rankdir=\"LR\";\n";
128 break;
129 case FileType::MD:
130 m_stream << "```mermaid\ngraph LR;\n\n";
131 break;
132 case FileType::ML:
133 m_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
134 "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n"
135 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
136 " xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns "
137 "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n"
138 " <key id=\"d1\" for=\"edge\" attr.name=\"label\" attr.type=\"string\"/>\n"
139 " <key id=\"d0\" for=\"node\" attr.name=\"label\" attr.type=\"string\"/>\n"
140 " <graph id=\"Dependencies\" edgedefault=\"directed\">\n";
141 break;
143 break;
144 }
145 }

◆ writeTrailer()

void Gaudi::Hive::Graph::writeTrailer ( )
private

Definition at line 147 of file GraphDumper.cpp.

147 {
148 switch ( m_type ) {
149 case FileType::DOT:
150 m_stream << "}\n";
151 break;
152 case FileType::MD:
153 m_stream << "```\n";
154 break;
155 case FileType::ML:
156 m_stream << " </graph>\n</graphml>";
157 break;
159 break;
160 }
161 }

Member Data Documentation

◆ m_fileName

std::string Gaudi::Hive::Graph::m_fileName
private

name of the filed used for storing the graph

Definition at line 56 of file GraphDumper.h.

◆ m_stream

std::ofstream Gaudi::Hive::Graph::m_stream
private

stream to the graph file

Definition at line 58 of file GraphDumper.h.

◆ m_type

FileType Gaudi::Hive::Graph::m_type { FileType::UNKNOWN }
private

type of file used

Definition at line 60 of file GraphDumper.h.


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