The Gaudi Framework  master (37c0b60a)
AlgsExecutionStates.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 <string>
22 #include <vector>
23 
24 // Boost include files
25 #include <boost/container/flat_set.hpp>
26 
27 //---------------------------------------------------------------------------
28 
38 class AlgsExecutionStates final {
39 public:
42  enum State : uint8_t {
43  INITIAL = 0,
45  DATAREADY = 2,
47  SCHEDULED = 4,
50  ERROR = 7,
51  MAXVALUE = 8 // Allows loop over all states
52  };
53 
54  AlgsExecutionStates( unsigned int algsNumber, SmartIF<IMessageSvc> MS )
55  : m_states( algsNumber, INITIAL ), m_algsInState( MAXVALUE ), m_MS( std::move( MS ) ) {
56 
57  m_algsInState[INITIAL].reserve( algsNumber );
58  for ( unsigned int i = 0; i < algsNumber; ++i ) m_algsInState[INITIAL].insert( i );
59  }
60 
61  StatusCode set( unsigned int iAlgo, State newState );
62 
63  void reset() {
65 
66  for ( auto& algs : m_algsInState ) algs.clear();
68  for ( unsigned int i = 0; i < m_states.size(); ++i ) m_algsInState[INITIAL].insert( i );
69  }
70 
72  bool contains( State state ) const { return m_algsInState[state].size() > 0; }
73 
76  for ( auto state : l )
77  if ( m_algsInState[state].size() > 0 ) return true;
78  return false;
79  }
80 
81  // copy the current set of algs in a particular state
82  // states change during scheduler loop over set, so cannot return reference
83  const boost::container::flat_set<int> algsInState( State state ) const { return m_algsInState[state]; }
84 
85  const State& operator[]( unsigned int i ) const { return m_states.at( i ); }
86 
87  size_t size() const { return m_states.size(); }
88 
89  size_t sizeOfSubset( State state ) const { return m_algsInState[state].size(); }
90 
91 private:
95 
96  MsgStream log() { return { m_MS, "AlgsExecutionStates" }; }
97 };
98 
102  switch ( x ) {
103  case State::INITIAL:
104  s << "INITIAL";
105  break;
106  case State::CONTROLREADY:
107  s << "CONTROLREADY";
108  break;
109  case State::DATAREADY:
110  s << "DATAREADY";
111  break;
112  case State::RESOURCELESS:
113  s << "RESOURCELESS";
114  break;
115  case State::SCHEDULED:
116  s << "SCHEDULED";
117  break;
118  case State::EVTACCEPTED:
119  s << "EVTACCEPTED";
120  break;
121  case State::EVTREJECTED:
122  s << "EVTREJECTED";
123  break;
124  case State::ERROR:
125  s << "ERROR";
126  break;
127  default:
128  s << "UNKNOWN";
129  }
130  return s;
131 }
132 
133 #endif // GAUDIHIVE_ALGSEXECUTIONSTATES_H
AlgsExecutionStates::m_algsInState
std::vector< boost::container::flat_set< int > > m_algsInState
Definition: AlgsExecutionStates.h:93
std::vector::reserve
T reserve(T... args)
gaudirun.s
string s
Definition: gaudirun.py:346
AlgsExecutionStates::MAXVALUE
@ MAXVALUE
Definition: AlgsExecutionStates.h:51
std::vector< State >
std::vector::size
T size(T... args)
AlgsExecutionStates
Definition: AlgsExecutionStates.h:38
AlgsExecutionStates::CONTROLREADY
@ CONTROLREADY
Definition: AlgsExecutionStates.h:44
std::fill
T fill(T... args)
AlgsExecutionStates::RESOURCELESS
@ RESOURCELESS
Definition: AlgsExecutionStates.h:46
AlgsExecutionStates::m_MS
SmartIF< IMessageSvc > m_MS
Definition: AlgsExecutionStates.h:94
Gaudi::StateMachine::State
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm,...
Definition: StateMachine.h:22
AlgsExecutionStates::log
MsgStream log()
Definition: AlgsExecutionStates.h:96
AlgsExecutionStates::ERROR
@ ERROR
Definition: AlgsExecutionStates.h:50
StatusCode
Definition: StatusCode.h:65
std::vector::at
T at(T... args)
AlgsExecutionStates::m_states
std::vector< State > m_states
Definition: AlgsExecutionStates.h:92
std::ostream
STL class.
AlgsExecutionStates::SCHEDULED
@ SCHEDULED
Definition: AlgsExecutionStates.h:47
operator<<
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values.
Definition: AlgsExecutionStates.h:100
AlgsExecutionStates::EVTREJECTED
@ EVTREJECTED
Definition: AlgsExecutionStates.h:49
SmartIF< IMessageSvc >
AlgsExecutionStates::reset
void reset()
Definition: AlgsExecutionStates.h:63
AlgsExecutionStates::AlgsExecutionStates
AlgsExecutionStates(unsigned int algsNumber, SmartIF< IMessageSvc > MS)
Definition: AlgsExecutionStates.h:54
MsgStream
Definition: MsgStream.h:33
AlgsExecutionStates::contains
bool contains(State state) const
check if the collection contains at least one state of requested type
Definition: AlgsExecutionStates.h:72
AlgsExecutionStates::containsAny
bool containsAny(std::initializer_list< State > l) const
check if the collection contains at least one state of any listed types
Definition: AlgsExecutionStates.h:75
Service.h
AlgsExecutionStates::set
StatusCode set(unsigned int iAlgo, State newState)
Definition: AlgsExecutionStates.cpp:23
gaudirun.l
dictionary l
Definition: gaudirun.py:583
std::vector::begin
T begin(T... args)
std
STL namespace.
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
AlgsExecutionStates::DATAREADY
@ DATAREADY
Definition: AlgsExecutionStates.h:45
AlgsExecutionStates::State
State
Execution states of the algorithms Must have contiguous integer values 0, 1...
Definition: AlgsExecutionStates.h:42
AlgsExecutionStates::EVTACCEPTED
@ EVTACCEPTED
Definition: AlgsExecutionStates.h:48
std::vector::end
T end(T... args)
AlgsExecutionStates::sizeOfSubset
size_t sizeOfSubset(State state) const
Definition: AlgsExecutionStates.h:89
compareRootHistos.state
state
Definition: compareRootHistos.py:496
AlgsExecutionStates::algsInState
const boost::container::flat_set< int > algsInState(State state) const
Definition: AlgsExecutionStates.h:83
AlgsExecutionStates::INITIAL
@ INITIAL
Definition: AlgsExecutionStates.h:43
Gaudi::Functional::details::insert
constexpr struct Gaudi::Functional::details::insert_t insert
AlgsExecutionStates::operator[]
const State & operator[](unsigned int i) const
Definition: AlgsExecutionStates.h:85
CollWrite.algs
algs
Definition: CollWrite.py:33
MsgStream.h
std::initializer_list
AlgsExecutionStates::size
size_t size() const
Definition: AlgsExecutionStates.h:87