The Gaudi Framework  v30r1 (5d4f4ae2)
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 153 of file PRGraphVisitors.cpp.

154  {
155 
156  bool foundNonResolvedChild = false;
157  bool foundNegativeChild = false;
158  bool foundPositiveChild = false;
159  int decision = -1;
160 
161  // If currently in a sub-slot, leave it if you've got to the exit
162  if ( m_slot->parentSlot && m_slot->entryPoint == node.getNodeName() ) m_slot = m_slot->parentSlot;
163 
164  // If children are in sub-slots, loop over all
165  auto searchResult = m_slot->subSlotsByNode.find( node.getNodeName() );
166  if ( searchResult != m_slot->subSlotsByNode.end() ) {
167  bool breakout = false;
168  for ( unsigned int slotIndex : searchResult->second ) {
169 
170  // Enter the sub-slot
171  m_slot = &( m_slot->allSubSlots[slotIndex] );
172 
173  for ( auto child : node.getDaughters() ) {
174 
175  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
176 
177  if ( childDecision == -1 )
178  foundNonResolvedChild = true;
179  else if ( childDecision == 1 )
180  foundPositiveChild = true;
181  else
182  foundNegativeChild = true;
183 
184  if ( node.m_modePromptDecision ) {
185  if ( node.m_modeOR && foundPositiveChild ) {
186  decision = 1;
187  breakout = true;
188  break;
189  } else if ( !node.m_modeOR && foundNegativeChild ) {
190  decision = 0;
191  breakout = true;
192  break;
193  }
194  } else {
195  if ( foundNonResolvedChild ) {
196  breakout = true;
197  break;
198  }
199  }
200  }
201 
202  // Leave the sub-slot
204  if ( breakout ) break;
205  }
206  } else {
207  for ( auto child : node.getDaughters() ) {
208  int& childDecision = m_slot->controlFlowState[child->getNodeIndex()];
209 
210  if ( childDecision == -1 )
211  foundNonResolvedChild = true;
212  else if ( childDecision == 1 )
213  foundPositiveChild = true;
214  else
215  foundNegativeChild = true;
216 
217  if ( node.m_modePromptDecision ) {
218  if ( node.m_modeOR && foundPositiveChild ) {
219  decision = 1;
220  break;
221  } else if ( !node.m_modeOR && foundNegativeChild ) {
222  decision = 0;
223  break;
224  }
225  } else {
226  if ( foundNonResolvedChild ) break;
227  }
228  }
229  } // end monitoring children
230 
231  if ( !foundNonResolvedChild && decision == -1 ) {
232  if ( node.m_modeOR ) { // OR
233  if ( foundPositiveChild )
234  decision = 1;
235  else
236  decision = 0;
237  } else { // AND
238  if ( foundNegativeChild )
239  decision = 0;
240  else
241  decision = 1;
242  }
243  }
244 
245  if ( node.m_inverted && decision == 1 )
246  decision = 0;
247  else if ( node.m_inverted && decision == 0 )
248  decision = 1;
249 
250  if ( node.m_allPass && !foundNonResolvedChild ) decision = 1;
251 
252  if ( decision != -1 ) {
253  m_slot->controlFlowState[node.getNodeIndex()] = decision;
254  return true;
255  }
256 
257  // if no decision can be made yet, request further information downwards
258  // Enter subslots for children if needed
259  if ( searchResult != m_slot->subSlotsByNode.end() ) {
260  for ( unsigned int slotIndex : searchResult->second ) {
261 
262  // Enter sub-slot
263  m_slot = &( m_slot->allSubSlots[slotIndex] );
264 
265  for ( auto child : node.getDaughters() ) {
266  bool result = child->accept( *this );
267  if ( !node.m_modeConcurrent )
268  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
269  }
270 
271  // Leave sub-slot
273  }
274  } else {
275  for ( auto child : node.getDaughters() ) {
276  bool result = child->accept( *this );
277  if ( !node.m_modeConcurrent )
278  if ( result ) break; // stop on first unresolved child if its decision hub is sequential
279  }
280  }
281 
282  return false;
283  }
T end(T...args)
std::string entryPoint
Name of the node this slot is attached to ("" for top level)
Definition: EventSlot.h:58
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:54
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:60
std::map< std::string, std::vector< unsigned int > > subSlotsByNode
Listing of sub-slots by the node (name) they are attached to.
Definition: EventSlot.h:56
T find(T...args)
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
Definition: EventSlot.h:66
bool concurrency::Supervisor::visit ( AlgorithmNode node)
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 294 of file PRGraphVisitors.cpp.

295  {
296 
297  bool result = false;
298 
299  auto& states = m_slot->algsStates;
300  auto& state = states[node.getAlgoIndex()];
301 
302  // Promote with INITIAL->CR
303  if ( State::INITIAL == state ) states.updateState( node.getAlgoIndex(), State::CONTROLREADY ).ignore();
304 
305  // Try to promote with CR->DR
306  if ( State::CONTROLREADY == state ) {
307  auto promoter = DataReadyPromoter( *m_slot, m_cause, m_trace );
308  result = promoter.visit( node );
309  } else {
310  result = true;
311  }
312 
313  // return true only when an algorithm is not lower than DR in its FSM
314  // i.e., the visitor has done everything it could with this algorithm
315  return result;
316  }
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:50
bool concurrency::Supervisor::visitEnter ( DecisionNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 145 of file PRGraphVisitors.cpp.

146  {
147 
148  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
149  return true;
150  }
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:54
bool concurrency::Supervisor::visitEnter ( AlgorithmNode node) const
overridevirtual

Reimplemented from concurrency::IGraphVisitor.

Definition at line 286 of file PRGraphVisitors.cpp.

287  {
288 
289  if ( m_slot->controlFlowState[node.getNodeIndex()] != -1 ) return false;
290  return true;
291  }
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:54

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: