1 #ifndef GAUDIHIVE_PRECEDENCERULESGRAPH_H 2 #define GAUDIHIVE_PRECEDENCERULESGRAPH_H 8 #include <unordered_map> 11 #include <boost/filesystem.hpp> 12 #include <boost/graph/adjacency_list.hpp> 13 #include <boost/graph/graphml.hpp> 14 #include <boost/variant.hpp> 27 using boost::static_visitor;
43 using PrecTrace = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps>;
51 , m_nodeIndex( nodeIndex )
52 , m_algoIndex( algoIndex )
54 , m_inverted( inverted )
55 , m_allPass( allPass )
56 , m_isIOBound( algo->isIOBound() )
68 bool m_inverted{
false};
70 bool m_allPass{
false};
72 bool m_isIOBound{
false};
77 bool modeOR,
bool allPass )
79 , m_nodeIndex( nodeIndex )
80 , m_modeConcurrent( modeConcurrent )
81 , m_modePromptDecision( modePromptDecision )
83 , m_allPass( allPass )
155 struct AllPass : static_visitor<std::string> {
191 case State::CONTROLREADY:
192 return "CONTROLREADY";
193 case State::DATAREADY:
195 case State::EVTACCEPTED:
196 return "EVTACCEPTED";
197 case State::EVTREJECTED:
198 return "EVTREJECTED";
221 if ( m_timelineSvc.isValid() ) {
225 m_timelineSvc->getTimelineEvent( te );
227 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
240 struct EndTime : static_visitor<std::string> {
248 if ( m_timelineSvc.isValid() ) {
252 m_timelineSvc->getTimelineEvent( te );
254 std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
275 if ( m_timelineSvc.isValid() ) {
279 m_timelineSvc->getTimelineEvent( te );
280 time =
std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.
end - te.
start ).count() );
308 using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
338 : m_graph( &graph ), m_nodeIndex( nodeIndex ), m_nodeName( name )
348 const std::vector<int>& node_decisions,
const unsigned int& recursionLevel )
const = 0;
359 std::string stateToString(
const int& stateId )
const;
369 bool modePromptDecision,
bool modeOR,
bool allPass )
371 , m_modeConcurrent( modeConcurrent )
372 , m_modePromptDecision( modePromptDecision )
374 , m_allPass( allPass )
392 const unsigned int& recursionLevel )
const override;
418 bool inverted,
bool allPass )
420 , m_algorithm( algoPtr )
421 , m_algoIndex( algoIndex )
422 , m_algoName( algoPtr->
name() )
423 , m_inverted( inverted )
424 , m_allPass( allPass )
426 , m_isIOBound( algoPtr->isIOBound() ){};
439 void addOutputDataNode(
DataNode* node );
441 void addInputDataNode(
DataNode* node );
465 bool isLiar()
const {
return m_inverted; };
469 const unsigned int& recursionLevel )
const override;
515 if (
std::find( m_producers.begin(), m_producers.end(), node ) == m_producers.end() )
516 m_producers.push_back( node );
521 if (
std::find( m_consumers.begin(), m_consumers.end(), node ) == m_consumers.end() )
522 m_consumers.push_back( node );
543 :
DataNode( graph, path ), m_condSvc( condSvc )
581 , m_svcLocator( svc )
583 , m_initTime(
std::chrono::system_clock::now() )
589 if ( m_headNode != 0 )
delete m_headNode;
603 void registerIODataObjects(
const Algorithm* algo );
608 void addHeadNode(
const std::string& headName,
bool modeConcurrent,
bool modePromptDecision,
bool modeOR,
618 bool modePromptDecision,
bool modeOR,
bool allPass );
634 const unsigned int& recursionLevel )
const 636 m_headNode->printState( output, states, node_decisions, recursionLevel );
686 bool m_conditionsRealmEnabled{
false};
std::vector< DataNode * > m_outputs
Algorithm outputs (DataNodes)
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps > PRGraph
std::string operator()(const DecisionHubProps &props) const
const unsigned int & getAlgoIndex() const
Get algorithm index.
std::string operator()(const DecisionHubProps &) const
std::vector< DecisionNode * > m_parents
Direct parent nodes.
AlgoTraceProps(const std::string &name, int index, int rank, double runtime)
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
std::string operator()(const AlgoProps &props) const
unsigned int m_algoIndex
The index of the algorithm.
const std::chrono::system_clock::time_point getInitTime() const
std::string operator()(const AlgoProps &props) const
DecisionNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Constructor.
AlgoProps(Algorithm *algo, uint nodeIndex, uint algoIndex, bool inverted, bool allPass)
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
void setIOBound(bool value)
Set the I/O-boundness flag.
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
const std::chrono::system_clock::time_point m_initTime
std::string m_algoName
The name of the algorithm.
const std::vector< DataNode * > & getInputDataNodes() const
Get all consumer nodes.
bool isOptimist() const
Check if positive control flow decision is enforced.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.
virtual bool visit(DecisionNode &)
bool accept(IGraphVisitor &visitor)
Need to hide the (identical) base method with this one so that visitEnter(ConditionNode&) and visit(C...
void setRank(float &rank)
Set Algorithm rank.
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
std::string operator()(const AlgoProps &) const
std::string operator()(const DecisionHubProps &props) const
DataProps(const DataObjID &id)
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.
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
bool m_isIOBound
If an algorithm is blocking.
SmartIF< ITimelineSvc > m_timelineSvc
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
std::string operator()(const DataProps &) const
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
bool m_allPass
Whether always passing regardless of daughter results.
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
bool m_inverted
Whether the selection result is negated or not.
bool m_allPass
Whether always passing regardless of daughter results.
std::string operator()(const DataProps &) const
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
std::string operator()(const DecisionHubProps &props) const
bool isIOBound() const
Check if algorithm is I/O-bound.
~PrecedenceRulesGraph() override
Destructor.
SmartIF< ITimelineSvc > m_timelineSvc
virtual bool visitEnter(DecisionNode &) const
Algorithm * getAlgorithm() const
get Algorithm representatives
std::string operator()(const DecisionHubProps &) const
virtual ~ControlFlowNode()
Destructor.
std::string operator()(const DataProps &) const
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const DataProps &) const
SmartIF< ITimelineSvc > m_timelineSvc
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...
std::string operator()(const DecisionHubProps &) const
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
PrecedenceRulesGraph * m_graph
std::string operator()(const DataProps &) const
const DataObjID & getPath()
DecisionNode * m_headNode
the head node of the control flow graph
std::string operator()(const DecisionHubProps &) const
std::vector< AlgorithmNode * > m_consumers
This class is used for returning status codes from appropriate routines.
const std::vector< ControlFlowNode * > & getDaughters() const
Get children nodes.
bool accept(IGraphVisitor &visitor)
Entry point for a visitor.
std::string operator()(const AlgoProps &props) const
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
std::string operator()(const DecisionHubProps &) const
DataNode(PrecedenceRulesGraph &graph, const DataObjID &path)
Constructor.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
std::string operator()(const AlgoProps &props) const
bool m_allPass
Whether the selection result is relevant or always "pass".
AlgoOutputsMap m_algoNameToAlgoOutputsMap
FSMState(const EventSlot &slot)
bool m_inverted
Whether the selection result is negated or not.
PrecedenceRulesGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
DataObjID m_data_object_path
StartTime(SmartIF< ITimelineSvc > timelineSvc)
float m_rank
Algorithm rank of any kind.
Base class from which all concrete algorithm classes should be derived.
std::string operator()(const DecisionHubProps &) const
std::vector< InputHandle_t< In > > m_inputs
std::string operator()(const AlgoProps &props) const
std::vector< DataNode * > m_inputs
Algorithm inputs (DataNodes)
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
Clock::time_point time_point
std::vector< AlgorithmNode * > m_producers
std::string operator()(const DataProps &) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &) const
unsigned int m_nodeCounter
Total number of nodes in the graph.
Class representing the event slot.
DecisionHubProps(const std::string &name, uint nodeIndex, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
std::string operator()(const DecisionHubProps &props) const
bool isLiar() const
Check if control flow logic is always inverted.
PrecedenceRulesGraph * m_graph
AlgorithmNode(PrecedenceRulesGraph &graph, Algorithm *algoPtr, unsigned int nodeIndex, unsigned int algoIndex, bool inverted, bool allPass)
Constructor.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
const std::string & getNodeName() const
Get node name.
const unsigned int & getNodeIndex() const
Get node index.
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
std::string operator()(const DecisionHubProps &props) const
EndTime(SmartIF< ITimelineSvc > timelineSvc)
State
Execution states of the algorithms.
std::string fullKey() const
std::string operator()(const DataProps &) const
const std::string & name() const override
Retrieve name of the service.
bool m_isIOBound
If an algorithm is blocking.
std::string operator()(const DecisionHubProps &props) const
Duration(SmartIF< ITimelineSvc > timelineSvc)
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &props) const
bool m_allPass
Whether the selection result is relevant or always "pass".
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
void addProducerNode(AlgorithmNode *node)
Add relationship to producer AlgorithmNode.
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
unsigned int getControlFlowNodeCounter() const
Get total number of control flow graph nodes.
std::string operator()(const DataProps &) const
SmartIF< ICondSvc > m_condSvc
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
ConditionNode(PrecedenceRulesGraph &graph, const DataObjID &path, SmartIF< ICondSvc > condSvc)
Constructor.
DecisionNode * getHeadNode() const
Get head node.
std::string operator()(const DataProps &) const
CFDecision(const EventSlot &slot)
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.