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 );
70 for (
auto parent : m_parents ) {
71 parent->accept( visitor );
77 for (
auto child : m_children ) {
78 bool result = child->accept( visitor );
79 if ( !m_modeConcurrent )
93 for (
auto node : m_outputs ) {
100 const std::vector<int>& node_decisions,
const unsigned int& recursionLevel )
const 113 visitor.
visit( *
this );
124 if (
std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
131 if (
std::find( m_outputs.begin(), m_outputs.end(), node ) == m_outputs.end() ) m_outputs.push_back( node );
145 if ( serviceLocator()->existsService(
"CondSvc" ) ) {
147 if ( condSvc.isValid() ) {
148 info() <<
"CondSvc found. DF precedence rules will be augmented with 'Conditions'" <<
endmsg;
149 m_conditionsRealmEnabled =
true;
154 if ( m_conditionsRealmEnabled ) {
156 auto& condAlgs = condSvc->
condAlgs();
157 for (
const auto algo : condAlgs ) {
158 auto itA = m_algoNameToAlgoNodeMap.find( algo->name() );
160 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
161 algoNode = itA->second;
162 debug() <<
"Detaching condition algorithm '" << algo->name() <<
"' from the CF realm.." <<
endmsg;
164 parent->m_children.erase(
std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
165 parent->m_children.end() );
170 warning() <<
"Algorithm '" << algo->name() <<
"' is not registered in the graph" <<
endmsg;
177 if ( !sc.
isSuccess() ) error() <<
"Could not build the data dependency realm." <<
endmsg;
195 verbose() <<
" Inputs of " << algoName <<
": ";
199 verbose() <<
" Outputs of " << algoName <<
": ";
212 for (
auto algo : m_algoNameToAlgoNodeMap ) {
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;
222 auto dataNode = getDataNode(
output );
223 dataNode->addProducerNode( algo.second );
224 algo.second->addOutputDataNode( dataNode );
227 boost::add_edge( node( algo.second->getNodeName() ), node(
output.fullKey() ), m_PRGraph );
233 for (
auto algo : m_algoNameToAlgoNodeMap ) {
235 for (
auto input : m_algoNameToAlgoInputsMap[algo.first] ) {
239 auto itP = m_dataPathToDataNodeMap.find( input );
241 if ( itP != m_dataPathToDataNodeMap.end() ) dataNode = getDataNode( input );
245 algo.second->addInputDataNode( dataNode );
248 boost::add_edge( node( input.fullKey() ), node( algo.second->getNodeName() ), m_PRGraph );
265 auto& algoName = algo->
name();
266 auto itA = m_algoNameToAlgoNodeMap.
find( algoName );
268 if ( itA != m_algoNameToAlgoNodeMap.end() ) {
269 algoNode = itA->second;
275 boost::add_vertex(
AlgoProps( algo, m_nodeCounter, m_algoCounter, inverted, allPass ), m_PRGraph );
276 boost::add_edge( source, node( parentName ), m_PRGraph );
280 m_algoNameToAlgoNodeMap[algoName] = algoNode;
282 registerIODataObjects( algo );
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 <<
"'" 292 parentNode->addDaughterNode( algoNode );
296 error() <<
"Requested DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
306 return m_algoNameToAlgoNodeMap.at( algoName );
315 auto itD = m_dataPathToDataNodeMap.find( dataPath );
317 if ( itD != m_dataPathToDataNodeMap.end() ) {
318 dataNode = itD->second;
321 if ( !m_conditionsRealmEnabled ) {
326 if ( condSvc->isRegistered( dataPath ) ) {
335 m_dataPathToDataNodeMap[dataPath] = dataNode;
340 boost::add_vertex(
DataProps( dataPath ), m_PRGraph );
351 return m_dataPathToDataNodeMap.at( dataPath );
356 bool modeConcurrent,
bool modePromptDecision,
bool modeOR,
362 auto& decisionHubName = decisionHubAlgo->
name();
364 auto itP = m_decisionNameToDecisionHubMap.
find( parentName );
366 if ( itP != m_decisionNameToDecisionHubMap.end() ) {
367 parentNode = itP->second;
368 auto itA = m_decisionNameToDecisionHubMap.find( decisionHubName );
370 if ( itA != m_decisionNameToDecisionHubMap.end() ) {
371 decisionHubNode = itA->second;
374 modePromptDecision, modeOR, allPass );
375 m_decisionNameToDecisionHubMap[decisionHubName] = decisionHubNode;
379 auto source = boost::add_vertex(
380 DecisionHubProps( decisionHubName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR, allPass ),
382 boost::add_edge( source, node( parentName ), m_PRGraph );
394 error() <<
"Decision hub node " << parentName <<
", requested to be parent, is not registered." <<
endmsg;
402 bool modeOR,
bool allPass )
405 auto itH = m_decisionNameToDecisionHubMap.find( headName );
406 if ( itH != m_decisionNameToDecisionHubMap.end() ) {
407 m_headNode = itH->second;
411 m_decisionNameToDecisionHubMap[headName] = m_headNode;
416 DecisionHubProps( headName, m_nodeCounter, modeConcurrent, modePromptDecision, modeOR, allPass ),
430 for (
auto vp = vertices( m_PRGraph ); vp.first != vp.second; ++vp.first ) {
444 getAlgorithmNode( algo_name )->accept( visitor );
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;
462 dumpControlFlow( ost, m_headNode, 0 );
472 if ( node != m_headNode ) {
476 ost << ( ( dn->
m_modeOR ) ?
" [OR] " :
"" );
477 ost << ( ( dn->
m_allPass ) ?
" [PASS] " :
"" );
482 dumpControlFlow( ost, *itr, indent + 1 );
484 }
else if ( an != 0 ) {
488 ost <<
" [n= " << ar->cardinality() <<
"]";
489 ost << ( ( !ar->isClonable() ) ?
" [unclonable] " :
"" );
499 const char idt[] =
" ";
502 ost <<
"\n" << idt <<
"====================================\n";
503 ost << idt <<
"Data origins and destinations:\n";
504 ost << idt <<
"====================================\n";
506 for (
auto& pair : m_dataPathToDataNodeMap ) {
508 for (
auto algoNode : pair.second->getProducers() ) ost << idt <<
" " << algoNode->getNodeName() <<
"\n";
510 ost << idt <<
" V\n";
511 ost << idt <<
" o " << pair.first <<
"\n";
512 ost << idt <<
" V\n";
514 for (
auto algoNode : pair.second->getConsumers() ) ost << idt <<
" " << algoNode->getNodeName() <<
"\n";
516 ost << idt <<
"====================================\n";
526 boost::filesystem::ofstream myfile;
530 boost::dynamic_properties dp;
532 using boost::make_transform_value_property_map;
533 using boost::apply_visitor;
535 using boost::vertex_bundle;
537 dp.property(
"Entity", make_transform_value_property_map(
539 get( vertex_bundle, m_PRGraph ) ) );
541 dp.property(
"Name", make_transform_value_property_map(
543 get( vertex_bundle, m_PRGraph ) ) );
545 dp.property(
"Mode", make_transform_value_property_map(
547 get( vertex_bundle, m_PRGraph ) ) );
549 dp.property(
"Logic",
550 make_transform_value_property_map(
552 get( vertex_bundle, m_PRGraph ) ) );
554 dp.property(
"Decision Negation",
555 make_transform_value_property_map(
557 get( vertex_bundle, m_PRGraph ) ) );
559 dp.property(
"Negative Decision Inversion",
560 make_transform_value_property_map(
562 get( vertex_bundle, m_PRGraph ) ) );
564 dp.property(
"Exit Policy",
565 make_transform_value_property_map(
567 get( vertex_bundle, m_PRGraph ) ) );
569 dp.property(
"Operations",
570 make_transform_value_property_map(
572 get( vertex_bundle, m_PRGraph ) ) );
574 dp.property(
"CF Decision", make_transform_value_property_map(
578 get( vertex_bundle, m_PRGraph ) ) );
580 dp.property(
"Algorithm State", make_transform_value_property_map(
584 get( vertex_bundle, m_PRGraph ) ) );
588 dp.property(
"Start Time (epoch ns)", make_transform_value_property_map(
592 get( vertex_bundle, m_PRGraph ) ) );
593 dp.property(
"End Time (epoch ns)", make_transform_value_property_map(
597 get( vertex_bundle, m_PRGraph ) ) );
598 dp.property(
"Runtime (ns)", make_transform_value_property_map(
602 get( vertex_bundle, m_PRGraph ) ) );
604 warning() <<
"Failed to get the TimelineSvc, timing will not be added to " 605 <<
"the task precedence rules dump" <<
endmsg;
608 boost::write_graphml( myfile, m_PRGraph, dp );
616 boost::filesystem::ofstream myfile;
621 if ( !timelineSvc.
isValid() ) {
622 warning() <<
"Failed to get the TimelineSvc, timing will not be added to " 623 <<
"the task precedence trace dump" <<
endmsg;
626 typedef boost::graph_traits<precedence::PRGraph>::vertex_iterator vertex_iter;
628 for ( vp = vertices( m_precTrace ); vp.first != vp.second; ++vp.first ) {
630 te.
algorithm = m_precTrace[*vp.first].m_name;
633 m_precTrace[*vp.first].m_runtime = runtime;
638 boost::dynamic_properties dp;
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 ) );
645 boost::write_graphml( myfile, m_precTrace, dp );
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;
664 m_prec_trace_map[
"ENTRY"] = source;
667 auto itS = m_prec_trace_map.find( u_name );
668 if ( itS != m_prec_trace_map.end() ) {
669 source = itS->second;
674 m_prec_trace_map[u_name] = source;
680 auto itP = m_prec_trace_map.find( v_name );
681 if ( itP != m_prec_trace_map.end() ) {
682 target = itP->second;
687 m_prec_trace_map[v_name] = target;
690 boost::add_edge( source, target, m_precTrace );
692 ON_DEBUG debug() << u_name <<
"-->" << v_name <<
" precedence trait added" <<
endmsg;
PRVertexDesc node(const std::string &) const
BGL-based facilities.
const unsigned int & getAlgoIndex() const
Get algorithm index.
StatusCode addAlgorithmNode(Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
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
bool isSuccess() const
Test for a status code of SUCCESS.
virtual bool visit(DecisionNode &)
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
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.
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
void addHeadNode(const std::string &headName, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Add a node, which has no parents.
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.
virtual bool visitEnter(DecisionNode &) const
Algorithm * getAlgorithm() const
get Algorithm representatives
virtual void getTimelineEvent(TimelineEvent &) const =0
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.
boost::variant< AlgoProps, DecisionHubProps, DataProps > VariantVertexProps
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
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.
void accept(const std::string &algo_name, IGraphVisitor &visitor) const
A method to update algorithm node decision, and propagate it upwards.
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
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
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.
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.
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.
static std::map< State, std::string > stateNames
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.