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