|
||||
File indexing completed on 2025-01-18 09:57:33
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 GAUDIALG_GETALG_H 0012 #define GAUDIALG_GETALG_H 1 0013 // ============================================================================ 0014 // Include files 0015 // ============================================================================ 0016 #include <type_traits> 0017 // ============================================================================ 0018 // GaudiKernel 0019 // ============================================================================ 0020 #include "GaudiKernel/IAlgorithm.h" 0021 // ============================================================================ 0022 // forward declarations 0023 // ============================================================================ 0024 class IAlgContextSvc; 0025 // ============================================================================ 0026 namespace Gaudi { 0027 namespace Utils { 0028 // ======================================================================== 0029 /** @class AlgSelector 0030 * Simple interface class for selection of algorithms 0031 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0032 * @date 2007-09-07 0033 */ 0034 class GAUDI_API AlgSelector { 0035 public: 0036 /// the only one essential method: 0037 virtual bool operator()( const IAlgorithm* ) const = 0; 0038 // virtual destructor 0039 virtual ~AlgSelector() = default; 0040 }; 0041 // ======================================================================== 0042 /** @class AlgTypeSelector 0043 * The trivial selector of algorithm by type 0044 * @see Gaudi::Utils::AlgSelector 0045 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0046 * @date 2007-09-07 0047 */ 0048 template <class TYPE> 0049 class GAUDI_API AlgTypeSelector : public AlgSelector { 0050 public: 0051 /// the only one essential method: 0052 bool operator()( const IAlgorithm* a ) const override { 0053 using TYPE_ = std::decay_t<TYPE>; 0054 using CTYPE = std::add_const_t<TYPE_>; 0055 using cptr = std::add_pointer_t<CTYPE>; 0056 return dynamic_cast<cptr>( a ); 0057 } 0058 }; 0059 // ======================================================================== 0060 /** @class AlgNameSelector 0061 * The trivial selector of algorithm by type 0062 * @see Gaudi::Utils::AlgSelector 0063 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0064 * @date 2007-09-07 0065 */ 0066 class GAUDI_API AlgNameSelector : public AlgSelector { 0067 public: 0068 AlgNameSelector() = delete; 0069 /// constructor form the name 0070 AlgNameSelector( std::string name ) : m_name( std::move( name ) ) {} 0071 /// the only one essential method: 0072 bool operator()( const IAlgorithm* a ) const override { return a && a->name() == m_name; } 0073 0074 private: 0075 // algorithm name 0076 std::string m_name; ///< algorithm name 0077 }; 0078 // ======================================================================== 0079 } // namespace Utils 0080 } // end of namespace Gaudi 0081 // ============================================================================ 0082 namespace Gaudi { 0083 namespace Utils { 0084 // ======================================================================== 0085 /** simple function to get the algorithm from Context Service 0086 * 0087 * @code 0088 * 0089 * // get the selector 0090 * const AlgSelector& selector = ... ; 0091 * 0092 * // get the context service: 0093 * const IAlgContextSvc* svc = ... ; 0094 * 0095 * // get the appropriate algorithm: 0096 * IAlgorithm* alg = getAlgorithm ( svc , selector ) ; 0097 * 0098 * @endcode 0099 * 0100 * @see IAlgContextSvc 0101 * @see Gaudi::Utils::AlgSelector 0102 * @param svc pointer to Algororithm Contetx Service 0103 * @param sel the selection functor 0104 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0105 * @date 2007-09-07 0106 */ 0107 GAUDI_API IAlgorithm* getAlgorithm( const IAlgContextSvc* svc, const AlgSelector& sel ); 0108 // ======================================================================== 0109 /** simple function to get the algorithm from Context Service 0110 * 0111 * @code 0112 * 0113 * // get the selector 0114 * const AlgSelector& selector = ... ; 0115 * 0116 * // get the list of algorithms: 0117 * const std::vector<IAlgorithm*>& algs = ... ; 0118 * 0119 * // get the appropriate algorithm: 0120 * IAlgorithm* alg = getAlgorithm ( algs , selector ) ; 0121 * 0122 * @endcode 0123 * 0124 * @see IAlgContextSvc 0125 * @see Gaudi::Utils::AlgSelector 0126 * @param lst list of the algorithms 0127 * @param sel the selection functor 0128 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0129 * @date 2007-09-07 0130 */ 0131 GAUDI_API IAlgorithm* getAlgorithm( const std::vector<IAlgorithm*>& lst, const AlgSelector& sel ); 0132 // ======================================================================== 0133 } // namespace Utils 0134 } // end of namespace Gaudi 0135 // ============================================================================ 0136 // The END 0137 // ============================================================================ 0138 #endif // GAUDIALG_GETALG_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |