| The Gaudi Framework v28r2p1 (f1a77ff4)

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Private Attributes | List of all members
concurrency::DecisionNode Class Reference

`#include <src/PrecedenceRulesGraph.h>`

Inheritance diagram for concurrency::DecisionNode:
[legend]
Collaboration diagram for concurrency::DecisionNode:
[legend]

## Public Member Functions
| DecisionNode (PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name, bool modeConcurrent, bool modePromptDecision, bool modeOR, bool allPass)
| Constructor. More...
| ~DecisionNode () override
| Destructor. More...
void | initialize (const std::unordered_map< std::string, unsigned int > &algname_index_map) override
| Initialize. More...
bool | accept (IGraphVisitor &visitor) override
bool | promoteToControlReadyState (const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
| XXX: CF tests. Method to set algos to CONTROLREADY, if possible. More...
void | updateDecision (const int &slotNum, AlgsExecutionStates &states, std::vector< int > &node_decisions, const AlgorithmNode *requestor=nullptr) const override
| XXX: CF tests. More...
int | updateState (AlgsExecutionStates &states, std::vector< int > &node_decisions) const override
| Method to set algos to CONTROLREADY, if possible. More...
void | addParentNode (DecisionNode *node)
| XXX: CF tests. Method to add a parent node. More...
void | addDaughterNode (ControlFlowNode *node)
| Add a daughter node. More...
const std::vector< ControlFlowNode * > & | getDaughters () const
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. More...
Public Member Functions inherited from concurrency::ControlFlowNode
| ControlFlowNode (PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
| Constructor. More...
virtual | ~ControlFlowNode ()
| Destructor. More...
const unsigned int & | getNodeIndex () const
| XXX: CF tests. More...
const std::string & | getNodeName () const

## Public Attributes
bool | m_modeConcurrent
| Whether all daughters will be evaluated concurrently or sequentially. More...
bool | m_modePromptDecision
| Whether to evaluate the hub decision ASA its child decisions allow to do that. More...
bool | m_modeOR
| Whether acting as "and" (false) or "or" node (true) More...
bool | m_allPass
| Whether always passing regardless of daughter results. More...
Public Attributes inherited from concurrency::ControlFlowNode
PrecedenceRulesGraph * | m_graph

## Private Attributes
std::vector< ControlFlowNode * > | m_children
| All direct daughter nodes in the tree. More...
std::vector< DecisionNode * > | m_parents
| XXX: CF tests. All direct parent nodes in the tree. More...

## Additional Inherited Members
Protected Member Functions inherited from concurrency::ControlFlowNode
std::string | stateToString (const int &stateId) const
| Translation between state id and name. More...
Protected Attributes inherited from concurrency::ControlFlowNode
unsigned int | m_nodeIndex
std::string | m_nodeName

## Detailed Description

Definition at line 86 of file PrecedenceRulesGraph.h.

## Constructor & Destructor Documentation

concurrency::DecisionNode::DecisionNode | ( | PrecedenceRulesGraph & | graph,
|  | unsigned int | nodeIndex,
|  | const std::string & | name,
|  | bool | modeConcurrent,
|  | bool | modePromptDecision,
|  | bool | modeOR,
|  | bool | allPass
| ) |  |
| inline

Constructor.

Definition at line 89 of file PrecedenceRulesGraph.h.

89 :
90 ControlFlowNode(graph, nodeIndex, name),
91 m_modeConcurrent(modeConcurrent), m_modePromptDecision(modePromptDecision), m_modeOR(modeOR), m_allPass(allPass), m_children()
92 {}
concurrency::ControlFlowNode::ControlFlowNode
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
Definition: PrecedenceRulesGraph.h:49
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133
concurrency::DecisionNode::m_allPass
bool m_allPass
Whether always passing regardless of daughter results.
Definition: PrecedenceRulesGraph.h:130
concurrency::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: PrecedenceRulesGraph.h:128
concurrency::DecisionNode::m_modePromptDecision
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Definition: PrecedenceRulesGraph.h:126
plotSpeedupsPyRoot.graph
graph
Definition: plotSpeedupsPyRoot.py:134
concurrency::DecisionNode::m_modeConcurrent
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
Definition: PrecedenceRulesGraph.h:123

concurrency::DecisionNode::~DecisionNode | ( |  | ) |
| override

Destructor.

Definition at line 22 of file PrecedenceRulesGraph.cpp.

23 {
24
25 for ( auto node : m_children ) delete node;
26 }
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133

## Member Function Documentation

bool concurrency::DecisionNode::accept | ( | IGraphVisitor & | visitor | ) |
| override virtual

Implements concurrency::ControlFlowNode.

Definition at line 192 of file PrecedenceRulesGraph.cpp.

193 {
194
195 if ( visitor.visitEnter( *this ) ) {
196 // try to aggregate a decision
197 bool result = visitor.visit( *this );
198
199 // if a decision was made for this node, propagate the result upwards
200 if ( result ) {
201 for ( auto parent : m_parents ) {
202 parent->accept( visitor );
203 }
204 return false;
205 }
206
207 // if no decision can be made yet, request further information downwards
208 for ( auto child : m_children ) {
209 bool result = child->accept( visitor );
210 if (!m_modeConcurrent)
211 if ( result ) break; //stop on first unresolved child if its decision hub is sequential
212 }
213
214 return true; // visitor was accepted to try to aggregate the node's decision
215 }
216
217 return false; // visitor was rejected (since the decision node has an aggregated decision already)
218 }
concurrency::DecisionNode::m_parents
std::vector< DecisionNode * > m_parents
XXX: CF tests. All direct parent nodes in the tree.
Definition: PrecedenceRulesGraph.h:135
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133
concurrency::DecisionNode::m_modeConcurrent
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
Definition: PrecedenceRulesGraph.h:123

void concurrency::DecisionNode::addDaughterNode | ( | ControlFlowNode * | node | ) |

Add a daughter node.

Definition at line 43 of file PrecedenceRulesGraph.cpp.

44 {
45
46 if ( std::find( m_children.begin(), m_children.end(), node ) == m_children.end() ) m_children.push_back( node );
47 }
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133
std::find
T find(T...args)

void concurrency::DecisionNode::addParentNode | ( | DecisionNode * | node | ) |

XXX: CF tests. Method to add a parent node.

Definition at line 36 of file PrecedenceRulesGraph.cpp.

37 {
38
39 if ( std::find( m_parents.begin(), m_parents.end(), node ) == m_parents.end() ) m_parents.push_back( node );
40 }
concurrency::DecisionNode::m_parents
std::vector< DecisionNode * > m_parents
XXX: CF tests. All direct parent nodes in the tree.
Definition: PrecedenceRulesGraph.h:135
std::find
T find(T...args)

const std::vector<ControlFlowNode*>& concurrency::DecisionNode::getDaughters | ( |  | ) | const
| inline

Definition at line 115 of file PrecedenceRulesGraph.h.

115 {return m_children;}
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133

void concurrency::DecisionNode::initialize | ( | const std::unordered_map< std::string, unsigned int > & | algname_index_map | ) |
| override virtual

Initialize.

Implements concurrency::ControlFlowNode.

Definition at line 29 of file PrecedenceRulesGraph.cpp.

30 {
31
32 for ( auto daughter : m_children ) daughter->initialize( algname_index_map );
33 }
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133

void concurrency::DecisionNode::printState | ( | std::stringstream & | output,
|  | AlgsExecutionStates & | states,
|  | const std::vector< int > & | node_decisions,
|  | const unsigned int & | recursionLevel
| ) |  | const
| override virtual

Print a string representing the control flow state.

Implements concurrency::ControlFlowNode.

Definition at line 50 of file PrecedenceRulesGraph.cpp.

52 {
53
54 output << std::string( recursionLevel, ' ' ) << m_nodeName << " (" << m_nodeIndex << ")"
55 << ", w/ decision: " << stateToString( node_decisions[m_nodeIndex] ) << "(" << node_decisions[m_nodeIndex]
56 << ")" << std::endl;
57 for ( auto daughter : m_children ) {
58 daughter->printState( output, states, node_decisions, recursionLevel + 2 );
59 }
60 }
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133
std::endl
T endl(T...args)
concurrency::ControlFlowNode::stateToString
std::string stateToString(const int &stateId) const
Translation between state id and name.
Definition: PrecedenceRulesGraph.cpp:10
std::string
STL class.
concurrency::ControlFlowNode::m_nodeIndex
unsigned int m_nodeIndex
Definition: PrecedenceRulesGraph.h:81
concurrency::ControlFlowNode::m_nodeName
std::string m_nodeName
Definition: PrecedenceRulesGraph.h:82

bool concurrency::DecisionNode::promoteToControlReadyState | ( | const int & | slotNum,
|  | AlgsExecutionStates & | states,
|  | std::vector< int > & | node_decisions
| ) |  | const
| override virtual

XXX: CF tests. Method to set algos to CONTROLREADY, if possible.

Implements concurrency::ControlFlowNode.

Definition at line 170 of file PrecedenceRulesGraph.cpp.

172 {
173 // std::cout << "REACHED DECISNODE " << m_nodeName << std::endl;
174 if ( -1 != node_decisions[m_nodeIndex] ) {
175 return true;
176 }
177
178 for ( auto daughter : m_children ) {
179 auto res = node_decisions[daughter->getNodeIndex()];
180 if ( -1 == res ) {
181 daughter->promoteToControlReadyState( slotNum, states, node_decisions );
182 if ( m_modePromptDecision ) return true;
183 } else if ( m_modePromptDecision ) {
184 if ( ( false == m_modeOR && res == 0 ) || ( true == m_modeOR && res == 1 ) ) return true;
185 }
186 }
187
188 return true;
189 }
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133
concurrency::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: PrecedenceRulesGraph.h:128
concurrency::ControlFlowNode::m_nodeIndex
unsigned int m_nodeIndex
Definition: PrecedenceRulesGraph.h:81
concurrency::DecisionNode::m_modePromptDecision
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Definition: PrecedenceRulesGraph.h:126

void concurrency::DecisionNode::updateDecision | ( | const int & | slotNum,
|  | AlgsExecutionStates & | states,
|  | std::vector< int > & | node_decisions,
|  | const AlgorithmNode * | requestor = `nullptr`
| ) |  | const
| override virtual

XXX: CF tests.

Implements concurrency::ControlFlowNode.

Definition at line 103 of file PrecedenceRulesGraph.cpp.

105 {
106
107 int decision = ( ( m_allPass && m_modePromptDecision ) ? 1 : -1 );
108 bool keepGoing = true;
109 bool hasUndecidedChild = false;
110 // std::cout << "++++++++++++++++++++BEGIN(UPDATING)++++++++++++++++++++" << std::endl;
111 // std::cout << "UPDATING DAUGHTERS of DECISION NODE: " << m_nodeName << std::endl;
112
113 for ( auto daughter : m_children ) {
114 // if prompt decision, return once result is known already or we can't fully evaluate
115 // right now because one daughter decision is missing still
116 // std::cout << "----UPDATING DAUGHTER: " << daughter->getNodeName() << std::endl;
117 if ( m_modePromptDecision && !keepGoing ) {
118 node_decisions[m_nodeIndex] = decision;
119 // std::cout << "STOPPING ITERATION OVER (UPDATING) DECISION NODE CHILDREN: " << m_nodeName << std::endl;
120 break;
121 // return;
122 }
123
124 // modified
125 int& res = node_decisions[daughter->getNodeIndex()];
126 if ( -1 == res ) {
127 hasUndecidedChild = true;
128 if ( typeid( *daughter ) != typeid( concurrency::DecisionNode ) ) {
129 auto algod = (AlgorithmNode*)daughter;
130 algod->promoteToControlReadyState( slotNum, states, node_decisions );
131 bool result = algod->promoteToDataReadyState( slotNum, requestor );
132 if ( result ) keepGoing = false;
133 } else {
134 daughter->updateDecision( slotNum, states, node_decisions, requestor );
135 }
136
137 // "and"-mode (once first result false, the overall decision is false)
138 } else if ( false == m_modeOR && res == 0 ) {
139 decision = 0;
140 keepGoing = false;
141 // "or"-mode (once first result true, the overall decision is true)
142 } else if ( true == m_modeOR && res == 1 ) {
143 decision = 1;
144 keepGoing = false;
145 }
146 }
147
148 // what to do with yet undefined answers depends on whether AND or OR mode applies
149 if ( !hasUndecidedChild && -1 == decision ) {
150 // OR mode: all results known, and none true -> reject
151 if ( true == m_modeOR ) {
152 decision = 0;
153 // AND mode: all results known, and no false -> accept
154 } else {
155 decision = 1;
156 }
157 }
158
159 // in all other cases I stay with previous decisions
160 node_decisions[m_nodeIndex] = decision;
161
162 // propagate decision upwards through the decision graph
163 if ( -1 != decision )
164 for ( auto p : m_parents ) p->updateDecision( slotNum, states, node_decisions, requestor );
165
166 // std::cout << "++++++++++++++++++++END(UPDATING)++++++++++++++++++++" << std::endl;
167 }
concurrency::DecisionNode::m_parents
std::vector< DecisionNode * > m_parents
XXX: CF tests. All direct parent nodes in the tree.
Definition: PrecedenceRulesGraph.h:135
concurrency::DecisionNode
Definition: PrecedenceRulesGraph.h:86
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133
concurrency::DecisionNode::m_allPass
bool m_allPass
Whether always passing regardless of daughter results.
Definition: PrecedenceRulesGraph.h:130
concurrency::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: PrecedenceRulesGraph.h:128
concurrency::ControlFlowNode::m_nodeIndex
unsigned int m_nodeIndex
Definition: PrecedenceRulesGraph.h:81
concurrency::DecisionNode::m_modePromptDecision
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Definition: PrecedenceRulesGraph.h:126

int concurrency::DecisionNode::updateState | ( | AlgsExecutionStates & | states,
|  | std::vector< int > & | node_decisions
| ) |  | const
| override virtual

Method to set algos to CONTROLREADY, if possible.

Implements concurrency::ControlFlowNode.

Definition at line 63 of file PrecedenceRulesGraph.cpp.

64 {
65 // check whether we already had a result earlier
66 // if (-1 != node_decisions[m_nodeIndex] ) { return node_decisions[m_nodeIndex]; }
67 int decision = ( ( m_allPass && m_modePromptDecision ) ? 1 : -1 );
68 bool hasUndecidedChild = false;
69 for ( auto daughter : m_children ) {
70 if ( m_modePromptDecision && ( -1 != decision || hasUndecidedChild ) ) {
71 node_decisions[m_nodeIndex] = decision;
72 return decision;
73 } // if prompt decision, return once result is known already or we can't fully evaluate right now because one daugther
74 // decision is missing still
75 auto res = daughter->updateState( states, node_decisions );
76 if ( -1 == res ) {
77 hasUndecidedChild = true;
78 } else if ( false == m_modeOR && res == 0 ) {
79 decision = 0;
80 } // "and"-mode (once first result false, the overall decision is false)
81 else if ( true == m_modeOR && res == 1 ) {
82 decision = 1;
83 } // "or"-mode (once first result true, the overall decision is true)
84 }
85 // what to do with yet undefined answers depends on whether AND or OR mode applies
86 if ( !hasUndecidedChild && -1 == decision ) {
87 // OR mode: all results known, and none true -> reject
88 if ( true == m_modeOR ) {
89 decision = 0;
90 }
91 // AND mode: all results known, and no false -> accept
92 else {
93 decision = 1;
94 }
95 }
96 // in all other cases I stay with previous decisions
97 node_decisions[m_nodeIndex] = decision;
98 if ( m_allPass ) decision = 1;
99 return decision;
100 }
concurrency::DecisionNode::m_children
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
Definition: PrecedenceRulesGraph.h:133
concurrency::DecisionNode::m_allPass
bool m_allPass
Whether always passing regardless of daughter results.
Definition: PrecedenceRulesGraph.h:130
concurrency::DecisionNode::m_modeOR
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
Definition: PrecedenceRulesGraph.h:128
concurrency::ControlFlowNode::m_nodeIndex
unsigned int m_nodeIndex
Definition: PrecedenceRulesGraph.h:81
concurrency::DecisionNode::m_modePromptDecision
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Definition: PrecedenceRulesGraph.h:126

## Member Data Documentation

bool concurrency::DecisionNode::m_allPass

Whether always passing regardless of daughter results.

Definition at line 130 of file PrecedenceRulesGraph.h.

std::vector<ControlFlowNode*> concurrency::DecisionNode::m_children
| private

All direct daughter nodes in the tree.

Definition at line 133 of file PrecedenceRulesGraph.h.

bool concurrency::DecisionNode::m_modeConcurrent

Whether all daughters will be evaluated concurrently or sequentially.

Definition at line 123 of file PrecedenceRulesGraph.h.

bool concurrency::DecisionNode::m_modeOR

Whether acting as "and" (false) or "or" node (true)

Definition at line 128 of file PrecedenceRulesGraph.h.

bool concurrency::DecisionNode::m_modePromptDecision

Whether to evaluate the hub decision ASA its child decisions allow to do that.

Applicable to both concurrent and sequential cases.

Definition at line 126 of file PrecedenceRulesGraph.h.

std::vector<DecisionNode*> concurrency::DecisionNode::m_parents
| private

XXX: CF tests. All direct parent nodes in the tree.

Definition at line 135 of file PrecedenceRulesGraph.h.

The documentation for this class was generated from the following files:

- GaudiHive/src/PrecedenceRulesGraph.h
- GaudiHive/src/PrecedenceRulesGraph.cpp