Start - do graph calculation here, to ensure EventLoopMgr initialized already.
25 {
26
27 std::function<void(IAlgorithm*,std::set<IAlgorithm*>&,
bool)>
func;
28
30
31
32 func = [&](IAlgorithm*
alg, std::set<IAlgorithm*>& thealgs,
bool isAdding) {
33 isAdding = (isAdding || std::regex_search( std::string(
alg->nameKey()) , sequenceNameRegex) );
34 if(isAdding) {
35 thealgs.insert(alg);
36 }
37 if(auto seq = dynamic_cast<Gaudi::Sequence*>( alg )) {
38 auto subalgs = seq->subAlgorithms();
39 for(auto thisAlg : *subalgs) {
40 func(thisAlg,thealgs,isAdding);
41 }
42 }
43 };
44
45
47 std::set<IAlgorithm*> subalgs;
48 for ( IAlgorithm* ialgoPtr : algos ) {
49 func(ialgoPtr,subalgs,
false);
50 }
51
52
53 DataObjIDColl globalInp, globalOutp;
54 std::map<std::string, DataObjIDColl> algosOutputDependenciesMap;
55 std::map<std::string, DataObjIDColl> algosInputDependenciesMap;
56
57 for ( IAlgorithm* ialgoPtr : subalgs ) {
58 if(ialgoPtr->isSequence()) continue;
59
60 Gaudi::Algorithm* algoPtr = dynamic_cast<Gaudi::Algorithm*>( ialgoPtr );
61 if ( !algoPtr ) continue;
62 DataObjIDColl algoOutputs;
63 for ( const auto & id : algoPtr->outputDataObjs() ) {
64 globalOutp.insert( id );
65 algoOutputs.insert( id );
66 }
67
68
69
70 DataObjIDColl i1, i2;
71 DHHVisitor avis( i1, i2 );
72 algoPtr->acceptDHVisitor( &avis );
73
74 DataObjIDColl algoDependencies;
75 for ( const DataObjID& id : algoPtr->inputDataObjs() ) {
76 algoDependencies.insert( id );
77 globalInp.insert( id );
78 }
79
80 std::string algoName = ialgoPtr->nameKey();
81 if(ialgoPtr->type()!= algoName) {
82 algoName = ialgoPtr->type() + "/" + algoName;
83 }
84
85 algosInputDependenciesMap[algoName] = std::move(algoDependencies);
86 algosOutputDependenciesMap[algoName] = std::move(algoOutputs);
87
88 }
89
90
93 stream <<
"digraph datadeps {\n rankdir=\"LR\";\n";
94
95 auto addNode = [&](std::string_view
id, std::string_view
name, std::string_view shape=
"box" ) {
96 stream <<
" " <<
id <<
" [label=\"" <<
name <<
"\";shape=" << shape <<
"];\n";
97 };
98 auto addEdge = [&](std::string_view srcId, std::string_view tgtId, std::string_view
label ) {
99 stream <<
" " << srcId <<
" -> " << tgtId <<
" [label=\"" <<
label <<
"\"];\n";
100 };
101
102
103 std::map<std::string,std::pair<std::set<std::string>,std::set<std::string>>> deps;
104
105
106
107
108 for ( const auto& [algName, ideps] : algosInputDependenciesMap ) {
109 for (const auto &dep: ideps) {
110 deps[dep.key()].second.insert(algName);
111 }
112 }
113 for ( const auto& [algName, odeps] : algosOutputDependenciesMap ) {
114 for (const auto &dep: odeps) {
115 deps[dep.key()].first.insert(algName);
116 }
117 }
118
119 std::size_t algoIndex = 0
ul;
120 std::map<std::string,std::string> keyToName;
122
123 for( auto& [dep, pcs] : deps) {
124 auto& [producers,consumers] =
pcs;
125 if(producers.empty()) {
126 std::string algIndex = "Input_" + std::to_string( algoIndex );
127 addNode( algIndex, dep, "plaintext" );
128 keyToName[dep] = algIndex;
129 algoIndex++;
130 producers.insert(dep);
131 inputs += algIndex +
"; ";
132 } else if(consumers.empty()) {
133 std::string algIndex = "Output_" + std::to_string( algoIndex );
134 addNode( algIndex, dep, "plaintext" );
135 keyToName[dep] = algIndex;
136 algoIndex++;
137 consumers.insert(dep);
139 }
140 }
141
142 for ( const auto& [algName, ideps] : algosInputDependenciesMap ) {
143 std::string algIndex = "Alg_" + std::to_string( algoIndex );
144 addNode( algIndex, algName, "box" );
145 keyToName[
algName] = std::move(algIndex);
146 algoIndex++;
147 }
148
149 for( const auto& [dep, pcs] : deps) {
150 auto& [producers,consumers] =
pcs;
151 for(auto& producer : producers) {
152 for(auto& consumer: consumers) {
153 addEdge(keyToName.at(producer),keyToName.at(consumer),dep!=producer && dep!=consumer ? dep : " ");
154 }
155 }
156 }
157
160 }
163 }
164
167
168 return StatusCode::SUCCESS;
169
170 }
StringProperty m_fileName
StringProperty m_topSequence
ServiceHandle< IAlgResourcePool > m_algResourcePool
std::string label(const std::string &format, int i)
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.