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 
29 public:
30 
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),
46  m_MS(MS) { };
47 
49 
50  StatusCode updateState(unsigned int iAlgo,State newState);
51 
53 
54  bool algsPresent(State state) const{
56  }
57 
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:
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 
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 
122  return(++(*this));
123  }
124 
125  uint operator*(){
126  return std::distance(v_->begin(), pos_);
127  }
128 
129  private:
133  };
134 
136  {
137  return(Iterator(Iterator::POS::BEGIN, kind, m_states));
138  }
139 
141  {
142  return(Iterator(Iterator::POS::END, kind, m_states));
143  }
144 
145 };
146 
149  return s << static_cast<unsigned short>(x);
150 }
151 
152 #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:26
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:245
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)