Back to home page

EIC code displayed by LXR

 
 

    


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

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_MINIMALEVENTLOOPMGR_H
0012 #define GAUDIKERNEL_MINIMALEVENTLOOPMGR_H 1
0013 
0014 #include <GaudiKernel/EventContext.h>
0015 #include <GaudiKernel/IAlgExecStateSvc.h>
0016 #include <GaudiKernel/IAlgorithm.h>
0017 #include <GaudiKernel/IAppMgrUI.h>
0018 #include <GaudiKernel/IEventProcessor.h>
0019 #include <GaudiKernel/IHiveWhiteBoard.h>
0020 #include <GaudiKernel/IIncidentListener.h>
0021 #include <GaudiKernel/IIncidentSvc.h>
0022 #include <GaudiKernel/Service.h>
0023 #include <vector>
0024 
0025 /** @class MinimalEventLoopMgr
0026  *  This is the default processing manager of the application manager.
0027  *  This object handles the minimal requirements needed by the application manager.
0028  *  It also is capable of handling a bunch of algorithms and output streams.
0029  *  However, the list may as well be empty.
0030  *
0031  *  @author Markus Frank
0032  *  @version 1.0
0033  */
0034 class GAUDI_API MinimalEventLoopMgr : public extends<Service, IEventProcessor> {
0035 private:
0036   class AbortEventListener : public implements<IIncidentListener> {
0037   public:
0038     /// Inform that a new incident has occurred
0039     void handle( const Incident& i ) override {
0040       if ( i.type() == IncidentType::AbortEvent ) {
0041         abortEvent       = true;
0042         abortEventSource = i.source();
0043       }
0044     }
0045 
0046   public:
0047     /// Flag signalling that the event being processed has to be aborted
0048     /// (skip all following top algs).
0049     bool abortEvent = false;
0050     /// Source of the AbortEvent incident.
0051     std::string abortEventSource;
0052   };
0053 
0054 public:
0055   typedef std::vector<SmartIF<IAlgorithm>> ListAlg;
0056 
0057 protected:
0058   // Properties
0059   Gaudi::Property<std::vector<std::string>> m_topAlgNames{
0060       this, "TopAlg", {}, &MinimalEventLoopMgr::topAlgHandler, "list of top level algorithms names" };
0061   Gaudi::Property<std::vector<std::string>> m_outStreamNames{
0062       this, "OutStream", {}, &MinimalEventLoopMgr::outStreamHandler, "list of output stream names" };
0063   Gaudi::Property<bool> m_printCFExp{ this, "PrintControlFlowExpression", false,
0064                                       "Print the control flow expression representing the content of TopAlg" };
0065 
0066   // enums
0067   enum State { OFFLINE, CONFIGURED, FINALIZED, INITIALIZED };
0068   /// Reference to the IAppMgrUI interface of the application manager
0069   SmartIF<IAppMgrUI> m_appMgrUI;
0070   /// Reference to the incident service
0071   SmartIF<IIncidentSvc> m_incidentSvc;
0072   /// List of top level algorithms
0073   SmartIF<IAlgExecStateSvc> m_aess;
0074   ListAlg                   m_topAlgList;
0075   /// List of output streams
0076   ListAlg m_outStreamList;
0077   /// State of the object
0078   State m_state = OFFLINE;
0079   /// Scheduled stop of event processing
0080   bool m_scheduledStop = false;
0081   /// Instance of the incident listener waiting for AbortEvent.
0082   AbortEventListener m_abortEventListener;
0083 
0084 public:
0085   /// Standard Constructor
0086   MinimalEventLoopMgr( const std::string& nam, ISvcLocator* svcLoc );
0087   /// No copy allowed.
0088   MinimalEventLoopMgr( const MinimalEventLoopMgr& ) = delete;
0089   /// No copy allowed.
0090   MinimalEventLoopMgr& operator=( const MinimalEventLoopMgr& ) = delete;
0091 
0092 #if defined( GAUDI_V20_COMPAT ) && !defined( G21_NO_DEPRECATED )
0093 protected:
0094   /// Helper to release interface pointer
0095   template <class T>
0096   [[deprecated]] T* releaseInterface( T* iface ) {
0097     if ( 0 != iface ) iface->release();
0098     return 0;
0099   }
0100 
0101 public:
0102 #endif
0103 
0104   /// implementation of IService::initialize
0105   StatusCode initialize() override;
0106   /// implementation of IService::start
0107   StatusCode start() override;
0108   /// implementation of IService::stop
0109   StatusCode stop() override;
0110   /// implementation of IService::finalize
0111   StatusCode finalize() override;
0112   /// implementation of IService::reinitialize
0113   StatusCode reinitialize() override;
0114   /// implementation of IService::restart
0115   StatusCode restart() override;
0116   /// implementation of IEventProcessor::createEventContext()
0117   EventContext createEventContext() override;
0118   /// implementation of IEventProcessor::nextEvent
0119   StatusCode nextEvent( int maxevt ) override;
0120   /// implementation of IEventProcessor::executeEvent(EventContext&&)
0121   StatusCode executeEvent( EventContext&& ctx ) override;
0122   /// implementation of IEventProcessor::executeRun( )
0123   StatusCode executeRun( int maxevt ) override;
0124   /// implementation of IEventProcessor::stopRun( )
0125   StatusCode stopRun() override;
0126 
0127   /// Top algorithm List handler
0128   void topAlgHandler( Gaudi::Details::PropertyBase& p );
0129   /// decodeTopAlgNameList & topAlgNameListHandler
0130   StatusCode decodeTopAlgs();
0131   /// Output stream List handler
0132   void outStreamHandler( Gaudi::Details::PropertyBase& p );
0133   /// decodeOutStreamNameList & outStreamNameListHandler
0134   StatusCode decodeOutStreams();
0135 
0136 protected:
0137   ///< Event data service (whiteboard)
0138   SmartIF<IHiveWhiteBoard> m_WB;
0139 
0140   // number of events processed
0141   size_t m_nevt{ 0 };
0142 };
0143 #endif // GAUDIKERNEL_MINIMALEVENTLOOPMGR_H