The Gaudi Framework  v32r0 (3325bb39)
AlgsExecutionStates.cpp
Go to the documentation of this file.
1 #include "AlgsExecutionStates.h"
2 
3 #include <cstdint>
4 
5 namespace {
6  constexpr auto transition( AlgsExecutionStates::State first, AlgsExecutionStates::State second ) {
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 } // namespace
12 
13 StatusCode AlgsExecutionStates::set( unsigned int iAlgo, State newState ) {
14  if ( iAlgo >= m_states.size() ) {
15  log() << MSG::ERROR << "Index out of bound (" << iAlgo << " / " << m_states.size() << ")" << endmsg;
16  return StatusCode::FAILURE;
17  }
18 
19  // Allow cycling of a single state
20  if ( m_states[iAlgo] == newState ) return StatusCode::SUCCESS;
21 
22  switch ( transition( m_states[iAlgo], newState ) ) {
23  case transition( INITIAL, CONTROLREADY ):
24  [[fallthrough]];
25  case transition( CONTROLREADY, DATAREADY ):
26  [[fallthrough]];
27  case transition( DATAREADY, SCHEDULED ):
28  [[fallthrough]];
29  case transition( DATAREADY, RESOURCELESS ):
30  [[fallthrough]];
31  case transition( RESOURCELESS, SCHEDULED ):
32  [[fallthrough]];
33  case transition( SCHEDULED, ERROR ):
34  [[fallthrough]];
35  case transition( SCHEDULED, EVTACCEPTED ):
36  [[fallthrough]];
37  case transition( SCHEDULED, EVTREJECTED ):
38  m_states[iAlgo] = newState;
39  return StatusCode::SUCCESS;
40  default:
41  log() << MSG::ERROR << "[AlgIndex " << iAlgo << "] Transition from " << m_states[iAlgo] << " to " << newState
42  << " is not allowed" << endmsg;
43  m_states[iAlgo] = ERROR;
44  return StatusCode::FAILURE;
45  }
46 }
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
constexpr double second
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode set(unsigned int iAlgo, State newState)
State
Execution states of the algorithms.
T size(T...args)
std::vector< State > m_states
constexpr static const auto FAILURE
Definition: StatusCode.h:86
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192