The Gaudi Framework  v30r2 (9eca68f7)
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 <cstdint>
10 #include <functional>
11 #include <iterator>
12 #include <map>
13 #include <string>
14 #include <vector>
15 
16 //---------------------------------------------------------------------------
17 
28 {
29 public:
31  enum State : uint8_t {
32  INITIAL = 0,
34  DATAREADY = 2,
35  SCHEDULED = 3,
38  ERROR = 6
39  };
40 
42 
43  AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
44  : m_states( algsNumber, INITIAL ), m_MS( std::move( MS ) ){};
45 
46  StatusCode updateState( unsigned int iAlgo, State newState );
47 
49 
50  bool algsPresent( State state ) const
51  {
52  return std::find( m_states.begin(), m_states.end(), state ) != m_states.end();
53  }
54 
56  {
57  return std::all_of( m_states.begin(), m_states.end(),
58  []( State s ) { return s == EVTACCEPTED || s == EVTREJECTED; } );
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  {
67  return std::count_if( m_states.begin(), m_states.end(), [&]( State s ) { return s == state; } );
68  }
69 
70 private:
73 
74  MsgStream log() { return {m_MS, "AlgsExecutionStates"}; }
75 
76 public:
77  class Iterator final : public std::iterator<std::forward_iterator_tag, uint>
78  {
79  auto find_valid( std::vector<State>::const_iterator iter ) const { return std::find( iter, m_v->end(), m_s ); }
80 
81  public:
83  : m_s( s ), m_v( &v ), m_pos( find_valid( pos ) )
84  {
85  }
86 
87  friend bool operator==( const Iterator& lhs, const Iterator& rhs )
88  {
89  return lhs.m_s == rhs.m_s && lhs.m_v == rhs.m_v && lhs.m_pos == rhs.m_pos;
90  }
91 
92  friend bool operator!=( const Iterator& lhs, const Iterator& rhs ) { return !( lhs == rhs ); }
93 
95  {
96  if ( m_pos != m_v->end() ) m_pos = find_valid( std::next( m_pos ) );
97  return *this;
98  }
99 
100  Iterator& operator++( int ) { return ++( *this ); }
101 
102  uint operator*() { return std::distance( m_v->begin(), m_pos ); }
103 
104  private:
108  };
109 
110  Iterator begin( State kind ) { return {kind, m_states, m_states.begin()}; }
111  Iterator end( State kind ) { return {kind, m_states, m_states.end()}; }
112 };
113 
116 {
117  return s << static_cast<std::underlying_type_t<AlgsExecutionStates::State>>( x );
118 }
119 
120 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
bool algsPresent(State state) const
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
auto find_valid(std::vector< State >::const_iterator iter) const
friend bool operator==(const Iterator &lhs, const Iterator &rhs)
T at(T...args)
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:51
SmartIF< IMessageSvc > m_MS
unsigned char uint8_t
Definition: instrset.h:137
State
Execution states of the algorithms.
T count_if(T...args)
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 (required by C++11 scoped enums).
T all_of(T...args)
string s
Definition: gaudirun.py:253
friend bool operator!=(const Iterator &lhs, const Iterator &rhs)
T fill(T...args)
std::vector< State >::const_iterator m_pos
STL class.
static std::map< State, std::string > stateNames
Iterator end(State kind)
StatusCode updateState(unsigned int iAlgo, State newState)