The Gaudi Framework  v30r3 (a5ef0a68)
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 
27 {
28 public:
30  enum State : uint8_t {
31  INITIAL = 0,
33  DATAREADY = 2,
34  SCHEDULED = 3,
37  ERROR = 6
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  {
53  return std::find_first_of( m_states.begin(), m_states.end(), l.begin(), l.end() ) != m_states.end();
54  }
55 
58  {
59  return std::all_of( m_states.begin(), m_states.end(),
60  [l]( State s ) { return std::find( l.begin(), l.end(), s ) != l.end(); } );
61  };
62 
63  const State& operator[]( unsigned int i ) const { return m_states.at( i ); };
64 
65  size_t size() const { return m_states.size(); }
66 
67  size_t sizeOfSubset( State state ) const
68  {
69  return std::count_if( m_states.begin(), m_states.end(), [&]( State s ) { return s == state; } );
70  }
71 
72 private:
75 
76  MsgStream log() { return {m_MS, "AlgsExecutionStates"}; }
77 
78 public:
79  class Iterator final : public std::iterator<std::forward_iterator_tag, uint>
80  {
81  auto find_valid( std::vector<State>::const_iterator iter ) const { return std::find( iter, m_v->end(), m_s ); }
82 
83  public:
85  : m_s( s ), m_v( &v ), m_pos( find_valid( pos ) )
86  {
87  }
88 
89  friend bool operator==( const Iterator& lhs, const Iterator& rhs )
90  {
91  return lhs.m_s == rhs.m_s && lhs.m_v == rhs.m_v && lhs.m_pos == rhs.m_pos;
92  }
93 
94  friend bool operator!=( const Iterator& lhs, const Iterator& rhs ) { return !( lhs == rhs ); }
95 
97  {
98  if ( m_pos != m_v->end() ) m_pos = find_valid( std::next( m_pos ) );
99  return *this;
100  }
101 
102  Iterator& operator++( int ) { return ++( *this ); }
103 
104  uint operator*() { return std::distance( m_v->begin(), m_pos ); }
105 
106  private:
110  };
111 
112  Iterator begin( State kind ) { return {kind, m_states, m_states.begin()}; }
113  Iterator end( State kind ) { return {kind, m_states, m_states.end()}; }
114 };
115 
118 {
120  switch ( x ) {
121  case State::INITIAL:
122  s << "INITIAL";
123  break;
124  case State::CONTROLREADY:
125  s << "CONTROLREADY";
126  break;
127  case State::DATAREADY:
128  s << "DATAREADY";
129  break;
130  case State::SCHEDULED:
131  s << "SCHEDULED";
132  break;
133  case State::EVTACCEPTED:
134  s << "EVTACCEPTED";
135  break;
136  case State::EVTREJECTED:
137  s << "EVTREJECTED";
138  break;
139  case State::ERROR:
140  s << "ERROR";
141  break;
142  default:
143  s << "UNKNOWN";
144  }
145  return s;
146 }
147 
148 #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:51
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:440
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:253
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)