Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:15:10

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_IALGEXECSTATESVC_H
0012 #define GAUDIKERNEL_IALGEXECSTATESVC_H 1
0013 
0014 #include <GaudiKernel/IAlgorithm.h>
0015 #include <GaudiKernel/IInterface.h>
0016 #include <GaudiKernel/StatusCode.h>
0017 #include <GaudiKernel/StringKey.h>
0018 #include <map>
0019 #include <sstream>
0020 
0021 class EventContext;
0022 
0023 //-----------------------------------------------------------------------------
0024 
0025 /** @class IAlgExecStateSvc GaudiKernel/IAlgExecStateSvc.h
0026  *
0027  *  @brief Abstract interface for a service that manages the Algorithm execution
0028  *         states
0029  *
0030  *  @author Charles Leggett
0031  *  @date   2016-04-12
0032  */
0033 
0034 //-----------------------------------------------------------------------------
0035 
0036 class AlgExecState {
0037 public:
0038   enum State { None = 0, Executing = 1, Done = 2 };
0039 
0040   bool              filterPassed() const { return m_filterPassed; }
0041   State             state() const { return m_state; }
0042   const StatusCode& execStatus() const { return m_execStatus; }
0043 
0044   void setFilterPassed( bool f = true ) { m_filterPassed = f; }
0045   void setState( State s ) { m_state = s; }
0046   void setState( State s, const StatusCode& sc ) {
0047     m_state      = s;
0048     m_execStatus = sc;
0049   }
0050   void setExecStatus( const StatusCode& sc = StatusCode::SUCCESS ) { m_execStatus = sc; }
0051   void reset() { *this = AlgExecState{}; }
0052 
0053   friend std::ostream& operator<<( std::ostream& ost, const AlgExecState& s ) {
0054     ost << "e: ";
0055     switch ( s.state() ) {
0056     case AlgExecState::State::None:
0057       return ost << "n";
0058     case AlgExecState::State::Executing:
0059       return ost << "e";
0060     default:
0061       return ost << "d f: " << s.filterPassed() << " sc: " << s.execStatus();
0062     }
0063   }
0064 
0065 private:
0066   bool       m_filterPassed{ true };
0067   State      m_state{ State::None };
0068   StatusCode m_execStatus{ StatusCode::FAILURE };
0069 };
0070 
0071 namespace EventStatus {
0072   enum Status { Invalid = 0, Success = 1, AlgFail = 2, AlgStall = 3, Other = 4 };
0073   inline std::ostream& operator<<( std::ostream& os, Status s ) {
0074     static constexpr std::array<const char*, 5> label{ "Invalid", "Success", "AlgFail", "AlgStall", "Other" };
0075     return os << label.at( s );
0076   }
0077 } // namespace EventStatus
0078 
0079 class GAUDI_API IAlgExecStateSvc : virtual public IInterface {
0080 public:
0081   /// InterfaceID
0082   DeclareInterfaceID( IAlgExecStateSvc, 1, 0 );
0083 
0084   typedef std::map<Gaudi::StringKey, AlgExecState> AlgStateMap_t;
0085 
0086   // get the Algorithm Execution State for a give Algorithm and EventContext
0087   virtual const AlgExecState& algExecState( const Gaudi::StringKey& algName, const EventContext& ctx ) const = 0;
0088   const AlgExecState&         algExecState( IAlgorithm* iAlg, const EventContext& ctx ) const {
0089     return algExecState( iAlg->nameKey(), ctx );
0090   }
0091   virtual AlgExecState& algExecState( IAlgorithm* iAlg, const EventContext& ctx ) = 0;
0092 
0093   // get all the Algorithm Execution States for a given EventContext
0094   virtual const AlgStateMap_t& algExecStates( const EventContext& ctx ) const = 0;
0095 
0096   virtual void reset( const EventContext& ctx ) = 0;
0097 
0098   virtual void addAlg( const Gaudi::StringKey& algName ) = 0;
0099   void         addAlg( IAlgorithm* iAlg ) { addAlg( iAlg->nameKey() ); }
0100 
0101   virtual const EventStatus::Status& eventStatus( const EventContext& ctx ) const = 0;
0102 
0103   virtual void setEventStatus( const EventStatus::Status& sc, const EventContext& ctx ) = 0;
0104 
0105   virtual void updateEventStatus( const bool& b, const EventContext& ctx ) = 0;
0106 
0107   virtual unsigned int algErrorCount( const IAlgorithm* iAlg ) const = 0;
0108   virtual void         resetErrorCount( const IAlgorithm* iAlg )     = 0;
0109   virtual unsigned int incrementErrorCount( const IAlgorithm* iAlg ) = 0;
0110 
0111   virtual void dump( std::ostringstream& ost, const EventContext& ctx ) const = 0;
0112 };
0113 
0114 #endif