The Gaudi Framework  master (ff829712)
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 name, std::string_view id)
 
void addEdge (std::string_view srcName, std::string_view srcId, std::string_view tgtName, 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 callin gthe 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 )
inline

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 40 of file GraphDumper.h.

41 // find out type of file if not given
42 if ( type == FileType::UNKNOWN ) {
43 // Check file extension
44 if ( m_fileName.ends_with( ".dot" ) ) {
46 } else if ( m_fileName.ends_with( ".md" ) ) {
48 } else if ( m_fileName.ends_with( ".graphml" ) ) {
50 } else {
52 m_fileName += ".dot";
53 }
54 }
55 // open file
56 m_stream = std::ofstream{ m_fileName, std::ofstream::out };
58 }
FileType m_type
type of file used
std::string m_fileName
name of the filed used for storing the graph
std::string const & fileName()
Definition GraphDumper.h:65
std::ofstream m_stream
stream to the graph file

◆ ~Graph()

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

Definition at line 60 of file GraphDumper.h.

60 {
62 m_stream.close();
63 }

Member Function Documentation

◆ addEdge()

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

Definition at line 83 of file GraphDumper.h.

84 {
85 switch ( m_type ) {
86 case FileType::DOT:
87 m_stream << " " << srcId << " -> " << tgtId;
88 if ( label != "" ) m_stream << " [label=\"" << label << "\"]";
89 m_stream << ";\n";
90 break;
91 case FileType::MD:
92 m_stream << " " << srcId << " --> " << tgtId;
93 if ( label != "" ) m_stream << " : " << label;
94 m_stream << "\n";
95 break;
96 case FileType::ML:
97 m_stream << " <edge source=\"" << srcName << "\" target=\"" << tgtName << "\"/>\n";
98 break;
100 break;
101 }
102 };

◆ addNode()

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

Definition at line 67 of file GraphDumper.h.

67 {
68 switch ( m_type ) {
69 case FileType::DOT:
70 m_stream << " " << id << " [label=\"" << name << "\";shape=box];\n";
71 break;
72 case FileType::MD:
73 m_stream << " " << id << "{{" << name << "}}\n";
74 break;
75 case FileType::ML:
76 m_stream << " <node id=\"" << name << "\"/>\n";
77 break;
79 break;
80 }
81 };

◆ fileName()

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

Definition at line 65 of file GraphDumper.h.

65{ return m_fileName; }

◆ writeHeader()

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

Definition at line 105 of file GraphDumper.h.

105 {
106 switch ( m_type ) {
107 case FileType::DOT:
108 m_stream << "digraph datadeps {\n rankdir=\"LR\";\n";
109 break;
110 case FileType::MD:
111 m_stream << "```mermaid\ngraph LR;\n\n";
112 break;
113 case FileType::ML:
114 m_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
115 "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n"
116 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
117 " xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns "
118 "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n"
119 " <graph id=\"Data dependencies\" edgedefault=\"directed\">\n";
120 break;
122 break;
123 }
124 }

◆ writeTrailer()

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

Definition at line 126 of file GraphDumper.h.

126 {
127 switch ( m_type ) {
128 case FileType::DOT:
129 m_stream << "}\n";
130 break;
131 case FileType::MD:
132 m_stream << "```\n";
133 break;
134 case FileType::ML:
135 m_stream << " </graph>\n</graphml>";
136 break;
138 break;
139 }
140 }

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 143 of file GraphDumper.h.

◆ m_stream

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

stream to the graph file

Definition at line 145 of file GraphDumper.h.

◆ m_type

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

type of file used

Definition at line 147 of file GraphDumper.h.


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