The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
PersistencySvc.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11// ============================================================
12//
13// PersistencySvc.h
14// ------------------------------------------------------------
15//
16// Package : PersistencySvc
17//
18// Author : Markus Frank
19//
20// ===========================================================
21#pragma once
22
27#include <GaudiKernel/Service.h>
28#include <algorithm>
29#include <functional>
30#include <map>
31#include <mutex>
32
57class PersistencySvc : public extends<Service, IConversionSvc, IPersistencySvc, IAddressCreator> {
58protected:
59 class ServiceEntry final {
64
65 public:
67 : m_serviceType( type )
68 , m_service( std::move( svc ) )
69 , m_cnvService( std::move( cnv ) )
70 , m_addrCreator( std::move( cr ) ) {}
72 : m_serviceType( type ), m_service( svc ), m_cnvService( cnv ), m_addrCreator( cr ) {}
73 ServiceEntry( const ServiceEntry& ) = default;
74
75 SmartIF<IService>& service() const { return m_service; }
78 long svcType() const { return m_serviceType; }
79 };
80 typedef std::map<long, ServiceEntry> Services;
81
82public:
85
86 long repSvcType() const override;
87
89 const CLID& objType() const override;
90
92 StatusCode createObj( IOpaqueAddress* pAddress, DataObject*& refpObject ) override;
93
95 StatusCode fillObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
96
98 StatusCode updateObj( IOpaqueAddress* pAddress, DataObject* refpObject ) override;
99
101 StatusCode updateObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
102
104 StatusCode createRep( DataObject* pObject, IOpaqueAddress*& refpAddress ) override;
105
107 StatusCode fillRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
108
110 StatusCode updateRep( IOpaqueAddress* pAddress, DataObject* pObject ) override;
111
113 StatusCode updateRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
114
116 StatusCode setDataProvider( IDataProviderSvc* pStore ) override;
117
119 SmartIF<IDataProviderSvc>& dataProvider() const override;
120
123
125 SmartIF<IConversionSvc>& conversionSvc() const override;
126
128 StatusCode setAddressCreator( IAddressCreator* creator ) override;
129
132
134 StatusCode addConverter( IConverter* pConverter ) override;
135
137 StatusCode addConverter( const CLID& clid ) override;
138
140 IConverter* converter( const CLID& clid ) override;
141
143 StatusCode removeConverter( const CLID& clid ) override;
144
146 StatusCode connectOutput( const std::string& outputFile, const std::string& openMode ) override;
148 StatusCode connectOutput( const std::string& outputFile ) override;
149
151 StatusCode commitOutput( const std::string& output, bool do_commit ) override;
152
154 StatusCode createAddress( long svc_type, const CLID& clid, const std::string* pars, const unsigned long* ipars,
155 IOpaqueAddress*& refpAddress ) override;
156
158 StatusCode convertAddress( const IOpaqueAddress* pAddress, std::string& refAddress ) override;
159
161 StatusCode createAddress( long svc_type, const CLID& clid, const std::string& refAddress,
162 IOpaqueAddress*& refpAddress ) override;
164
167
169
171 StatusCode removeCnvService( long type ) override;
172
174 StatusCode setDefaultCnvService( long type ) override;
175
177 StatusCode getService( long service_type, IConversionSvc*& refpSvc ) override;
178
180 StatusCode getService( const std::string& service_type, IConversionSvc*& refpSvc ) override;
182
185
186 StatusCode initialize() override;
187
189 StatusCode finalize() override;
191
194
195 using extends::extends;
196
197protected:
199 SmartIF<IConversionSvc>& service( const std::string& nam );
200
202 SmartIF<IConversionSvc>& service( long service_type );
203
205 SmartIF<IAddressCreator>& addressCreator( long service_type );
206
208 void encodeAddrHdr( long service_type, const CLID& clid, std::string& address ) const;
209
211 void decodeAddrHdr( const std::string& address, long& service_type, CLID& clid, std::string& address_trailer ) const;
212
214 StatusCode makeCall( int typ, IOpaqueAddress*& pAddress, DataObject*& pObject );
215
217 bool enable( bool value );
219
227 mutable std::recursive_mutex m_servicesMutex;
228
231
233 this,
234 "CnvServices",
235 {},
236 [this]( auto& p ) {
237 if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << p << endmsg;
238 },
239 "Names of services to be requested from the service locator and added by default",
240 "OrderedSet<std::string>" };
241
243 bool m_enable = true;
244
247};
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
const long TEST_StorageType
Definition ClassID.h:57
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
IAddressCreator interface definition.
The data converters are responsible to translate data from one representation into another.
Definition IConverter.h:65
Data provider interface definition.
Opaque address interface definition.
General service interface definition.
Definition IService.h:26
SmartIF< IAddressCreator > & addrCreator() const
ServiceEntry(long type, IService *svc, IConversionSvc *cnv, IAddressCreator *cr)
SmartIF< IConversionSvc > & conversionSvc() const
SmartIF< IService > m_service
long m_serviceType
ServiceEntry(const ServiceEntry &)=default
ServiceEntry(long type, SmartIF< IService > svc, SmartIF< IConversionSvc > cnv, SmartIF< IAddressCreator > cr)
long svcType() const
SmartIF< IService > & service() const
SmartIF< IAddressCreator > m_addrCreator
SmartIF< IConversionSvc > m_cnvService
PersistencySvc class implementation definition.
bool m_enable
Flag to indicate that the service is enabled.
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
StatusCode connectOutput(const std::string &outputFile, const std::string &openMode) override
Connect the output file to the service with open mode.
long repSvcType() const override
Return default service type.
void decodeAddrHdr(const std::string &address, long &service_type, CLID &clid, std::string &address_trailer) const
Retrieve storage type and clid from address header of string.
StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject) override
Implementation of IConverter: Create the transient representation of an object.
Gaudi::Property< std::vector< std::string > > m_svcNames
StatusCode setAddressCreator(IAddressCreator *creator) override
Set address creator facility.
StatusCode setDefaultCnvService(long type) override
Set default service type.
StatusCode updateRepRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the references of an already converted object.
void encodeAddrHdr(long service_type, const CLID &clid, std::string &address) const
Retrieve string from storage type and clid.
SmartIF< IDataProviderSvc > & dataProvider() const override
Access reference to transient datastore.
StatusCode commitOutput(const std::string &output, bool do_commit) override
Commit pending output.
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
const CLID & objType() const override
Retrieve the class type of objects the converter produces. (DUMMY)
std::recursive_mutex m_servicesMutex
Mutex to protect accesses to m_cnvServices.
StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the references of an updated transient object.
StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress) override
Convert an address to string form.
SmartIF< IConversionSvc > m_cnvDefault
Default output service.
SmartIF< IAddressCreator > m_addrCreator
Pointer to the IAddressCreator interface of this, for addressCreator().
StatusCode addConverter(IConverter *pConverter) override
Add converter object to conversion service.
StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Resolve the references of the created transient object.
long m_cnvDefType
Default service type.
std::map< long, ServiceEntry > Services
StatusCode removeCnvService(long type) override
Remove a Service.
StatusCode setDataProvider(IDataProviderSvc *pStore) override
Define transient datastore.
StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Resolve the references of the converted object.
IConverter * converter(const CLID &clid) override
Retrieve converter from list.
StatusCode addCnvService(IConversionSvc *service) override
Add a new Service.
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the converted representation of a transient object.
Services m_cnvServices
List of conversion workers.
SmartIF< IAddressCreator > & addressCreator() const override
Retrieve address creator facility.
StatusCode initialize() override
Initialize the service.
bool enable(bool value)
Set enabled flag.
StatusCode createAddress(long svc_type, const CLID &clid, const std::string *pars, const unsigned long *ipars, IOpaqueAddress *&refpAddress) override
Create a Generic address using explicit arguments to identify a single object.
StatusCode makeCall(int typ, IOpaqueAddress *&pAddress, DataObject *&pObject)
Implementation helper.
StatusCode removeConverter(const CLID &clid) override
Remove converter object from conversion service (if present).
StatusCode finalize() override
stop the service.
StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject) override
Implementation of IConverter: Update the transient object from the other representation.
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
StatusCode getService(long service_type, IConversionSvc *&refpSvc) override
Retrieve conversion service identified by technology.
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to data provider service.
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
@ DEBUG
Definition IMessageSvc.h:22
STL namespace.