| The Gaudi Framework v32r1 (f65d50dc)

PersistencySvc.h
Go to the documentation of this file.
1 // ============================================================
2 //
3 // PersistencySvc.h
4 // ------------------------------------------------------------
5 //
6 // Package : PersistencySvc
7 //
8 // Author : Markus Frank
9 //
10 // ===========================================================
11 #ifndef PERSISTENCYSVC_PERSISTENCYSVC_H
12 #define PERSISTENCYSVC_PERSISTENCYSVC_H 1
13
14 // Framework include files
15 #include "GaudiKernel/IAddressCreator.h"
16 #include "GaudiKernel/IConversionSvc.h"
17 #include "GaudiKernel/IDataProviderSvc.h"
18 #include "GaudiKernel/IPersistencySvc.h"
19 #include "GaudiKernel/Service.h"
20
21 // STL include files
22 #include <algorithm>
23 #include <functional>
24 #include <map>
25
50 class PersistencySvc : public extends<Service, IConversionSvc, IPersistencySvc, IAddressCreator> {
51 protected:
52 class ServiceEntry final {
53 long m_serviceType;
54 mutable SmartIF<IService> m_service;
55 mutable SmartIF<IConversionSvc> m_cnvService;
56 mutable SmartIF<IAddressCreator> m_addrCreator;
57
58 public:
59 ServiceEntry( long type, SmartIF<IService> svc, SmartIF<IConversionSvc> cnv, SmartIF<IAddressCreator> cr )
60 : m_serviceType( type )
61 , m_service( std::move( svc ) )
62 , m_cnvService( std::move( cnv ) )
63 , m_addrCreator( std::move( cr ) ) {}
64 ServiceEntry( long type, IService* svc, IConversionSvc* cnv, IAddressCreator* cr ) {
65 m_serviceType = type;
66 m_addrCreator = cr;
67 m_cnvService = cnv;
68 m_service = svc;
69 }
70 ServiceEntry( const ServiceEntry& ) = default;
71
72 SmartIF<IService>& service() const { return m_service; }
73 SmartIF<IConversionSvc>& conversionSvc() const { return m_cnvService; }
74 SmartIF<IAddressCreator>& addrCreator() const { return m_addrCreator; }
75 long svcType() const { return m_serviceType; }
76 };
77 typedef std::map<long, ServiceEntry> Services;
78 /*
79 class SvcTest final {
80 public:
81 SvcTest(long test) : m_test(test) {
82 }
83 bool operator()( const ServiceEntry& testee ) const {
84 return m_test == testee.svcType();
85 }
86 private:
87 long m_test;
88 };
89 */
90 public:
93 long repSvcType() const override;
95
97 const CLID& objType() const override;
98
100 StatusCode createObj( IOpaqueAddress* pAddress, DataObject*& refpObject ) override;
101
103 StatusCode fillObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
104
106 StatusCode updateObj( IOpaqueAddress* pAddress, DataObject* refpObject ) override;
107
109 StatusCode updateObjRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
110
112 StatusCode createRep( DataObject* pObject, IOpaqueAddress*& refpAddress ) override;
113
115 StatusCode fillRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
116
118 StatusCode updateRep( IOpaqueAddress* pAddress, DataObject* pObject ) override;
119
121 StatusCode updateRepRefs( IOpaqueAddress* pAddress, DataObject* pObject ) override;
122
124 StatusCode setDataProvider( IDataProviderSvc* pStore ) override;
125
127 SmartIF<IDataProviderSvc>& dataProvider() const override;
128
130 StatusCode setConversionSvc( IConversionSvc* svc ) override;
131
133 SmartIF<IConversionSvc>& conversionSvc() const override;
134
136 StatusCode setAddressCreator( IAddressCreator* creator ) override;
137
139 SmartIF<IAddressCreator>& addressCreator() const override;
140
142 StatusCode addConverter( IConverter* pConverter ) override;
143
145 StatusCode addConverter( const CLID& clid ) override;
146
148 IConverter* converter( const CLID& clid ) override;
149
151 StatusCode removeConverter( const CLID& clid ) override;
152
154 StatusCode connectOutput( const std::string& outputFile, const std::string& openMode ) override;
156 StatusCode connectOutput( const std::string& outputFile ) override;
157
159 StatusCode commitOutput( const std::string& output, bool do_commit ) override;
160
162 StatusCode createAddress( long svc_type, const CLID& clid, const std::string* pars, const unsigned long* ipars,
163 IOpaqueAddress*& refpAddress ) override;
164
166 StatusCode convertAddress( const IOpaqueAddress* pAddress, std::string& refAddress ) override;
167
169 StatusCode createAddress( long svc_type, const CLID& clid, const std::string& refAddress,
170 IOpaqueAddress*& refpAddress ) override;
172
175 StatusCode addCnvService( IConversionSvc* service ) override;
177
179 StatusCode removeCnvService( long type ) override;
180
182 StatusCode setDefaultCnvService( long type ) override;
183
185 StatusCode getService( long service_type, IConversionSvc*& refpSvc ) override;
186
188 StatusCode getService( const std::string& service_type, IConversionSvc*& refpSvc ) override;
190
193 StatusCode initialize() override;
195
197 StatusCode finalize() override;
199
202 using extends::extends;
204
205 protected:
207 SmartIF<IConversionSvc>& service( const std::string& nam );
208
210 SmartIF<IConversionSvc>& service( long service_type );
211
213 SmartIF<IAddressCreator>& addressCreator( long service_type );
214
216 void encodeAddrHdr( long service_type, const CLID& clid, std::string& address ) const;
217
219 void decodeAddrHdr( const std::string& address, long& service_type, CLID& clid, std::string& address_trailer ) const;
220
222 StatusCode makeCall( int typ, IOpaqueAddress*& pAddress, DataObject*& pObject );
223
225 bool enable( bool value );
227
229 long m_cnvDefType = TEST_StorageType;
231 mutable SmartIF<IDataProviderSvc> m_dataSvc;
233 Services m_cnvServices;
235 mutable SmartIF<IConversionSvc> m_cnvDefault;
236
237 Gaudi::Property<std::vector<std::string>> m_svcNames{
238 this,
239 "CnvServices",
240 {},
241 [this]( auto& p ) {
242 if ( this->msgLevel( MSG::DEBUG ) ) this->debug() << p << endmsg;
243 },
244 "Names of services to be requested from the service locator and added by default"};
245
247 bool m_enable = true;
248
250 mutable SmartIF<IAddressCreator> m_addrCreator;
251 };
252 #endif // PERSISTENCYSVC_PERSISTENCYSVC_H
PersistencySvc::m_addrCreator
SmartIF< IAddressCreator > m_addrCreator
Pointer to the IAddressCreator interface of this, for addressCreator().
Definition: PersistencySvc.h:250
PersistencySvc::addressCreator
SmartIF< IAddressCreator > & addressCreator() const override
Retrieve address creator facility.
Definition: PersistencySvc.cpp:404
PersistencySvc::service
SmartIF< IConversionSvc > & service(const std::string &nam)
Retrieve conversion service by name.
Definition: PersistencySvc.cpp:204
TEST_StorageType
const long TEST_StorageType
Definition: ClassID.h:49
SmartIF< IService >
IConverter
The data converters are responsible to translate data from one representation into another.
Definition: IConverter.h:58
PersistencySvc::m_cnvDefType
long m_cnvDefType
Default service type.
Definition: PersistencySvc.h:229
PersistencySvc::initialize
StatusCode initialize() override
Initialize the service.
Definition: PersistencySvc.cpp:489
IConversionSvc
Definition: IConversionSvc.h:37
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
PersistencySvc::ServiceEntry::addrCreator
SmartIF< IAddressCreator > & addrCreator() const
Definition: PersistencySvc.h:74
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:285
PersistencySvc::ServiceEntry
Definition: PersistencySvc.h:52
gaudirun.output
output
Definition: gaudirun.py:484
PersistencySvc::m_svcNames
Gaudi::Property< std::vector< std::string > > m_svcNames
Definition: PersistencySvc.h:237
MSG::DEBUG
Definition: IMessageSvc.h:15
IAddressCreator
IAddressCreator interface definition.
Definition: IAddressCreator.h:28
PersistencySvc::m_enable
bool m_enable
Flag to indicate that the service is enabled.
Definition: PersistencySvc.h:247
PersistencySvc::setConversionSvc
StatusCode setConversionSvc(IConversionSvc *svc) override
Set conversion service the converter is connected to.
Definition: PersistencySvc.cpp:171
std
STL namespace.
PersistencySvc::makeCall
StatusCode makeCall(int typ, IOpaqueAddress *&pAddress, DataObject *&pObject)
Implementation helper.
Definition: PersistencySvc.cpp:50
PersistencySvc::ServiceEntry::m_service
SmartIF< IService > m_service
Definition: PersistencySvc.h:54
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:43
PersistencySvc::removeConverter
StatusCode removeConverter(const CLID &clid) override
Remove converter object from conversion service (if present).
Definition: PersistencySvc.cpp:190
std::map< long, ServiceEntry >
PersistencySvc::updateRep
StatusCode updateRep(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the converted representation of a transient object.
Definition: PersistencySvc.cpp:135
PersistencySvc::updateObjRefs
StatusCode updateObjRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the references of an updated transient object.
Definition: PersistencySvc.cpp:120
PersistencySvc::addConverter
StatusCode addConverter(IConverter *pConverter) override
Add converter object to conversion service.
Definition: PersistencySvc.cpp:183
PersistencySvc::convertAddress
StatusCode convertAddress(const IOpaqueAddress *pAddress, std::string &refAddress) override
Convert an address to string form.
Definition: PersistencySvc.cpp:304
CommonMessaging< implements< IService, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:138
std::string
STL class.
PersistencySvc::repSvcType
long repSvcType() const override
Return default service type.
Definition: PersistencySvc.cpp:276
PersistencySvc::fillObjRefs
StatusCode fillObjRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Resolve the references of the created transient object.
Definition: PersistencySvc.cpp:110
IPersistencySvc.h
Service.h
PersistencySvc::enable
bool enable(bool value)
Set enabled flag.
Definition: PersistencySvc.cpp:507
PersistencySvc::setDataProvider
StatusCode setDataProvider(IDataProviderSvc *pStore) override
Define transient datastore.
Definition: PersistencySvc.cpp:161
IDataProviderSvc.h
PersistencySvc::objType
const CLID & objType() const override
Retrieve the class type of objects the converter produces. (DUMMY)
Definition: PersistencySvc.cpp:486
IService
General service interface definition.
Definition: IService.h:18
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
gaudirun.type
type
Definition: gaudirun.py:142
PersistencySvc::createRep
StatusCode createRep(DataObject *pObject, IOpaqueAddress *&refpAddress) override
Implementation of IConverter: Convert the transient object to the requested representation.
Definition: PersistencySvc.cpp:125
PersistencySvc::finalize
StatusCode finalize() override
stop the service.
Definition: PersistencySvc.cpp:498
PersistencySvc::getService
StatusCode getService(long service_type, IConversionSvc *&refpSvc) override
Retrieve conversion service identified by technology.
Definition: PersistencySvc.cpp:407
PersistencySvc::ServiceEntry::ServiceEntry
ServiceEntry(long type, IService *svc, IConversionSvc *cnv, IAddressCreator *cr)
Definition: PersistencySvc.h:64
PersistencySvc::ServiceEntry::ServiceEntry
ServiceEntry(long type, SmartIF< IService > svc, SmartIF< IConversionSvc > cnv, SmartIF< IAddressCreator > cr)
Definition: PersistencySvc.h:59
PersistencySvc::encodeAddrHdr
void encodeAddrHdr(long service_type, const CLID &clid, std::string &address) const
Retrieve string from storage type and clid.
Definition: PersistencySvc.cpp:344
PersistencySvc::m_cnvDefault
SmartIF< IConversionSvc > m_cnvDefault
Default output service.
Definition: PersistencySvc.h:235
PersistencySvc::commitOutput
StatusCode commitOutput(const std::string &output, bool do_commit) override
Commit pending output.
Definition: PersistencySvc.cpp:293
PersistencySvc
PersistencySvc class implementation definition.
Definition: PersistencySvc.h:50
PersistencySvc::fillRepRefs
StatusCode fillRepRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Resolve the references of the converted object.
Definition: PersistencySvc.cpp:130
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:107
PersistencySvc::ServiceEntry::m_cnvService
SmartIF< IConversionSvc > m_cnvService
Definition: PersistencySvc.h:55
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
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:354
PersistencySvc::addCnvService
StatusCode addCnvService(IConversionSvc *service) override
Add a new Service.
Definition: PersistencySvc.cpp:235
PersistencySvc::removeCnvService
StatusCode removeCnvService(long type) override
Remove a Service.
Definition: PersistencySvc.cpp:266
PersistencySvc::updateObj
StatusCode updateObj(IOpaqueAddress *pAddress, DataObject *refpObject) override
Implementation of IConverter: Update the transient object from the other representation.
Definition: PersistencySvc.cpp:115
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:296
PersistencySvc::Services
std::map< long, ServiceEntry > Services
Definition: PersistencySvc.h:77
PersistencySvc::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const override
Get conversion service the converter is connected to.
Definition: PersistencySvc.cpp:177
PersistencySvc::ServiceEntry::m_serviceType
long m_serviceType
Definition: PersistencySvc.h:53
IAddressCreator.h
IConversionSvc.h
PersistencySvc::dataProvider
SmartIF< IDataProviderSvc > & dataProvider() const override
Access reference to transient datastore.
Definition: PersistencySvc.cpp:168
PersistencySvc::ServiceEntry::conversionSvc
SmartIF< IConversionSvc > & conversionSvc() const
Definition: PersistencySvc.h:73
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
PersistencySvc::createObj
StatusCode createObj(IOpaqueAddress *pAddress, DataObject *&refpObject) override
Implementation of IConverter: Create the transient representation of an object.
Definition: PersistencySvc.cpp:105
PersistencySvc::m_cnvServices
Services m_cnvServices
List of convermsion workers.
Definition: PersistencySvc.h:233
PersistencySvc::setAddressCreator
StatusCode setAddressCreator(IAddressCreator *creator) override
Set address creator facility.
Definition: PersistencySvc.cpp:395
PersistencySvc::ServiceEntry::svcType
long svcType() const
Definition: PersistencySvc.h:75
PersistencySvc::ServiceEntry::m_addrCreator
SmartIF< IAddressCreator > m_addrCreator
Definition: PersistencySvc.h:56
IOpaqueAddress
Opaque address interface definition.
Definition: IOpaqueAddress.h:23
PersistencySvc::setDefaultCnvService
StatusCode setDefaultCnvService(long type) override
Set default service type.
Definition: PersistencySvc.cpp:279
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
PersistencySvc::updateRepRefs
StatusCode updateRepRefs(IOpaqueAddress *pAddress, DataObject *pObject) override
Implementation of IConverter: Update the references of an already converted object.
Definition: PersistencySvc.cpp:140
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
PersistencySvc::ServiceEntry::service
SmartIF< IService > & service() const
Definition: PersistencySvc.h:72
PersistencySvc::m_dataSvc
SmartIF< IDataProviderSvc > m_dataSvc
Pointer to datma provider service.
Definition: PersistencySvc.h:231
PersistencySvc::converter
IConverter * converter(const CLID &clid) override
Retrieve converter from list.
Definition: PersistencySvc.cpp:201