The Gaudi Framework  master (37c0b60a)
PersistencySvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 
57 class PersistencySvc : public extends<Service, IConversionSvc, IPersistencySvc, IAddressCreator> {
58 protected:
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 ) ) {}
73  m_addrCreator = cr;
74  m_cnvService = cnv;
75  m_service = svc;
76  }
77  ServiceEntry( const ServiceEntry& ) = default;
78 
79  SmartIF<IService>& service() const { return m_service; }
82  long svcType() const { return m_serviceType; }
83  };
85 
86 public:
89  long repSvcType() const override;
91 
93  const CLID& objType() const override;
94 
96  StatusCode createObj( IOpaqueAddress* pAddress, DataObject*& refpObject ) override;
97 
99  StatusCode fillObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
100 
102  StatusCode updateObj( IOpaqueAddress* pAddress, DataObject* refpObject ) override;
103 
105  StatusCode updateObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
106 
108  StatusCode createRep( DataObject* pObject, IOpaqueAddress*& refpAddress ) override;
109 
111  StatusCode fillRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
112 
114  StatusCode updateRep( IOpaqueAddress* pAddress, DataObject* pObject ) override;
115 
117  StatusCode updateRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
118 
120  StatusCode setDataProvider( IDataProviderSvc* pStore ) override;
121 
123  SmartIF<IDataProviderSvc>& dataProvider() const override;
124 
126  StatusCode setConversionSvc( IConversionSvc* svc ) override;
127 
129  SmartIF<IConversionSvc>& conversionSvc() const override;
130 
133 
135  SmartIF<IAddressCreator>& addressCreator() const override;
136 
138  StatusCode addConverter( IConverter* pConverter ) override;
139 
141  StatusCode addConverter( const CLID& clid ) override;
142 
144  IConverter* converter( const CLID& clid ) override;
145 
147  StatusCode removeConverter( const CLID& clid ) override;
148 
150  StatusCode connectOutput( const std::string& outputFile, const std::string& openMode ) override;
152  StatusCode connectOutput( const std::string& outputFile ) override;
153 
155  StatusCode commitOutput( const std::string& output, bool do_commit ) override;
156 
158  StatusCode createAddress( long svc_type, const CLID& clid, const std::string* pars, const unsigned long* ipars,
159  IOpaqueAddress*& refpAddress ) override;
160 
162  StatusCode convertAddress( const IOpaqueAddress* pAddress, std::string& refAddress ) override;
163 
165  StatusCode createAddress( long svc_type, const CLID& clid, const std::string& refAddress,
166  IOpaqueAddress*& refpAddress ) override;
168 
173 
175  StatusCode removeCnvService( long type ) override;
176 
178  StatusCode setDefaultCnvService( long type ) override;
179 
181  StatusCode getService( long service_type, IConversionSvc*& refpSvc ) override;
182 
184  StatusCode getService( const std::string& service_type, IConversionSvc*& refpSvc ) override;
186 
189  StatusCode initialize() override;
191 
193  StatusCode finalize() override;
195 
198  using extends::extends;
200 
201 protected:
204 
206  SmartIF<IConversionSvc>& service( long service_type );
207 
209  SmartIF<IAddressCreator>& addressCreator( long service_type );
210 
212  void encodeAddrHdr( long service_type, const CLID& clid, std::string& address ) const;
213 
215  void decodeAddrHdr( const std::string& address, long& service_type, CLID& clid, std::string& address_trailer ) const;
216 
218  StatusCode makeCall( int typ, IOpaqueAddress*& pAddress, DataObject*& pObject );
219 
221  bool enable( bool value );
223 
232 
235 
237  this,
238  "CnvServices",
239  {},
240  [this]( auto& p ) {
241  if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << p << endmsg;
242  },
243  "Names of services to be requested from the service locator and added by default",
244  "OrderedSet<std::string>" };
245 
247  bool m_enable = true;
248 
251 };
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
PersistencySvc::encodeAddrHdr
void encodeAddrHdr(long service_type, const CLID &clid, std::string &address) const
Retrieve string from storage type and clid.
Definition: PersistencySvc.cpp:341
IService
Definition: IService.h:28
PersistencySvc::commitOutput
StatusCode commitOutput(const std::string &output, bool do_commit) override
Commit pending output.
Definition: PersistencySvc.cpp:290
PersistencySvc
PersistencySvc class implementation definition.
Definition: PersistencySvc.h:57
PersistencySvc::createRep
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: PersistencySvc.cpp:111
PersistencySvc::finalize
StatusCode finalize() override
stop the service.
Definition: PersistencySvc.cpp:496
PersistencySvc::ServiceEntry::m_serviceType
long m_serviceType
Definition: PersistencySvc.h:60
IAddressCreator
Definition: IAddressCreator.h:38
PersistencySvc::ServiceEntry::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const
Definition: PersistencySvc.h:80
std::string
STL class.
PersistencySvc::fillRepRefs
StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Resolve the references of the converted object.
Definition: PersistencySvc.cpp:116
PersistencySvc::m_cnvDefault
SmartIF< IConversionSvc > m_cnvDefault
Default output service.
Definition: PersistencySvc.h:234
PersistencySvc::updateObj
StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject) override
Implementation of IConverter: Update the transient object from the other representation.
Definition: PersistencySvc.cpp:101
PersistencySvc::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
Definition: PersistencySvc.cpp:166
IOpaqueAddress
Definition: IOpaqueAddress.h:33
PersistencySvc::dataProvider
SmartIF< IDataProviderSvc > & dataProvider() const override
Access reference to transient datastore.
Definition: PersistencySvc.cpp:157
PersistencySvc::ServiceEntry::ServiceEntry
ServiceEntry(long type, SmartIF< IService > svc, SmartIF< IConversionSvc > cnv, SmartIF< IAddressCreator > cr)
Definition: PersistencySvc.h:66
IPersistencySvc.h
PersistencySvc::addCnvService
StatusCode addCnvService(IConversionSvc *service) override
Add a new Service.
Definition: PersistencySvc.cpp:229
IAddressCreator.h
PersistencySvc::ServiceEntry::ServiceEntry
ServiceEntry(long type, IService *svc, IConversionSvc *cnv, IAddressCreator *cr)
Definition: PersistencySvc.h:71
PersistencySvc::decodeAddrHdr
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.
Definition: PersistencySvc.cpp:351
IConverter
Definition: IConverter.h:68
PersistencySvc::createAddress
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.
Definition: PersistencySvc.cpp:293
PersistencySvc::removeCnvService
StatusCode removeCnvService(long type) override
Remove a Service.
Definition: PersistencySvc.cpp:261
PersistencySvc::createObj
StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject) override
Implementation of IConverter: Create the transient representation of an object.
Definition: PersistencySvc.cpp:91
PersistencySvc::ServiceEntry::m_cnvService
SmartIF< IConversionSvc > m_cnvService
Definition: PersistencySvc.h:62
PersistencySvc::Services
std::map< long, ServiceEntry > Services
Definition: PersistencySvc.h:84
std::recursive_mutex
STL class.
PersistencySvc::ServiceEntry::svcType
long svcType() const
Definition: PersistencySvc.h:82
gaudirun.output
output
Definition: gaudirun.py:521
PersistencySvc::ServiceEntry::service
SmartIF< IService > & service() const
Definition: PersistencySvc.h:79
CommonMessaging< implements< IService, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
PersistencySvc::m_cnvServices
Services m_cnvServices
List of conversion workers.
Definition: PersistencySvc.h:229
IDataProviderSvc.h
PersistencySvc::setAddressCreator
StatusCode setAddressCreator(IAddressCreator *creator) override
Set address creator facility.
Definition: PersistencySvc.cpp:392
PersistencySvc::updateRepRefs
StatusCode updateRepRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the references of an already converted object.
Definition: PersistencySvc.cpp:126
PersistencySvc::ServiceEntry::m_addrCreator
SmartIF< IAddressCreator > m_addrCreator
Definition: PersistencySvc.h:63
StatusCode
Definition: StatusCode.h:65
PersistencySvc::m_dataSvc
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to data provider service.
Definition: PersistencySvc.h:227
PersistencySvc::setDefaultCnvService
StatusCode setDefaultCnvService(long type) override
Set default service type.
Definition: PersistencySvc.cpp:276
PersistencySvc::service
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
Definition: PersistencySvc.cpp:194
PersistencySvc::m_addrCreator
SmartIF< IAddressCreator > m_addrCreator
Pointer to the IAddressCreator interface of this, for addressCreator().
Definition: PersistencySvc.h:250
PersistencySvc::ServiceEntry::addrCreator
SmartIF< IAddressCreator > & addrCreator() const
Definition: PersistencySvc.h:81
PersistencySvc::converter
IConverter * converter(const CLID &clid) override
Retrieve converter from list.
Definition: PersistencySvc.cpp:191
Write.creator
creator
Definition: Write.py:23
PersistencySvc::addressCreator
SmartIF< IAddressCreator > & addressCreator() const override
Retrieve address creator facility.
Definition: PersistencySvc.cpp:401
SmartIF< IService >
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
PersistencySvc::connectOutput
StatusCode connectOutput(const std::string &outputFile, const std::string &openMode) override
Connect the output file to the service with open mode.
Definition: PersistencySvc.cpp:282
PersistencySvc::ServiceEntry
Definition: PersistencySvc.h:59
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
std::map< long, ServiceEntry >
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
PersistencySvc::m_svcNames
Gaudi::Property< std::vector< std::string > > m_svcNames
Definition: PersistencySvc.h:236
PersistencySvc::m_cnvDefType
long m_cnvDefType
Default service type.
Definition: PersistencySvc.h:225
Service.h
PersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: PersistencySvc.cpp:487
gaudirun.type
type
Definition: gaudirun.py:160
PersistencySvc::setConversionSvc
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
Definition: PersistencySvc.cpp:160
PersistencySvc::ServiceEntry::m_service
SmartIF< IService > m_service
Definition: PersistencySvc.h:61
PersistencySvc::makeCall
StatusCode makeCall(int typ, IOpaqueAddress *&pAddress, DataObject *&pObject)
Implementation helper.
Definition: PersistencySvc.cpp:36
PersistencySvc::ServiceEntry::ServiceEntry
ServiceEntry(const ServiceEntry &)=default
PersistencySvc::removeConverter
StatusCode removeConverter(const CLID &clid) override
Remove converter object from conversion service (if present).
Definition: PersistencySvc.cpp:179
PersistencySvc::m_servicesMutex
std::recursive_mutex m_servicesMutex
Mutex to protect accesses to m_cnvServices.
Definition: PersistencySvc.h:231
std
STL namespace.
PersistencySvc::addConverter
StatusCode addConverter(IConverter *pConverter) override
Add converter object to conversion service.
Definition: PersistencySvc.cpp:172
DataObject
Definition: DataObject.h:36
PersistencySvc::m_enable
bool m_enable
Flag to indicate that the service is enabled.
Definition: PersistencySvc.h:247
PersistencySvc::updateObjRefs
StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the references of an updated transient object.
Definition: PersistencySvc.cpp:106
PersistencySvc::updateRep
StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the converted representation of a transient object.
Definition: PersistencySvc.cpp:121
PersistencySvc::repSvcType
long repSvcType() const override
Return default service type.
Definition: PersistencySvc.cpp:273
PersistencySvc::fillObjRefs
StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Resolve the references of the created transient object.
Definition: PersistencySvc.cpp:96
IDataProviderSvc
Definition: IDataProviderSvc.h:53
IConversionSvc.h
PersistencySvc::enable
bool enable(bool value)
Set enabled flag.
Definition: PersistencySvc.cpp:506
PersistencySvc::convertAddress
StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress) override
Convert an address to string form.
Definition: PersistencySvc.cpp:301
TEST_StorageType
const long TEST_StorageType
Definition: ClassID.h:59
PersistencySvc::objType
const CLID & objType() const override
Retrieve the class type of objects the converter produces. (DUMMY)
Definition: PersistencySvc.cpp:484
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:37
PersistencySvc::setDataProvider
StatusCode setDataProvider(IDataProviderSvc *pStore) override
Define transient datastore.
Definition: PersistencySvc.cpp:149
PersistencySvc::getService
StatusCode getService(long service_type, IConversionSvc *&refpSvc) override
Retrieve conversion service identified by technology.
Definition: PersistencySvc.cpp:404
IConversionSvc
Definition: IConversionSvc.h:47