| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 <vector>
9 #include <string>
10 #include <unordered_map>
11 #include <functional>
12 #include <thread>
13 #include <iterator>
14
15 #include <boost/dynamic_bitset.hpp>
16
17 //---------------------------------------------------------------------------
18
28 class AlgsExecutionStates{
29 public:
30
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),
46 m_MS(MS) { };
47
48 ~AlgsExecutionStates(){};
49
50 StatusCode updateState(unsigned int iAlgo,State newState);
51
52 void reset(){m_states.assign(m_states.size(),INITIAL);};
53
54 bool algsPresent(State state) const{
55 return std::find(m_states.begin(),m_states.end(),state)!=m_states.end();
56 }
57
58 bool allAlgsExecuted(){
59 int execAlgos=std::count_if(m_states.begin(),m_states.end(),[](State s) {return (s == EVTACCEPTED || s== EVTREJECTED);});
60 return m_states.size() == (unsigned int)execAlgos;
61 };
62
63 const State & operator[](unsigned int i) const {
64
65 return m_states.at(i);
66
67 };
68
69 size_t size() const {
70 return m_states.size();
71 }
72
73 size_t sizeOfSubset(State state) const {
74 return std::count_if(m_states.begin(),m_states.end(),[&](State s) {return (s == state);});
75 }
76
77 private:
78 std::vector<State> m_states;
79 SmartIF<IMessageSvc> m_MS;
80
81 public:
82 class Iterator : public std::iterator<std::forward_iterator_tag, uint> {
83
84 public:
85
86 enum POS { BEGIN, END};
87
88 Iterator(POS pos, State s, const std::vector<State> & v) : s_(s), v_(&v) {
89 if(pos == POS::BEGIN)
90 pos_ = std::find(v_->begin(),v_->end(), s_);
91 if(pos == POS::END)
92 pos_ = v_->end();
93 //std::cout << "initialized iterator at " << pos_ << std::endl;
94 }
95
96 ~Iterator() {}
97
98 Iterator& operator=(const Iterator& other){
99 pos_ = other.pos_;
100 v_ = other.v_;
101 s_ = other.s_;
102 return(*this);
103 }
104
105 bool operator==(const Iterator& other){
106 return pos_ == other.pos_ && s_ == other.s_ && v_ == other.v_;
107 }
108
109 bool operator!=(const Iterator& other){
110 return pos_ != other.pos_ || s_ != other.s_ || v_ != other.v_;
111 }
112
113 Iterator& operator++(){
114 if (pos_ != v_->end()){
115 pos_ = std::find(++pos_, v_->end(), s_);
116 //std::cout << "advanced iterator to " << pos_ << std::endl;
117 }
118 return(*this);
119 }
120
121 Iterator& operator++(int){
122 return(++(*this));
123 }
124
125 uint operator*(){
126 return std::distance(v_->begin(), pos_);
127 }
128
129 private:
130 std::vector<State>::const_iterator pos_;
131 State s_;
132 const std::vector<State> * v_;
133 };
134
135 Iterator begin(State kind)
136 {
137 return(Iterator(Iterator::POS::BEGIN, kind, m_states));
138 }
139
140 Iterator end(State kind)
141 {
142 return(Iterator(Iterator::POS::END, kind, m_states));
143 }
144
145 };
146
148 inline std::ostream& operator<<(std::ostream& s, AlgsExecutionStates::State x) {
149 return s << static_cast<unsigned short>(x);
150 }
151
152 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
AlgsExecutionStates::algsPresent
bool algsPresent(State state) const
Definition: AlgsExecutionStates.h:54
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:132
compareRootHistos.state
state
Definition: compareRootHistos.py:348
AlgsExecutionStates::Iterator::operator=
Iterator & operator=(const Iterator &other)
Definition: AlgsExecutionStates.h:98
std::iterator
AlgsExecutionStates::Iterator::~Iterator
~Iterator()
Definition: AlgsExecutionStates.h:96
AlgsExecutionStates::Iterator::operator*
uint operator*()
Definition: AlgsExecutionStates.h:125
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:73
std::map< State, std::string >
AlgsExecutionStates::SCHEDULED
Definition: AlgsExecutionStates.h:36
AlgsExecutionStates::Iterator::operator==
bool operator==(const Iterator &other)
Definition: AlgsExecutionStates.h:105
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:121
AlgsExecutionStates::m_MS
SmartIF< IMessageSvc > m_MS
Definition: AlgsExecutionStates.h:79
AlgsExecutionStates::Iterator::operator++
Iterator & operator++()
Definition: AlgsExecutionStates.h:113
AlgsExecutionStates::CONTROLREADY
Definition: AlgsExecutionStates.h:34
AlgsExecutionStates::Iterator::POS
POS
Definition: AlgsExecutionStates.h:86
AlgsExecutionStates::Iterator::pos_
std::vector< State >::const_iterator pos_
Definition: AlgsExecutionStates.h:130
AlgsExecutionStates::~AlgsExecutionStates
~AlgsExecutionStates()
Definition: AlgsExecutionStates.h:48
std::count_if
T count_if(T...args)
AlgsExecutionStates::size
size_t size() const
Definition: AlgsExecutionStates.h:69
AlgsExecutionStates::Iterator
Definition: AlgsExecutionStates.h:82
AlgsExecutionStates::operator[]
const State & operator[](unsigned int i) const
Definition: AlgsExecutionStates.h:63
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:86
AlgsExecutionStates::m_states
std::vector< State > m_states
Definition: AlgsExecutionStates.h:78
std::vector::begin
T begin(T...args)
AlgsExecutionStates::begin
Iterator begin(State kind)
Definition: AlgsExecutionStates.h:135
operator<<
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values (required by C++11 scoped enums).
Definition: AlgsExecutionStates.h:148
AlgsExecutionStates::Iterator::BEGIN
Definition: AlgsExecutionStates.h:86
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:52
AlgsExecutionStates::Iterator::s_
State s_
Definition: AlgsExecutionStates.h:131
AlgsExecutionStates::DATAREADY
Definition: AlgsExecutionStates.h:35
AlgsExecutionStates::Iterator::operator!=
bool operator!=(const Iterator &other)
Definition: AlgsExecutionStates.h:109
gaudirun.s
string s
Definition: gaudirun.py:245
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:88
AlgsExecutionStates::stateNames
static std::map< State, std::string > stateNames
Definition: AlgsExecutionStates.h:42
AlgsExecutionStates::end
Iterator end(State kind)
Definition: AlgsExecutionStates.h:140
AlgsExecutionStates::updateState
StatusCode updateState(unsigned int iAlgo, State newState)
Definition: AlgsExecutionStates.cpp:14