Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
33  SCHEDULED = 3,
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 
45 
47  bool contains( State state ) const { return std::find( m_states.begin(), m_states.end(), state ) != m_states.end(); }
48 
51  return std::find_first_of( m_states.begin(), m_states.end(), l.begin(), l.end() ) != m_states.end();
52  }
53 
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:
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:
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 
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:
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 
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
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:517
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:312
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)