| The Gaudi Framework v32r1 (f65d50dc)

AlgsExecutionStates.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_ALGSEXECUTIONSTATES_H
2 #define GAUDIHIVE_ALGSEXECUTIONSTATES_H
3
4 // Framework include files
5 #include "GaudiKernel/MsgStream.h"
6 #include "GaudiKernel/Service.h"
7
8 // C++ include files
9 #include <algorithm>
10 #include <initializer_list>
11 #include <iterator>
12 #include <string>
13 #include <vector>
14
15 //---------------------------------------------------------------------------
16
26 class AlgsExecutionStates final {
27 public:
29 enum State : uint8_t {
30 INITIAL = 0,
31 CONTROLREADY = 1,
32 DATAREADY = 2,
33 SCHEDULED = 3,
34 EVTACCEPTED = 4,
35 EVTREJECTED = 5,
36 ERROR = 6
37 };
38
39 AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
40 : m_states( algsNumber, INITIAL ), m_MS( std::move( MS ) ){};
41
42 StatusCode set( unsigned int iAlgo, State newState );
43
44 void reset() { std::fill( m_states.begin(), m_states.end(), INITIAL ); };
45
47 bool contains( State state ) const { return std::find( m_states.begin(), m_states.end(), state ) != m_states.end(); }
48
50 bool containsAny( std::initializer_list<State> l ) const {
51 return std::find_first_of( m_states.begin(), m_states.end(), l.begin(), l.end() ) != m_states.end();
52 }
53
55 bool containsOnly( std::initializer_list<State> l ) const {
56 return std::all_of( m_states.begin(), m_states.end(),
57 [l]( State s ) { return std::find( l.begin(), l.end(), s ) != l.end(); } );
58 };
59
60 const State& operator[]( unsigned int i ) const { return m_states.at( i ); };
61
62 size_t size() const { return m_states.size(); }
63
64 size_t sizeOfSubset( State state ) const {
65 return std::count_if( m_states.begin(), m_states.end(), [&]( State s ) { return s == state; } );
66 }
67
68 private:
69 std::vector<State> m_states;
70 SmartIF<IMessageSvc> m_MS;
71
72 MsgStream log() { return {m_MS, "AlgsExecutionStates"}; }
73
74 public:
75 class Iterator final : public std::iterator<std::forward_iterator_tag, uint> {
76 auto find_valid( std::vector<State>::const_iterator iter ) const { return std::find( iter, m_v->end(), m_s ); }
77
78 public:
79 Iterator( State s, const std::vector<State>& v, std::vector<State>::const_iterator pos )
80 : m_s( s ), m_v( &v ), m_pos( find_valid( pos ) ) {}
81
82 friend bool operator==( const Iterator& lhs, const Iterator& rhs ) {
83 return lhs.m_s == rhs.m_s && lhs.m_v == rhs.m_v && lhs.m_pos == rhs.m_pos;
84 }
85
86 friend bool operator!=( const Iterator& lhs, const Iterator& rhs ) { return !( lhs == rhs ); }
87
88 Iterator& operator++() {
89 if ( m_pos != m_v->end() ) m_pos = find_valid( std::next( m_pos ) );
90 return *this;
91 }
92
93 Iterator& operator++( int ) { return ++( *this ); }
94
95 uint operator*() { return std::distance( m_v->begin(), m_pos ); }
96
97 private:
98 State m_s;
99 const std::vector<State>* m_v;
100 std::vector<State>::const_iterator m_pos;
101 };
102
103 Iterator begin( State kind ) { return {kind, m_states, m_states.begin()}; }
104 Iterator end( State kind ) { return {kind, m_states, m_states.end()}; }
105 };
106
108 inline std::ostream& operator<<( std::ostream& s, AlgsExecutionStates::State x ) {
109 using State = AlgsExecutionStates::State;
110 switch ( x ) {
111 case State::INITIAL:
112 s << "INITIAL";
113 break;
114 case State::CONTROLREADY:
115 s << "CONTROLREADY";
116 break;
117 case State::DATAREADY:
118 s << "DATAREADY";
119 break;
120 case State::SCHEDULED:
121 s << "SCHEDULED";
122 break;
123 case State::EVTACCEPTED:
124 s << "EVTACCEPTED";
125 break;
126 case State::EVTREJECTED:
127 s << "EVTREJECTED";
128 break;
129 case State::ERROR:
130 s << "ERROR";
131 break;
132 default:
133 s << "UNKNOWN";
134 }
135 return s;
136 }
137
138 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
AlgsExecutionStates::Iterator::operator *
uint operator *()
Definition: AlgsExecutionStates.h:95
SmartIF< IMessageSvc >
std::distance
T distance(T... args)
AlgsExecutionStates::containsAny
bool containsAny(std::initializer_list< State > l) const
check if the collection contains at least one state of any listed types
Definition: AlgsExecutionStates.h:50
AlgsExecutionStates::ERROR
Definition: AlgsExecutionStates.h:36
MsgStream.h
AlgsExecutionStates::Iterator::m_v
const std::vector< State > * m_v
Definition: AlgsExecutionStates.h:99
AlgsExecutionStates::Iterator::Iterator
Iterator(State s, const std::vector< State > &v, std::vector< State >::const_iterator pos)
Definition: AlgsExecutionStates.h:79
std::iterator
AlgsExecutionStates::operator[]
const State & operator[](unsigned int i) const
Definition: AlgsExecutionStates.h:60
std
STL namespace.
AlgsExecutionStates::AlgsExecutionStates
AlgsExecutionStates(unsigned int algsNumber, SmartIF< IMessageSvc > MS)
Definition: AlgsExecutionStates.h:39
std::vector::end
T end(T... args)
Gaudi::StateMachine::State
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm,...
Definition: StateMachine.h:12
AlgsExecutionStates::DATAREADY
Definition: AlgsExecutionStates.h:32
AlgsExecutionStates::Iterator::operator==
friend bool operator==(const Iterator &lhs, const Iterator &rhs)
Definition: AlgsExecutionStates.h:82
Service.h
std::vector::at
T at(T... args)
AlgsExecutionStates::Iterator::m_s
State m_s
Definition: AlgsExecutionStates.h:98
AlgsExecutionStates
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Definition: AlgsExecutionStates.h:26
AlgsExecutionStates::size
size_t size() const
Definition: AlgsExecutionStates.h:62
std::next
T next(T... args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
AlgsExecutionStates::EVTREJECTED
Definition: AlgsExecutionStates.h:35
AlgsExecutionStates::sizeOfSubset
size_t sizeOfSubset(State state) const
Definition: AlgsExecutionStates.h:64
AlgsExecutionStates::set
StatusCode set(unsigned int iAlgo, State newState)
Definition: AlgsExecutionStates.cpp:13
AlgsExecutionStates::Iterator::operator++
Iterator & operator++(int)
Definition: AlgsExecutionStates.h:93
AlgsExecutionStates::EVTACCEPTED
Definition: AlgsExecutionStates.h:34
AlgsExecutionStates::m_MS
SmartIF< IMessageSvc > m_MS
Definition: AlgsExecutionStates.h:70
AlgsExecutionStates::SCHEDULED
Definition: AlgsExecutionStates.h:33
AlgsExecutionStates::Iterator::operator++
Iterator & operator++()
Definition: AlgsExecutionStates.h:88
compareRootHistos.state
def state
Definition: compareRootHistos.py:455
std::find_first_of
T find_first_of(T... args)
uint8_t
unsigned char uint8_t
Definition: instrset.h:137
AlgsExecutionStates::CONTROLREADY
Definition: AlgsExecutionStates.h:31
AlgsExecutionStates::State
State
Execution states of the algorithms.
Definition: AlgsExecutionStates.h:29
std::count_if
T count_if(T... args)
gaudirun.l
dictionary l
Definition: gaudirun.py:521
AlgsExecutionStates::Iterator
Definition: AlgsExecutionStates.h:75
AlgsExecutionStates::INITIAL
Definition: AlgsExecutionStates.h:30
std::find
T find(T... args)
AlgsExecutionStates::Iterator::find_valid
auto find_valid(std::vector< State >::const_iterator iter) const
Definition: AlgsExecutionStates.h:76
std::vector::size
T size(T... args)
std::vector< State >
AlgsExecutionStates::m_states
std::vector< State > m_states
Definition: AlgsExecutionStates.h:69
std::vector::begin
T begin(T... args)
AlgsExecutionStates::begin
Iterator begin(State kind)
Definition: AlgsExecutionStates.h:103
operator<<
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values.
Definition: AlgsExecutionStates.h:108
std::all_of
T all_of(T... args)
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:44
AlgsExecutionStates::containsOnly
bool containsOnly(std::initializer_list< State > l) const
check if the collection contains only states of listed types
Definition: AlgsExecutionStates.h:55
gaudirun.s
string s
Definition: gaudirun.py:316
MSG::ERROR
Definition: IMessageSvc.h:15
AlgsExecutionStates::Iterator::operator!=
friend bool operator!=(const Iterator &lhs, const Iterator &rhs)
Definition: AlgsExecutionStates.h:86
std::fill
T fill(T... args)
AlgsExecutionStates::Iterator::m_pos
std::vector< State >::const_iterator m_pos
Definition: AlgsExecutionStates.h:100
AlgsExecutionStates::log
MsgStream log()
Definition: AlgsExecutionStates.h:72
std::ostream
STL class.
std::initializer_list
AlgsExecutionStates::contains
bool contains(State state) const
check if the collection contains at least one state of requested type
Definition: AlgsExecutionStates.h:47
AlgsExecutionStates::end
Iterator end(State kind)
Definition: AlgsExecutionStates.h:104