Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (01b473db)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IAlgExecStateSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 
13 #include <GaudiKernel/IAlgorithm.h>
14 #include <GaudiKernel/IInterface.h>
15 #include <GaudiKernel/StatusCode.h>
16 #include <GaudiKernel/StringKey.h>
17 #include <sstream>
18 
19 class EventContext;
20 class IAlgExecStateSvc;
21 
22 namespace AlgExecState {
23  enum State { None = 0, Executing = 1, Done = 2 };
24 } // namespace AlgExecState
25 
33 public:
35  enum struct AlgKey : size_t {};
37  : m_svc{ svc }, m_ctx{ ctx }, m_algKey{ algKey } {}
38 
39  bool filterPassed() const;
40  void setFilterPassed( bool f = true );
41  State state() const;
42  void setState( State s );
43  void setState( State s, const StatusCode& sc );
44  const StatusCode& execStatus() const;
45  void setExecStatus( const StatusCode& sc = StatusCode::SUCCESS );
46  void reset();
47  friend std::ostream& operator<<( std::ostream& ost, const AlgExecStateRef& s );
48 
49 private:
53 };
54 
59 public:
61  : m_svc{ svc }, m_ctx{ ctx }, m_algKey{ algKey } {}
62 
63  bool filterPassed() const;
65  const StatusCode& execStatus() const;
66  friend std::ostream& operator<<( std::ostream& ost, const AlgExecStateRefConst& s );
67 
68 private:
72 };
73 
74 namespace EventStatus {
75  enum Status { Invalid = 0, Success = 1, AlgFail = 2, AlgStall = 3, Other = 4 };
76  inline std::ostream& operator<<( std::ostream& os, Status s ) {
77  static constexpr std::array<const char*, 5> label{ "Invalid", "Success", "AlgFail", "AlgStall", "Other" };
78  return os << label.at( s );
79  }
80 } // namespace EventStatus
81 
94 class GAUDI_API IAlgExecStateSvc : virtual public IInterface {
95 public:
98 
101  virtual AlgExecStateRef algExecState( const std::string& algName, const EventContext& ctx ) = 0;
102 
105  virtual AlgExecStateRef algExecState( const IAlgorithm* iAlg, const EventContext& ctx ) = 0;
106 
109  virtual AlgExecStateRefConst algExecState( const std::string& algName, const EventContext& ctx ) const = 0;
110 
113  virtual AlgExecStateRefConst algExecState( const IAlgorithm* iAlg, const EventContext& ctx ) const = 0;
114 
116  virtual void reset( const EventContext& ctx ) = 0;
117 
119  virtual AlgExecStateRef::AlgKey addAlg( const Gaudi::StringKey& algName ) = 0;
120  AlgExecStateRef::AlgKey addAlg( const IAlgorithm* iAlg ) { return addAlg( iAlg->nameKey() ); }
121 
122  virtual const EventStatus::Status& eventStatus( const EventContext& ctx ) const = 0;
123  virtual void setEventStatus( const EventStatus::Status& sc, const EventContext& ctx ) = 0;
124  virtual void updateEventStatus( const bool& b, const EventContext& ctx ) = 0;
125 
126  virtual unsigned int algErrorCount( const IAlgorithm* iAlg ) const = 0;
127  virtual void resetErrorCount( const IAlgorithm* iAlg ) = 0;
128  virtual void resetErrorCount() = 0;
129  virtual unsigned int incrementErrorCount( const IAlgorithm* iAlg ) = 0;
130 
131  virtual void dump( std::ostream& ost, const EventContext& ctx ) const = 0;
132  virtual void dump( std::ostream&, const EventContext&, AlgExecStateRef::AlgKey ) const = 0;
133 
134 private:
135  virtual bool filterPassed( const EventContext&, AlgExecStateRef::AlgKey ) const = 0;
136  virtual void setFilterPassed( const EventContext&, AlgExecStateRef::AlgKey, bool ) = 0;
140  virtual const StatusCode& execStatus( const EventContext&, AlgExecStateRef::AlgKey ) const = 0;
141  virtual void setExecStatus( const EventContext&, AlgExecStateRef::AlgKey, const StatusCode& ) = 0;
142  virtual const std::string& algName( AlgExecStateRef::AlgKey ) const = 0;
143 
144  friend class AlgExecStateRefConst;
145  friend class AlgExecStateRef;
146 };
147 
148 inline bool AlgExecStateRef::filterPassed() const { return m_svc.filterPassed( m_ctx, m_algKey ); }
153  m_svc.setState( m_ctx, m_algKey, s, sc );
154 }
158 inline std::ostream& operator<<( std::ostream& ost, const AlgExecStateRef& s ) {
159  s.m_svc.dump( ost, s.m_ctx, s.m_algKey );
160  return ost;
161 }
162 
166 inline std::ostream& operator<<( std::ostream& ost, const AlgExecStateRefConst& s ) {
167  s.m_svc.dump( ost, s.m_ctx, s.m_algKey );
168  return ost;
169 }
IAlgExecStateSvc::DeclareInterfaceID
DeclareInterfaceID(IAlgExecStateSvc, 2, 0)
InterfaceID.
AlgExecStateRef::operator<<
friend std::ostream & operator<<(std::ostream &ost, const AlgExecStateRef &s)
Definition: IAlgExecStateSvc.h:158
IAlgExecStateSvc::setExecStatus
virtual void setExecStatus(const EventContext &, AlgExecStateRef::AlgKey, const StatusCode &)=0
IAlgExecStateSvc::dump
virtual void dump(std::ostream &, const EventContext &, AlgExecStateRef::AlgKey) const =0
AlgExecStateRef
wrapper on an Algorithm state.
Definition: IAlgExecStateSvc.h:32
AlgExecState::None
@ None
Definition: IAlgExecStateSvc.h:23
EventStatus
Definition: IAlgExecStateSvc.h:74
IAlgExecStateSvc::state
virtual AlgExecStateRef::State state(const EventContext &, AlgExecStateRef::AlgKey) const =0
AlgExecStateRef::filterPassed
bool filterPassed() const
Definition: IAlgExecStateSvc.h:148
IAlgExecStateSvc::addAlg
AlgExecStateRef::AlgKey addAlg(const IAlgorithm *iAlg)
Definition: IAlgExecStateSvc.h:120
IAlgExecStateSvc::dump
virtual void dump(std::ostream &ost, const EventContext &ctx) const =0
gaudirun.s
string s
Definition: gaudirun.py:346
AlgExecStateRef::AlgExecStateRef
AlgExecStateRef(IAlgExecStateSvc &svc, const EventContext &ctx, AlgKey algKey)
Definition: IAlgExecStateSvc.h:36
AlgExecStateRef::m_svc
IAlgExecStateSvc & m_svc
Definition: IAlgExecStateSvc.h:50
EventStatus::Other
@ Other
Definition: IAlgExecStateSvc.h:75
AlgExecStateRef::setState
void setState(State s)
Definition: IAlgExecStateSvc.h:151
StringKey.h
EventStatus::Success
@ Success
Definition: IAlgExecStateSvc.h:75
AlgExecStateRef::setExecStatus
void setExecStatus(const StatusCode &sc=StatusCode::SUCCESS)
Definition: IAlgExecStateSvc.h:156
AlgExecStateRef::m_ctx
const EventContext & m_ctx
Definition: IAlgExecStateSvc.h:51
AlgExecStateRef::State
AlgExecState::State State
Definition: IAlgExecStateSvc.h:34
IAlgExecStateSvc::algErrorCount
virtual unsigned int algErrorCount(const IAlgorithm *iAlg) const =0
AlgExecStateRefConst::filterPassed
bool filterPassed() const
Definition: IAlgExecStateSvc.h:163
IAlgExecStateSvc::resetErrorCount
virtual void resetErrorCount()=0
StatusCode.h
EventStatus::Invalid
@ Invalid
Definition: IAlgExecStateSvc.h:75
AlgExecState::State
State
Definition: IAlgExecStateSvc.h:23
AlgExecStateRefConst::execStatus
const StatusCode & execStatus() const
Definition: IAlgExecStateSvc.h:165
AlgExecStateRef::state
State state() const
Definition: IAlgExecStateSvc.h:150
AlgExecState::Done
@ Done
Definition: IAlgExecStateSvc.h:23
IAlgExecStateSvc::setState
virtual void setState(const EventContext &, AlgExecStateRef::AlgKey, AlgExecStateRef::State)=0
IAlgExecStateSvc::resetErrorCount
virtual void resetErrorCount(const IAlgorithm *iAlg)=0
Gaudi::StringKey
Definition: StringKey.h:66
EventStatus::AlgStall
@ AlgStall
Definition: IAlgExecStateSvc.h:75
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:64
IInterface.h
IAlgorithm
Definition: IAlgorithm.h:36
AlgExecStateRef::reset
void reset()
Definition: IAlgExecStateSvc.h:157
IAlgExecStateSvc::algName
virtual const std::string & algName(AlgExecStateRef::AlgKey) const =0
IAlgExecStateSvc
Abstract interface for a service that manages the Algorithm execution states.
Definition: IAlgExecStateSvc.h:94
AlgExecState::Executing
@ Executing
Definition: IAlgExecStateSvc.h:23
AlgExecStateRef::m_algKey
AlgKey m_algKey
Definition: IAlgExecStateSvc.h:52
IAlgExecStateSvc::reset
virtual void reset(const EventContext &ctx)=0
reset all states for the given EventContext
IAlgorithm::nameKey
virtual const Gaudi::StringKey & nameKey() const =0
StringKey rep of name.
AlgExecState
Definition: IAlgExecStateSvc.h:22
EventStatus::AlgFail
@ AlgFail
Definition: IAlgExecStateSvc.h:75
IAlgExecStateSvc::execStatus
virtual const StatusCode & execStatus(const EventContext &, AlgExecStateRef::AlgKey) const =0
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
AlgExecStateRef::setFilterPassed
void setFilterPassed(bool f=true)
Definition: IAlgExecStateSvc.h:149
AlgExecStateRef::AlgKey
AlgKey
Definition: IAlgExecStateSvc.h:35
IAlgExecStateSvc::algExecState
virtual AlgExecStateRefConst algExecState(const IAlgorithm *iAlg, const EventContext &ctx) const =0
get the Algorithm Execution State for a give Algorithm and EventContext, const version prefer using I...
IAlgExecStateSvc::setState
virtual void setState(const EventContext &, AlgExecStateRef::AlgKey, AlgExecStateRef::State, const StatusCode &)=0
operator<<
std::ostream & operator<<(std::ostream &ost, const AlgExecStateRef &s)
Definition: IAlgExecStateSvc.h:158
AlgExecStateRefConst
wrapper on an Algorithm state, const version.
Definition: IAlgExecStateSvc.h:58
IAlgExecStateSvc::algExecState
virtual AlgExecStateRefConst algExecState(const std::string &algName, const EventContext &ctx) const =0
get the Algorithm Execution State for a give Algorithm by name, const version prefer using IAlgorithm...
IInterface
Definition: IInterface.h:225
EventContext
Definition: EventContext.h:34
IAlgExecStateSvc::algExecState
virtual AlgExecStateRef algExecState(const IAlgorithm *iAlg, const EventContext &ctx)=0
get the Algorithm Execution State for a give Algorithm and EventContext prefer using IAlgorithm::exec...
EventStatus::Status
Status
Definition: IAlgExecStateSvc.h:75
AlgExecStateRefConst::m_algKey
AlgExecStateRef::AlgKey m_algKey
Definition: IAlgExecStateSvc.h:71
IAlgExecStateSvc::addAlg
virtual AlgExecStateRef::AlgKey addAlg(const Gaudi::StringKey &algName)=0
adds a new algorithm to the service
IAlgExecStateSvc::incrementErrorCount
virtual unsigned int incrementErrorCount(const IAlgorithm *iAlg)=0
IAlgExecStateSvc::setEventStatus
virtual void setEventStatus(const EventStatus::Status &sc, const EventContext &ctx)=0
AlgExecStateRefConst::AlgExecStateRefConst
AlgExecStateRefConst(const IAlgExecStateSvc &svc, const EventContext &ctx, AlgExecStateRef::AlgKey algKey)
Definition: IAlgExecStateSvc.h:60
IAlgExecStateSvc::eventStatus
virtual const EventStatus::Status & eventStatus(const EventContext &ctx) const =0
IAlgorithm.h
AlgExecStateRefConst::m_ctx
const EventContext & m_ctx
Definition: IAlgExecStateSvc.h:70
AlgExecStateRefConst::m_svc
const IAlgExecStateSvc & m_svc
Definition: IAlgExecStateSvc.h:69
AlgExecStateRefConst::state
AlgExecStateRef::State state() const
Definition: IAlgExecStateSvc.h:164
IAlgExecStateSvc::setFilterPassed
virtual void setFilterPassed(const EventContext &, AlgExecStateRef::AlgKey, bool)=0
IAlgExecStateSvc::filterPassed
virtual bool filterPassed(const EventContext &, AlgExecStateRef::AlgKey) const =0
IAlgExecStateSvc::updateEventStatus
virtual void updateEventStatus(const bool &b, const EventContext &ctx)=0
IAlgExecStateSvc::algExecState
virtual AlgExecStateRef algExecState(const std::string &algName, const EventContext &ctx)=0
get the Algorithm Execution State for a give Algorithm by name prefer using IAlgorithm::execState,...
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
AlgExecStateRefConst::operator<<
friend std::ostream & operator<<(std::ostream &ost, const AlgExecStateRefConst &s)
Definition: IAlgExecStateSvc.h:166
EventStatus::operator<<
std::ostream & operator<<(std::ostream &os, Status s)
Definition: IAlgExecStateSvc.h:76
AlgExecStateRef::execStatus
const StatusCode & execStatus() const
Definition: IAlgExecStateSvc.h:155