The Gaudi Framework  v33r0 (d5ea422b)
AlgsExecutionStates.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIHIVE_ALGSEXECUTIONSTATES_H
12 #define GAUDIHIVE_ALGSEXECUTIONSTATES_H
13 
14 // Framework include files
15 #include "GaudiKernel/MsgStream.h"
16 #include "GaudiKernel/Service.h"
17 
18 // C++ include files
19 #include <algorithm>
20 #include <initializer_list>
21 #include <iterator>
22 #include <string>
23 #include <vector>
24 
25 //---------------------------------------------------------------------------
26 
36 class AlgsExecutionStates final {
37 public:
39  enum State : uint8_t {
40  INITIAL = 0,
42  DATAREADY = 2,
44  SCHEDULED = 4,
47  ERROR = 7
48  };
49 
50  AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
51  : m_states( algsNumber, INITIAL ), m_MS( std::move( MS ) ){};
52 
53  StatusCode set( unsigned int iAlgo, State newState );
54 
56 
58  bool contains( State state ) const { return std::find( m_states.begin(), m_states.end(), state ) != m_states.end(); }
59 
62  return std::find_first_of( m_states.begin(), m_states.end(), l.begin(), l.end() ) != m_states.end();
63  }
64 
67  return std::all_of( m_states.begin(), m_states.end(),
68  [l]( State s ) { return std::find( l.begin(), l.end(), s ) != l.end(); } );
69  };
70 
71  const State& operator[]( unsigned int i ) const { return m_states.at( i ); };
72 
73  size_t size() const { return m_states.size(); }
74 
75  size_t sizeOfSubset( State state ) const {
76  return std::count_if( m_states.begin(), m_states.end(), [&]( State s ) { return s == state; } );
77  }
78 
79 private:
82 
83  MsgStream log() { return {m_MS, "AlgsExecutionStates"}; }
84 
85 public:
86  class Iterator final : public std::iterator<std::forward_iterator_tag, uint> {
87  auto find_valid( std::vector<State>::const_iterator iter ) const { return std::find( iter, m_v->end(), m_s ); }
88 
89  public:
91  : m_s( s ), m_v( &v ), m_pos( find_valid( pos ) ) {}
92 
93  friend bool operator==( const Iterator& lhs, const Iterator& rhs ) {
94  return lhs.m_s == rhs.m_s && lhs.m_v == rhs.m_v && lhs.m_pos == rhs.m_pos;
95  }
96 
97  friend bool operator!=( const Iterator& lhs, const Iterator& rhs ) { return !( lhs == rhs ); }
98 
100  if ( m_pos != m_v->end() ) m_pos = find_valid( std::next( m_pos ) );
101  return *this;
102  }
103 
104  Iterator& operator++( int ) { return ++( *this ); }
105 
106  uint operator*() { return std::distance( m_v->begin(), m_pos ); }
107 
108  private:
112  };
113 
114  Iterator begin( State kind ) { return {kind, m_states, m_states.begin()}; }
115  Iterator end( State kind ) { return {kind, m_states, m_states.end()}; }
116 };
117 
121  switch ( x ) {
122  case State::INITIAL:
123  s << "INITIAL";
124  break;
125  case State::CONTROLREADY:
126  s << "CONTROLREADY";
127  break;
128  case State::DATAREADY:
129  s << "DATAREADY";
130  break;
131  case State::RESOURCELESS:
132  s << "RESOURCELESS";
133  break;
134  case State::SCHEDULED:
135  s << "SCHEDULED";
136  break;
137  case State::EVTACCEPTED:
138  s << "EVTACCEPTED";
139  break;
140  case State::EVTREJECTED:
141  s << "EVTREJECTED";
142  break;
143  case State::ERROR:
144  s << "ERROR";
145  break;
146  default:
147  s << "UNKNOWN";
148  }
149  return s;
150 }
151 
152 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
T distance(T... args)
bool containsAny(std::initializer_list< State > l) const
check if the collection contains at least one state of any listed types
const std::vector< State > * m_v
Iterator(State s, const std::vector< State > &v, std::vector< State >::const_iterator pos)
const State & operator[](unsigned int i) const
STL namespace.
AlgsExecutionStates(unsigned int algsNumber, SmartIF< IMessageSvc > MS)
T end(T... args)
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm,...
Definition: StateMachine.h:22
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:61
size_t sizeOfSubset(State state) const
StatusCode set(unsigned int iAlgo, State newState)
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:543
T find(T... args)
auto find_valid(std::vector< State >::const_iterator iter) const
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)
bool containsOnly(std::initializer_list< State > l) const
check if the collection contains only states of listed types
string s
Definition: gaudirun.py:328
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)