The Gaudi Framework  master (37c0b60a)
IAlgExecStateSvc.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 GAUDIKERNEL_IALGEXECSTATESVC_H
12 #define GAUDIKERNEL_IALGEXECSTATESVC_H 1
13 
14 #include <GaudiKernel/IAlgorithm.h>
15 #include <GaudiKernel/IInterface.h>
16 #include <GaudiKernel/StatusCode.h>
17 #include <GaudiKernel/StringKey.h>
18 #include <map>
19 #include <sstream>
20 
21 class EventContext;
22 
23 //-----------------------------------------------------------------------------
24 
34 //-----------------------------------------------------------------------------
35 
36 class AlgExecState {
37 public:
38  enum State { None = 0, Executing = 1, Done = 2 };
39 
40  bool filterPassed() const { return m_filterPassed; }
41  State state() const { return m_state; }
42  const StatusCode& execStatus() const { return m_execStatus; }
43 
44  void setFilterPassed( bool f = true ) { m_filterPassed = f; }
45  void setState( State s ) { m_state = s; }
46  void setState( State s, const StatusCode& sc ) {
47  m_state = s;
48  m_execStatus = sc;
49  }
51  void reset() { *this = AlgExecState{}; }
52 
54  ost << "e: ";
55  switch ( s.state() ) {
56  case AlgExecState::State::None:
57  return ost << "n";
58  case AlgExecState::State::Executing:
59  return ost << "e";
60  default:
61  return ost << "d f: " << s.filterPassed() << " sc: " << s.execStatus();
62  }
63  }
64 
65 private:
66  bool m_filterPassed{ true };
67  State m_state{ State::None };
69 };
70 
71 namespace EventStatus {
72  enum Status { Invalid = 0, Success = 1, AlgFail = 2, AlgStall = 3, Other = 4 };
74  static constexpr std::array<const char*, 5> label{ "Invalid", "Success", "AlgFail", "AlgStall", "Other" };
75  return os << label.at( s );
76  }
77 } // namespace EventStatus
78 
79 class GAUDI_API IAlgExecStateSvc : virtual public IInterface {
80 public:
83 
85 
86  // get the Algorithm Execution State for a give Algorithm and EventContext
87  virtual const AlgExecState& algExecState( const Gaudi::StringKey& algName, const EventContext& ctx ) const = 0;
88  const AlgExecState& algExecState( IAlgorithm* iAlg, const EventContext& ctx ) const {
89  return algExecState( iAlg->nameKey(), ctx );
90  }
91  virtual AlgExecState& algExecState( IAlgorithm* iAlg, const EventContext& ctx ) = 0;
92 
93  // get all the Algorithm Execution States for a given EventContext
94  virtual const AlgStateMap_t& algExecStates( const EventContext& ctx ) const = 0;
95 
96  virtual void reset( const EventContext& ctx ) = 0;
97 
98  virtual void addAlg( const Gaudi::StringKey& algName ) = 0;
99  void addAlg( IAlgorithm* iAlg ) { addAlg( iAlg->nameKey() ); }
100 
101  virtual const EventStatus::Status& eventStatus( const EventContext& ctx ) const = 0;
102 
103  virtual void setEventStatus( const EventStatus::Status& sc, const EventContext& ctx ) = 0;
104 
105  virtual void updateEventStatus( const bool& b, const EventContext& ctx ) = 0;
106 
107  virtual unsigned int algErrorCount( const IAlgorithm* iAlg ) const = 0;
108  virtual void resetErrorCount( const IAlgorithm* iAlg ) = 0;
109  virtual unsigned int incrementErrorCount( const IAlgorithm* iAlg ) = 0;
110 
111  virtual void dump( std::ostringstream& ost, const EventContext& ctx ) const = 0;
112 };
113 
114 #endif
EventStatus
Definition: IAlgExecStateSvc.h:71
AlgExecState::operator<<
friend std::ostream & operator<<(std::ostream &ost, const AlgExecState &s)
Definition: IAlgExecStateSvc.h:53
AlgExecState::reset
void reset()
Definition: IAlgExecStateSvc.h:51
AlgExecState::state
State state() const
Definition: IAlgExecStateSvc.h:41
gaudirun.s
string s
Definition: gaudirun.py:346
AlgExecState::m_state
State m_state
Definition: IAlgExecStateSvc.h:67
EventStatus::Other
@ Other
Definition: IAlgExecStateSvc.h:72
AlgExecState::setState
void setState(State s, const StatusCode &sc)
Definition: IAlgExecStateSvc.h:46
IAlgExecStateSvc::dump
virtual void dump(std::ostringstream &ost, const EventContext &ctx) const =0
StringKey.h
EventStatus::Success
@ Success
Definition: IAlgExecStateSvc.h:72
IAlgExecStateSvc::AlgStateMap_t
std::map< Gaudi::StringKey, AlgExecState > AlgStateMap_t
Definition: IAlgExecStateSvc.h:84
IAlgExecStateSvc::algErrorCount
virtual unsigned int algErrorCount(const IAlgorithm *iAlg) const =0
AlgExecState::Done
@ Done
Definition: IAlgExecStateSvc.h:38
StatusCode.h
IAlgExecStateSvc::algExecState
virtual AlgExecState & algExecState(IAlgorithm *iAlg, const EventContext &ctx)=0
EventStatus::Invalid
@ Invalid
Definition: IAlgExecStateSvc.h:72
AlgExecState::m_filterPassed
bool m_filterPassed
Definition: IAlgExecStateSvc.h:66
AlgExecState::Executing
@ Executing
Definition: IAlgExecStateSvc.h:38
IAlgExecStateSvc::resetErrorCount
virtual void resetErrorCount(const IAlgorithm *iAlg)=0
Gaudi::StringKey
Definition: StringKey.h:44
EventStatus::AlgStall
@ AlgStall
Definition: IAlgExecStateSvc.h:72
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
IInterface.h
IAlgorithm
Definition: IAlgorithm.h:38
std::ostream
STL class.
AlgExecState::None
@ None
Definition: IAlgExecStateSvc.h:38
IAlgExecStateSvc::addAlg
virtual void addAlg(const Gaudi::StringKey &algName)=0
AlgExecState::setState
void setState(State s)
Definition: IAlgExecStateSvc.h:45
IAlgExecStateSvc
Abstract interface for a service that manages the Algorithm execution states.
Definition: IAlgExecStateSvc.h:79
std::array
STL class.
AlgExecState::execStatus
const StatusCode & execStatus() const
Definition: IAlgExecStateSvc.h:42
IAlgExecStateSvc::algExecStates
virtual const AlgStateMap_t & algExecStates(const EventContext &ctx) const =0
IAlgExecStateSvc::reset
virtual void reset(const EventContext &ctx)=0
IAlgorithm::nameKey
virtual const Gaudi::StringKey & nameKey() const =0
StringKey rep of name.
std::map
STL class.
EventStatus::AlgFail
@ AlgFail
Definition: IAlgExecStateSvc.h:72
std::ostringstream
STL class.
IAlgExecStateSvc::algExecState
const AlgExecState & algExecState(IAlgorithm *iAlg, const EventContext &ctx) const
Definition: IAlgExecStateSvc.h:88
AlgExecState::setExecStatus
void setExecStatus(const StatusCode &sc=StatusCode::SUCCESS)
Definition: IAlgExecStateSvc.h:50
AlgExecState::m_execStatus
StatusCode m_execStatus
Definition: IAlgExecStateSvc.h:68
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
IAlgExecStateSvc::addAlg
void addAlg(IAlgorithm *iAlg)
Definition: IAlgExecStateSvc.h:99
AlgExecState::State
State
Definition: IAlgExecStateSvc.h:38
IInterface
Definition: IInterface.h:239
EventContext
Definition: EventContext.h:34
EventStatus::Status
Status
Definition: IAlgExecStateSvc.h:72
AlgExecState::filterPassed
bool filterPassed() const
Definition: IAlgExecStateSvc.h:40
IAlgExecStateSvc::incrementErrorCount
virtual unsigned int incrementErrorCount(const IAlgorithm *iAlg)=0
IAlgExecStateSvc::setEventStatus
virtual void setEventStatus(const EventStatus::Status &sc, const EventContext &ctx)=0
IAlgExecStateSvc::algExecState
virtual const AlgExecState & algExecState(const Gaudi::StringKey &algName, const EventContext &ctx) const =0
IAlgExecStateSvc::eventStatus
virtual const EventStatus::Status & eventStatus(const EventContext &ctx) const =0
IAlgorithm.h
AlgExecState
Definition: IAlgExecStateSvc.h:36
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
AlgExecState::setFilterPassed
void setFilterPassed(bool f=true)
Definition: IAlgExecStateSvc.h:44
IAlgExecStateSvc::DeclareInterfaceID
DeclareInterfaceID(IAlgExecStateSvc, 1, 0)
InterfaceID.
IAlgExecStateSvc::updateEventStatus
virtual void updateEventStatus(const bool &b, const EventContext &ctx)=0
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
EventStatus::operator<<
std::ostream & operator<<(std::ostream &os, Status s)
Definition: IAlgExecStateSvc.h:73