Back to home page

EIC code displayed by LXR

 
 

    


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

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_CONVERTER_H
0012 #define GAUDIKERNEL_CONVERTER_H
0013 
0014 // generic experiment headers
0015 #include "GaudiKernel/ConversionSvc.h"
0016 #include "GaudiKernel/IConverter.h"
0017 #include "GaudiKernel/IDataManagerSvc.h"
0018 #include "GaudiKernel/IDataProviderSvc.h"
0019 #include "GaudiKernel/IService.h"
0020 #include "GaudiKernel/ISvcLocator.h"
0021 
0022 // Forward declarations
0023 class IMessageSvc;
0024 class IRegistry;
0025 
0026 /** @class Converter Converter.h GaudiKernel/Converter.h
0027 
0028     Converter base class. See interface for detailed description,
0029     arguments and return values
0030 
0031     @author Markus Frank
0032     @version 1.0
0033 */
0034 class GAUDI_API Converter : public implements<IConverter> {
0035 public:
0036   using Factory = Gaudi::PluginService::Factory<IConverter*( ISvcLocator* )>;
0037 
0038   /// Initialize the converter
0039   StatusCode initialize() override;
0040 
0041   /// Initialize the converter
0042   StatusCode finalize() override;
0043 
0044   /// Set Data provider service
0045   StatusCode setDataProvider( IDataProviderSvc* svc ) override;
0046 
0047   /// Get Data provider service
0048   SmartIF<IDataProviderSvc>& dataProvider() const override;
0049 
0050   /// Set conversion service the converter is connected to
0051   StatusCode setConversionSvc( IConversionSvc* svc ) override;
0052 
0053   /// Get conversion service the converter is connected to
0054   SmartIF<IConversionSvc>& conversionSvc() const override;
0055 
0056   /// Set address creator facility
0057   StatusCode setAddressCreator( IAddressCreator* creator ) override;
0058 
0059   /// Retrieve address creator facility
0060   SmartIF<IAddressCreator>& addressCreator() const override;
0061 
0062   /// Retrieve the class type of objects the converter produces.
0063   const CLID& objType() const override;
0064 
0065   /// Retrieve the class type of the data store the converter uses.
0066   // MSF: Masked to generate compiler error due to interface change
0067   virtual long i_repSvcType() const;
0068 
0069   /// Create the transient representation of an object.
0070   StatusCode createObj( IOpaqueAddress* pAddress, DataObject*& refpObject ) override;
0071 
0072   /// Resolve the references of the created transient object.
0073   StatusCode fillObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0074 
0075   /// Update the transient object from the other representation.
0076   StatusCode updateObj( IOpaqueAddress* pAddress, DataObject* refpObject ) override;
0077 
0078   /// Update the references of an updated transient object.
0079   StatusCode updateObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0080 
0081   /// Convert the transient object to the requested representation.
0082   StatusCode createRep( DataObject* pObject, IOpaqueAddress*& refpAddress ) override;
0083 
0084   /// Resolve the references of the converted object.
0085   StatusCode fillRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0086 
0087   /// Update the converted representation of a transient object.
0088   StatusCode updateRep( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0089 
0090   /// Update the references of an already converted object.
0091   StatusCode updateRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0092 
0093   /// Standard Constructor
0094   Converter( long storage_type, const CLID& class_type, ISvcLocator* svc = 0 );
0095 
0096   /// Access a service by name, creating it if it doesn't already exist.
0097   template <class T>
0098   StatusCode service( const std::string& name, T*& psvc, bool createIf = false ) const {
0099     return service_i( name, createIf, T::interfaceID(), (void**)&psvc );
0100   }
0101 
0102   /// Access a service by name, type creating it if it doesn't already exist.
0103   template <class T>
0104   StatusCode service( const std::string& type, const std::string& name, T*& psvc ) const {
0105     return service_i( type, name, T::interfaceID(), reinterpret_cast<void**>( &psvc ) );
0106   }
0107 
0108   /// Return a pointer to the service identified by name (or "type/name")
0109   SmartIF<IService> service( const std::string& name, const bool createIf = true ) const;
0110 
0111 protected:
0112   /// Retrieve pointer to service locator
0113   SmartIF<ISvcLocator>& serviceLocator() const;
0114   /// Retrieve pointer to message service
0115   SmartIF<IMessageSvc>& msgSvc() const;
0116   /// Get Data Manager service
0117   SmartIF<IDataManagerSvc>& dataManager() const;
0118 
0119 private:
0120   /// Storage type
0121   long m_storageType;
0122   /// Class type the converter can handle
0123   const CLID m_classType;
0124   /// Pointer to the address creation service interface
0125   mutable SmartIF<IAddressCreator> m_addressCreator;
0126   /// Pointer to data provider service
0127   mutable SmartIF<IDataProviderSvc> m_dataProvider;
0128   /// Pointer to data manager service
0129   mutable SmartIF<IDataManagerSvc> m_dataManager;
0130   /// Pointer to the connected conversion service
0131   mutable SmartIF<IConversionSvc> m_conversionSvc;
0132   /// Service Locator reference
0133   mutable SmartIF<ISvcLocator> m_svcLocator;
0134   /// MessageSvc reference
0135   mutable SmartIF<IMessageSvc> m_messageSvc;
0136 
0137   /** implementation of service method */
0138   StatusCode service_i( const std::string& svcName, bool createIf, const InterfaceID& iid, void** ppSvc ) const;
0139   StatusCode service_i( const std::string& svcType, const std::string& svcName, const InterfaceID& iid,
0140                         void** ppSvc ) const;
0141 };
0142 
0143 // Identified class for converters' factories
0144 class GAUDI_API ConverterID final {
0145 public:
0146   ConverterID( long stype, CLID clid ) : m_stype( stype ), m_clid( clid ) {}
0147   inline bool operator==( const ConverterID& id ) const { return m_stype == id.m_stype && m_clid == id.m_clid; }
0148 
0149 private:
0150   friend std::ostream& operator<<( std::ostream&, const ConverterID& );
0151   long                 m_stype;
0152   CLID                 m_clid;
0153 };
0154 
0155 inline std::ostream& operator<<( std::ostream& s, const ConverterID& id ) {
0156   return s << "CNV_" << id.m_stype << "_" << id.m_clid;
0157 }
0158 
0159 // Macro to declare component factories
0160 #define DECLARE_CONVERTER( x ) DECLARE_COMPONENT_WITH_ID( x, ConverterID( x::storageType(), x::classID() ) )
0161 
0162 #endif // GAUDIKERNEL_CONVERTER_H