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_CONVERSIONSVC_H
0012 #define GAUDIKERNEL_CONVERSIONSVC_H 1
0013 
0014 // Include files
0015 #include "GaudiKernel/IAddressCreator.h"
0016 #include "GaudiKernel/IConversionSvc.h"
0017 #include "GaudiKernel/IDataProviderSvc.h"
0018 #include "GaudiKernel/Kernel.h"
0019 #include "GaudiKernel/Service.h"
0020 #include <algorithm>
0021 #include <utility>
0022 #include <vector>
0023 
0024 /** @class ConversionSvc ConversionSvc.h GaudiKernel/ConversionSvc.h
0025 
0026     Base class for all conversion services. It manages a set of Converters that
0027     are specialized for conversions of specific objects.
0028 
0029     This supports self learning converters:
0030     User hooks include the following (overridable) entries:
0031     - findCnvFactory:      returns a suitable converter factory
0032     - createConverter:     the actual convetrer creation
0033     - configureConverter:  configure converter before initialize
0034     - initializeConverter: initializes the converter
0035     - activateConverter:   any additional configuration to be done after
0036                            initialize.
0037 
0038     configureConverter and activateConverter are user hooks, where
0039     the convetrer can be manipulated by the hosting service
0040     and knowledge can be supplied, which a "generic" converter cannot
0041     aquire itself.
0042 
0043     These hooks allow any sub-classed conversion service to
0044     override the calls and create converters, which aquire
0045     the knowledge about their persistency type and the
0046     object type they convert during the initialization.
0047 
0048     Only AFTER these three steps the converter must satisfy the
0049     storage type of the hosting service and the class type of
0050     the required object type.
0051 
0052     @author Markus Frank
0053     @version 1.0
0054 */
0055 class GAUDI_API ConversionSvc : public extends<Service, IConversionSvc, IAddressCreator> {
0056   class WorkerEntry final {
0057     CLID        m_class;
0058     IConverter* m_converter;
0059 
0060   public:
0061     WorkerEntry( const CLID& cl, IConverter* cnv ) : m_class( cl ), m_converter( cnv ) {
0062       if ( m_converter ) m_converter->addRef();
0063     }
0064 
0065     ~WorkerEntry() {
0066       if ( m_converter ) m_converter->release();
0067     }
0068 
0069     WorkerEntry( WorkerEntry&& orig ) noexcept
0070         : m_class{ orig.m_class }, m_converter{ std::exchange( orig.m_converter, nullptr ) } {}
0071 
0072     WorkerEntry& operator=( WorkerEntry&& orig ) noexcept {
0073       m_class = orig.m_class;
0074       std::swap( m_converter, orig.m_converter );
0075       return *this;
0076     }
0077 
0078     WorkerEntry( const WorkerEntry& copy )            = delete;
0079     WorkerEntry& operator=( const WorkerEntry& copy ) = delete;
0080 
0081     IConverter* converter() { return m_converter; }
0082 
0083     const CLID& clID() const { return m_class; }
0084   };
0085 
0086 public:
0087   /// Standard Constructor
0088   ConversionSvc( const std::string& name, ISvcLocator* svc, long type );
0089 
0090   /// disable copy and assignment
0091   ConversionSvc( const ConversionSvc& )            = delete;
0092   ConversionSvc& operator=( const ConversionSvc& ) = delete;
0093 
0094   /// Initialize the service.
0095   StatusCode initialize() override;
0096 
0097   /// stop the service.
0098   StatusCode finalize() override;
0099 
0100   /// Retrieve the class type of the data store the converter uses.
0101   long repSvcType() const override;
0102 
0103   /// Implementation of IConverter: dummy call
0104   const CLID& objType() const override;
0105 
0106   /** Implementation of IConverter: Set Data provider service
0107       @return    Status code indicating success or failure
0108       @param     pService   Pointer to data provider service
0109   */
0110   StatusCode setDataProvider( IDataProviderSvc* pService ) override;
0111 
0112   /** Implementation of IConverter: Get Data provider service
0113       @return    Pointer to data provider service
0114   */
0115   SmartIF<IDataProviderSvc>& dataProvider() const override;
0116 
0117   /// Implementation of IConverter: Set conversion service the converter is connected to
0118   StatusCode setConversionSvc( IConversionSvc* svc ) override;
0119 
0120   /// Implementation of IConverter: Get conversion service the converter is connected to
0121   SmartIF<IConversionSvc>& conversionSvc() const override;
0122 
0123   /// Set address creator facility
0124   StatusCode setAddressCreator( IAddressCreator* creator ) override;
0125 
0126   /// Retrieve address creator facility
0127   SmartIF<IAddressCreator>& addressCreator() const override;
0128 
0129   /// Implementation of IConverter: Create the transient representation of an object.
0130   StatusCode createObj( IOpaqueAddress* pAddress, DataObject*& refpObject ) override;
0131 
0132   /// Implementation of IConverter: Resolve the references of the created transient object.
0133   StatusCode fillObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0134 
0135   /// Implementation of IConverter: Update the transient object from the other representation.
0136   StatusCode updateObj( IOpaqueAddress* pAddress, DataObject* refpObject ) override;
0137 
0138   /// Implementation of IConverter: Update the references of an updated transient object.
0139   StatusCode updateObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0140 
0141   /// Implementation of IConverter: Convert the transient object to the requested representation.
0142   StatusCode createRep( DataObject* pObject, IOpaqueAddress*& refpAddress ) override;
0143 
0144   /// Implementation of IConverter: Resolve the references of the converted object.
0145   StatusCode fillRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0146 
0147   /// Implementation of IConverter: Update the converted representation of a transient object.
0148   StatusCode updateRep( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0149 
0150   /// Implementation of IConverter: Update the references of an already converted object.
0151   StatusCode updateRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
0152 
0153   /// Add converter object to conversion service.
0154   StatusCode addConverter( const CLID& clid ) override;
0155 
0156   /// Add converter object to conversion service.
0157   StatusCode addConverter( IConverter* pConverter ) override;
0158 
0159   /// Remove converter object from conversion service (if present).
0160   StatusCode removeConverter( const CLID& clid ) override;
0161 
0162   /// Retrieve converter from list
0163   IConverter* converter( const CLID& wanted ) override;
0164 
0165   /// Connect the output file to the service with open mode.
0166   StatusCode connectOutput( const std::string& outputFile, const std::string& openMode ) override;
0167 
0168   /// Connect the output file to the service.
0169   StatusCode connectOutput( const std::string& output ) override;
0170 
0171   /// Commit pending output.
0172   StatusCode commitOutput( const std::string& output, bool do_commit ) override;
0173 
0174   /// Create a Generic address using explicit arguments to identify a single object.
0175   StatusCode createAddress( long svc_type, const CLID& clid, const std::string* par, const unsigned long* ip,
0176                             IOpaqueAddress*& refpAddress ) override;
0177 
0178   /// Convert an address to string form
0179   StatusCode convertAddress( const IOpaqueAddress* pAddress, std::string& refAddress ) override;
0180 
0181   /// Convert an address in string form to object form
0182   StatusCode createAddress( long svc_type, const CLID& clid, const std::string& refAddress,
0183                             IOpaqueAddress*& refpAddress ) override;
0184 
0185   /// Update state of the service
0186   virtual StatusCode updateServiceState( IOpaqueAddress* pAddress );
0187 
0188 protected:
0189   /// Create new Converter using factory
0190   virtual IConverter* createConverter( long typ, const CLID& clid, const ICnvFactory* fac );
0191 
0192   /// Configure the new converter before initialize is called
0193   virtual StatusCode configureConverter( long typ, const CLID& clid, IConverter* cnv );
0194 
0195   /// Initialize the new converter
0196   virtual StatusCode initializeConverter( long typ, const CLID& clid, IConverter* cnv );
0197 
0198   /// Activate the new converter after initialization
0199   virtual StatusCode activateConverter( long typ, const CLID& clid, IConverter* cnv );
0200 
0201   /// Load converter or dictionary needed by the converter
0202   virtual void loadConverter( DataObject* pObject );
0203 
0204   /// Retrieve address creation interface
0205   virtual SmartIF<IAddressCreator>& addressCreator() { return m_addressCreator; }
0206 
0207 protected:
0208   StatusCode makeCall( int typ, bool ignore_add, bool ignore_obj, bool update, IOpaqueAddress*& pAddress,
0209                        DataObject*& pObject );
0210 
0211   /// Pointer to data provider service
0212   mutable SmartIF<IDataProviderSvc> m_dataSvc;
0213   /// Pointer to the address creation service interface
0214   mutable SmartIF<IAddressCreator> m_addressCreator;
0215   /// Pointer to the IConversionSvc interface of this
0216   mutable SmartIF<IConversionSvc> m_cnvSvc;
0217   /// Conversion service type
0218   long m_type;
0219   /// List of conversion workers
0220   std::vector<WorkerEntry> m_workers;
0221 };
0222 #endif // GAUDIKERNEL_CONVERSIONSVC_H