The Gaudi Framework  v30r3 (a5ef0a68)
concurrency::Supervisor Class Reference

#include <src/PRGraphVisitors.h>

Inheritance diagram for concurrency::Supervisor:
Collaboration diagram for concurrency::Supervisor:

Public Member Functions

 Supervisor (EventSlot &slot, const Cause &cause, bool ifTrace=false)
 Constructor. More...
 
bool visitEnter (DecisionNode &) const override
 
bool visit (DecisionNode &) override
 
bool visitEnter (AlgorithmNode &) const override
 
bool visit (AlgorithmNode &) override
 
- Public Member Functions inherited from concurrency::IGraphVisitor
virtual ~IGraphVisitor ()=default
 
virtual bool visitEnter (DataNode &) const
 
virtual bool visit (DataNode &)
 
virtual bool visitEnter (ConditionNode &) const
 
virtual bool visit (ConditionNode &)
 
virtual void reset ()
 

Public Attributes

EventSlotm_slot
 
Cause m_cause
 
bool m_trace
 

Detailed Description

Definition at line 54 of file PRGraphVisitors.h.

Constructor & Destructor Documentation

concurrency::Supervisor::Supervisor ( EventSlot slot,
const Cause cause,
bool  ifTrace = false 
)
inline

Constructor.

Definition at line 58 of file PRGraphVisitors.h.

59  : m_slot( &slot ), m_cause( cause ), m_trace( ifTrace ){};

Member Function Documentation

bool concurrency::Supervisor::visit ( DecisionNode node)
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 179 of file PRGraphVisitors.cpp.

180  {
181 
182  bool foundNonResolvedChild = false;
183  bool foundNegativeChild = false;
184  bool foundPositiveChild = false;
185  int decision = -1;
186 
187  // Leave a sub-slot if this is the exit node
188  EventSlot* oldSlot = nullptr;
189  if ( m_slot->parentSlot && m_slot->entryPoint == node.getNodeName() ) {
190  oldSlot = m_slot;
192  }
193 
194  // If children are in sub-slots, loop over all
195  auto searchResult = m_slot->subSlotsByNode.find( node.getNodeName() );
196  if ( searchResult != m_slot->subSlotsByNode.end() ) {
197  bool breakout = false;
198  for ( unsigned int slotIndex : searchResult->second ) {
199 
200  // Enter the sub-slot
201  m_slot = &( m_slot->allSubSlots[slotIndex] );
202 
203  for ( auto child : node.getDaughters() ) {
204 
205  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
206 
207  if ( childDecision == -1 )
208  foundNonResolvedChild = true;
209  else if ( childDecision == 1 )
210  foundPositiveChild = true;
211  else
212  foundNegativeChild = true;
213 
214  if ( node.m_modePromptDecision ) {
215  if ( node.m_modeOR && foundPositiveChild ) {
216  decision = 1;
217  breakout = true;
218  break;
219  } else if ( !node.m_modeOR && foundNegativeChild ) {
220  decision = 0;
221  breakout = true;
222  break;
223  }
224  } else {
225  if ( foundNonResolvedChild ) {
226  breakout = true;
227  break;
228  }
229  }
230  }
231 
232  // Leave the sub-slot
234  if ( breakout ) break;
235  }
236  } else {
237  for ( auto child : node.getDaughters() ) {
238  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
239 
240  if ( childDecision == -1 )
241  foundNonResolvedChild = true;
242  else if ( childDecision == 1 )
243  foundPositiveChild = true;
244  else
245  foundNegativeChild = true;
246 
247  if ( node.m_modePromptDecision ) {
248  if ( node.m_modeOR && foundPositiveChild ) {
249  decision = 1;
250  break;
251  } else if ( !node.m_modeOR && foundNegativeChild ) {
252  decision = 0;
253  break;
254  }
255  } else {
256  if ( foundNonResolvedChild ) break;
257  }
258  }
259  } // end monitoring children
260 
261  if ( !foundNonResolvedChild && decision == -1 ) {
262  if ( node.m_modeOR ) { // OR
263  if ( foundPositiveChild )
264  decision = 1;
265  else
266  decision = 0;
267  } else { // AND
268  if ( foundNegativeChild )
269  decision = 0;
270  else
271  decision = 1;
272  }
273  }
274 
275  if ( node.m_inverted && decision == 1 )
276  decision = 0;
277  else if ( node.m_inverted && decision == 0 )
278  decision = 1;
279 
280  if ( node.m_allPass && !foundNonResolvedChild ) decision = 1;
281 
282  if ( decision != -1 ) {
283  m_slot->controlFlowState[node.getNodeIndex()] = decision;
284 
285  // if a decision was made for this node, propagate the result upwards
286  for ( auto parent : node.m_parents ) {
287  parent->accept( *this );
288  }
289 
290  if ( oldSlot ) m_slot = oldSlot;
291  return true;
292  }
293 
294  // if no decision can be made yet, request further information downwards
295  // Enter subslots for children if needed
296  if ( searchResult != m_slot->subSlotsByNode.end() ) {
297  for ( unsigned int slotIndex : searchResult->second ) {
298 
299  // Enter sub-slot
300  m_slot = &( m_slot->allSubSlots[slotIndex] );
301 
302  for ( auto child : node.getDaughters() ) {
303  bool result = child->accept( *this );
304  if ( !node.m_modeConcurrent )
305  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
306  }
307 
308  // Leave sub-slot
310  }
311  } else {
312  for ( auto child : node.getDaughters() ) {
313  bool result = child->accept( *this );
314  if ( !node.m_modeConcurrent )
315  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
316  }
317  }
318 
319  if ( oldSlot ) m_slot = oldSlot;
320  return false;
321  }
T end(T...args)
std::string entryPoint
Name of the node this slot is attached to ("" for top level)
Definition: EventSlot.h:57
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:53
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:59
std::map< std::string, std::vector< unsigned int > > subSlotsByNode
Listing of sub-slots by the node (name) they are attached to.
Definition: EventSlot.h:55
T find(T...args)
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
Definition: EventSlot.h:63
Class representing the event slot.
Definition: EventSlot.h:10
bool concurrency::Supervisor::visit ( AlgorithmNode node)
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 332 of file PRGraphVisitors.cpp.

333  {
334 
335  bool result = false;
336 
337  auto& states = m_slot->algsStates;
338  auto& state = states[node.getAlgoIndex()];
339 
340  // Promote with INITIAL->CR
341  if ( AState::INITIAL == state ) states.set( node.getAlgoIndex(), AState::CONTROLREADY ).ignore();
342 
343  // Try to promote with CR->DR
344  if ( AState::CONTROLREADY == state ) {
345  auto promoter = DataReadyPromoter( *m_slot, m_cause, m_trace );
346  result = promoter.visit( node );
347  } else {
348  result = true;
349  }
350 
351  // return true only when an algorithm is not lower than DR in its FSM
352  // i.e., the visitor has done everything it could with this algorithm
353  return result;
354  }
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:49
bool concurrency::Supervisor::visitEnter ( DecisionNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 141 of file PRGraphVisitors.cpp.

142  {
143  // Protect against graph traversal escaping from sub-slots
144  if ( m_slot->parentSlot ) {
145  // Examine the ancestry of this node, looking for sub-slot entry point
146  bool canFindExit = false;
147  std::queue<DecisionNode*> allAncestors;
148  allAncestors.push( &node );
149  while ( allAncestors.size() ) {
150 
151  DecisionNode* thisAncestor = allAncestors.front();
152  allAncestors.pop();
153 
154  if ( thisAncestor->getNodeName() == m_slot->entryPoint ) {
155 
156  // This ancestor is the sub-slot exit
157  canFindExit = true;
158  break;
159 
160  } else {
161 
162  // Go further up the node ancestry
163  for ( auto& evenOlder : thisAncestor->m_parents ) {
164 
165  allAncestors.push( evenOlder );
166  }
167  }
168  }
169 
170  // If the sub-slot entry point is not in this node's ancestry, don't visit the node
171  if ( !canFindExit ) return false;
172  }
173 
174  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
175  return true;
176  }
T front(T...args)
T pop(T...args)
std::string entryPoint
Name of the node this slot is attached to ("" for top level)
Definition: EventSlot.h:57
T push(T...args)
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:53
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:59
T size(T...args)
STL class.
bool concurrency::Supervisor::visitEnter ( AlgorithmNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 324 of file PRGraphVisitors.cpp.

325  {
326 
327  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
328  return true;
329  }
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:53

Member Data Documentation

Cause concurrency::Supervisor::m_cause

Definition at line 73 of file PRGraphVisitors.h.

EventSlot* concurrency::Supervisor::m_slot

Definition at line 72 of file PRGraphVisitors.h.

bool concurrency::Supervisor::m_trace

Definition at line 74 of file PRGraphVisitors.h.


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