The Gaudi Framework  v29r0 (ff2e7097)
concurrency::PrecedenceRulesGraph Class Reference

#include <src/PrecedenceRulesGraph.h>

Inheritance diagram for concurrency::PrecedenceRulesGraph:
Collaboration diagram for concurrency::PrecedenceRulesGraph:

Public Member Functions

 PrecedenceRulesGraph (const std::string &name, SmartIF< ISvcLocator > svc)
 Constructor. More...
 
 ~PrecedenceRulesGraph () override
 Destructor. More...
 
StatusCode initialize ()
 Initialize graph. More...
 
void accept (const std::string &algo_name, IGraphVisitor &visitor) const
 A method to update algorithm node decision, and propagate it upwards. More...
 
StatusCode addDataNode (const DataObjID &dataPath)
 Add DataNode that represents DataObject. More...
 
DataNodegetDataNode (const DataObjID &dataPath) const
 Get DataNode by DataObject path using graph index. More...
 
void registerIODataObjects (const Algorithm *algo)
 Register algorithm in the Data Dependency index. More...
 
StatusCode buildDataDependenciesRealm ()
 Build data dependency realm WITH data object nodes participating. More...
 
void addHeadNode (const std::string &headName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
 Add a node, which has no parents. More...
 
DecisionNodegetHeadNode () const
 Get head node. More...
 
StatusCode addAlgorithmNode (Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
 Add algorithm node. More...
 
AlgorithmNodegetAlgorithmNode (const std::string &algoName) const
 Get the AlgorithmNode from by algorithm name using graph index. More...
 
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. More...
 
unsigned int getControlFlowNodeCounter () const
 Get total number of control flow graph nodes. More...
 
void rankAlgorithms (IGraphVisitor &ranker) const
 Rank Algorithm nodes by the number of data outputs. More...
 
const std::stringname () const override
 Retrieve name of the service. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
const std::chrono::system_clock::time_point getInitTime () const
 
void printState (std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const
 Print a string representing the control flow state. More...
 
PRVertexDesc node (const std::string &) const
 BGL-based facilities. More...
 
std::string dumpDataFlow () const
 Print out all data origins and destinations, as reflected in the EF graph. More...
 
std::string dumpControlFlow () const
 Print out control flow of Algorithms and Sequences. More...
 
void dumpPrecRules (const boost::filesystem::path &, const EventSlot &slot)
 dump to file the precedence rules More...
 
void dumpPrecTrace (const boost::filesystem::path &)
 dump to file the precedence trace More...
 
void addEdgeToPrecTrace (const AlgorithmNode *u, const AlgorithmNode *v)
 set cause-effect connection between two algorithms in the precedence trace More...
 
void dumpControlFlow (std::ostringstream &, ControlFlowNode *, const int &) const
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Private Attributes

DecisionNodem_headNode
 the head node of the control flow graph More...
 
AlgoNodesMap m_algoNameToAlgoNodeMap
 Index: map of algorithm's name to AlgorithmNode. More...
 
DecisionHubsMap m_decisionNameToDecisionHubMap
 Index: map of decision's name to DecisionHub. More...
 
DataNodesMap m_dataPathToDataNodeMap
 Index: map of data path to DataNode. More...
 
AlgoInputsMap m_algoNameToAlgoInputsMap
 Indexes: maps of algorithm's name to algorithm's inputs/outputs. More...
 
AlgoOutputsMap m_algoNameToAlgoOutputsMap
 
unsigned int m_nodeCounter
 Total number of nodes in the graph. More...
 
unsigned int m_algoCounter
 Total number of algorithm nodes in the graph. More...
 
SmartIF< ISvcLocatorm_svcLocator
 Service locator (needed to access the MessageSvc) More...
 
const std::string m_name
 
const std::chrono::system_clock::time_point m_initTime
 
precedence::PrecTrace m_precTrace
 facilities for algorithm precedence tracing More...
 
std::map< std::string, precedence::AlgoTraceVertexm_prec_trace_map
 
precedence::PRGraph m_PRGraph
 BGL-based graph of precedence rules. More...
 
bool m_conditionsRealmEnabled {false}
 Enable conditions realm of precedence rules. More...
 

Additional Inherited Members

- Public Types inherited from CommonMessaging< IPrecedenceRulesGraph >
using base_class = CommonMessaging
 
- Protected Member Functions inherited from CommonMessaging< IPrecedenceRulesGraph >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Detailed Description

Definition at line 573 of file PrecedenceRulesGraph.h.

Constructor & Destructor Documentation

concurrency::PrecedenceRulesGraph::PrecedenceRulesGraph ( const std::string name,
SmartIF< ISvcLocator svc 
)
inline

Constructor.

Definition at line 577 of file PrecedenceRulesGraph.h.

578  : m_headNode( 0 )
579  , m_nodeCounter( 0 )
580  , m_algoCounter( 0 )
581  , m_svcLocator( svc )
582  , m_name( name )
584  {
585  }
const std::chrono::system_clock::time_point m_initTime
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
DecisionNode * m_headNode
the head node of the control flow graph
unsigned int m_nodeCounter
Total number of nodes in the graph.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
concurrency::PrecedenceRulesGraph::~PrecedenceRulesGraph ( )
inlineoverride

Destructor.

Definition at line 587 of file PrecedenceRulesGraph.h.

588  {
589  if ( m_headNode != 0 ) delete m_headNode;
590  }
DecisionNode * m_headNode
the head node of the control flow graph

Member Function Documentation

void concurrency::PrecedenceRulesGraph::accept ( const std::string algo_name,
IGraphVisitor visitor 
) const

A method to update algorithm node decision, and propagate it upwards.

Definition at line 442 of file PrecedenceRulesGraph.cpp.

443  {
444  getAlgorithmNode( algo_name )->accept( visitor );
445  }
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
StatusCode concurrency::PrecedenceRulesGraph::addAlgorithmNode ( Algorithm daughterAlgo,
const std::string parentName,
bool  inverted,
bool  allPass 
)

Add algorithm node.

Definition at line 258 of file PrecedenceRulesGraph.cpp.

260  {
261 
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  }
PRVertexDesc node(const std::string &) const
BGL-based facilities.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
#define ON_DEBUG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
T find(T...args)
void registerIODataObjects(const Algorithm *algo)
Register algorithm in the Data Dependency index.
unsigned int m_nodeCounter
Total number of nodes in the graph.
void addParentNode(DecisionNode *node)
Add a parent node.
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
StatusCode concurrency::PrecedenceRulesGraph::addDataNode ( const DataObjID dataPath)

Add DataNode that represents DataObject.

Definition at line 310 of file PrecedenceRulesGraph.cpp.

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  }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
#define ON_DEBUG
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
T find(T...args)
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
StatusCode concurrency::PrecedenceRulesGraph::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 at line 355 of file PrecedenceRulesGraph.cpp.

358  {
359 
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  }
PRVertexDesc node(const std::string &) const
BGL-based facilities.
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
#define ON_DEBUG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
T find(T...args)
void addParentNode(DecisionNode *node)
Add a parent node.
unsigned int m_nodeCounter
Total number of nodes in the graph.
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
void concurrency::PrecedenceRulesGraph::addEdgeToPrecTrace ( const AlgorithmNode u,
const AlgorithmNode v 
)

set cause-effect connection between two algorithms in the precedence trace

Definition at line 650 of file PrecedenceRulesGraph.cpp.

651  {
652 
653  std::string u_name = u == nullptr ? "ENTRY" : u->getNodeName();
654  std::string v_name = v->getNodeName();
655 
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 
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  }
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
T end(T...args)
#define ON_DEBUG
STL class.
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void concurrency::PrecedenceRulesGraph::addHeadNode ( const std::string headName,
bool  modeConcurrent,
bool  modePromptDecision,
bool  modeOR,
bool  allPass 
)

Add a node, which has no parents.

Definition at line 401 of file PrecedenceRulesGraph.cpp.

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 );
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  }
#define ON_DEBUG
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
DecisionNode * m_headNode
the head node of the control flow graph
T find(T...args)
unsigned int m_nodeCounter
Total number of nodes in the graph.
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
StatusCode concurrency::PrecedenceRulesGraph::buildDataDependenciesRealm ( )

Build data dependency realm WITH data object nodes participating.

Definition at line 206 of file PrecedenceRulesGraph.cpp.

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  }
PRVertexDesc node(const std::string &) const
BGL-based facilities.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
#define ON_DEBUG
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
T find(T...args)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.
std::string concurrency::PrecedenceRulesGraph::dumpControlFlow ( ) const

Print out control flow of Algorithms and Sequences.

Definition at line 459 of file PrecedenceRulesGraph.cpp.

460  {
461  std::ostringstream ost;
462  dumpControlFlow( ost, m_headNode, 0 );
463  return ost.str();
464  }
DecisionNode * m_headNode
the head node of the control flow graph
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
void concurrency::PrecedenceRulesGraph::dumpControlFlow ( std::ostringstream ost,
ControlFlowNode node,
const int &  indent 
) const

Definition at line 466 of file PrecedenceRulesGraph.cpp.

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  }
PRVertexDesc node(const std::string &) const
BGL-based facilities.
T end(T...args)
STL class.
DecisionNode * m_headNode
the head node of the control flow graph
STL class.
T begin(T...args)
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
std::string concurrency::PrecedenceRulesGraph::dumpDataFlow ( ) const

Print out all data origins and destinations, as reflected in the EF graph.

Definition at line 496 of file PrecedenceRulesGraph.cpp.

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  }
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
void concurrency::PrecedenceRulesGraph::dumpPrecRules ( const boost::filesystem::path &  fileName,
const EventSlot slot 
)

dump to file the precedence rules

Definition at line 524 of file PrecedenceRulesGraph.cpp.

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  }
STL class.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
boost::variant< AlgoProps, DecisionHubProps, DataProps > VariantVertexProps
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
void concurrency::PrecedenceRulesGraph::dumpPrecTrace ( const boost::filesystem::path &  fileName)

dump to file the precedence trace

Definition at line 614 of file PrecedenceRulesGraph.cpp.

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;
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;
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  }
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
std::string algorithm
Definition: ITimelineSvc.h:18
T duration_cast(T...args)
virtual void getTimelineEvent(TimelineEvent &) const =0
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
T count(T...args)
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
AlgorithmNode * concurrency::PrecedenceRulesGraph::getAlgorithmNode ( const std::string algoName) const

Get the AlgorithmNode from by algorithm name using graph index.

Definition at line 303 of file PrecedenceRulesGraph.cpp.

304  {
305 
306  return m_algoNameToAlgoNodeMap.at( algoName );
307  }
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
unsigned int concurrency::PrecedenceRulesGraph::getControlFlowNodeCounter ( ) const
inline

Get total number of control flow graph nodes.

Definition at line 620 of file PrecedenceRulesGraph.h.

620 { return m_nodeCounter; }
unsigned int m_nodeCounter
Total number of nodes in the graph.
DataNode * concurrency::PrecedenceRulesGraph::getDataNode ( const DataObjID dataPath) const

Get DataNode by DataObject path using graph index.

Definition at line 348 of file PrecedenceRulesGraph.cpp.

349  {
350 
351  return m_dataPathToDataNodeMap.at( dataPath );
352  }
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
DecisionNode* concurrency::PrecedenceRulesGraph::getHeadNode ( ) const
inline

Get head node.

Definition at line 611 of file PrecedenceRulesGraph.h.

611 { return m_headNode; };
DecisionNode * m_headNode
the head node of the control flow graph
const std::chrono::system_clock::time_point concurrency::PrecedenceRulesGraph::getInitTime ( ) const
inline

Definition at line 630 of file PrecedenceRulesGraph.h.

630 { return m_initTime; }
const std::chrono::system_clock::time_point m_initTime
StatusCode concurrency::PrecedenceRulesGraph::initialize ( )

Initialize graph.

Definition at line 142 of file PrecedenceRulesGraph.cpp.

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;
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 
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  }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
#define ON_DEBUG
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
T remove(T...args)
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
T find(T...args)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
const std::string& concurrency::PrecedenceRulesGraph::name ( ) const
inlineoverride

Retrieve name of the service.

Definition at line 626 of file PrecedenceRulesGraph.h.

626 { return m_name; }
PRVertexDesc concurrency::PrecedenceRulesGraph::node ( const std::string name) const

BGL-based facilities.

Definition at line 425 of file PrecedenceRulesGraph.cpp.

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  }
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
void concurrency::PrecedenceRulesGraph::printState ( std::stringstream output,
AlgsExecutionStates states,
const std::vector< int > &  node_decisions,
const unsigned int &  recursionLevel 
) const
inline

Print a string representing the control flow state.

Definition at line 633 of file PrecedenceRulesGraph.h.

635  {
636  m_headNode->printState( output, states, node_decisions, recursionLevel );
637  }
DecisionNode * m_headNode
the head node of the control flow graph
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.
void concurrency::PrecedenceRulesGraph::rankAlgorithms ( IGraphVisitor ranker) const

Rank Algorithm nodes by the number of data outputs.

Definition at line 448 of file PrecedenceRulesGraph.cpp.

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  }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
#define ON_DEBUG
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
void concurrency::PrecedenceRulesGraph::registerIODataObjects ( const Algorithm algo)

Register algorithm in the Data Dependency index.

Definition at line 185 of file PrecedenceRulesGraph.cpp.

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  }
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:731
const DataObjIDColl & outputDataObjs() const override
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
STL class.
const DataObjIDColl & inputDataObjs() const override
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
SmartIF<ISvcLocator>& concurrency::PrecedenceRulesGraph::serviceLocator ( ) const
inlineoverride

Retrieve pointer to service locator.

Definition at line 628 of file PrecedenceRulesGraph.h.

628 { return m_svcLocator; }
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)

Member Data Documentation

unsigned int concurrency::PrecedenceRulesGraph::m_algoCounter
private

Total number of algorithm nodes in the graph.

Definition at line 671 of file PrecedenceRulesGraph.h.

AlgoInputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoInputsMap
private

Indexes: maps of algorithm's name to algorithm's inputs/outputs.

Definition at line 665 of file PrecedenceRulesGraph.h.

AlgoNodesMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoNodeMap
private

Index: map of algorithm's name to AlgorithmNode.

Definition at line 659 of file PrecedenceRulesGraph.h.

AlgoOutputsMap concurrency::PrecedenceRulesGraph::m_algoNameToAlgoOutputsMap
private

Definition at line 666 of file PrecedenceRulesGraph.h.

bool concurrency::PrecedenceRulesGraph::m_conditionsRealmEnabled {false}
private

Enable conditions realm of precedence rules.

Definition at line 686 of file PrecedenceRulesGraph.h.

DataNodesMap concurrency::PrecedenceRulesGraph::m_dataPathToDataNodeMap
private

Index: map of data path to DataNode.

Definition at line 663 of file PrecedenceRulesGraph.h.

DecisionHubsMap concurrency::PrecedenceRulesGraph::m_decisionNameToDecisionHubMap
private

Index: map of decision's name to DecisionHub.

Definition at line 661 of file PrecedenceRulesGraph.h.

DecisionNode* concurrency::PrecedenceRulesGraph::m_headNode
private

the head node of the control flow graph

Definition at line 657 of file PrecedenceRulesGraph.h.

const std::chrono::system_clock::time_point concurrency::PrecedenceRulesGraph::m_initTime
private

Definition at line 677 of file PrecedenceRulesGraph.h.

const std::string concurrency::PrecedenceRulesGraph::m_name
private

Definition at line 675 of file PrecedenceRulesGraph.h.

unsigned int concurrency::PrecedenceRulesGraph::m_nodeCounter
private

Total number of nodes in the graph.

Definition at line 669 of file PrecedenceRulesGraph.h.

std::map<std::string, precedence::AlgoTraceVertex> concurrency::PrecedenceRulesGraph::m_prec_trace_map
private

Definition at line 681 of file PrecedenceRulesGraph.h.

precedence::PrecTrace concurrency::PrecedenceRulesGraph::m_precTrace
private

facilities for algorithm precedence tracing

Definition at line 680 of file PrecedenceRulesGraph.h.

precedence::PRGraph concurrency::PrecedenceRulesGraph::m_PRGraph
private

BGL-based graph of precedence rules.

Definition at line 683 of file PrecedenceRulesGraph.h.

SmartIF<ISvcLocator> concurrency::PrecedenceRulesGraph::m_svcLocator
mutableprivate

Service locator (needed to access the MessageSvc)

Definition at line 674 of file PrecedenceRulesGraph.h.


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