The Gaudi Framework  v30r2 (9eca68f7)
AlgsExecutionStates.cpp
Go to the documentation of this file.
1 #include "AlgsExecutionStates.h"
2 
3 namespace
4 {
5  constexpr auto transition( AlgsExecutionStates::State first, AlgsExecutionStates::State second )
6  {
7  static_assert( sizeof( AlgsExecutionStates::State ) == 1, "no more than 255 states please!" );
8  using ui16 = uint_fast16_t;
9  return static_cast<ui16>( first ) * 256 + static_cast<ui16>( second );
10  }
11 }
12 
13 // A simple map to easily translate a state to its name
15  {INITIAL, "INITIAL"}, {CONTROLREADY, "CONTROLREADY"}, {DATAREADY, "DATAREADY"}, {SCHEDULED, "SCHEDULED"},
16  {EVTACCEPTED, "EVTACCEPTED"}, {EVTREJECTED, "EVTREJECTED"}, {ERROR, "ERROR"}};
17 
18 StatusCode AlgsExecutionStates::updateState( unsigned int iAlgo, State newState )
19 {
20  if ( iAlgo >= m_states.size() ) {
21  log() << MSG::ERROR << "Index out of bound (" << iAlgo << " / " << m_states.size() << ")" << endmsg;
22  return StatusCode::FAILURE;
23  }
24 
25  switch ( transition( m_states[iAlgo], newState ) ) {
26  case transition( INITIAL, CONTROLREADY ): // Fallthrough
27  case transition( CONTROLREADY, DATAREADY ): // Fallthrough
28  case transition( DATAREADY, SCHEDULED ): // Fallthrough
29  case transition( SCHEDULED, EVTACCEPTED ): // Fallthrough
30  case transition( SCHEDULED, EVTREJECTED ):
31  m_states[iAlgo] = newState;
32  return StatusCode::SUCCESS;
33  default:
34  log() << MSG::ERROR << "[AlgIndex " << iAlgo << "] Transition from " << stateNames.at( m_states[iAlgo] ) << " to "
35  << stateNames.at( newState ) << " is not allowed" << endmsg;
36  m_states[iAlgo] = ERROR;
37  return StatusCode::FAILURE;
38  }
39 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
STL class.
constexpr double second
T at(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
State
Execution states of the algorithms.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T size(T...args)
std::vector< State > m_states
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
static std::map< State, std::string > stateNames
StatusCode updateState(unsigned int iAlgo, State newState)