The Gaudi Framework  v32r0 (3325bb39)
AlgsExecutionStates.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_ALGSEXECUTIONSTATES_H
2 #define GAUDIHIVE_ALGSEXECUTIONSTATES_H
3 
4 // Framework include files
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,
32  DATAREADY = 2,
34  SCHEDULED = 4,
37  ERROR = 7
38  };
39 
40  AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
41  : m_states( algsNumber, INITIAL ), m_MS( std::move( MS ) ){};
42 
43  StatusCode set( unsigned int iAlgo, State newState );
44 
46 
48  bool contains( State state ) const { return std::find( m_states.begin(), m_states.end(), state ) != m_states.end(); }
49 
52  return std::find_first_of( m_states.begin(), m_states.end(), l.begin(), l.end() ) != m_states.end();
53  }
54 
57  return std::all_of( m_states.begin(), m_states.end(),
58  [l]( State s ) { return std::find( l.begin(), l.end(), s ) != l.end(); } );
59  };
60 
61  const State& operator[]( unsigned int i ) const { return m_states.at( i ); };
62 
63  size_t size() const { return m_states.size(); }
64 
65  size_t sizeOfSubset( State state ) const {
66  return std::count_if( m_states.begin(), m_states.end(), [&]( State s ) { return s == state; } );
67  }
68 
69 private:
72 
73  MsgStream log() { return {m_MS, "AlgsExecutionStates"}; }
74 
75 public:
76  class Iterator final : public std::iterator<std::forward_iterator_tag, uint> {
77  auto find_valid( std::vector<State>::const_iterator iter ) const { return std::find( iter, m_v->end(), m_s ); }
78 
79  public:
81  : m_s( s ), m_v( &v ), m_pos( find_valid( pos ) ) {}
82 
83  friend bool operator==( const Iterator& lhs, const Iterator& rhs ) {
84  return lhs.m_s == rhs.m_s && lhs.m_v == rhs.m_v && lhs.m_pos == rhs.m_pos;
85  }
86 
87  friend bool operator!=( const Iterator& lhs, const Iterator& rhs ) { return !( lhs == rhs ); }
88 
90  if ( m_pos != m_v->end() ) m_pos = find_valid( std::next( m_pos ) );
91  return *this;
92  }
93 
94  Iterator& operator++( int ) { return ++( *this ); }
95 
96  uint operator*() { return std::distance( m_v->begin(), m_pos ); }
97 
98  private:
102  };
103 
104  Iterator begin( State kind ) { return {kind, m_states, m_states.begin()}; }
105  Iterator end( State kind ) { return {kind, m_states, m_states.end()}; }
106 };
107 
111  switch ( x ) {
112  case State::INITIAL:
113  s << "INITIAL";
114  break;
115  case State::CONTROLREADY:
116  s << "CONTROLREADY";
117  break;
118  case State::DATAREADY:
119  s << "DATAREADY";
120  break;
121  case State::RESOURCELESS:
122  s << "RESOURCELESS";
123  break;
124  case State::SCHEDULED:
125  s << "SCHEDULED";
126  break;
127  case State::EVTACCEPTED:
128  s << "EVTACCEPTED";
129  break;
130  case State::EVTREJECTED:
131  s << "EVTREJECTED";
132  break;
133  case State::ERROR:
134  s << "ERROR";
135  break;
136  default:
137  s << "UNKNOWN";
138  }
139  return s;
140 }
141 
142 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
T distance(T...args)
const std::vector< State > * m_v
Iterator(State s, const std::vector< State > &v, std::vector< State >::const_iterator pos)
STL namespace.
AlgsExecutionStates(unsigned int algsNumber, SmartIF< IMessageSvc > MS)
T end(T...args)
size_t sizeOfSubset(State state) const
bool containsOnly(std::initializer_list< State > l) const
check if the collection contains only states of listed types
auto find_valid(std::vector< State >::const_iterator iter) const
friend bool operator==(const Iterator &lhs, const Iterator &rhs)
T at(T...args)
bool containsAny(std::initializer_list< State > l) const
check if the collection contains at least one state of any listed types
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
T next(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
SmartIF< IMessageSvc > m_MS
T find_first_of(T...args)
unsigned char uint8_t
Definition: instrset.h:137
State
Execution states of the algorithms.
T count_if(T...args)
dictionary l
Definition: gaudirun.py:521
const State & operator[](unsigned int i) const
T find(T...args)
T size(T...args)
std::vector< State > m_states
T begin(T...args)
Iterator begin(State kind)
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values.
T all_of(T...args)
string s
Definition: gaudirun.py:316
friend bool operator!=(const Iterator &lhs, const Iterator &rhs)
T fill(T...args)
std::vector< State >::const_iterator m_pos
STL class.
bool contains(State state) const
check if the collection contains at least one state of requested type
Iterator end(State kind)