Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2020 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_PROPERTYMGR_H
0012 #define GAUDIKERNEL_PROPERTYMGR_H
0013 // ============================================================================
0014 // Include files
0015 // ============================================================================
0016 // STD & STL
0017 // ============================================================================
0018 #include <iostream>
0019 #include <stdexcept>
0020 #include <utility>
0021 #include <vector>
0022 // ============================================================================
0023 // GaudiKernel
0024 // ============================================================================
0025 #include "GaudiKernel/DataHandle.h"
0026 #include "GaudiKernel/GaudiHandle.h"
0027 #include "GaudiKernel/IProperty.h"
0028 #include <Gaudi/Property.h>
0029 
0030 // ============================================================================
0031 
0032 /** @class PropertyMgr PropertyMgr.h GaudiKernel/PropertyMgr.h
0033  *
0034  *  Property manager helper class. This class is used by algorithms and services
0035  *  for helping to manage its own set of properties. It implements the IProperty
0036  *  interface.
0037  *
0038  *  @author Paul Maley
0039  *  @author David Quarrie
0040  *
0041  *  \deprecated will be removed in v29r0, consider using PropertyHolder instead
0042  */
0043 class [[deprecated( "will be removed in v29r0, consider using PropertyHolder instead" )]] PropertyMgr
0044     : public implements<IProperty> {
0045 public:
0046   /// constructor from the interface
0047   PropertyMgr( IInterface* iface = nullptr );
0048   // copy constructor
0049   PropertyMgr( const PropertyMgr& ) = delete;
0050   // assignment operator
0051   PropertyMgr& operator=( const PropertyMgr& ) = delete;
0052 
0053 public:
0054   /// Declare a property (templated)
0055   template <class TYPE, typename = std::enable_if_t<!std::is_base_of_v<GaudiHandleBase, TYPE> &&
0056                                                     !std::is_base_of_v<GaudiHandleArrayBase, TYPE> &&
0057                                                     !std::is_base_of_v<Gaudi::DataHandle, TYPE>>>
0058   Gaudi::Details::PropertyBase* declareProperty( const std::string& name, TYPE& value,
0059                                                  const std::string& doc = "none" );
0060   /// Declare a property (specialization)
0061   template <class TYPE>
0062   Gaudi::Details::PropertyBase* declareProperty( const std::string& name, Gaudi::Property<TYPE>& prop,
0063                                                  const std::string& doc = "none" );
0064   /// Declare a property (specialization)
0065   template <class TYPE>
0066   Gaudi::Details::PropertyBase* declareProperty( const std::string& name, Gaudi::Property<TYPE&>& prop,
0067                                                  const std::string& doc = "none" );
0068 
0069   // partial specializations for various GaudiHandles
0070   /// Declare a property (specialization)
0071   Gaudi::Details::PropertyBase* declareProperty( const std::string& name, GaudiHandleBase& ref,
0072                                                  const std::string& doc = "none" );
0073   /// Declare a property (specialization)
0074   Gaudi::Details::PropertyBase* declareProperty( const std::string& name, GaudiHandleArrayBase& ref,
0075                                                  const std::string& doc = "none" );
0076   /// Declare a property (specialization)
0077   Gaudi::Details::PropertyBase* declareProperty( const std::string& name, Gaudi::DataHandle& ref,
0078                                                  const std::string& doc = "none" );
0079   /// Declare a remote property
0080   Gaudi::Details::PropertyBase* declareRemoteProperty( const std::string& name, IProperty* rsvc,
0081                                                        const std::string& rname = "" );
0082   // ==========================================================================
0083   // IProperty implementation
0084   // ==========================================================================
0085   /** set the property form another property
0086    *  @see IProperty
0087    */
0088   StatusCode setProperty( const std::string& name, const Gaudi::Details::PropertyBase& p ) override;
0089   // ==========================================================================
0090   /** set the property from the property formatted string
0091    *  @see IProperty
0092    */
0093   StatusCode setProperty( const std::string& s ) override;
0094   // ==========================================================================
0095   /** set the property from name and the value
0096    *  @see IProperty
0097    */
0098   StatusCode setPropertyRepr( const std::string& n, const std::string& v ) override;
0099   // ==========================================================================
0100   /** get the property
0101    *  @see IProperty
0102    */
0103   StatusCode getProperty( Gaudi::Details::PropertyBase* p ) const override;
0104   // ==========================================================================
0105   /** get the property by name
0106    *  @see IProperty
0107    */
0108   const Gaudi::Details::PropertyBase& getProperty( std::string_view name ) const override;
0109   // ==========================================================================
0110   /** convert the property to the string
0111    *  @see IProperty
0112    */
0113   StatusCode getProperty( std::string_view n, std::string& v ) const override;
0114   // ==========================================================================
0115   /** get all properties
0116    *  @see IProperty
0117    */
0118   const std::vector<Gaudi::Details::PropertyBase*>& getProperties() const override;
0119   // ==========================================================================
0120   /** Return true if we have a property with the given name.
0121    *  @see IProperty
0122    */
0123   bool hasProperty( std::string_view name ) const override;
0124   // ==========================================================================
0125   // IInterface implementation
0126   StatusCode queryInterface( const InterfaceID& iid, void** pinterface ) override;
0127   // ==========================================================================
0128 protected:
0129   // get local or remote property by name
0130   Gaudi::Details::PropertyBase* property( std::string_view name ) const;
0131 
0132 private:
0133   /// get the property by name form the proposed list
0134   Gaudi::Details::PropertyBase* property( std::string_view                                  name,
0135                                           const std::vector<Gaudi::Details::PropertyBase*>& props ) const;
0136 
0137   /// Throw an exception if the name is already present in the
0138   /// list of properties (see GAUDI-1023).
0139   void assertUniqueName( const std::string& name ) const;
0140 
0141   // Some typedef to simply typing
0142   typedef std::vector<Gaudi::Details::PropertyBase*>                 Properties;
0143   typedef std::pair<std::string, std::pair<IProperty*, std::string>> RemProperty;
0144   typedef std::vector<RemProperty>                                   RemoteProperties;
0145 
0146   /// Collection of all declared properties
0147   Properties m_properties; // local  properties
0148   /// Collection of all declared remote properties
0149   RemoteProperties m_remoteProperties; // Remote properties
0150   /// Properties to be deleted
0151   std::vector<std::unique_ptr<Gaudi::Details::PropertyBase>> m_todelete; // properties to be deleted
0152   /// Interface hub reference (ApplicationMgr)
0153   IInterface* m_pOuter; // Interface hub reference
0154 };
0155 // ============================================================================
0156 /// Declare a property (templated)
0157 // ============================================================================
0158 template <class TYPE, typename>
0159 inline Gaudi::Details::PropertyBase* PropertyMgr::declareProperty( const std::string& name, TYPE& value,
0160                                                                    const std::string& doc ) {
0161   assertUniqueName( name );
0162   m_todelete.emplace_back( new Gaudi::Property<TYPE&>( name, value ) );
0163   Gaudi::Details::PropertyBase* p = m_todelete.back().get();
0164   //
0165   p->setDocumentation( doc );
0166   m_properties.push_back( p );
0167   //
0168   return p;
0169 }
0170 // ============================================================================
0171 /// Declare a property (templated)
0172 // ============================================================================
0173 template <class TYPE>
0174 inline Gaudi::Details::PropertyBase* PropertyMgr::declareProperty( const std::string& name, Gaudi::Property<TYPE>& prop,
0175                                                                    const std::string& doc ) {
0176   assertUniqueName( name );
0177   Gaudi::Details::PropertyBase* p = &prop;
0178   //
0179   p->setName( name );
0180   p->setDocumentation( doc );
0181   m_properties.push_back( p );
0182   //
0183   return p;
0184 }
0185 // ============================================================================
0186 /// Declare a property
0187 // ============================================================================
0188 template <class TYPE>
0189 inline Gaudi::Details::PropertyBase*
0190 PropertyMgr::declareProperty( const std::string& name, Gaudi::Property<TYPE&>& prop, const std::string& doc ) {
0191   assertUniqueName( name );
0192   Gaudi::Details::PropertyBase* p = &prop;
0193   //
0194   p->setName( name );
0195   p->setDocumentation( doc );
0196   m_properties.push_back( p );
0197   //
0198   return p;
0199 }
0200 
0201 // ============================================================================
0202 // The END
0203 // ============================================================================
0204 #endif // GAUDIKERNEL_PROPERTYMGR_H