The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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
15namespace {
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
23StatusCode 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;
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 );
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 );
61 }
62}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
std::vector< State > m_states
std::vector< boost::container::flat_set< int > > m_algsInState
State
Execution states of the algorithms Must have contiguous integer values 0, 1... N.
StatusCode set(unsigned int iAlgo, State newState)
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ ERROR
Definition IMessageSvc.h:22