Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2022 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_AUDITOR_H
0012 #define GAUDIKERNEL_AUDITOR_H
0013 
0014 // Include files
0015 #include "GaudiKernel/CommonMessaging.h"
0016 #include "GaudiKernel/IAuditor.h"
0017 #include "GaudiKernel/IProperty.h"
0018 #include "GaudiKernel/IService.h"
0019 #include "GaudiKernel/ISvcLocator.h" /*used by service(..)*/
0020 #include "GaudiKernel/PropertyHolder.h"
0021 #include <Gaudi/PluginService.h>
0022 #include <Gaudi/PropertyFwd.h>
0023 #include <string>
0024 #include <vector>
0025 
0026 // Forward declarations
0027 class IService;
0028 class IMessageSvc;
0029 
0030 /** @class Auditor Auditor.h GaudiKernel/Auditor.h
0031 
0032     Base class from which all concrete auditor classes should be derived.
0033     The only base class functionality which may be used in the
0034     constructor of a concrete auditor is the declaration of
0035     member variables as properties. All other functionality,
0036     i.e. the use of services, may be used only in
0037     initialize() and afterwards.
0038 
0039     @author David Quarrie
0040     @date   2000
0041     @author Marco Clemencic
0042     @date   2008-03
0043 */
0044 class GAUDI_API Auditor : public PropertyHolder<CommonMessaging<implements<IAuditor, IProperty>>> {
0045 public:
0046   using Factory = Gaudi::PluginService::Factory<IAuditor*( const std::string&, ISvcLocator* )>;
0047 
0048   /** Constructor
0049       @param name    The algorithm object's name
0050       @param svcloc  A pointer to a service location service */
0051   Auditor( std::string name, ISvcLocator* svcloc );
0052 
0053   Auditor( const Auditor& a )              = delete;
0054   Auditor& operator=( const Auditor& rhs ) = delete;
0055 
0056   /** Initialization method invoked by the framework. This method is responsible
0057       for any bookkeeping of initialization required by the framework itself.
0058   */
0059   StatusCode sysInitialize() override;
0060   /** Finalization method invoked by the framework. This method is responsible
0061       for any bookkeeping of initialization required by the framework itself.
0062   */
0063   StatusCode sysFinalize() override;
0064 
0065   /// The following methods are meant to be implemented by the child class...
0066 
0067   void before( StandardEventType, INamedInterface* ) override;
0068   void before( StandardEventType, const std::string& ) override;
0069 
0070   void before( CustomEventTypeRef, INamedInterface* ) override;
0071   void before( CustomEventTypeRef, const std::string& ) override;
0072 
0073   void after( StandardEventType, INamedInterface*, const StatusCode& ) override;
0074   void after( StandardEventType, const std::string&, const StatusCode& ) override;
0075 
0076   void after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) override;
0077   void after( CustomEventTypeRef, const std::string&, const StatusCode& ) override;
0078 
0079   // Obsolete methods
0080 
0081   void beforeInitialize( INamedInterface* ) override;
0082   void afterInitialize( INamedInterface* ) override;
0083 
0084   void beforeReinitialize( INamedInterface* ) override;
0085   void afterReinitialize( INamedInterface* ) override;
0086 
0087   void beforeExecute( INamedInterface* ) override;
0088   void afterExecute( INamedInterface*, const StatusCode& ) override;
0089 
0090   void beforeFinalize( INamedInterface* ) override;
0091   void afterFinalize( INamedInterface* ) override;
0092 
0093   virtual StatusCode initialize();
0094   virtual StatusCode finalize();
0095 
0096   const std::string& name() const override;
0097 
0098   bool isEnabled() const override;
0099 
0100   /** The standard service locator. Returns a pointer to the service locator service.
0101       This service may be used by an auditor to request any services it requires in
0102       addition to those provided by default.
0103   */
0104   SmartIF<ISvcLocator>& serviceLocator() const override;
0105 
0106   /** Access a service by name, creating it if it doesn't already exist.
0107    */
0108   template <class T>
0109   StatusCode service( std::string_view name, T*& svc, bool createIf = false ) const {
0110     auto ptr = serviceLocator()->service<T>( name, createIf );
0111     if ( ptr ) {
0112       svc = ptr.get();
0113       svc->addRef();
0114       return StatusCode::SUCCESS;
0115     }
0116     svc = nullptr;
0117     return StatusCode::FAILURE;
0118   }
0119 
0120   template <class T = IService>
0121   SmartIF<T> service( std::string_view name, bool createIf = false ) const {
0122     return serviceLocator()->service<T>( name, createIf );
0123   }
0124 
0125 private:
0126   std::string m_name; ///< Auditor's name for identification
0127 
0128   mutable SmartIF<ISvcLocator> m_pSvcLocator; ///< Pointer to service locator service
0129 
0130   Gaudi::Property<int> m_outputLevel{
0131       this, "OutputLevel", MSG::NIL,
0132       [this]( Gaudi::Details::PropertyBase& ) { this->updateMsgStreamOutputLevel( this->m_outputLevel ); },
0133       "output level" };
0134   Gaudi::Property<bool> m_isEnabled{ this, "Enable", true, "should the auditor be used or not" };
0135 
0136   bool m_isInitialized = false; ///< Auditor has been initialized flag
0137   bool m_isFinalized   = false; ///< Auditor has been finalized flag
0138 };
0139 
0140 #endif // GAUDIKERNEL_AUDITOR_H