The Gaudi Framework  v29r0 (ff2e7097)
AlgsExecutionStates.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_ALGSEXECUTIONSTATES_H
2 #define GAUDIHIVE_ALGSEXECUTIONSTATES_H
3 
4 // Framework include files
5 #include "GaudiKernel/Service.h"
6 
7 // C++ include files
8 #include <functional>
9 #include <iterator>
10 #include <string>
11 #include <thread>
12 #include <unordered_map>
13 #include <vector>
14 
15 #include <boost/dynamic_bitset.hpp>
16 
17 //---------------------------------------------------------------------------
18 
29 {
30 public:
32  enum State : unsigned short {
33  INITIAL = 0,
35  DATAREADY = 2,
36  SCHEDULED = 3,
39  ERROR = 6
40  };
41 
43 
44  AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
45  : m_states( algsNumber, INITIAL ), m_MS( MS ){};
46 
48 
49  StatusCode updateState( unsigned int iAlgo, State newState );
50 
52 
53  bool algsPresent( State state ) const
54  {
55  return std::find( m_states.begin(), m_states.end(), state ) != m_states.end();
56  }
57 
59  {
60  int execAlgos = std::count_if( m_states.begin(), m_states.end(),
61  []( State s ) { return ( s == EVTACCEPTED || s == EVTREJECTED ); } );
62  return m_states.size() == (unsigned int)execAlgos;
63  };
64 
65  const State& operator[]( unsigned int i ) const { return m_states.at( i ); };
66 
67  size_t size() const { return m_states.size(); }
68 
69  size_t sizeOfSubset( State state ) const
70  {
71  return std::count_if( m_states.begin(), m_states.end(), [&]( State s ) { return ( s == state ); } );
72  }
73 
74 private:
77 
78 public:
79  class Iterator : public std::iterator<std::forward_iterator_tag, uint>
80  {
81 
82  public:
83  enum POS { BEGIN, END };
84 
85  Iterator( POS pos, State s, const std::vector<State>& v ) : s_( s ), v_( &v )
86  {
87  if ( pos == POS::BEGIN ) pos_ = std::find( v_->begin(), v_->end(), s_ );
88  if ( pos == POS::END ) pos_ = v_->end();
89  // std::cout << "initialized iterator at " << pos_ << std::endl;
90  }
91 
92  ~Iterator() {}
93 
94  Iterator& operator=( const Iterator& other )
95  {
96  pos_ = other.pos_;
97  v_ = other.v_;
98  s_ = other.s_;
99  return ( *this );
100  }
101 
102  bool operator==( const Iterator& other ) { return pos_ == other.pos_ && s_ == other.s_ && v_ == other.v_; }
103 
104  bool operator!=( const Iterator& other ) { return pos_ != other.pos_ || s_ != other.s_ || v_ != other.v_; }
105 
107  {
108  if ( pos_ != v_->end() ) {
109  pos_ = std::find( ++pos_, v_->end(), s_ );
110  // std::cout << "advanced iterator to " << pos_ << std::endl;
111  }
112  return ( *this );
113  }
114 
115  Iterator& operator++( int ) { return ( ++( *this ) ); }
116 
117  uint operator*() { return std::distance( v_->begin(), pos_ ); }
118 
119  private:
123  };
124 
125  Iterator begin( State kind ) { return ( Iterator( Iterator::POS::BEGIN, kind, m_states ) ); }
126 
127  Iterator end( State kind ) { return ( Iterator( Iterator::POS::END, kind, m_states ) ); }
128 };
129 
132 {
133  return s << static_cast<unsigned short>( x );
134 }
135 
136 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
bool algsPresent(State state) const
T distance(T...args)
const std::vector< State > * v_
Iterator & operator=(const Iterator &other)
AlgsExecutionStates(unsigned int algsNumber, SmartIF< IMessageSvc > MS)
T end(T...args)
size_t sizeOfSubset(State state) const
bool operator==(const Iterator &other)
T at(T...args)
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
SmartIF< IMessageSvc > m_MS
std::vector< State >::const_iterator pos_
T count_if(T...args)
const State & operator[](unsigned int i) const
T find(T...args)
T size(T...args)
T assign(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).
bool operator!=(const Iterator &other)
string s
Definition: gaudirun.py:253
State
Execution states of the algorithms.
STL class.
Iterator(POS pos, State s, const std::vector< State > &v)
static std::map< State, std::string > stateNames
Iterator end(State kind)
StatusCode updateState(unsigned int iAlgo, State newState)