4 #include <boost/property_map/transform_value_property_map.hpp> 9 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 10 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 21 else if ( 1 == stateId )
31 for (
auto node : m_children )
delete node;
38 if (
std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
45 if (
std::find( m_children.begin(), m_children.end(), node ) == m_children.end() ) m_children.push_back( node );
50 const std::vector<int>& node_decisions,
const unsigned int& recursionLevel )
const 57 for (
auto daughter : m_children ) daughter->printState( output, states, node_decisions, recursionLevel + 2 );
66 bool result = visitor.
visit( *
this );
77 for (
auto node : m_outputs ) {
84 const std::vector<int>& node_decisions,
const unsigned int& recursionLevel )
const 97 visitor.
visit( *
this );
108 if (
std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
115 if (
std::find( m_outputs.begin(), m_outputs.end(), node ) == m_outputs.end() ) m_outputs.push_back( node );
128 if ( serviceLocator()->existsService(
"CondSvc" ) ) {
130 if ( condSvc.isValid() ) {
131 info() <<
"CondSvc found. DF precedence rules will be augmented with 'Conditions'" <<
endmsg;
132 m_conditionsRealmEnabled =
true;
137 if ( m_conditionsRealmEnabled ) {
139 auto& condAlgs = condSvc->
condAlgs();
140 for (
const auto algo : condAlgs ) {
141 auto itA = m_algoNameToAlgoNodeMap.find( algo->name() );
143 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
144 algoNode = itA->second;
145 debug() <<
"Detaching condition algorithm '" << algo->name() <<
"' from the CF realm.." <<
endmsg;
147 parent->m_children.erase(
std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
148 parent->m_children.end() );
150 if ( m_enableAnalysis )
151 boost::remove_edge( node( algoNode->
getNodeName() ), node( parent->getNodeName() ), m_PRGraph );
156 warning() <<
"Algorithm '" << algo->name() <<
"' is not registered in the graph" <<
endmsg;
163 if ( !sc.
isSuccess() ) error() <<
"Could not build the data dependency realm." <<
endmsg;
181 verbose() <<
" Inputs of " << algoName <<
": ";
185 verbose() <<
" Outputs of " << algoName <<
": ";
198 for (
auto algo : m_algoNameToAlgoNodeMap ) {
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;
208 auto dataNode = getDataNode(
output );
209 dataNode->addProducerNode( algo.second );
210 algo.second->addOutputDataNode( dataNode );
213 if ( m_enableAnalysis )
214 boost::add_edge( node( algo.second->getNodeName() ), node(
output.fullKey() ), m_PRGraph );
219 for (
auto algo : m_algoNameToAlgoNodeMap ) {
221 for (
auto input : m_algoNameToAlgoInputsMap[algo.first] ) {
225 auto itP = m_dataPathToDataNodeMap.find( input );
227 if ( itP != m_dataPathToDataNodeMap.end() ) dataNode = getDataNode( input );
231 algo.second->addInputDataNode( dataNode );
234 if ( m_enableAnalysis )
235 boost::add_edge( node( input.fullKey() ), node( algo.second->getNodeName() ), m_PRGraph );
251 auto& algoName = algo->
name();
252 auto itA = m_algoNameToAlgoNodeMap.
find( algoName );
254 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
255 algoNode = itA->second;
259 if ( m_enableAnalysis ) {
261 boost::add_vertex(
AlgoProps( algo, m_nodeCounter, m_algoCounter, inverted, allPass ), m_PRGraph );
262 boost::add_edge( source, node( parentName ), m_PRGraph );
266 m_algoNameToAlgoNodeMap[algoName] = algoNode;
268 registerIODataObjects( algo );
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 <<
"'" 278 parentNode->addDaughterNode( algoNode );
282 error() <<
"Requested DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
292 return m_algoNameToAlgoNodeMap.at( algoName );
301 auto itD = m_dataPathToDataNodeMap.find( dataPath );
303 if ( itD != m_dataPathToDataNodeMap.end() ) {
304 dataNode = itD->second;
307 if ( !m_conditionsRealmEnabled ) {
311 if ( m_enableAnalysis ) boost::add_vertex(
DataProps( dataPath ), m_PRGraph );
314 if ( condSvc->isRegistered( dataPath ) ) {
318 if ( m_enableAnalysis ) boost::add_vertex(
CondDataProps( dataPath ), m_PRGraph );
323 if ( m_enableAnalysis ) boost::add_vertex(
DataProps( dataPath ), m_PRGraph );
327 m_dataPathToDataNodeMap[dataPath] = dataNode;
339 return m_dataPathToDataNodeMap.at( dataPath );
350 auto& decisionHubName = decisionHubAlgo->
name();
352 auto itP = m_decisionNameToDecisionHubMap.
find( parentName );
354 if ( itP != m_decisionNameToDecisionHubMap.end() ) {
355 parentNode = itP->second;
356 auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
358 if ( itA != m_decisionNameToDecisionHubMap.end() ) {
359 decisionHubNode = itA->second;
362 modePromptDecision, modeOR, allPass, isInverted );
363 m_decisionNameToDecisionHubMap[decisionHubName] = decisionHubNode;
366 if ( m_enableAnalysis ) {
367 auto source = boost::add_vertex(
DecisionHubProps( decisionHubName, m_nodeCounter, modeConcurrent,
368 modePromptDecision, modeOR, allPass, isInverted ),
370 boost::add_edge( source, node( parentName ), m_PRGraph );
382 error() <<
"Decision hub node " << parentName <<
", requested to be parent, is not registered." <<
endmsg;
394 auto itH = m_decisionNameToDecisionHubMap.find( headName );
395 if ( itH != m_decisionNameToDecisionHubMap.end() ) {
396 m_headNode = itH->second;
399 modeOR, allPass, isInverted );
400 m_decisionNameToDecisionHubMap[headName] = m_headNode;
403 if ( m_enableAnalysis ) {
404 boost::add_vertex(
DecisionHubProps( headName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR,
405 allPass, isInverted ),
419 for (
auto vp = vertices( m_PRGraph ); vp.first != vp.second; ++vp.first ) {
434 for (
auto pr : m_algoNameToAlgoNodeMap ) pr.second->accept( visitor );
437 for (
auto pr : m_decisionNameToDecisionHubMap ) pr.second->accept( visitor );
440 for (
auto pr : m_dataPathToDataNodeMap ) pr.second->accept( visitor );
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;
458 dumpControlFlow( ost, m_headNode, 0 );
468 if ( node != m_headNode ) {
472 ost << ( ( dn->
m_modeOR ) ?
" [OR] " :
"" );
473 ost << ( ( dn->
m_allPass ) ?
" [PASS] " :
"" );
478 dumpControlFlow( ost, *itr, indent + 1 );
480 }
else if ( an != 0 ) {
484 ost <<
" [n= " << ar->cardinality() <<
"]";
485 ost << ( ( !ar->isClonable() ) ?
" [unclonable] " :
"" );
495 const char idt[] =
" ";
498 ost <<
"\n" << idt <<
"====================================\n";
499 ost << idt <<
"Data origins and destinations:\n";
500 ost << idt <<
"====================================\n";
502 for (
auto& pair : m_dataPathToDataNodeMap ) {
504 for (
auto algoNode : pair.second->getProducers() ) ost << idt <<
" " << algoNode->getNodeName() <<
"\n";
506 ost << idt <<
" V\n";
507 ost << idt <<
" o " << pair.first <<
"\n";
508 ost << idt <<
" V\n";
510 for (
auto algoNode : pair.second->getConsumers() ) ost << idt <<
" " << algoNode->getNodeName() <<
"\n";
512 ost << idt <<
"====================================\n";
522 boost::filesystem::ofstream myfile;
523 myfile.open( fileName, std::ios::app );
526 boost::dynamic_properties dp;
528 using boost::make_transform_value_property_map;
529 using boost::apply_visitor;
531 using boost::vertex_bundle;
533 dp.property(
"Entity", make_transform_value_property_map(
535 get( vertex_bundle, m_PRGraph ) ) );
538 dp.property(
"Name", make_transform_value_property_map(
540 get( vertex_bundle, m_PRGraph ) ) );
543 dp.property(
"Mode", make_transform_value_property_map(
545 get( vertex_bundle, m_PRGraph ) ) );
548 dp.property(
"Logic", make_transform_value_property_map(
550 get( vertex_bundle, m_PRGraph ) ) );
553 dp.property(
"Decision Negation", make_transform_value_property_map(
555 get( vertex_bundle, m_PRGraph ) ) );
558 dp.property(
"Negative Decision Inversion",
559 make_transform_value_property_map(
561 get( vertex_bundle, m_PRGraph ) ) );
564 dp.property(
"Exit Policy", make_transform_value_property_map(
566 get( vertex_bundle, m_PRGraph ) ) );
569 dp.property(
"Operations", make_transform_value_property_map(
571 get( vertex_bundle, m_PRGraph ) ) );
574 dp.property(
"CF Decision", make_transform_value_property_map(
576 get( vertex_bundle, m_PRGraph ) ) );
579 dp.property(
"State", make_transform_value_property_map(
581 get( vertex_bundle, m_PRGraph ) ) );
584 dp.property(
"Start Time (Epoch ns)",
585 make_transform_value_property_map(
587 get( vertex_bundle, m_PRGraph ) ) );
590 dp.property(
"End Time (Epoch ns)",
591 make_transform_value_property_map(
593 get( vertex_bundle, m_PRGraph ) ) );
596 dp.property(
"Runtime (ns)", make_transform_value_property_map(
598 get( vertex_bundle, m_PRGraph ) ) );
600 boost::write_graphml( myfile, m_PRGraph, dp );
608 boost::filesystem::ofstream myfile;
609 myfile.open( fileName, std::ios::app );
613 if ( !timelineSvc.
isValid() ) {
614 warning() <<
"Failed to get the TimelineSvc, timing will not be added to " 615 <<
"the task precedence trace dump" <<
endmsg;
618 typedef boost::graph_traits<precedence::PRGraph>::vertex_iterator vertex_iter;
620 for ( vp = vertices( m_precTrace ); vp.first != vp.second; ++vp.first ) {
622 te.
algorithm = m_precTrace[*vp.first].m_name;
625 m_precTrace[*vp.first].m_runtime = runtime;
630 boost::dynamic_properties dp;
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 ) );
637 boost::write_graphml( myfile, m_precTrace, dp );
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;
656 m_prec_trace_map[
"ENTRY"] = source;
659 auto itS = m_prec_trace_map.find( u_name );
660 if ( itS != m_prec_trace_map.end() ) {
661 source = itS->second;
666 m_prec_trace_map[u_name] = source;
672 auto itP = m_prec_trace_map.find( v_name );
673 if ( itP != m_prec_trace_map.end() ) {
674 target = itP->second;
679 m_prec_trace_map[v_name] = target;
682 boost::add_edge( source, target, m_precTrace );
684 ON_DEBUG debug() << u_name <<
"-->" << v_name <<
" precedence trait added" <<
endmsg;
constexpr static const auto FAILURE
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.
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
virtual bool visit(DecisionNode &)
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
std::string stateToString(const int &stateId) const
Translation between state id and name.
T duration_cast(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.
bool m_allPass
Whether always passing regardless of daughter results.
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
~AlgorithmNode()
Destructor.
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
virtual bool visitEnter(DecisionNode &) const
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.
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
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.
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.
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.
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.
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.
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.