The Gaudi Framework  v33r0 (d5ea422b)
IAlgExecStateSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 #include <string>
21 
22 class EventContext;
23 
24 //-----------------------------------------------------------------------------
25 
35 //-----------------------------------------------------------------------------
36 
37 class AlgExecState {
38 public:
39  enum State { None = 0, Executing = 1, Done = 2 };
40 
41  bool filterPassed() const { return m_filterPassed; }
42  State state() const { return m_state; }
43  const StatusCode& execStatus() const { return m_execStatus; }
44 
45  void setFilterPassed( bool f = true ) { m_filterPassed = f; }
46  void setState( State s ) { m_state = s; }
47  void setState( State s, const StatusCode& sc ) {
48  m_state = s;
49  m_execStatus = sc;
50  }
52  void reset() { *this = AlgExecState{}; }
53 
54 private:
55  bool m_filterPassed{true};
56  State m_state{State::None};
58 };
59 
61  ost << "e: ";
62  switch ( s.state() ) {
63  case AlgExecState::State::None:
64  return ost << "n";
65  case AlgExecState::State::Executing:
66  return ost << "e";
67  default:
68  return ost << "d f: " << s.filterPassed() << " sc: " << s.execStatus();
69  }
70 }
71 
72 namespace EventStatus {
73  enum Status { Invalid = 0, Success = 1, AlgFail = 2, AlgStall = 3, Other = 4 };
75  static constexpr std::array<const char*, 5> label{"Invalid", "Success", "AlgFail", "AlgStall", "Other"};
76  return os << label.at( s );
77  }
78 } // namespace EventStatus
79 
80 class GAUDI_API IAlgExecStateSvc : virtual public IInterface {
81 public:
84 
86 
87  // get the Algorithm Execution State for a give Algorithm and EventContext
88  virtual const AlgExecState& algExecState( const Gaudi::StringKey& algName, const EventContext& ctx ) const = 0;
89  const AlgExecState& algExecState( IAlgorithm* iAlg, const EventContext& ctx ) const {
90  return algExecState( iAlg->nameKey(), ctx );
91  }
92  virtual AlgExecState& algExecState( IAlgorithm* iAlg, const EventContext& ctx ) = 0;
93 
94  // get all the Algorithm Execution States for a given EventContext
95  virtual const AlgStateMap_t& algExecStates( const EventContext& ctx ) const = 0;
96 
97  virtual void reset( const EventContext& ctx ) = 0;
98 
99  virtual void addAlg( const Gaudi::StringKey& algName ) = 0;
100  void addAlg( IAlgorithm* iAlg ) { addAlg( iAlg->nameKey() ); }
101 
102  virtual const EventStatus::Status& eventStatus( const EventContext& ctx ) const = 0;
103 
104  virtual void setEventStatus( const EventStatus::Status& sc, const EventContext& ctx ) = 0;
105 
106  virtual void updateEventStatus( const bool& b, const EventContext& ctx ) = 0;
107 
108  virtual unsigned int algErrorCount( const IAlgorithm* iAlg ) const = 0;
109  virtual void resetErrorCount( const IAlgorithm* iAlg ) = 0;
110  virtual unsigned int incrementErrorCount( const IAlgorithm* iAlg ) = 0;
111 
112  virtual void dump( std::ostringstream& ost, const EventContext& ctx ) const = 0;
113 };
114 
115 #endif
std::ostream & operator<<(std::ostream &os, Status s)
void setExecStatus(const StatusCode &sc=StatusCode::SUCCESS)
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
bool filterPassed() const
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
STL class.
The helper class to represent the efficient "key" for access.
Definition: StringKey.h:44
void setState(State s)
const AlgExecState & algExecState(IAlgorithm *iAlg, const EventContext &ctx) const
virtual const Gaudi::StringKey & nameKey() const =0
StringKey rep of name.
Abstract interface for a service that manages the Algorithm execution states.
void setState(State s, const StatusCode &sc)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
State state() const
Definition of the basic interface.
Definition: IInterface.h:254
const StatusCode & execStatus() const
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:38
#define DeclareInterfaceID(iface, major, minor)
Macro to declare the interface ID when using the new mechanism of extending and implementing interfac...
Definition: IInterface.h:23
string s
Definition: gaudirun.py:328
STL class.
constexpr static const auto FAILURE
Definition: StatusCode.h:97
StatusCode m_execStatus
void setFilterPassed(bool f=true)
std::ostream & operator<<(std::ostream &ost, const AlgExecState &s)
void addAlg(IAlgorithm *iAlg)
#define GAUDI_API
Definition: Kernel.h:81
STL class.
std::map< Gaudi::StringKey, AlgExecState > AlgStateMap_t