1 #ifndef GAUDIHIVE_EXECUTIONFLOWGRAPH_H
2 #define GAUDIHIVE_EXECUTIONFLOWGRAPH_H
7 #include <unordered_map>
12 #include <boost/graph/adjacency_list.hpp>
13 #include <boost/graph/graphml.hpp>
19 #include "GaudiKernel/Algorithm.h"
20 #include "GaudiKernel/CommonMessaging.h"
28 AlgoNodeStruct (
const std::string&
name,
const int index = -1,
const int& rank = -1,
const double& runtime = -1,
const double& eccentricity = -1.0) :
37 typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoNodeStruct>
ExecPlan;
38 typedef graph_traits<ExecPlan>::vertex_descriptor
AlgoVertex;
54 virtual void initialize(
const std::unordered_map<std::string,unsigned int>& algname_index_map) = 0;
60 std::vector<int>& node_decisions)
const = 0;
63 std::vector<int>& node_decisions)
const = 0;
65 virtual void printState(std::stringstream& output,
67 const std::vector<int>& node_decisions,
68 const unsigned int& recursionLevel)
const = 0;
74 std::vector<int>& node_decisions,
96 virtual void initialize(
const std::unordered_map<std::string,unsigned int>& algname_index_map);
101 std::vector<int>& node_decisions)
const;
105 std::vector<int>& node_decisions,
109 std::vector<int>& node_decisions)
const;
117 virtual void printState(std::stringstream& output,
119 const std::vector<int>& node_decisions,
120 const unsigned int& recursionLevel)
const;
147 virtual void initialize(
const std::unordered_map<std::string,unsigned int>& algname_index_map);
186 std::vector<int>& node_decisions)
const;
190 std::vector<int>& node_decisions)
const;
196 std::vector<int>& node_decisions,
199 virtual void printState(std::stringstream& output,
201 const std::vector<int>& node_decisions,
202 const unsigned int& recursionLevel)
const;
262 typedef std::unordered_map<std::string,const DataObjectDescriptorCollection*>
AlgoInputsMap;
263 typedef std::unordered_map<std::string,const DataObjectDescriptorCollection*>
AlgoOutputsMap;
284 std::vector<EventSlot>& eventSlots);
292 void addHeadNode(
const std::string& headName,
bool modeOR,
bool allPass,
bool isLazy);
299 for (
auto ialgoIt = container.unsafe_begin(); ialgoIt != container.unsafe_end(); ++ialgoIt)
300 node->attachAlgorithm(*ialgoIt);
314 std::vector<int>& node_decisions)
const;
319 std::vector<int>& node_decisions)
const;
325 const std::vector<int>& node_decisions,
326 const unsigned int& recursionLevel)
const {
m_headNode->
printState(output,states,node_decisions,recursionLevel);};
void dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
bool m_isLazy
Whether to evaluate lazily - i.e. whether to stop once result known.
std::string stateToString(const int &stateId) const
Translation between state id and name.
std::vector< DataNode * > m_outputs
Vectors, used in augmented data dependencies realm Outputs of the algorithm, represented as DataNode'...
const std::vector< AlgorithmNode * > getDataIndependentNodes() const
const unsigned int & getAlgoIndex() const
XXX: CF tests.
virtual bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX: CF tests.
std::vector< DecisionNode * > m_parents
XXX: CF tests. All direct parent nodes in the tree.
StatusCode initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize graph.
unsigned int m_algoIndex
The index of the algorithm.
unsigned int m_nodeCounter
Total number of nodes in the graph.
unsigned int getControlFlowNodeCounter() const
Get total number of graph nodes.
virtual ~IExecutionFlowGraph()=default
AlgoNodeStruct(const std::string &name, const int index=-1, const int &rank=-1, const double &runtime=-1, const double &eccentricity=-1.0)
boost::ExecPlan m_ExecPlan
temporary items to experiment with execution planning
StatusCode buildAugmentedDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
The namespace threadpool contains a thread pool and related utility classes.
friend ExecutionFlowManager
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
StatusCode addDecisionHubNode(Algorithm *daughterAlgo, const std::string &parentName, bool modeOR, bool allPass, bool isLazy)
Add a node, which aggregates decisions of direct daughter nodes.
virtual int updateState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
Method to set algos to CONTROLREADY, if possible.
virtual bool accept(IGraphVisitor &visitor)
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
virtual void initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)=0
Initialize.
std::string m_algoName
The name of the algorithm.
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoNodeStruct > ExecPlan
const std::vector< DataNode * > & getInputDataNodes() const
Get all consumer nodes.
bool dataDependenciesSatisfied(const int &slotNum) const
Method to check whether the Algorithm has its all data dependency satisfied.
std::vector< AlgorithmNode * > m_consumers
AlgorithmNodes that represent algorithms which need the output of the algorithm.
DataNode(ExecutionFlowGraph &, const std::string &path)
Constructor.
Clock::time_point time_point
AlgorithmNode(ExecutionFlowGraph &graph, unsigned int nodeIndex, const std::string &algoName, bool inverted, bool allPass)
Constructor.
void setRank(float &rank)
Set Algorithm rank.
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
DataNodesMap m_dataPathToDataNodeMap
Index: map of data path to DataNode.
std::unordered_map< std::string, DecisionNode * > DecisionHubsMap
AlgoOutputsMap m_algoNameToAlgoOutputsMap
const std::vector< IAlgorithm * > & getAlgorithmRepresentatives() const
get Algorithm representatives
std::vector< DecisionNode * > m_parents
XXX: CF tests.
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
void updateDecision(const std::string &algo_name, const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
A method to update algorithm node decision, and propagate it upwards.
std::map< std::string, boost::AlgoVertex > m_exec_plan_map
virtual bool accept(IGraphVisitor &visitor)=0
std::vector< int > & getNodeDecisions(const int &slotNum) const
virtual void updateDecision(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions, const AlgorithmNode *requestor=nullptr) const =0
bool m_inverted
Whether the selection result is negated or not.
bool m_allPass
Whether always passing regardless of daughter results.
ExecutionFlowGraph * m_graph
~AlgorithmNode()
Destructor.
virtual void initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize.
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.
AlgsExecutionStates & getAlgoStates(const int &slotNum) const
void registerIODataObjects(const Algorithm *algo)
Register algorithm in the Data Dependency index.
virtual ~ControlFlowNode()
Destructor.
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.
const float & getRank() const
Get Algorithm rank.
DecisionNode * m_headNode
the head node of the control flow graph; may want to have multiple ones once supporting trigger paths...
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Manage the execution flow using an execution flow graph Once initialized, the graph is const and can ...
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
~ExecutionFlowGraph() override
Destructor.
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::vector< AlgorithmNode * > m_consumers
This class is used for returning status codes from appropriate routines.
virtual bool accept(IGraphVisitor &visitor)
const std::vector< ControlFlowNode * > & getDaughters() const
graph_traits< ExecPlan >::vertex_descriptor AlgoVertex
ExecutionFlowGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
virtual 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::string m_data_object_path
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
const std::vector< AlgorithmNode * > & getConsumerNodes() const
Get all consumer nodes.
void addConsumerNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
virtual ~DecisionNode()
Destructor.
const std::string & name() const override
Retrieve name of the service.
void attachAlgorithm(IAlgorithm *ialgo)
Attach Algorithm representative.
The IAlgorithm is the interface implemented by the Algorithm base class.
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITHOUT data object nodes: just interconnect algorithm nodes directly...
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
virtual void initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize.
std::unordered_map< std::string, const DataObjectDescriptorCollection * > AlgoOutputsMap
virtual bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const =0
XXX: CF tests. Method to set algos to CONTROLREADY, if possible.
float m_rank
Algorithm rank of any kind.
void addOutputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
std::vector< IAlgorithm * > m_representatives
Representatives (including clones) of the node.
std::unordered_map< std::string, AlgorithmNode * > AlgoNodesMap
Base class from which all concrete algorithm classes should be derived.
void addSupplierNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
virtual void updateDecision(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions, const AlgorithmNode *requestor=nullptr) const
XXX: CF tests.
void addEdgeToExecutionPlan(const AlgorithmNode *u, const AlgorithmNode *v)
set cause-effect connection between two algorithms in the execution plan
StatusCode addAlgorithmNode(Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
const std::vector< AlgorithmNode * > & getSupplierNodes() const
Get all supplier nodes.
std::vector< DataNode * > m_inputs
Inputs of the algorithm, represented as DataNode's.
ControlFlowNode(ExecutionFlowGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
void addParentNode(DecisionNode *node)
XXX: CF tests. Method to add a parent node.
virtual void printState(std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const =0
Print a string representing the control flow state.
StatusCode addDataNode(const std::string &dataPath)
Add DataNode that represents DataObject.
DataNode * getDataNode(const std::string &dataPath) const
Get DataNode by DataObject path using graph index.
virtual int updateState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const =0
XXX: CF tests. Method to set algos to CONTROLREADY, if possible.
std::vector< AlgorithmNode * > m_producers
virtual int updateState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
Method to set algos to CONTROLREADY, if possible.
const std::chrono::system_clock::time_point m_initTime
void dumpExecutionPlan()
dump to file encountered execution plan
std::vector< EventSlot > * m_eventSlots
void addHeadNode(const std::string &headName, bool modeOR, bool allPass, bool isLazy)
Add a node, which has no parents.
void addParentNode(DecisionNode *node)
XXX: CF tests. Method to add a parent node.
std::unordered_map< std::string, const DataObjectDescriptorCollection * > AlgoInputsMap
virtual 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.
virtual void updateDecision(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions, const AlgorithmNode *requestor=nullptr) const
XXX: CF tests.
AlgoInputsMap m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
const std::string & getNodeName() const
const unsigned int & getNodeIndex() const
XXX: CF tests.
std::vector< AlgorithmNode * > m_suppliers
Vectors, used in data dependencies realm AlgorithmNodes that represent algorithms producing an input ...
State
Execution states of the algorithms.
void attachAlgorithmsToNodes(const std::string &algo_name, const T &container)
Attach pointers to real Algorithms (and their clones) to Algorithm nodes of the graph.
void updateEventState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX CF tests. Is needed for older CF implementation.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
const std::chrono::system_clock::time_point getInitTime() const
const std::string & getPath()
bool m_allPass
Whether the selection result is relevant or always "pass".
void addProducerNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
DecisionNode(ExecutionFlowGraph &graph, unsigned int nodeIndex, const std::string &name, bool modeOR, bool allPass, bool isLazy)
Constructor.
bool promoteToDataReadyState(const int &slotNum, const AlgorithmNode *requestor=nullptr) const
std::unordered_map< std::string, DataNode * > DataNodesMap
AlgsExecutionStates::State State
void addConsumerNode(AlgorithmNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
virtual bool promoteToControlReadyState(const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const
XXX: CF tests. Method to set algos to CONTROLREADY, if possible.