Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:30

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 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 #include <string>
0021 
0022 class EventContext;
0023 
0024 //-----------------------------------------------------------------------------
0025 
0026 /** @class IAlgExecStateSvc GaudiKernel/IAlgExecStateSvc.h
0027  *
0028  *  @brief Abstract interface for a service that manages the Algorithm execution
0029  *         states
0030  *
0031  *  @author Charles Leggett
0032  *  @date   2016-04-12
0033  */
0034 
0035 //-----------------------------------------------------------------------------
0036 
0037 class AlgExecState {
0038 public:
0039   enum State { None = 0, Executing = 1, Done = 2 };
0040 
0041   bool              filterPassed() const { return m_filterPassed; }
0042   State             state() const { return m_state; }
0043   const StatusCode& execStatus() const { return m_execStatus; }
0044 
0045   void setFilterPassed( bool f = true ) { m_filterPassed = f; }
0046   void setState( State s ) { m_state = s; }
0047   void setState( State s, const StatusCode& sc ) {
0048     m_state      = s;
0049     m_execStatus = sc;
0050   }
0051   void setExecStatus( const StatusCode& sc = StatusCode::SUCCESS ) { m_execStatus = sc; }
0052   void reset() { *this = AlgExecState{}; }
0053 
0054 private:
0055   bool       m_filterPassed{ true };
0056   State      m_state{ State::None };
0057   StatusCode m_execStatus{ StatusCode::FAILURE };
0058 };
0059 
0060 inline std::ostream& operator<<( std::ostream& ost, const AlgExecState& s ) {
0061   ost << "e: ";
0062   switch ( s.state() ) {
0063   case AlgExecState::State::None:
0064     return ost << "n";
0065   case AlgExecState::State::Executing:
0066     return ost << "e";
0067   default:
0068     return ost << "d f: " << s.filterPassed() << " sc: " << s.execStatus();
0069   }
0070 }
0071 
0072 namespace EventStatus {
0073   enum Status { Invalid = 0, Success = 1, AlgFail = 2, AlgStall = 3, Other = 4 };
0074   inline std::ostream& operator<<( std::ostream& os, Status s ) {
0075     static constexpr std::array<const char*, 5> label{ "Invalid", "Success", "AlgFail", "AlgStall", "Other" };
0076     return os << label.at( s );
0077   }
0078 } // namespace EventStatus
0079 
0080 class GAUDI_API IAlgExecStateSvc : virtual public IInterface {
0081 public:
0082   /// InterfaceID
0083   DeclareInterfaceID( IAlgExecStateSvc, 1, 0 );
0084 
0085   typedef std::map<Gaudi::StringKey, AlgExecState> AlgStateMap_t;
0086 
0087   // get the Algorithm Execution State for a give Algorithm and EventContext
0088   virtual const AlgExecState& algExecState( const Gaudi::StringKey& algName, const EventContext& ctx ) const = 0;
0089   const AlgExecState&         algExecState( IAlgorithm* iAlg, const EventContext& ctx ) const {
0090     return algExecState( iAlg->nameKey(), ctx );
0091   }
0092   virtual AlgExecState& algExecState( IAlgorithm* iAlg, const EventContext& ctx ) = 0;
0093 
0094   // get all the Algorithm Execution States for a given EventContext
0095   virtual const AlgStateMap_t& algExecStates( const EventContext& ctx ) const = 0;
0096 
0097   virtual void reset( const EventContext& ctx ) = 0;
0098 
0099   virtual void addAlg( const Gaudi::StringKey& algName ) = 0;
0100   void         addAlg( IAlgorithm* iAlg ) { addAlg( iAlg->nameKey() ); }
0101 
0102   virtual const EventStatus::Status& eventStatus( const EventContext& ctx ) const = 0;
0103 
0104   virtual void setEventStatus( const EventStatus::Status& sc, const EventContext& ctx ) = 0;
0105 
0106   virtual void updateEventStatus( const bool& b, const EventContext& ctx ) = 0;
0107 
0108   virtual unsigned int algErrorCount( const IAlgorithm* iAlg ) const = 0;
0109   virtual void         resetErrorCount( const IAlgorithm* iAlg )     = 0;
0110   virtual unsigned int incrementErrorCount( const IAlgorithm* iAlg ) = 0;
0111 
0112   virtual void dump( std::ostringstream& ost, const EventContext& ctx ) const = 0;
0113 };
0114 
0115 #endif