10#include <framework/core/Module.h>
11#include <framework/core/Path.h>
12#include <framework/core/ModuleManager.h>
14#include <framework/core/DataFlowVisualization.h>
15#include <framework/datastore/DataStore.h>
23 const std::string unknownfillcolor =
"gray82";
40 std::ofstream file(filename.c_str());
41 file <<
"digraph allModules {\n";
42 file <<
" rankdir=LR;\n";
43 file <<
" compound=true;\n";
47 const bool steeringFileFlow =
true;
48 for (
const ModulePtr& mod : path.buildModulePathList())
63 file <<
" \"" << name <<
"\" [shape=box,style=filled,fillcolor=" << unknownfillcolor <<
"];\n";
68 B2INFO(
"Data flow diagram created. You can use 'dot dataflow.dot -Tps -o dataflow.ps' to create a PostScript file from it.");
74 const std::string graphname = pathName.empty() ?
"clusterMain" : (
"cluster" + pathName);
75 file <<
" subgraph \"" << graphname <<
"\" {\n";
76 if (pathName.empty()) {
77 file <<
" rank=min;\n";
79 file <<
" rank=same;\n";
81 file <<
" style=solid;\n";
82 file <<
" color=grey;\n";
83 file <<
" \"" << graphname <<
"_inv\" [shape=point,style=invis];\n";
84 std::string lastModule(
"");
86 for (
const ModulePtr& mod : path.getModules()) {
88 file <<
" \"" << module <<
"\";\n";
89 if (!lastModule.empty()) {
90 file <<
" \"" << lastModule <<
"\" -> \"" << module <<
"\" [color=black];\n";
92 if (mod->hasCondition()) {
93 for (
const auto& condition : mod->getAllConditions()) {
94 const std::string& conditionName = condition.getString();
95 plotPath(file, *condition.getPath(), conditionName);
96 file <<
" \"" << module <<
"\" -> \"cluster" << conditionName <<
"_inv\" " <<
97 "[color=grey,lhead=\"cluster" << conditionName <<
"\",label=\"" << conditionName <<
"\",fontcolor=grey];\n";
109 const std::string& label = mod.getName();
110 if (!steeringFileFlow)
111 file <<
"digraph \"" << name <<
"\" {\n";
112 file <<
" " << name <<
" [label=\"" << label <<
"\"];\n";
118 const std::set<std::string>& entries = moduleInfo.
entries[i];
119 const std::set<std::string>& relations = moduleInfo.
relations[i];
123 for (
const std::string& dsentry : entries) {
124 if (!steeringFileFlow)
125 file <<
" \"" << dsentry <<
"\" [shape=box,style=filled,fillcolor=" << fillcolor <<
"];\n";
128 file <<
" \"" << name <<
"\" -> \"" << dsentry <<
"\" [color=" << arrowcolor <<
"];\n";
131 file <<
" \"" << dsentry <<
"\" -> \"" << name <<
"\" [color=" << arrowcolor <<
"];\n";
135 for (
const std::string& relname : relations) {
136 size_t pos = relname.rfind(
"To");
137 if (pos == std::string::npos or pos != relname.find(
"To")) {
138 B2WARNING(
"generateModulePlot(): couldn't split relation name!");
143 const std::string from = relname.substr(0, pos);
144 const std::string to = relname.substr(pos + 2);
148 if (!steeringFileFlow)
149 file <<
" \"" << from <<
"\" [shape=box,style=filled,fillcolor=" << unknownfillcolor <<
"];\n";
152 if (!steeringFileFlow)
153 file <<
" \"" << to <<
"\" [shape=box,style=filled,fillcolor=" << unknownfillcolor <<
"];\n";
156 file <<
" \"" << from <<
"\" -> \"" << to <<
"\" [color=" << arrowcolor <<
",style=dashed];\n";
160 if (!steeringFileFlow)
174 gearboxPtr->initialize();
176 modulePtr->initialize();
179 const std::string filename = module +
".dot";
181 std::ofstream file(filename.c_str());
185 modulePtr->terminate();
186 gearboxPtr->terminate();
191 for (
const auto& entry : info.entries) {
192 if (entry.count(name) != 0)
class to visualize data flow between modules.
DataFlowVisualization(const DependencyMap *dependencyMap)
Constructor.
std::set< std::string > m_allInputs
set of all inputs (including optionals), for steering file visualisation.
static void executeModuleAndCreateIOPlot(const std::string &module)
Create independent I/O graph for a single module (without requiring a steering file).
bool checkArrayUnknown(const std::string &name, const DependencyMap::ModuleInfo &info)
If the given array name isn't found in any of info's fields, it is added to m_unknownArrays (and true...
std::set< std::string > m_allOutputs
set of all outputs, for steering file visualisation.
static void plotPath(std::ofstream &file, const Path &path, const std::string &pathName="")
Create a subgraph for the given Path (including conditional paths).
void generateModulePlot(std::ofstream &file, const Module &mod, bool steeringFileFlow=false)
Create I/O graph for a single module (written to file).
std::string m_arrowcolor[DependencyMap::c_NEntryTypes]
arrow colors.
void visualizePath(const std::string &filename, const Path &path)
Create graphs with datastore inputs/outputs of each module in path.
std::string m_fillcolor[DependencyMap::c_NEntryTypes]
fill colors.
const DependencyMap * m_map
Stores information on inputs/outputs of each module, as obtained by require()/createEntry();.
std::set< std::string > m_unknownArrays
set of array only being used in relations, for steering file visualisation.
static DataStore & Instance()
Instance of singleton Store.
DependencyMap & getDependencyMap()
Return map of depedencies between modules.
Collect information about the dependencies between modules.
@ c_NEntryTypes
size of this enum.
@ c_Output
registered output.
@ c_OptionalInput
optional input.
void setModule(const Module &mod)
Set the current module (for getCurrentModuleInfo())
const std::map< std::string, ModuleInfo > & getModuleInfoMap() const
return information on inputs/outputs of each module, as obtained by requireInput()/optionalInput()/re...
static std::string getModuleID(const Module &mod)
Return unique ID for given module.
std::shared_ptr< Module > registerModule(const std::string &moduleName, std::string sharedLibPath="") noexcept(false)
Creates an instance of a module and registers it to the ModuleManager.
static ModuleManager & Instance()
Exception is thrown if the requested module could not be created by the ModuleManager.
Implements a path consisting of Module and/or Path objects.
std::shared_ptr< Module > ModulePtr
Defines a pointer to a module object as a boost shared pointer.
Abstract base class for different kinds of events.
Stores information on inputs/outputs of a module, as obtained by requireInput()/optionalInput()/regis...
std::set< std::string > entries[c_NEntryTypes]
objects/arrays.
std::set< std::string > relations[c_NEntryTypes]
relations between them.