| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
28 class AlgsExecutionStates
29 {
30 public:
32 enum State : unsigned short {
33 INITIAL = 0,
34 CONTROLREADY = 1,
35 DATAREADY = 2,
36 SCHEDULED = 3,
37 EVTACCEPTED = 4,
38 EVTREJECTED = 5,
39 ERROR = 6
40 };
41
42 static std::map<State, std::string> stateNames;
43
44 AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
45 : m_states( algsNumber, INITIAL ), m_MS( MS ){};
46
47 ~AlgsExecutionStates(){};
48
49 StatusCode updateState( unsigned int iAlgo, State newState );
50
51 void reset() { m_states.assign( m_states.size(), INITIAL ); };
52
53 bool algsPresent( State state ) const
54 {
55 return std::find( m_states.begin(), m_states.end(), state ) != m_states.end();
56 }
57
58 bool allAlgsExecuted()
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:
75 std::vector<State> m_states;
76 SmartIF<IMessageSvc> m_MS;
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
106 Iterator& operator++()
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:
120 std::vector<State>::const_iterator pos_;
121 State s_;
122 const std::vector<State>* v_;
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
131 inline std::ostream& operator<<( std::ostream& s, AlgsExecutionStates::State x )
132 {
133 return s << static_cast<unsigned short>( x );
134 }
135
136 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
AlgsExecutionStates::algsPresent
bool algsPresent(State state) const
Definition: AlgsExecutionStates.h:53
SmartIF< IMessageSvc >
AlgsExecutionStates::ERROR
Definition: AlgsExecutionStates.h:39
std::distance
T distance(T...args)
AlgsExecutionStates::Iterator::v_
const std::vector< State > * v_
Definition: AlgsExecutionStates.h:122
compareRootHistos.state
state
Definition: compareRootHistos.py:424
AlgsExecutionStates::Iterator::operator=
Iterator & operator=(const Iterator &other)
Definition: AlgsExecutionStates.h:94
std::iterator
AlgsExecutionStates::Iterator::~Iterator
~Iterator()
Definition: AlgsExecutionStates.h:92
AlgsExecutionStates::Iterator::operator*
uint operator*()
Definition: AlgsExecutionStates.h:117
AlgsExecutionStates::AlgsExecutionStates
AlgsExecutionStates(unsigned int algsNumber, SmartIF< IMessageSvc > MS)
Definition: AlgsExecutionStates.h:44
std::vector::end
T end(T...args)
AlgsExecutionStates::allAlgsExecuted
bool allAlgsExecuted()
Definition: AlgsExecutionStates.h:58
AlgsExecutionStates::sizeOfSubset
size_t sizeOfSubset(State state) const
Definition: AlgsExecutionStates.h:69
std::map< State, std::string >
AlgsExecutionStates::SCHEDULED
Definition: AlgsExecutionStates.h:36
AlgsExecutionStates::Iterator::operator==
bool operator==(const Iterator &other)
Definition: AlgsExecutionStates.h:102
Service.h
std::vector::at
T at(T...args)
AlgsExecutionStates::EVTACCEPTED
Definition: AlgsExecutionStates.h:37
AlgsExecutionStates
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
Definition: AlgsExecutionStates.h:28
AlgsExecutionStates::INITIAL
Definition: AlgsExecutionStates.h:33
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
AlgsExecutionStates::Iterator::operator++
Iterator & operator++(int)
Definition: AlgsExecutionStates.h:115
AlgsExecutionStates::m_MS
SmartIF< IMessageSvc > m_MS
Definition: AlgsExecutionStates.h:76
AlgsExecutionStates::Iterator::operator++
Iterator & operator++()
Definition: AlgsExecutionStates.h:106
AlgsExecutionStates::CONTROLREADY
Definition: AlgsExecutionStates.h:34
AlgsExecutionStates::Iterator::POS
POS
Definition: AlgsExecutionStates.h:83
AlgsExecutionStates::Iterator::pos_
std::vector< State >::const_iterator pos_
Definition: AlgsExecutionStates.h:120
AlgsExecutionStates::~AlgsExecutionStates
~AlgsExecutionStates()
Definition: AlgsExecutionStates.h:47
std::count_if
T count_if(T...args)
AlgsExecutionStates::size
size_t size() const
Definition: AlgsExecutionStates.h:67
AlgsExecutionStates::Iterator
Definition: AlgsExecutionStates.h:79
AlgsExecutionStates::operator[]
const State & operator[](unsigned int i) const
Definition: AlgsExecutionStates.h:65
std::find
T find(T...args)
std::vector::size
T size(T...args)
std::vector::assign
T assign(T...args)
std::vector< State >
AlgsExecutionStates::Iterator::END
Definition: AlgsExecutionStates.h:83
AlgsExecutionStates::m_states
std::vector< State > m_states
Definition: AlgsExecutionStates.h:75
std::vector::begin
T begin(T...args)
AlgsExecutionStates::begin
Iterator begin(State kind)
Definition: AlgsExecutionStates.h:125
operator<<
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values (required by C++11 scoped enums).
Definition: AlgsExecutionStates.h:131
AlgsExecutionStates::Iterator::BEGIN
Definition: AlgsExecutionStates.h:83
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:51
AlgsExecutionStates::Iterator::s_
State s_
Definition: AlgsExecutionStates.h:121
AlgsExecutionStates::DATAREADY
Definition: AlgsExecutionStates.h:35
AlgsExecutionStates::Iterator::operator!=
bool operator!=(const Iterator &other)
Definition: AlgsExecutionStates.h:104
gaudirun.s
string s
Definition: gaudirun.py:253
AlgsExecutionStates::EVTREJECTED
Definition: AlgsExecutionStates.h:38
AlgsExecutionStates::State
State
Execution states of the algorithms.
Definition: AlgsExecutionStates.h:32
std::ostream
STL class.
AlgsExecutionStates::Iterator::Iterator
Iterator(POS pos, State s, const std::vector< State > &v)
Definition: AlgsExecutionStates.h:85
AlgsExecutionStates::stateNames
static std::map< State, std::string > stateNames
Definition: AlgsExecutionStates.h:42
AlgsExecutionStates::end
Iterator end(State kind)
Definition: AlgsExecutionStates.h:127
AlgsExecutionStates::updateState
StatusCode updateState(unsigned int iAlgo, State newState)
Definition: AlgsExecutionStates.cpp:8