The Gaudi Framework  v30r3 (a5ef0a68)
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...
 
StatusCode initialize ()
 Initialize graph. More...
 
void accept (IGraphVisitor &visitor) const
 An entry point to visit all graph nodes. 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, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
 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, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
 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...
 
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...
 
void enableAnalysis ()
 BGL-based facilities. More...
 
PRVertexDesc node (const std::string &) const
 
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 CommonMessaging< IPrecedenceRulesGraph >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const
 Backward compatibility function for getting the output level. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
const 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...
 

Private Attributes

DecisionNodem_headNode = nullptr
 the head node of the control flow graph More...
 
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
 Index: map of algorithm's name to AlgorithmNode. More...
 
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
 Index: map of decision's name to DecisionHub. More...
 
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasherm_dataPathToDataNodeMap
 Index: map of data path to DataNode. More...
 
std::unordered_map< std::string, DataObjIDCollm_algoNameToAlgoInputsMap
 Indexes: maps of algorithm's name to algorithm's inputs/outputs. More...
 
std::unordered_map< std::string, DataObjIDCollm_algoNameToAlgoOutputsMap
 
unsigned int m_nodeCounter = 0
 Total number of nodes in the graph. More...
 
unsigned int m_algoCounter = 0
 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
 
precedence::PrecTrace m_precTrace
 facilities for algorithm precedence tracing More...
 
std::map< std::string, precedence::AlgoTraceVertexm_prec_trace_map
 
bool m_enableAnalysis {false}
 
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 >
MSG::Level setUpMessaging () const
 Set up local caches. More...
 
MSG::Level resetMessaging ()
 Reinitialize internal states. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Detailed Description

Definition at line 658 of file PrecedenceRulesGraph.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 662 of file PrecedenceRulesGraph.h.

662  : m_svcLocator( svc ), m_name( name )
663  {
664  // make sure that CommonMessaging is initialized
665  setUpMessaging();
666  }
MSG::Level setUpMessaging() const
Set up local caches.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)

Member Function Documentation

void concurrency::PrecedenceRulesGraph::accept ( IGraphVisitor visitor) const

An entry point to visit all graph nodes.

Definition at line 404 of file PrecedenceRulesGraph.cpp.

405  {
406  // iterate through Algorithm nodes
407  for ( auto& pr : m_algoNameToAlgoNodeMap ) pr.second->accept( visitor );
408 
409  // iterate through DecisionHub nodes
410  for ( auto& pr : m_decisionNameToDecisionHubMap ) pr.second->accept( visitor );
411 
412  // iterate through Data [and Conditions] nodes
413  for ( auto& pr : m_dataPathToDataNodeMap ) pr.second->accept( visitor );
414  }
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
StatusCode concurrency::PrecedenceRulesGraph::addAlgorithmNode ( Algorithm daughterAlgo,
const std::string parentName,
bool  inverted,
bool  allPass 
)

Add algorithm node.

Create new, or fetch existent, AlgorithmNode

Attach AlgorithmNode to its parent DecisionNode

Definition at line 229 of file PrecedenceRulesGraph.cpp.

231  {
232 
234 
236 
237  auto& algoName = algo->name();
238 
239  concurrency::AlgorithmNode* algoNode;
240 
241  auto itA = m_algoNameToAlgoNodeMap.find( algoName );
242  if ( itA != m_algoNameToAlgoNodeMap.end() ) {
243  algoNode = itA->second.get();
244  } else {
245  auto r = m_algoNameToAlgoNodeMap.emplace(
246  algoName, std::make_unique<concurrency::AlgorithmNode>( *this, algo, m_nodeCounter, m_algoCounter, inverted,
247  allPass ) );
248  algoNode = r.first->second.get();
249 
250  // Mirror AlgorithmNode in the BGL-based graph
251  if ( m_enableAnalysis ) {
252  boost::add_vertex( AlgoProps( algo, m_nodeCounter, m_algoCounter, inverted, allPass ), m_PRGraph );
253  }
254  ++m_nodeCounter;
255  ++m_algoCounter;
256  ON_VERBOSE verbose() << "AlgorithmNode '" << algoName << "' added @ " << algoNode << endmsg;
257 
258  registerIODataObjects( algo );
259  }
260 
262  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
263  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
264  auto parentNode = itP->second.get();
265 
266  parentNode->addDaughterNode( algoNode );
267  algoNode->addParentNode( parentNode );
268 
269  // Mirror algorithm to CF parent relationship in the BGL-based graph
270  if ( m_enableAnalysis ) boost::add_edge( node( algo->name() ), node( parentName ), m_PRGraph );
271 
272  ON_VERBOSE verbose() << "Attached AlgorithmNode '" << algo->name() << "' to parent DecisionNode '" << parentName
273  << "'" << endmsg;
274  } else {
275  sc = StatusCode::FAILURE;
276  error() << "Parent DecisionNode '" << parentName << "' was not found" << endmsg;
277  }
278 
279  return sc;
280  }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
PRVertexDesc node(const std::string &) const
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
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
StatusCode concurrency::PrecedenceRulesGraph::addDataNode ( const DataObjID dataPath)

Add DataNode that represents DataObject.

Definition at line 283 of file PrecedenceRulesGraph.cpp.

284  {
285 
286  auto itD = m_dataPathToDataNodeMap.find( dataPath );
287  if ( itD != m_dataPathToDataNodeMap.end() ) return StatusCode::SUCCESS;
288 
290  if ( !m_conditionsRealmEnabled ) {
291  dataNode = std::make_unique<concurrency::DataNode>( *this, dataPath );
292  ON_VERBOSE verbose() << " DataNode " << dataPath << " added @ " << dataNode.get() << endmsg;
293  // Mirror the action above in the BGL-based graph
294  if ( m_enableAnalysis ) boost::add_vertex( DataProps( dataPath ), m_PRGraph );
295  } else {
296  SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc", false )};
297  if ( condSvc->isRegistered( dataPath ) ) {
298  dataNode = std::make_unique<concurrency::ConditionNode>( *this, dataPath, condSvc );
299  ON_VERBOSE verbose() << " ConditionNode " << dataPath << " added @ " << dataNode.get() << endmsg;
300  // Mirror the action above in the BGL-based graph
301  if ( m_enableAnalysis ) boost::add_vertex( CondDataProps( dataPath ), m_PRGraph );
302  } else {
303  dataNode = std::make_unique<concurrency::DataNode>( *this, dataPath );
304  ON_VERBOSE verbose() << " DataNode " << dataPath << " added @ " << dataNode.get() << endmsg;
305  // Mirror the action above in the BGL-based graph
306  if ( m_enableAnalysis ) boost::add_vertex( DataProps( dataPath ), m_PRGraph );
307  }
308  }
309  m_dataPathToDataNodeMap.emplace( dataPath, std::move( dataNode ) );
310  return StatusCode::SUCCESS;
311  }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
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.
T move(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T get(T...args)
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
StatusCode concurrency::PrecedenceRulesGraph::addDecisionHubNode ( Algorithm daughterAlgo,
const std::string parentName,
concurrency::Concurrent  modeConcurrent,
concurrency::PromptDecision  modePromptDecision,
concurrency::ModeOr  modeOR,
concurrency::AllPass  allPass,
concurrency::Inverted  isInverted 
)

Add a node, which aggregates decisions of direct daughter nodes.

Create new, or fetch existent, DecisionNode

Attach DecisionNode to its parent DecisionNode

Definition at line 314 of file PrecedenceRulesGraph.cpp.

317  {
318 
320 
322 
323  auto& decisionHubName = decisionHubAlgo->name();
324 
325  auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
326  concurrency::DecisionNode* decisionHubNode;
327  if ( itA != m_decisionNameToDecisionHubMap.end() ) {
328  decisionHubNode = itA->second.get();
329  } else {
330  auto r = m_decisionNameToDecisionHubMap.emplace(
331  decisionHubName,
332  std::make_unique<concurrency::DecisionNode>( *this, m_nodeCounter, decisionHubName, modeConcurrent,
333  modePromptDecision, modeOR, allPass, isInverted ) );
334  decisionHubNode = r.first->second.get();
335  // Mirror DecisionNode in the BGL-based graph
336  if ( m_enableAnalysis ) {
337  boost::add_vertex( DecisionHubProps( decisionHubName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR,
338  allPass, isInverted ),
339  m_PRGraph );
340  }
341 
342  ++m_nodeCounter;
343 
344  ON_VERBOSE verbose() << "DecisionNode '" << decisionHubName << "' added @ " << decisionHubNode << endmsg;
345  }
346 
348  auto itP = m_decisionNameToDecisionHubMap.find( parentName );
349  if ( itP != m_decisionNameToDecisionHubMap.end() ) {
350  auto parentNode = itP->second.get();
351  parentNode->addDaughterNode( decisionHubNode );
352  decisionHubNode->addParentNode( parentNode );
353 
354  // Mirror DecisionNode-to-DecisionNode relationship in the BGL-based graph
355  if ( m_enableAnalysis ) boost::add_edge( node( decisionHubName ), node( parentName ), m_PRGraph );
356 
357  ON_VERBOSE verbose() << "Attached DecisionNode '" << decisionHubName << "' to parent DecisionNode '" << parentName
358  << "'" << endmsg;
359  } else {
360  sc = StatusCode::FAILURE;
361  error() << "Parent DecisionNode '" << parentName << "' was not found" << endmsg;
362  }
363 
364  return sc;
365  }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
PRVertexDesc node(const std::string &) const
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
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:51
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
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
void concurrency::PrecedenceRulesGraph::addEdgeToPrecTrace ( const AlgorithmNode u,
const AlgorithmNode v 
)

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

Definition at line 563 of file PrecedenceRulesGraph.cpp.

564  {
565 
566  std::string u_name = u == nullptr ? "ENTRY" : u->getNodeName();
567  std::string v_name = v->getNodeName();
568 
570 
571  if ( !u ) {
572  auto itT = m_prec_trace_map.find( "ENTRY" );
573  if ( itT != m_prec_trace_map.end() ) {
574  source = itT->second;
575  } else {
576  source = boost::add_vertex( precedence::AlgoTraceProps( "ENTRY", -1, -1, -1.0 ), m_precTrace );
577  m_prec_trace_map["ENTRY"] = source;
578  }
579  } else {
580  auto itS = m_prec_trace_map.find( u_name );
581  if ( itS != m_prec_trace_map.end() ) {
582  source = itS->second;
583  } else {
584 
585  source =
586  boost::add_vertex( precedence::AlgoTraceProps( u_name, u->getAlgoIndex(), u->getRank(), -1 ), m_precTrace );
587  m_prec_trace_map[u_name] = source;
588  }
589  }
590 
592 
593  auto itP = m_prec_trace_map.find( v_name );
594  if ( itP != m_prec_trace_map.end() ) {
595  target = itP->second;
596  } else {
597 
598  target =
599  boost::add_vertex( precedence::AlgoTraceProps( v_name, v->getAlgoIndex(), v->getRank(), -1 ), m_precTrace );
600  m_prec_trace_map[v_name] = target;
601  }
602 
603  boost::add_edge( source, target, m_precTrace );
604 
605  ON_DEBUG debug() << u_name << "-->" << v_name << " precedence trait added" << endmsg;
606  }
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,
concurrency::Concurrent  modeConcurrent,
concurrency::PromptDecision  modePromptDecision,
concurrency::ModeOr  modeOR,
concurrency::AllPass  allPass,
concurrency::Inverted  isInverted 
)

Add a node, which has no parents.

Definition at line 368 of file PrecedenceRulesGraph.cpp.

371  {
372 
373  auto itH = m_decisionNameToDecisionHubMap.find( headName );
374  if ( itH != m_decisionNameToDecisionHubMap.end() ) {
375  m_headNode = itH->second.get();
376  } else {
377  auto r = m_decisionNameToDecisionHubMap.emplace(
378  headName, std::make_unique<concurrency::DecisionNode>( *this, m_nodeCounter, headName, modeConcurrent,
379  modePromptDecision, modeOR, allPass, isInverted ) );
380  m_headNode = r.first->second.get();
381 
382  // Mirror the action above in the BGL-based graph
383  if ( m_enableAnalysis ) {
384  boost::add_vertex( DecisionHubProps( headName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR,
385  allPass, isInverted ),
386  m_PRGraph );
387  }
388 
389  ++m_nodeCounter;
390  }
391  }
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
DecisionNode * m_headNode
the head node of the control flow graph
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
unsigned int m_nodeCounter
Total number of nodes in the graph.
StatusCode concurrency::PrecedenceRulesGraph::buildDataDependenciesRealm ( )

Build data dependency realm WITH data object nodes participating.

Definition at line 180 of file PrecedenceRulesGraph.cpp.

181  {
182 
183  StatusCode global_sc( StatusCode::SUCCESS, true );
184 
185  // Production of DataNodes by AlgorithmNodes (DataNodes are created here)
186  for ( auto& algo : m_algoNameToAlgoNodeMap ) {
187 
188  auto& outputs = m_algoNameToAlgoOutputsMap[algo.first];
189  for ( auto output : outputs ) {
190  const auto sc = addDataNode( output );
191  if ( !sc.isSuccess() ) {
192  error() << "Extra producer (" << algo.first << ") for DataObject @ " << output
193  << " has been detected: this is not allowed." << endmsg;
194  global_sc = sc;
195  }
196  auto dataNode = getDataNode( output );
197  dataNode->addProducerNode( algo.second.get() );
198  algo.second->addOutputDataNode( dataNode );
199 
200  // Mirror the action above in the BGL-based graph
201  if ( m_enableAnalysis )
202  boost::add_edge( node( algo.second->getNodeName() ), node( output.fullKey() ), m_PRGraph );
203  }
204  }
205 
206  // Consumption of DataNodes by AlgorithmNodes
207  for ( auto& algo : m_algoNameToAlgoNodeMap ) {
208 
209  for ( auto input : m_algoNameToAlgoInputsMap[algo.first] ) {
210 
211  auto itP = m_dataPathToDataNodeMap.find( input );
212 
213  DataNode* dataNode = ( itP != m_dataPathToDataNodeMap.end() ? getDataNode( input ) : nullptr );
214  if ( dataNode ) {
215  dataNode->addConsumerNode( algo.second.get() );
216  algo.second->addInputDataNode( dataNode );
217 
218  // Mirror the action above in the BGL-based graph
219  if ( m_enableAnalysis )
220  boost::add_edge( node( input.fullKey() ), node( algo.second->getNodeName() ), m_PRGraph );
221  }
222  }
223  }
224 
225  return global_sc;
226  }
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
PRVertexDesc node(const std::string &) const
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
std::string concurrency::PrecedenceRulesGraph::dumpControlFlow ( ) const

Print out control flow of Algorithms and Sequences.

Definition at line 428 of file PrecedenceRulesGraph.cpp.

429  {
430  std::ostringstream ost;
431  dumpControlFlow( ost, m_headNode, 0 );
432  return ost.str();
433  }
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 435 of file PrecedenceRulesGraph.cpp.

436  {
437  ost << std::string( indent * 2, ' ' );
438  DecisionNode* dn = dynamic_cast<DecisionNode*>( node );
439  AlgorithmNode* an = dynamic_cast<AlgorithmNode*>( node );
440  if ( dn != 0 ) {
441  if ( node != m_headNode ) {
442  ost << node->getNodeName() << " [Seq] ";
443  ost << ( ( dn->m_modeConcurrent ) ? " [Concurrent] " : " [Sequential] " );
444  ost << ( ( dn->m_modePromptDecision ) ? " [Prompt] " : "" );
445  ost << ( ( dn->m_modeOR ) ? " [OR] " : "" );
446  ost << ( ( dn->m_allPass ) ? " [PASS] " : "" );
447  ost << "\n";
448  }
449  for ( const auto& i : dn->getDaughters() ) dumpControlFlow( ost, i, indent + 1 );
450  } else if ( an != 0 ) {
451  ost << node->getNodeName() << " [Alg] ";
452  if ( an != 0 ) {
453  auto ar = an->getAlgorithm();
454  ost << " [n= " << ar->cardinality() << "]";
455  ost << ( ( !ar->isClonable() ) ? " [unclonable] " : "" );
456  }
457  ost << "\n";
458  }
459  }
PRVertexDesc node(const std::string &) const
STL class.
DecisionNode * m_headNode
the head node of the control flow graph
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 462 of file PrecedenceRulesGraph.cpp.

463  {
464 
465  const char idt[] = " ";
466  std::ostringstream ost;
467 
468  ost << "\n" << idt << "====================================\n";
469  ost << idt << "Data origins and destinations:\n";
470  ost << idt << "====================================\n";
471 
472  for ( auto& pair : m_dataPathToDataNodeMap ) {
473 
474  for ( auto algoNode : pair.second->getProducers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
475 
476  ost << idt << " V\n";
477  ost << idt << " o " << pair.first << "\n";
478  ost << idt << " V\n";
479 
480  for ( auto algoNode : pair.second->getConsumers() ) ost << idt << " " << algoNode->getNodeName() << "\n";
481 
482  ost << idt << "====================================\n";
483  }
484 
485  return ost.str();
486  }
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > 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 490 of file PrecedenceRulesGraph.cpp.

491  {
492  boost::filesystem::ofstream myfile;
493  myfile.open( fileName, std::ios::app );
494 
495  // Declare properties to dump
496  boost::dynamic_properties dp;
497 
498  dp.property( "Entity", boost::make_transform_value_property_map(
499  []( const VariantVertexProps& v ) { return boost::lexical_cast<std::string>( v ); },
500  boost::get( boost::vertex_bundle, m_PRGraph ) ) );
501 
502  auto add_prop = [&]( auto name, auto&& vis ) {
503  dp.property( name,
504  boost::make_transform_value_property_map( [vis = std::forward<decltype( vis )>( vis )](
505  const VariantVertexProps&
506  v ) { return boost::apply_visitor( vis, v ); },
507  boost::get( boost::vertex_bundle, m_PRGraph ) ) );
508  };
509 
510  add_prop( "Name", precedence::VertexName() );
511  add_prop( "Mode", precedence::GroupMode() );
512  add_prop( "Logic", precedence::GroupLogic() );
513  add_prop( "Decision Negation", precedence::DecisionNegation() );
514  add_prop( "Negative Decision Inversion", precedence::AllPass() );
515  add_prop( "Exit Policy", precedence::GroupExit() );
516  add_prop( "Operations", precedence::Operations() );
517  add_prop( "CF Decision", precedence::CFDecision( slot ) );
518  add_prop( "State", precedence::EntityState( slot, serviceLocator(), m_conditionsRealmEnabled ) );
519  add_prop( "Start Time (Epoch ns)", precedence::StartTime( slot, serviceLocator() ) );
520  add_prop( "End Time (Epoch ns)", precedence::EndTime( slot, serviceLocator() ) );
521  add_prop( "Runtime (ns)", precedence::Duration( slot, serviceLocator() ) );
522 
523  boost::write_graphml( myfile, m_PRGraph, dp );
524 
525  myfile.close();
526  }
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
STL class.
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
const std::string & name() const override
Retrieve name of the service.
T forward(T...args)
boost::variant< AlgoProps, DecisionHubProps, DataProps, CondDataProps > VariantVertexProps
void concurrency::PrecedenceRulesGraph::dumpPrecTrace ( const boost::filesystem::path &  fileName)

dump to file the precedence trace

Definition at line 529 of file PrecedenceRulesGraph.cpp.

530  {
531  boost::filesystem::ofstream myfile;
532  myfile.open( fileName, std::ios::app );
533 
534  // Fill runtimes (as this could not be done on the fly during trace assembling)
535  SmartIF<ITimelineSvc> timelineSvc = m_svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
536  if ( !timelineSvc.isValid() ) {
537  warning() << "Failed to get the TimelineSvc, timing will not be added to "
538  << "the task precedence trace dump" << endmsg;
539  } else {
540 
541  for ( auto vp = vertices( m_precTrace ); vp.first != vp.second; ++vp.first ) {
542  TimelineEvent te{};
543  te.algorithm = m_precTrace[*vp.first].m_name;
544  timelineSvc->getTimelineEvent( te );
545  int runtime = std::chrono::duration_cast<std::chrono::nanoseconds>( te.end - te.start ).count();
546  m_precTrace[*vp.first].m_runtime = runtime;
547  }
548  }
549 
550  // Declare properties to dump
551  boost::dynamic_properties dp;
552  using boost::get;
554  dp.property( "Name", get( &AlgoTraceProps::m_name, m_precTrace ) );
555  dp.property( "Rank", get( &AlgoTraceProps::m_rank, m_precTrace ) );
556  dp.property( "Runtime", get( &AlgoTraceProps::m_runtime, m_precTrace ) );
557 
558  boost::write_graphml( myfile, m_precTrace, dp );
559 
560  myfile.close();
561  }
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
std::string algorithm
Definition: ITimelineSvc.h:21
T duration_cast(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 & warning() const
shortcut for the method msgStream(MSG::WARNING)
T count(T...args)
virtual bool getTimelineEvent(TimelineEvent &) const =0
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::enableAnalysis ( )
inline

BGL-based facilities.

Definition at line 718 of file PrecedenceRulesGraph.h.

AlgorithmNode* concurrency::PrecedenceRulesGraph::getAlgorithmNode ( const std::string algoName) const
inline

Get the AlgorithmNode from by algorithm name using graph index.

Definition at line 691 of file PrecedenceRulesGraph.h.

692  {
693  return m_algoNameToAlgoNodeMap.at( algoName ).get();
694  }
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > 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 700 of file PrecedenceRulesGraph.h.

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

Get DataNode by DataObject path using graph index.

Definition at line 677 of file PrecedenceRulesGraph.h.

677 { return m_dataPathToDataNodeMap.at( dataPath ).get(); }
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
DecisionNode* concurrency::PrecedenceRulesGraph::getHeadNode ( ) const
inline

Get head node.

Definition at line 687 of file PrecedenceRulesGraph.h.

687 { return m_headNode; };
DecisionNode * m_headNode
the head node of the control flow graph
StatusCode concurrency::PrecedenceRulesGraph::initialize ( )

Initialize graph.

Definition at line 115 of file PrecedenceRulesGraph.cpp.

116  {
117  if ( serviceLocator()->existsService( "CondSvc" ) ) {
118  SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc" )};
119  if ( condSvc.isValid() ) {
120  info() << "CondSvc found. DF precedence rules will be augmented with 'Conditions'" << endmsg;
122  }
123  }
124 
125  // Detach condition algorithms from the CF realm
126  if ( m_conditionsRealmEnabled ) {
127  SmartIF<ICondSvc> condSvc{serviceLocator()->service( "CondSvc", false )};
128  auto& condAlgs = condSvc->condAlgs();
129  for ( const auto algo : condAlgs ) {
130  auto itA = m_algoNameToAlgoNodeMap.find( algo->name() );
131  if ( itA != m_algoNameToAlgoNodeMap.end() ) {
132  concurrency::AlgorithmNode* algoNode = itA->second.get();
133  debug() << "Detaching condition algorithm '" << algo->name() << "' from the CF realm.." << endmsg;
134  for ( auto parent : algoNode->getParentDecisionHubs() ) {
135  parent->m_children.erase( std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
136  parent->m_children.end() );
137  // clean up also auxiliary BGL-based graph of precedence rules
138  if ( m_enableAnalysis )
139  boost::remove_edge( node( algoNode->getNodeName() ), node( parent->getNodeName() ), m_PRGraph );
140  }
141  algoNode->m_parents.clear();
142 
143  } else {
144  warning() << "Algorithm '" << algo->name() << "' is not registered in the graph" << endmsg;
145  }
146  }
147  }
148 
150 
151  if ( !sc.isSuccess() ) error() << "Could not build the data dependency realm." << endmsg;
152 
153  ON_DEBUG debug() << dumpDataFlow() << endmsg;
154 
155  return sc;
156  }
PRVertexDesc node(const std::string &) const
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool isSuccess() const
Definition: StatusCode.h:287
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
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)
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
precedence::PRGraph m_PRGraph
BGL-based graph 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:51
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
const std::string & getNodeName() const
Get node name.
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 706 of file PrecedenceRulesGraph.h.

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

Definition at line 394 of file PrecedenceRulesGraph.cpp.

395  {
396  auto vp = vertices( m_PRGraph );
397  auto i = std::find_if( vp.first, vp.second, [&]( const PRVertexDesc& v ) {
398  return boost::apply_visitor( precedence::VertexName(), m_PRGraph[v] ) == name;
399  } );
400  return i != vp.second ? *i : PRVertexDesc{};
401  }
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
T find_if(T...args)
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 711 of file PrecedenceRulesGraph.h.

713  {
714  m_headNode->printState( output, states, node_decisions, recursionLevel );
715  }
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 417 of file PrecedenceRulesGraph.cpp.

418  {
419 
420  info() << "Starting ranking by data outputs .. " << endmsg;
421  for ( auto& pair : m_algoNameToAlgoNodeMap ) {
422  ON_DEBUG debug() << " Ranking " << pair.first << "... " << endmsg;
423  pair.second->accept( ranker );
424  ON_DEBUG debug() << " ... rank of " << pair.first << ": " << pair.second->getRank() << endmsg;
425  }
426  }
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
#define ON_DEBUG
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
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 159 of file PrecedenceRulesGraph.cpp.

160  {
161 
162  const std::string& algoName = algo->name();
163 
164  m_algoNameToAlgoInputsMap[algoName] = algo->inputDataObjs();
165  m_algoNameToAlgoOutputsMap[algoName] = algo->outputDataObjs();
166 
167  ON_VERBOSE
168  {
169  verbose() << " Inputs of " << algoName << ": ";
170  for ( auto tag : algo->inputDataObjs() ) verbose() << tag << " | ";
171  verbose() << endmsg;
172 
173  verbose() << " Outputs of " << algoName << ": ";
174  for ( auto tag : algo->outputDataObjs() ) verbose() << tag << " | ";
175  verbose() << endmsg;
176  }
177  }
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm&#39;s name to algorithm&#39;s inputs/outputs.
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:765
const DataObjIDColl & outputDataObjs() const override
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
STL class.
const DataObjIDColl & inputDataObjs() const override
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
#define ON_VERBOSE
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
SmartIF<ISvcLocator>& concurrency::PrecedenceRulesGraph::serviceLocator ( ) const
inlineoverride

Retrieve pointer to service locator.

Definition at line 708 of file PrecedenceRulesGraph.h.

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

Member Data Documentation

unsigned int concurrency::PrecedenceRulesGraph::m_algoCounter = 0
private

Total number of algorithm nodes in the graph.

Definition at line 750 of file PrecedenceRulesGraph.h.

std::unordered_map<std::string, DataObjIDColl> concurrency::PrecedenceRulesGraph::m_algoNameToAlgoInputsMap
private

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

Definition at line 744 of file PrecedenceRulesGraph.h.

std::unordered_map<std::string, std::unique_ptr<AlgorithmNode> > concurrency::PrecedenceRulesGraph::m_algoNameToAlgoNodeMap
private

Index: map of algorithm's name to AlgorithmNode.

Definition at line 738 of file PrecedenceRulesGraph.h.

std::unordered_map<std::string, DataObjIDColl> concurrency::PrecedenceRulesGraph::m_algoNameToAlgoOutputsMap
private

Definition at line 745 of file PrecedenceRulesGraph.h.

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

Enable conditions realm of precedence rules.

Definition at line 764 of file PrecedenceRulesGraph.h.

std::unordered_map<DataObjID, std::unique_ptr<DataNode>, DataObjID_Hasher> concurrency::PrecedenceRulesGraph::m_dataPathToDataNodeMap
private

Index: map of data path to DataNode.

Definition at line 742 of file PrecedenceRulesGraph.h.

std::unordered_map<std::string, std::unique_ptr<DecisionNode> > concurrency::PrecedenceRulesGraph::m_decisionNameToDecisionHubMap
private

Index: map of decision's name to DecisionHub.

Definition at line 740 of file PrecedenceRulesGraph.h.

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

Definition at line 759 of file PrecedenceRulesGraph.h.

DecisionNode* concurrency::PrecedenceRulesGraph::m_headNode = nullptr
private

the head node of the control flow graph

Definition at line 736 of file PrecedenceRulesGraph.h.

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

Definition at line 754 of file PrecedenceRulesGraph.h.

unsigned int concurrency::PrecedenceRulesGraph::m_nodeCounter = 0
private

Total number of nodes in the graph.

Definition at line 748 of file PrecedenceRulesGraph.h.

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

Definition at line 758 of file PrecedenceRulesGraph.h.

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

facilities for algorithm precedence tracing

Definition at line 757 of file PrecedenceRulesGraph.h.

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

BGL-based graph of precedence rules.

Definition at line 761 of file PrecedenceRulesGraph.h.

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

Service locator (needed to access the MessageSvc)

Definition at line 753 of file PrecedenceRulesGraph.h.


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