| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

PrecedenceRulesGraph.cpp
Go to the documentation of this file.
1 #include "PrecedenceRulesGraph.h"
2 #include "PRGraphVisitors.h"
3
4 #include <boost/property_map/transform_value_property_map.hpp>
5 #include <fstream>
6
7 #include "GaudiKernel/DataHandleHolderVisitor.h"
8
9 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
10 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
11
12 namespace concurrency
13 {
14
15 //---------------------------------------------------------------------------
16 std::string ControlFlowNode::stateToString( const int& stateId ) const
17 {
18
19 if ( 0 == stateId )
20 return "FALSE";
21 else if ( 1 == stateId )
22 return "TRUE";
23 else
24 return "UNDEFINED";
25 }
26
27 //---------------------------------------------------------------------------
28 DecisionNode::~DecisionNode()
29 {
30
31 for ( auto node : m_children ) delete node;
32 }
33
34 //---------------------------------------------------------------------------
35 void DecisionNode::addParentNode( DecisionNode* node )
36 {
37
38 if ( std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
39 }
40
41 //--------------------------------------------------------------------------
42 void DecisionNode::addDaughterNode( ControlFlowNode* node )
43 {
44
45 if ( std::find( m_children.begin(), m_children.end(), node ) == m_children.end() ) m_children.push_back( node );
46 }
47
48 //---------------------------------------------------------------------------
49 void DecisionNode::printState( std::stringstream& output, AlgsExecutionStates& states,
50 const std::vector<int>& node_decisions, const unsigned int& recursionLevel ) const
51 {
52
53 output << std::string( recursionLevel, ' ' ) << m_nodeName << " (" << m_nodeIndex << ")"
54 << ", w/ decision: " << stateToString( node_decisions[m_nodeIndex] ) << "(" << node_decisions[m_nodeIndex]
55 << ")" << std::endl;
56
57 for ( auto daughter : m_children ) daughter->printState( output, states, node_decisions, recursionLevel + 2 );
58 }
59
60 //---------------------------------------------------------------------------
61 bool DecisionNode::accept( IGraphVisitor& visitor )
62 {
63
64 if ( visitor.visitEnter( *this ) ) {
65 // try to aggregate a decision
66 bool result = visitor.visit( *this );
67
68 // if a decision was made for this node, propagate the result upwards
69 if ( result ) {
70 for ( auto parent : m_parents ) {
71 parent->accept( visitor );
72 }
73 return false;
74 }
75
76 // if no decision can be made yet, request further information downwards
77 for ( auto child : m_children ) {
78 bool result = child->accept( visitor );
79 if ( !m_modeConcurrent )
80 if ( result ) break; // stop on first unresolved child if its decision hub is sequential
81 }
82
83 return true; // visitor was accepted to try to aggregate the node's decision
84 }
85
86 return false; // visitor was rejected (since the decision node has an aggregated decision already)
87 }
88
89 //---------------------------------------------------------------------------
90 AlgorithmNode::~AlgorithmNode()
91 {
92
93 for ( auto node : m_outputs ) {
94 delete node;
95 }
96 }
97
98 //---------------------------------------------------------------------------
99 void AlgorithmNode::printState( std::stringstream& output, AlgsExecutionStates& states,
100 const std::vector<int>& node_decisions, const unsigned int& recursionLevel ) const
101 {
102 output << std::string( recursionLevel, ' ' ) << m_nodeName << " (" << m_nodeIndex << ")"
103 << ", w/ decision: " << stateToString( node_decisions[m_nodeIndex] ) << "(" << node_decisions[m_nodeIndex]
104 << ")"
105 << ", in state: " << AlgsExecutionStates::stateNames[states[m_algoIndex]] << std::endl;
106 }
107
108 //---------------------------------------------------------------------------
109 bool AlgorithmNode::accept( IGraphVisitor& visitor )
110 {
111
112 if ( visitor.visitEnter( *this ) ) {
113 visitor.visit( *this );
114 return true; // visitor was accepted to promote the algorithm
115 }
116
117 return false; // visitor was rejected (since the algorithm already produced a decision)
118 }
119
120 //---------------------------------------------------------------------------
121 void AlgorithmNode::addParentNode( DecisionNode* node )
122 {
123
124 if ( std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
125 }
126
127 //---------------------------------------------------------------------------
128 void AlgorithmNode::addOutputDataNode( DataNode* node )
129 {
130
131 if ( std::find( m_outputs.begin(), m_outputs.end(), node ) == m_outputs.end() ) m_outputs.push_back( node );
132 }
133
134 //---------------------------------------------------------------------------
135 void AlgorithmNode::addInputDataNode( DataNode* node )
136 {
137
138 if ( std::find( m_inputs.begin(), m_inputs.end(), node ) == m_inputs.end() ) m_inputs.push_back( node );
139 }
140
141 //---------------------------------------------------------------------------
142 StatusCode PrecedenceRulesGraph::initialize()
143 {
144
145 if ( serviceLocator()->existsService( "CondSvc" ) ) {
146 SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc" )};
147 if ( condSvc.isValid() ) {
148 info() << "CondSvc found. DF precedence rules will be augmented with 'Conditions'" << endmsg;
149 m_conditionsRealmEnabled = true;
150 }
151 }
152
153 // Detach condition algorithms from the CF realm
154 if ( m_conditionsRealmEnabled ) {
155 SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc", false )};
156 auto& condAlgs = condSvc->condAlgs();
157 for ( const auto algo : condAlgs ) {
158 auto itA = m_algoNameToAlgoNodeMap.find( algo->name() );
159 concurrency::AlgorithmNode* algoNode;
160 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
161 algoNode = itA->second;
162 debug() << "Detaching condition algorithm '" << algo->name() << "' from the CF realm.." << endmsg;
163 for ( auto parent : algoNode->getParentDecisionHubs() ) {
164 parent->m_children.erase( std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
165 parent->m_children.end() );
166 }
167 algoNode->m_parents.clear();
168
169 } else {
170 warning() << "Algorithm '" << algo->name() << "' is not registered in the graph" << endmsg;
171 }
172 }
173 }
174
175 StatusCode sc = buildDataDependenciesRealm();
176
177 if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
178
179 ON_DEBUG debug() << dumpDataFlow() << endmsg;
180
181 return sc;
182 }
183
184 //---------------------------------------------------------------------------
185 void PrecedenceRulesGraph::registerIODataObjects( const Algorithm* algo )
186 {
187
188 const std::string& algoName = algo->name();
189
190 m_algoNameToAlgoInputsMap[algoName] = algo->inputDataObjs();
191 m_algoNameToAlgoOutputsMap[algoName] = algo->outputDataObjs();
192
193 ON_VERBOSE
194 {
195 verbose() << " Inputs of " << algoName << ": ";
196 for ( auto tag : algo->inputDataObjs() ) verbose() << tag << " | ";
197 verbose() << endmsg;
198
199 verbose() << " Outputs of " << algoName << ": ";
200 for ( auto tag : algo->outputDataObjs() ) verbose() << tag << " | ";
201 verbose() << endmsg;
202 }
203 }
204
205 //---------------------------------------------------------------------------
206 StatusCode PrecedenceRulesGraph::buildDataDependenciesRealm()
207 {
208
209 StatusCode global_sc( StatusCode::SUCCESS, true );
210
211 // Production of DataNodes by AlgorithmNodes (DataNodes are created here)
212 for ( auto algo : m_algoNameToAlgoNodeMap ) {
213
214 auto& outputs = m_algoNameToAlgoOutputsMap[algo.first];
215 for ( auto output : outputs ) {
216 const auto sc = addDataNode( output );
217 if ( !sc.isSuccess() ) {
218 error() << "Extra producer (" << algo.first << ") for DataObject @ " << output
219 << " has been detected: this is not allowed." << endmsg;
220 global_sc = sc;
221 }
222 auto dataNode = getDataNode( output );
223 dataNode->addProducerNode( algo.second );
224 algo.second->addOutputDataNode( dataNode );
225 ON_DEBUG
226 { // Mirror the action above in the BGL-based graph
227 boost::add_edge( node( algo.second->getNodeName() ), node( output.fullKey() ), m_PRGraph );
228 }
229 }
230 }
231
232 // Consumption of DataNodes by AlgorithmNodes
233 for ( auto algo : m_algoNameToAlgoNodeMap ) {
234
235 for ( auto input : m_algoNameToAlgoInputsMap[algo.first] ) {
236
237 DataNode* dataNode = nullptr;
238
239 auto itP = m_dataPathToDataNodeMap.find( input );
240
241 if ( itP != m_dataPathToDataNodeMap.end() ) dataNode = getDataNode( input );
242
243 if ( dataNode ) {
244 dataNode->addConsumerNode( algo.second );
245 algo.second->addInputDataNode( dataNode );
246 ON_DEBUG
247 { // Mirror the action above in the BGL-based graph
248 boost::add_edge( node( input.fullKey() ), node( algo.second->getNodeName() ), m_PRGraph );
249 }
250 }
251 }
252 }
253
254 return global_sc;
255 }
256
257 //---------------------------------------------------------------------------
258 StatusCode PrecedenceRulesGraph::addAlgorithmNode( Algorithm* algo, const std::string& parentName, bool inverted,
259 bool allPass )
260 {
261
262 StatusCode sc = StatusCode::SUCCESS;
263
264 // Create new, or fetch existent, AlgorithmNode
265 auto& algoName = algo->name();
266 auto itA = m_algoNameToAlgoNodeMap.find( algoName );
267 concurrency::AlgorithmNode* algoNode;
268 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
269 algoNode = itA->second;
270 } else {
271 algoNode = new concurrency::AlgorithmNode( *this, algo, m_nodeCounter, m_algoCounter, inverted, allPass );
272 ON_DEBUG
273 { // Mirror the action above in the BGL-based graph
274 auto source =
275 boost::add_vertex( AlgoProps( algo, m_nodeCounter, m_algoCounter, inverted, allPass ), m_PRGraph );
276 boost::add_edge( source, node( parentName ), m_PRGraph );
277 }
278 ++m_nodeCounter;
279 ++m_algoCounter;
280 m_algoNameToAlgoNodeMap[algoName] = algoNode;
281 ON_VERBOSE verbose() << "AlgoNode " << algoName << " added @ " << algoNode << endmsg;
282 registerIODataObjects( algo );
283 }
284
285 // Attach AlgorithmNode to its CF decision hub
286 auto itP = m_decisionNameToDecisionHubMap.find( parentName );
287 if ( itP != m_decisionNameToDecisionHubMap.end() ) {
288 auto parentNode = itP->second;
289 ON_VERBOSE verbose() << "Attaching AlgorithmNode '" << algo->name() << "' to DecisionNode '" << parentName << "'"
290 << endmsg;
291
292 parentNode->addDaughterNode( algoNode );
293 algoNode->addParentNode( parentNode );
294 } else {
295 sc = StatusCode::FAILURE;
296 error() << "Requested DecisionNode '" << parentName << "' was not found" << endmsg;
297 }
298
299 return sc;
300 }
301
302 //---------------------------------------------------------------------------
303 AlgorithmNode* PrecedenceRulesGraph::getAlgorithmNode( const std::string& algoName ) const
304 {
305
306 return m_algoNameToAlgoNodeMap.at( algoName );
307 }
308
309 //---------------------------------------------------------------------------
310 StatusCode PrecedenceRulesGraph::addDataNode( const DataObjID& dataPath )
311 {
312
313 StatusCode sc;
314
315 auto itD = m_dataPathToDataNodeMap.find( dataPath );
316 concurrency::DataNode* dataNode;
317 if ( itD != m_dataPathToDataNodeMap.end() ) {
318 dataNode = itD->second;
319 sc = StatusCode::SUCCESS;
320 } else {
321 if ( !m_conditionsRealmEnabled ) {
322 dataNode = new concurrency::DataNode( *this, dataPath );
323 ON_VERBOSE verbose() << " DataNode for " << dataPath << " added @ " << dataNode << endmsg;
324 } else {
325 SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc", false )};
326 if ( condSvc->isRegistered( dataPath ) ) {
327 dataNode = new concurrency::ConditionNode( *this, dataPath, condSvc );
328 ON_VERBOSE verbose() << " ConditionNode for " << dataPath << " added @ " << dataNode << endmsg;
329 } else {
330 dataNode = new concurrency::DataNode( *this, dataPath );
331 ON_VERBOSE verbose() << " DataNode for " << dataPath << " added @ " << dataNode << endmsg;
332 }
333 }
334
335 m_dataPathToDataNodeMap[dataPath] = dataNode;
336
337 sc = StatusCode::SUCCESS;
338 ON_DEBUG
339 { // Mirror the action above in the BGL-based graph
340 boost::add_vertex( DataProps( dataPath ), m_PRGraph );
341 }
342 }
343
344 return sc;
345 }
346
347 //---------------------------------------------------------------------------
348 DataNode* PrecedenceRulesGraph::getDataNode( const DataObjID& dataPath ) const
349 {
350
351 return m_dataPathToDataNodeMap.at( dataPath );
352 }
353
354 //---------------------------------------------------------------------------
355 StatusCode PrecedenceRulesGraph::addDecisionHubNode( Algorithm* decisionHubAlgo, const std::string& parentName,
356 bool modeConcurrent, bool modePromptDecision, bool modeOR,
357 bool allPass )
358 {
359
360 StatusCode sc = StatusCode::SUCCESS;
361
362 auto& decisionHubName = decisionHubAlgo->name();
363
364 auto itP = m_decisionNameToDecisionHubMap.find( parentName );
365 concurrency::DecisionNode* parentNode;
366 if ( itP != m_decisionNameToDecisionHubMap.end() ) {
367 parentNode = itP->second;
368 auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
369 concurrency::DecisionNode* decisionHubNode;
370 if ( itA != m_decisionNameToDecisionHubMap.end() ) {
371 decisionHubNode = itA->second;
372 } else {
373 decisionHubNode = new concurrency::DecisionNode( *this, m_nodeCounter, decisionHubName, modeConcurrent,
374 modePromptDecision, modeOR, allPass );
375 m_decisionNameToDecisionHubMap[decisionHubName] = decisionHubNode;
376
377 ON_DEBUG
378 { // Mirror the action above in the BGL-based graph
379 auto source = boost::add_vertex(
380 DecisionHubProps( decisionHubName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR, allPass ),
381 m_PRGraph );
382 boost::add_edge( source, node( parentName ), m_PRGraph );
383 }
384
385 ++m_nodeCounter;
386
387 ON_VERBOSE verbose() << "Decision hub node " << decisionHubName << " added @ " << decisionHubNode << endmsg;
388 }
389
390 parentNode->addDaughterNode( decisionHubNode );
391 decisionHubNode->addParentNode( parentNode );
392 } else {
393 sc = StatusCode::FAILURE;
394 error() << "Decision hub node " << parentName << ", requested to be parent, is not registered." << endmsg;
395 }
396
397 return sc;
398 }
399
400 //---------------------------------------------------------------------------
401 void PrecedenceRulesGraph::addHeadNode( const std::string& headName, bool modeConcurrent, bool modePromptDecision,
402 bool modeOR, bool allPass )
403 {
404
405 auto itH = m_decisionNameToDecisionHubMap.find( headName );
406 if ( itH != m_decisionNameToDecisionHubMap.end() ) {
407 m_headNode = itH->second;
408 } else {
409 m_headNode = new concurrency::DecisionNode( *this, m_nodeCounter, headName, modeConcurrent, modePromptDecision,
410 modeOR, allPass );
411 m_decisionNameToDecisionHubMap[headName] = m_headNode;
412
413 ON_DEBUG
414 { // Mirror the action above in the BGL-based graph
415 boost::add_vertex(
416 DecisionHubProps( headName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR, allPass ),
417 m_PRGraph );
418 }
419
420 ++m_nodeCounter;
421 }
422 }
423
424 //---------------------------------------------------------------------------
425 PRVertexDesc PrecedenceRulesGraph::node( const std::string& name ) const
426 {
427
428 PRVertexDesc target{};
429
430 for ( auto vp = vertices( m_PRGraph ); vp.first != vp.second; ++vp.first ) {
431 PRVertexDesc v = *vp.first;
432 if ( boost::apply_visitor( precedence::VertexName(), m_PRGraph[v] ) == name ) {
433 target = v;
434 break;
435 }
436 }
437
438 return target;
439 }
440
441 //---------------------------------------------------------------------------
442 void PrecedenceRulesGraph::accept( const std::string& algo_name, IGraphVisitor& visitor ) const
443 {
444 getAlgorithmNode( algo_name )->accept( visitor );
445 }
446
447 //---------------------------------------------------------------------------
448 void PrecedenceRulesGraph::rankAlgorithms( IGraphVisitor& ranker ) const
449 {
450
451 info() << "Starting ranking by data outputs .. " << endmsg;
452 for ( auto& pair : m_algoNameToAlgoNodeMap ) {
453 ON_DEBUG debug() << " Ranking " << pair.first << "... " << endmsg;
454 pair.second->accept( ranker );
455 ON_DEBUG debug() << " ... rank of " << pair.first << ": " << pair.second->getRank() << endmsg;
456 }
457 }
458
459 std::string PrecedenceRulesGraph::dumpControlFlow() const
460 {
461 std::ostringstream ost;
462 dumpControlFlow( ost, m_headNode, 0 );
463 return ost.str();
464 }
465
466 void PrecedenceRulesGraph::dumpControlFlow( std::ostringstream& ost, ControlFlowNode* node, const int& indent ) const
467 {
468 ost << std::string( indent * 2, ' ' );
469 DecisionNode* dn = dynamic_cast<DecisionNode*>( node );
470 AlgorithmNode* an = dynamic_cast<AlgorithmNode*>( node );
471 if ( dn != 0 ) {
472 if ( node != m_headNode ) {
473 ost << node->getNodeName() << " [Seq] ";
474 ost << ( ( dn->m_modeConcurrent ) ? " [Concurrent] " : " [Sequential] " );
475 ost << ( ( dn->m_modePromptDecision ) ? " [Prompt] " : "" );
476 ost << ( ( dn->m_modeOR ) ? " [OR] " : "" );
477 ost << ( ( dn->m_allPass ) ? " [PASS] " : "" );
478 ost << "\n";
479 }
480 const std::vector<ControlFlowNode*>& dth = dn->getDaughters();
481 for ( std::vector<ControlFlowNode*>::const_iterator itr = dth.begin(); itr != dth.end(); ++itr ) {
482 dumpControlFlow( ost, *itr, indent + 1 );
483 }
484 } else if ( an != 0 ) {
485 ost << node->getNodeName() << " [Alg] ";
486 if ( an != 0 ) {
487 auto ar = an->getAlgorithm();
488 ost << " [n= " << ar->cardinality() << "]";
489 ost << ( ( !ar->isClonable() ) ? " [unclonable] " : "" );
490 }
491 ost << "\n";
492 }
493 }
494
495 //---------------------------------------------------------------------------
496 std::string PrecedenceRulesGraph::dumpDataFlow() const
497 {
498
499 const char idt[] = " ";
500 std::ostringstream ost;
501
502 ost << "\n" << idt << "====================================\n";
503 ost << idt << "Data origins and destinations:\n";
504 ost << idt << "====================================\n";
505
506 for ( auto& pair : m_dataPathToDataNodeMap ) {
507
508 for ( auto algoNode : pair.second->getProducers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
509
510 ost << idt << " V\n";
511 ost << idt << " o " << pair.first << "\n";
512 ost << idt << " V\n";
513
514 for ( auto algoNode : pair.second->getConsumers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
515
516 ost << idt << "====================================\n";
517 }
518
519 return ost.str();
520 }
521
522 //---------------------------------------------------------------------------
523
524 void PrecedenceRulesGraph::dumpPrecRules( const boost::filesystem::path& fileName, const EventSlot& slot )
525 {
526 boost::filesystem::ofstream myfile;
527 myfile.open( fileName, std::ios::app );
528
529 // Declare properties to dump
530 boost::dynamic_properties dp;
531
532 using boost::make_transform_value_property_map;
533 using boost::apply_visitor;
534 using boost::get;
535 using boost::vertex_bundle;
536
537 dp.property( "Entity", make_transform_value_property_map(
538 []( VariantVertexProps const& v ) { return boost::lexical_cast<std::string>( v ); },
539 get( vertex_bundle, m_PRGraph ) ) );
540
541 dp.property( "Name", make_transform_value_property_map(
542 []( VariantVertexProps const& v ) { return apply_visitor( precedence::VertexName(), v ); },
543 get( vertex_bundle, m_PRGraph ) ) );
544
545 dp.property( "Mode", make_transform_value_property_map(
546 []( VariantVertexProps const& v ) { return apply_visitor( precedence::GroupMode(), v ); },
547 get( vertex_bundle, m_PRGraph ) ) );
548
549 dp.property( "Logic",
550 make_transform_value_property_map(
551 []( VariantVertexProps const& v ) { return apply_visitor( precedence::GroupLogic(), v ); },
552 get( vertex_bundle, m_PRGraph ) ) );
553
554 dp.property( "Decision Negation",
555 make_transform_value_property_map(
556 []( VariantVertexProps const& v ) { return apply_visitor( precedence::DecisionNegation(), v ); },
557 get( vertex_bundle, m_PRGraph ) ) );
558
559 dp.property( "Negative Decision Inversion",
560 make_transform_value_property_map(
561 []( VariantVertexProps const& v ) { return apply_visitor( precedence::AllPass(), v ); },
562 get( vertex_bundle, m_PRGraph ) ) );
563
564 dp.property( "Exit Policy",
565 make_transform_value_property_map(
566 []( VariantVertexProps const& v ) { return apply_visitor( precedence::GroupExit(), v ); },
567 get( vertex_bundle, m_PRGraph ) ) );
568
569 dp.property( "Operations",
570 make_transform_value_property_map(
571 []( VariantVertexProps const& v ) { return apply_visitor( precedence::Operations(), v ); },
572 get( vertex_bundle, m_PRGraph ) ) );
573
574 dp.property( "CF Decision", make_transform_value_property_map(
575 [&slot]( VariantVertexProps const& v ) {
576 return apply_visitor( precedence::CFDecision( slot ), v );
577 },
578 get( vertex_bundle, m_PRGraph ) ) );
579
580 dp.property( "Algorithm State", make_transform_value_property_map(
581 [&slot]( VariantVertexProps const& v ) {
582 return apply_visitor( precedence::FSMState( slot ), v );
583 },
584 get( vertex_bundle, m_PRGraph ) ) );
585
586 SmartIF<ITimelineSvc> timelineSvc = m_svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
587 if ( timelineSvc.isValid() ) {
588 dp.property( "Start Time (epoch ns)", make_transform_value_property_map(
589 [&timelineSvc]( VariantVertexProps const& v ) {
590 return apply_visitor( precedence::StartTime( timelineSvc ), v );
591 },
592 get( vertex_bundle, m_PRGraph ) ) );
593 dp.property( "End Time (epoch ns)", make_transform_value_property_map(
594 [&timelineSvc]( VariantVertexProps const& v ) {
595 return apply_visitor( precedence::EndTime( timelineSvc ), v );
596 },
597 get( vertex_bundle, m_PRGraph ) ) );
598 dp.property( "Runtime (ns)", make_transform_value_property_map(
599 [&timelineSvc]( VariantVertexProps const& v ) {
600 return apply_visitor( precedence::Duration( timelineSvc ), v );
601 },
602 get( vertex_bundle, m_PRGraph ) ) );
603 } else {
604 warning() << "Failed to get the TimelineSvc, timing will not be added to "
605 << "the task precedence rules dump" << endmsg;
606 }
607
608 boost::write_graphml( myfile, m_PRGraph, dp );
609
610 myfile.close();
611 }
612
613 //---------------------------------------------------------------------------
614 void PrecedenceRulesGraph::dumpPrecTrace( const boost::filesystem::path& fileName )
615 {
616 boost::filesystem::ofstream myfile;
617 myfile.open( fileName, std::ios::app );
618
619 // Fill runtimes (as this could not be done on the fly during trace assembling)
620 SmartIF<ITimelineSvc> timelineSvc = m_svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
621 if ( !timelineSvc.isValid() ) {
622 warning() << "Failed to get the TimelineSvc, timing will not be added to "
623 << "the task precedence trace dump" << endmsg;
624 } else {
625
626 typedef boost::graph_traits<precedence::PRGraph>::vertex_iterator vertex_iter;
627 std::pair<vertex_iter, vertex_iter> vp;
628 for ( vp = vertices( m_precTrace ); vp.first != vp.second; ++vp.first ) {
629 TimelineEvent te{};
630 te.algorithm = m_precTrace[*vp.first].m_name;
631 timelineSvc->getTimelineEvent( te );
632 int runtime = std::chrono::duration_cast<std::chrono::nanoseconds>( te.end - te.start ).count();
633 m_precTrace[*vp.first].m_runtime = runtime;
634 }
635 }
636
637 // Declare properties to dump
638 boost::dynamic_properties dp;
639 using boost::get;
640 using precedence::AlgoTraceProps;
641 dp.property( "Name", get( &AlgoTraceProps::m_name, m_precTrace ) );
642 dp.property( "Rank", get( &AlgoTraceProps::m_rank, m_precTrace ) );
643 dp.property( "Runtime", get( &AlgoTraceProps::m_runtime, m_precTrace ) );
644
645 boost::write_graphml( myfile, m_precTrace, dp );
646
647 myfile.close();
648 }
649
650 void PrecedenceRulesGraph::addEdgeToPrecTrace( const AlgorithmNode* u, const AlgorithmNode* v )
651 {
652
653 std::string u_name = u == nullptr ? "ENTRY" : u->getNodeName();
654 std::string v_name = v->getNodeName();
655
656 precedence::AlgoTraceVertex source;
657
658 if ( u == nullptr ) {
659 auto itT = m_prec_trace_map.find( "ENTRY" );
660 if ( itT != m_prec_trace_map.end() ) {
661 source = itT->second;
662 } else {
663 source = boost::add_vertex( precedence::AlgoTraceProps( "ENTRY", -1, -1, -1.0 ), m_precTrace );
664 m_prec_trace_map["ENTRY"] = source;
665 }
666 } else {
667 auto itS = m_prec_trace_map.find( u_name );
668 if ( itS != m_prec_trace_map.end() ) {
669 source = itS->second;
670 } else {
671
672 source =
673 boost::add_vertex( precedence::AlgoTraceProps( u_name, u->getAlgoIndex(), u->getRank(), -1 ), m_precTrace );
674 m_prec_trace_map[u_name] = source;
675 }
676 }
677
678 precedence::AlgoTraceVertex target;
679
680 auto itP = m_prec_trace_map.find( v_name );
681 if ( itP != m_prec_trace_map.end() ) {
682 target = itP->second;
683 } else {
684
685 target =
686 boost::add_vertex( precedence::AlgoTraceProps( v_name, v->getAlgoIndex(), v->getRank(), -1 ), m_precTrace );
687 m_prec_trace_map[v_name] = target;
688 }
689
690 boost::add_edge( source, target, m_precTrace );
691
692 ON_DEBUG debug() << u_name << "-->" << v_name << " precedence trait added" << endmsg;
693 }
694
695 } // namespace
concurrency::PrecedenceRulesGraph::node
PRVertexDesc node(const std::string &) const
BGL-based facilities.
Definition: PrecedenceRulesGraph.cpp:425
std::chrono::nanoseconds
StatusCode::SUCCESS
Definition: StatusCode.h:31
concurrency::AlgorithmNode::getAlgoIndex
const unsigned int & getAlgoIndex() const
Get algorithm index.
Definition: PrecedenceRulesGraph.h:455
precedence::CFDecision
Definition: PrecedenceRulesGraph.h:163
SmartIF< ICondSvc >
precedence::GroupMode
Definition: PrecedenceRulesGraph.h:117
PRGraphVisitors.h
concurrency::DecisionNode
Definition: PrecedenceRulesGraph.h:364
precedence::Duration
Definition: PrecedenceRulesGraph.h:267
concurrency::PrecedenceRulesGraph::addAlgorithmNode
StatusCode addAlgorithmNode(Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
Definition: PrecedenceRulesGraph.cpp:258
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:731
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:895
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
StatusCode::FAILURE
Definition: StatusCode.h:31
concurrency::DecisionNode::addDaughterNode
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
Definition: PrecedenceRulesGraph.cpp:42
precedence::AlgoTraceVertex
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
Definition: PrecedenceRulesGraph.h:44
DataObjID
Definition: DataObjID.h:37
concurrency::DataNode
Definition: PrecedenceRulesGraph.h:498
precedence::PRVertexDesc
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
Definition: PrecedenceRulesGraph.h:309
gaudirun.output
output
Definition: gaudirun.py:404
concurrency
Definition: ControlFlowGraph.cpp:4
DataHandleHolderBase::outputDataObjs
const DataObjIDColl & outputDataObjs() const override
Definition: DataHandleHolderBase.h:62
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
concurrency::IGraphVisitor::visit
virtual bool visit(DecisionNode &)
Definition: IGraphVisitor.h:18
precedence::FSMState
Definition: PrecedenceRulesGraph.h:181
precedence::AlgoProps
Definition: PrecedenceRulesGraph.h:47
concurrency::PrecedenceRulesGraph::dumpPrecRules
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
Definition: PrecedenceRulesGraph.cpp:524
std::endl
T endl(T...args)
concurrency::PrecedenceRulesGraph::addDecisionHubNode
StatusCode addDecisionHubNode(Algorithm *daughterAlgo, const std::string &parentName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Add a node, which aggregates decisions of direct daughter nodes.
Definition: PrecedenceRulesGraph.cpp:355
concurrency::AlgorithmNode::m_parents
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
Definition: PrecedenceRulesGraph.h:473
concurrency::ControlFlowNode
Definition: PrecedenceRulesGraph.h:333
concurrency::PrecedenceRulesGraph::addHeadNode
void addHeadNode(const std::string &headName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Add a node, which has no parents.
Definition: PrecedenceRulesGraph.cpp:401
TimelineEvent::algorithm
std::string algorithm
Definition: ITimelineSvc.h:18
precedence::AlgoTraceProps
Definition: PrecedenceRulesGraph.h:30
concurrency::ControlFlowNode::stateToString
std::string stateToString(const int &stateId) const
Translation between state id and name.
Definition: PrecedenceRulesGraph.cpp:16
std::chrono::duration_cast
T duration_cast(T...args)
std::vector::end
T end(T...args)
concurrency::PrecedenceRulesGraph::addDataNode
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
Definition: PrecedenceRulesGraph.cpp:310
concurrency::PrecedenceRulesGraph::getAlgorithmNode
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
Definition: PrecedenceRulesGraph.cpp:303
concurrency::PrecedenceRulesGraph::rankAlgorithms
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
Definition: PrecedenceRulesGraph.cpp:448
ON_DEBUG
#define ON_DEBUG
Definition: PrecedenceRulesGraph.cpp:9
concurrency::DecisionNode::m_allPass
bool m_allPass
Whether always passing regardless of daughter results.
Definition: PrecedenceRulesGraph.h:403
concurrency::AlgorithmNode::getParentDecisionHubs
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
Definition: PrecedenceRulesGraph.h:436
concurrency::AlgorithmNode::~AlgorithmNode
~AlgorithmNode()
Destructor.
Definition: PrecedenceRulesGraph.cpp:90
TimelineEvent
Definition: ITimelineSvc.h:13
std::remove
T remove(T...args)
std::stringstream
STL class.
concurrency::IGraphVisitor::visitEnter
virtual bool visitEnter(DecisionNode &) const
Definition: IGraphVisitor.h:17
std::string
STL class.
concurrency::AlgorithmNode::getAlgorithm
Algorithm * getAlgorithm() const
get Algorithm representatives
Definition: PrecedenceRulesGraph.h:453
ITimelineSvc::getTimelineEvent
virtual void getTimelineEvent(TimelineEvent &) const =0
concurrency::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: PrecedenceRulesGraph.h:401
concurrency::AlgorithmNode::addInputDataNode
void addInputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
Definition: PrecedenceRulesGraph.cpp:135
concurrency::DecisionNode::accept
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
Definition: PrecedenceRulesGraph.cpp:61
concurrency::PrecedenceRulesGraph::initialize
StatusCode initialize()
Initialize graph.
Definition: PrecedenceRulesGraph.cpp:142
concurrency::PrecedenceRulesGraph::dumpPrecTrace
void dumpPrecTrace(const boost::filesystem::path &)
dump to file the precedence trace
Definition: PrecedenceRulesGraph.cpp:614
concurrency::AlgorithmNode::getRank
const float & getRank() const
Get Algorithm rank.
Definition: PrecedenceRulesGraph.h:450
precedence::VariantVertexProps
boost::variant< AlgoProps, DecisionHubProps, DataProps > VariantVertexProps
Definition: PrecedenceRulesGraph.h:307
precedence::GroupExit
Definition: PrecedenceRulesGraph.h:136
AlgsExecutionStates
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Definition: AlgsExecutionStates.h:28
ICondSvc::condAlgs
virtual const std::set< IAlgorithm * > & condAlgs() const =0
get list of all registered condition Algorithms
concurrency::ControlFlowNode::m_nodeIndex
unsigned int m_nodeIndex
Definition: PrecedenceRulesGraph.h:360
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
DataHandleHolderBase::inputDataObjs
const DataObjIDColl & inputDataObjs() const override
Definition: DataHandleHolderBase.h:61
std::ostringstream
STL class.
concurrency::PrecedenceRulesGraph::dumpDataFlow
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
Definition: PrecedenceRulesGraph.cpp:496
concurrency::DecisionNode::getDaughters
const std::vector< ControlFlowNode * > & getDaughters() const
Get children nodes.
Definition: PrecedenceRulesGraph.h:389
precedence::EndTime
Definition: PrecedenceRulesGraph.h:240
std::ostringstream::str
T str(T...args)
concurrency::IGraphVisitor
Definition: IGraphVisitor.h:12
concurrency::PrecedenceRulesGraph::accept
void accept(const std::string &algo_name, IGraphVisitor &visitor) const
A method to update algorithm node decision, and propagate it upwards.
Definition: PrecedenceRulesGraph.cpp:442
DataHandleHolderVisitor.h
ITimelineSvc
Definition: ITimelineSvc.h:24
precedence::VertexName
Definition: PrecedenceRulesGraph.h:109
concurrency::PrecedenceRulesGraph::getDataNode
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
Definition: PrecedenceRulesGraph.cpp:348
concurrency::DecisionNode::m_modePromptDecision
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Definition: PrecedenceRulesGraph.h:399
std::pair
concurrency::PrecedenceRulesGraph::addEdgeToPrecTrace
void addEdgeToPrecTrace(const AlgorithmNode *u, const AlgorithmNode *v)
set cause-effect connection between two algorithms in the precedence trace
Definition: PrecedenceRulesGraph.cpp:650
concurrency::ControlFlowNode::m_nodeName
std::string m_nodeName
Definition: PrecedenceRulesGraph.h:361
precedence::StartTime
Definition: PrecedenceRulesGraph.h:213
concurrency::AlgorithmNode::addOutputDataNode
void addOutputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
Definition: PrecedenceRulesGraph.cpp:128
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
std::find
T find(T...args)
Gaudi::Functional::m_inputs
std::vector< InputHandle_t< In > > m_inputs
Definition: MergingTransformer.h:45
std::vector< int >
GaudiPython.Persistency.get
def get(type_)
Definition: Persistency.py:29
precedence::DecisionNegation
Definition: PrecedenceRulesGraph.h:147
concurrency::DecisionNode::addParentNode
void addParentNode(DecisionNode *node)
Add a parent node.
Definition: PrecedenceRulesGraph.cpp:35
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
std::vector::begin
T begin(T...args)
genconfuser.verbose
verbose
Definition: genconfuser.py:19
concurrency::PrecedenceRulesGraph::registerIODataObjects
void registerIODataObjects(const Algorithm *algo)
Register algorithm in the Data Dependency index.
Definition: PrecedenceRulesGraph.cpp:185
concurrency::DecisionNode::m_modeConcurrent
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
Definition: PrecedenceRulesGraph.h:396
precedence::Operations
Definition: PrecedenceRulesGraph.h:293
concurrency::DecisionNode::printState
void printState(std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
Definition: PrecedenceRulesGraph.cpp:49
concurrency::ConditionNode
Definition: PrecedenceRulesGraph.h:538
EventSlot
Class representing the event slot.
Definition: EventSlot.h:11
BrunelScenarioForwardScheduler.app
app
Definition: BrunelScenarioForwardScheduler.py:147
concurrency::AlgorithmNode
Definition: PrecedenceRulesGraph.h:413
concurrency::AlgorithmNode::addParentNode
void addParentNode(DecisionNode *node)
Add a parent node.
Definition: PrecedenceRulesGraph.cpp:121
concurrency::AlgorithmNode::accept
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
Definition: PrecedenceRulesGraph.cpp:109
precedence::GroupLogic
Definition: PrecedenceRulesGraph.h:128
concurrency::ControlFlowNode::getNodeName
const std::string & getNodeName() const
Get node name.
Definition: PrecedenceRulesGraph.h:352
ON_VERBOSE
#define ON_VERBOSE
Definition: PrecedenceRulesGraph.cpp:10
concurrency::AlgorithmNode::printState
void printState(std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
Definition: PrecedenceRulesGraph.cpp:99
concurrency::PrecedenceRulesGraph::buildDataDependenciesRealm
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
Definition: PrecedenceRulesGraph.cpp:206
precedence::AllPass
Definition: PrecedenceRulesGraph.h:155
precedence::DecisionHubProps
Definition: PrecedenceRulesGraph.h:75
concurrency::PrecedenceRulesGraph::dumpControlFlow
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
Definition: PrecedenceRulesGraph.cpp:459
concurrency::DecisionNode::~DecisionNode
~DecisionNode() override
Destructor.
Definition: PrecedenceRulesGraph.cpp:28
PrecedenceRulesGraph.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
AlgsExecutionStates::stateNames
static std::map< State, std::string > stateNames
Definition: AlgsExecutionStates.h:42
precedence::DataProps
Definition: PrecedenceRulesGraph.h:101
concurrency::DataNode::addConsumerNode
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.
Definition: PrecedenceRulesGraph.h:519