The Gaudi Framework  master (37c0b60a)
AlgsExecutionStates.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "AlgsExecutionStates.h"
12 
13 #include <cstdint>
14 
15 namespace {
16  constexpr auto transition( AlgsExecutionStates::State first, AlgsExecutionStates::State second ) {
17  static_assert( sizeof( AlgsExecutionStates::State ) == 1, "no more than 255 states please!" );
18  using ui16 = uint_fast16_t;
19  return static_cast<ui16>( first ) * 256 + static_cast<ui16>( second );
20  }
21 } // namespace
22 
23 StatusCode AlgsExecutionStates::set( unsigned int iAlgo, State newState ) {
24  if ( iAlgo >= m_states.size() ) {
25  log() << MSG::ERROR << "Index out of bound (" << iAlgo << " / " << m_states.size() << ")" << endmsg;
26  return StatusCode::FAILURE;
27  }
28 
29  State oldState = m_states[iAlgo];
30 
31  // Allow cycling of a single state
32  if ( oldState == newState ) return StatusCode::SUCCESS;
33 
34  switch ( transition( oldState, newState ) ) {
35  case transition( INITIAL, CONTROLREADY ):
36  [[fallthrough]];
37  case transition( CONTROLREADY, DATAREADY ):
38  [[fallthrough]];
39  case transition( DATAREADY, SCHEDULED ):
40  [[fallthrough]];
41  case transition( DATAREADY, RESOURCELESS ):
42  [[fallthrough]];
43  case transition( RESOURCELESS, SCHEDULED ):
44  [[fallthrough]];
45  case transition( SCHEDULED, ERROR ):
46  [[fallthrough]];
47  case transition( SCHEDULED, EVTACCEPTED ):
48  [[fallthrough]];
49  case transition( SCHEDULED, EVTREJECTED ):
50  m_states[iAlgo] = newState;
51  m_algsInState[oldState].erase( iAlgo );
52  m_algsInState[newState].insert( iAlgo );
53  return StatusCode::SUCCESS;
54  default:
55  log() << MSG::ERROR << "[AlgIndex " << iAlgo << "] Transition from " << m_states[iAlgo] << " to " << newState
56  << " is not allowed" << endmsg;
57  m_states[iAlgo] = ERROR;
58  m_algsInState[oldState].erase( iAlgo );
59  m_algsInState[ERROR].insert( iAlgo );
60  return StatusCode::FAILURE;
61  }
62 }
AlgsExecutionStates::m_algsInState
std::vector< boost::container::flat_set< int > > m_algsInState
Definition: AlgsExecutionStates.h:93
std::vector::size
T size(T... args)
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:139
AlgsExecutionStates::CONTROLREADY
@ CONTROLREADY
Definition: AlgsExecutionStates.h:44
AlgsExecutionStates.h
AlgsExecutionStates::RESOURCELESS
@ RESOURCELESS
Definition: AlgsExecutionStates.h:46
AlgsExecutionStates::log
MsgStream log()
Definition: AlgsExecutionStates.h:96
AlgsExecutionStates::ERROR
@ ERROR
Definition: AlgsExecutionStates.h:50
StatusCode
Definition: StatusCode.h:65
AlgsExecutionStates::m_states
std::vector< State > m_states
Definition: AlgsExecutionStates.h:92
AlgsExecutionStates::SCHEDULED
@ SCHEDULED
Definition: AlgsExecutionStates.h:47
std::vector::erase
T erase(T... args)
AlgsExecutionStates::EVTREJECTED
@ EVTREJECTED
Definition: AlgsExecutionStates.h:49
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
AlgsExecutionStates::set
StatusCode set(unsigned int iAlgo, State newState)
Definition: AlgsExecutionStates.cpp:23
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::vector::insert
T insert(T... args)
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
AlgsExecutionStates::DATAREADY
@ DATAREADY
Definition: AlgsExecutionStates.h:45
AlgsExecutionStates::State
State
Execution states of the algorithms Must have contiguous integer values 0, 1...
Definition: AlgsExecutionStates.h:42
AlgsExecutionStates::EVTACCEPTED
@ EVTACCEPTED
Definition: AlgsExecutionStates.h:48
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
AlgsExecutionStates::INITIAL
@ INITIAL
Definition: AlgsExecutionStates.h:43