The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
AlgsExecutionStates.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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#pragma once
12
13// Framework include files
15#include <GaudiKernel/Service.h>
16
17// C++ include files
18#include <algorithm>
19#include <initializer_list>
20#include <string>
21#include <vector>
22
23// Boost include files
24#include <boost/container/flat_set.hpp>
25
26//---------------------------------------------------------------------------
27
38public:
41 enum State : uint8_t {
49 ERROR = 7,
50 MAXVALUE = 8 // Allows loop over all states
51 };
52
53 AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
54 : m_states( algsNumber, INITIAL ), m_algsInState( MAXVALUE ), m_MS( std::move( MS ) ) {
55
56 m_algsInState[INITIAL].reserve( algsNumber );
57 for ( unsigned int i = 0; i < algsNumber; ++i ) m_algsInState[INITIAL].insert( i );
58 }
59
60 StatusCode set( unsigned int iAlgo, State newState );
61
62 void reset() {
63 std::fill( m_states.begin(), m_states.end(), INITIAL );
64
65 for ( auto& algs : m_algsInState ) algs.clear();
66 m_algsInState[INITIAL].reserve( m_states.size() );
67 for ( unsigned int i = 0; i < m_states.size(); ++i ) m_algsInState[INITIAL].insert( i );
68 }
69
71 bool contains( State state ) const { return m_algsInState[state].size() > 0; }
72
74 bool containsAny( std::initializer_list<State> l ) const {
75 for ( auto state : l )
76 if ( m_algsInState[state].size() > 0 ) return true;
77 return false;
78 }
79
80 // copy the current set of algs in a particular state
81 // states change during scheduler loop over set, so cannot return reference
82 const boost::container::flat_set<int> algsInState( State state ) const { return m_algsInState[state]; }
83
84 const State& operator[]( unsigned int i ) const { return m_states.at( i ); }
85
86 size_t size() const { return m_states.size(); }
87
88 size_t sizeOfSubset( State state ) const { return m_algsInState[state].size(); }
89
90private:
91 std::vector<State> m_states;
92 std::vector<boost::container::flat_set<int>> m_algsInState;
94
95 MsgStream log() { return { m_MS, "AlgsExecutionStates" }; }
96};
97
99inline std::ostream& operator<<( std::ostream& s, AlgsExecutionStates::State x ) {
100 using State = AlgsExecutionStates::State;
101 switch ( x ) {
102 case State::INITIAL:
103 s << "INITIAL";
104 break;
105 case State::CONTROLREADY:
106 s << "CONTROLREADY";
107 break;
108 case State::DATAREADY:
109 s << "DATAREADY";
110 break;
111 case State::RESOURCELESS:
112 s << "RESOURCELESS";
113 break;
114 case State::SCHEDULED:
115 s << "SCHEDULED";
116 break;
117 case State::EVTACCEPTED:
118 s << "EVTACCEPTED";
119 break;
120 case State::EVTREJECTED:
121 s << "EVTREJECTED";
122 break;
123 case State::ERROR:
124 s << "ERROR";
125 break;
126 default:
127 s << "UNKNOWN";
128 }
129 return s;
130}
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values.
AlgsExecutionStates(unsigned int algsNumber, SmartIF< IMessageSvc > MS)
const State & operator[](unsigned int i) const
const boost::container::flat_set< int > algsInState(State state) const
std::vector< State > m_states
std::vector< boost::container::flat_set< int > > m_algsInState
size_t sizeOfSubset(State state) const
bool contains(State state) const
check if the collection contains at least one state of requested type
State
Execution states of the algorithms Must have contiguous integer values 0, 1... N.
bool containsAny(std::initializer_list< State > l) const
check if the collection contains at least one state of any listed types
StatusCode set(unsigned int iAlgo, State newState)
SmartIF< IMessageSvc > m_MS
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
STL namespace.