| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ControlFlowGraph.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_CONTROLFLOWGRAPH_H
2 #define GAUDIHIVE_CONTROLFLOWGRAPH_H
3
4 // std includes
5 #include <sstream>
6 #include <unordered_map>
7 #include <vector>
8
9 // local includes
10 #include "AlgsExecutionStates.h"
11
12 // Framework includes
13 #include "GaudiKernel/Algorithm.h"
14 #include "GaudiKernel/CommonMessaging.h"
15
16 namespace concurrency
17 {
18
19 namespace recursive_CF
20 {
21
22 typedef AlgsExecutionStates::State State;
23 class ControlFlowGraph;
24
25 class ControlFlowNode
26 {
27 public:
29 ControlFlowNode( ControlFlowGraph& graph, unsigned int nodeIndex, const std::string& name )
30 : m_graph( &graph ), m_nodeIndex( nodeIndex ), m_nodeName( name )
31 {
32 }
34 virtual ~ControlFlowNode() {}
36 virtual void initialize( const std::unordered_map<std::string, unsigned int>& algname_index_map ) = 0;
38 virtual int updateState( AlgsExecutionStates& states, std::vector<int>& node_decisions ) const = 0;
40 virtual void printState( std::stringstream& output, AlgsExecutionStates& states,
41 const std::vector<int>& node_decisions, const unsigned int& recursionLevel ) const = 0;
43 const unsigned int& getNodeIndex() const { return m_nodeIndex; }
45 const std::string& getNodeName() const { return m_nodeName; }
46
47 public:
48 ControlFlowGraph* m_graph;
49
50 protected:
52 std::string stateToString( const int& stateId ) const;
53 unsigned int m_nodeIndex;
54 std::string m_nodeName;
55 };
56
57 class DecisionNode : public ControlFlowNode
58 {
59 public:
61 DecisionNode( ControlFlowGraph& graph, unsigned int nodeIndex, const std::string& name, bool modeConcurrent,
62 bool modePromptDecision, bool modeOR, bool allPass )
63 : ControlFlowNode( graph, nodeIndex, name )
64 , m_modeConcurrent( modeConcurrent )
65 , m_modePromptDecision( modePromptDecision )
66 , m_modeOR( modeOR )
67 , m_allPass( allPass )
68 , m_children()
69 {
70 }
72 ~DecisionNode() override;
74 void initialize( const std::unordered_map<std::string, unsigned int>& algname_index_map ) override;
76 int updateState( AlgsExecutionStates& states, std::vector<int>& node_decisions ) const override;
78 void addDaughterNode( ControlFlowNode* node );
80 const std::vector<ControlFlowNode*>& getDaughters() const { return m_children; }
82 void printState( std::stringstream& output, AlgsExecutionStates& states, const std::vector<int>& node_decisions,
83 const unsigned int& recursionLevel ) const override;
84
85 public:
87 bool m_modeConcurrent;
90 bool m_modePromptDecision;
92 bool m_modeOR;
94 bool m_allPass;
95
96 private:
98 std::vector<ControlFlowNode*> m_children;
99 };
100
101 class AlgorithmNode : public ControlFlowNode
102 {
103 public:
105 AlgorithmNode( ControlFlowGraph& graph, Algorithm* algoPtr, unsigned int nodeIndex, unsigned int algoIndex,
106 bool inverted, bool allPass )
107 : ControlFlowNode( graph, nodeIndex, algoPtr->name() )
108 , m_algoIndex( algoIndex )
109 , m_algoName( algoPtr->name() )
110 , m_inverted( inverted )
111 , m_allPass( allPass )
112 , m_algorithm( algoPtr ){};
113
115 void initialize( const std::unordered_map<std::string, unsigned int>& algname_index_map ) override;
117 Algorithm* getAlgorithm() const { return m_algorithm; }
119 int updateState( AlgsExecutionStates& states, std::vector<int>& node_decisions ) const override;
121 void printState( std::stringstream& output, AlgsExecutionStates& states, const std::vector<int>& node_decisions,
122 const unsigned int& recursionLevel ) const override;
123
124 private:
126 unsigned int m_algoIndex;
128 std::string m_algoName;
130 bool m_inverted;
132 bool m_allPass;
134 Algorithm* m_algorithm;
135 };
136
137 typedef std::unordered_map<std::string, AlgorithmNode*> AlgoNodesMap;
138 typedef std::unordered_map<std::string, DecisionNode*> DecisionHubsMap;
139
140 struct IControlFlowGraph {
141 virtual ~IControlFlowGraph() = default;
142 };
143
144 class ControlFlowGraph : public CommonMessaging<IControlFlowGraph>
145 {
146 public:
148 ControlFlowGraph( const std::string& name, SmartIF<ISvcLocator> svc ) : m_svcLocator( svc ), m_name( name )
149 {
150 setUpMessaging();
151 }
153 ~ControlFlowGraph() override
154 {
155 if ( m_headNode != 0 ) delete m_headNode;
156 }
157
159 void initialize( const std::unordered_map<std::string, unsigned int>& algname_index_map );
161 void addHeadNode( const std::string& headName, bool modeConcurrent, bool modePromptDecision, bool modeOR,
162 bool allPass );
164 DecisionNode* getHeadNode() const { return m_headNode; };
166 StatusCode addAlgorithmNode( Algorithm* daughterAlgo, const std::string& parentName, bool inverted,
167 bool allPass );
169 StatusCode addDecisionHubNode( Algorithm* daughterAlgo, const std::string& parentName, bool modeConcurrent,
170 bool modePromptDecision, bool modeOR, bool allPass );
172 unsigned int getControlFlowNodeCounter() const { return m_nodeCounter; }
174 void updateEventState( AlgsExecutionStates& states, std::vector<int>& node_decisions ) const;
176 void printState( std::stringstream& output, AlgsExecutionStates& states, const std::vector<int>& node_decisions,
177 const unsigned int& recursionLevel ) const
178 {
179 m_headNode->printState( output, states, node_decisions, recursionLevel );
180 }
182 const std::string& name() const override { return m_name; }
184 SmartIF<ISvcLocator>& serviceLocator() const override { return m_svcLocator; }
186 std::string dumpControlFlow() const;
188 void dumpControlFlow( std::ostringstream&, ControlFlowNode*, const int& ) const;
189
190 private:
192 DecisionNode* m_headNode{nullptr};
194 AlgoNodesMap m_algoNameToAlgoNodeMap;
196 DecisionHubsMap m_decisionNameToDecisionHubMap;
198 unsigned int m_nodeCounter{0};
200 unsigned int m_algoCounter{0};
202 mutable SmartIF<ISvcLocator> m_svcLocator;
203 const std::string m_name;
204 };
205
206 } // namespace recursive_CF
207 } // namespace concurrency
208
209 #endif
concurrency::recursive_CF::DecisionNode::DecisionNode
DecisionNode(ControlFlowGraph &graph, unsigned int nodeIndex, const std::string &name, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
Constructor.
Definition: ControlFlowGraph.h:61
Algorithm.h
SmartIF< ISvcLocator >
concurrency::recursive_CF::ControlFlowNode::printState
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.
concurrency::recursive_CF::DecisionHubsMap
std::unordered_map< std::string, DecisionNode * > DecisionHubsMap
Definition: ControlFlowGraph.h:138
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
concurrency::recursive_CF::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: ControlFlowGraph.h:98
gaudirun.output
output
Definition: gaudirun.py:404
concurrency::recursive_CF::AlgorithmNode::m_algorithm
Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
Definition: ControlFlowGraph.h:134
concurrency
Definition: ControlFlowGraph.cpp:4
concurrency::recursive_CF::ControlFlowNode::getNodeName
const std::string & getNodeName() const
Get node name.
Definition: ControlFlowGraph.h:45
concurrency::recursive_CF::ControlFlowNode::stateToString
std::string stateToString(const int &stateId) const
Translation between state id and name.
Definition: ControlFlowGraph.cpp:11
concurrency::recursive_CF::ControlFlowNode::getNodeIndex
const unsigned int & getNodeIndex() const
Get node index.
Definition: ControlFlowGraph.h:43
concurrency::recursive_CF::DecisionNode::m_modePromptDecision
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Definition: ControlFlowGraph.h:90
concurrency::recursive_CF::ControlFlowGraph::getControlFlowNodeCounter
unsigned int getControlFlowNodeCounter() const
Get total number of graph nodes.
Definition: ControlFlowGraph.h:172
concurrency::recursive_CF::ControlFlowGraph::~ControlFlowGraph
~ControlFlowGraph() override
Destructor.
Definition: ControlFlowGraph.h:153
concurrency::recursive_CF::DecisionNode
Definition: ControlFlowGraph.h:57
concurrency::recursive_CF::DecisionNode::m_allPass
bool m_allPass
Whether always passing regardless of daughter results.
Definition: ControlFlowGraph.h:94
concurrency::recursive_CF::AlgorithmNode::getAlgorithm
Algorithm * getAlgorithm() const
get Algorithm representatives
Definition: ControlFlowGraph.h:117
concurrency::recursive_CF::State
AlgsExecutionStates::State State
Definition: ControlFlowGraph.h:22
concurrency::recursive_CF::ControlFlowNode::updateState
virtual int updateState(AlgsExecutionStates &states, std::vector< int > &node_decisions) const =0
Method to set algos to CONTROLREADY, if possible.
std::stringstream
STL class.
concurrency::recursive_CF::AlgorithmNode::m_algoName
std::string m_algoName
The name of the algorithm.
Definition: ControlFlowGraph.h:128
concurrency::recursive_CF::ControlFlowNode
Definition: ControlFlowGraph.h:25
std::string
STL class.
concurrency::recursive_CF::ControlFlowGraph::name
const std::string & name() const override
Retrieve name of the service.
Definition: ControlFlowGraph.h:182
concurrency::recursive_CF::ControlFlowGraph
Definition: ControlFlowGraph.h:144
AlgsExecutionStates
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Definition: AlgsExecutionStates.h:28
concurrency::recursive_CF::ControlFlowGraph::m_name
const std::string m_name
Definition: ControlFlowGraph.h:203
concurrency::recursive_CF::AlgorithmNode::AlgorithmNode
AlgorithmNode(ControlFlowGraph &graph, Algorithm *algoPtr, unsigned int nodeIndex, unsigned int algoIndex, bool inverted, bool allPass)
Constructor.
Definition: ControlFlowGraph.h:105
concurrency::recursive_CF::DecisionNode::getDaughters
const std::vector< ControlFlowNode * > & getDaughters() const
Definition: ControlFlowGraph.h:80
concurrency::recursive_CF::ControlFlowNode::ControlFlowNode
ControlFlowNode(ControlFlowGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
Definition: ControlFlowGraph.h:29
concurrency::recursive_CF::ControlFlowNode::m_graph
ControlFlowGraph * m_graph
Definition: ControlFlowGraph.h:48
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::ostringstream
STL class.
concurrency::recursive_CF::IControlFlowGraph
Definition: ControlFlowGraph.h:140
CommonMessaging.h
concurrency::recursive_CF::ControlFlowNode::~ControlFlowNode
virtual ~ControlFlowNode()
Destructor.
Definition: ControlFlowGraph.h:34
concurrency::recursive_CF::ControlFlowNode::initialize
virtual void initialize(const std::unordered_map< std::string, unsigned int > &algname_index_map)=0
Initialize.
concurrency::recursive_CF::AlgorithmNode::m_allPass
bool m_allPass
Whether the selection result is relevant or always "pass".
Definition: ControlFlowGraph.h:132
concurrency::recursive_CF::AlgorithmNode
Definition: ControlFlowGraph.h:101
concurrency::recursive_CF::AlgorithmNode::m_inverted
bool m_inverted
Whether the selection result is negated or not.
Definition: ControlFlowGraph.h:130
plotSpeedupsPyRoot.graph
graph
Definition: plotSpeedupsPyRoot.py:142
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
std::vector< int >
concurrency::recursive_CF::ControlFlowGraph::getHeadNode
DecisionNode * getHeadNode() const
Get head node.
Definition: ControlFlowGraph.h:164
concurrency::recursive_CF::ControlFlowNode::m_nodeName
std::string m_nodeName
Definition: ControlFlowGraph.h:54
concurrency::recursive_CF::ControlFlowGraph::printState
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.
Definition: ControlFlowGraph.h:176
concurrency::recursive_CF::ControlFlowGraph::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: ControlFlowGraph.h:184
CommonMessaging
Definition: CommonMessaging.h:62
concurrency::recursive_CF::ControlFlowGraph::m_algoNameToAlgoNodeMap
AlgoNodesMap m_algoNameToAlgoNodeMap
Index: map of algorithm&#39;s name to AlgorithmNode.
Definition: ControlFlowGraph.h:194
concurrency::recursive_CF::ControlFlowGraph::m_decisionNameToDecisionHubMap
DecisionHubsMap m_decisionNameToDecisionHubMap
Index: map of decision&#39;s name to DecisionHub.
Definition: ControlFlowGraph.h:196
AlgsExecutionStates.h
concurrency::recursive_CF::AlgorithmNode::m_algoIndex
unsigned int m_algoIndex
The index of the algorithm.
Definition: ControlFlowGraph.h:126
concurrency::recursive_CF::ControlFlowGraph::ControlFlowGraph
ControlFlowGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
Definition: ControlFlowGraph.h:148
AlgsExecutionStates::State
State
Execution states of the algorithms.
Definition: AlgsExecutionStates.h:32
concurrency::recursive_CF::AlgoNodesMap
std::unordered_map< std::string, AlgorithmNode * > AlgoNodesMap
Definition: ControlFlowGraph.h:137
concurrency::recursive_CF::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: ControlFlowGraph.h:92
concurrency::recursive_CF::DecisionNode::m_modeConcurrent
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
Definition: ControlFlowGraph.h:87
concurrency::recursive_CF::ControlFlowGraph::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Definition: ControlFlowGraph.h:202
concurrency::recursive_CF::ControlFlowNode::m_nodeIndex
unsigned int m_nodeIndex
Definition: ControlFlowGraph.h:53
std::unordered_map< std::string, unsigned int >