18 #define DATASVC_MULTISTORESVC_CPP
21 #include "GaudiKernel/Service.h"
22 #include "GaudiKernel/SmartIF.h"
23 #include "GaudiKernel/TypeNameString.h"
24 #include "GaudiKernel/MsgStream.h"
25 #include "GaudiKernel/AttribStringParser.h"
26 #include "GaudiKernel/DataObject.h"
27 #include "GaudiKernel/ISvcLocator.h"
28 #include "GaudiKernel/ISvcManager.h"
29 #include "GaudiKernel/IOpaqueAddress.h"
30 #include "GaudiKernel/IConversionSvc.h"
31 #include "GaudiKernel/IDataManagerSvc.h"
32 #include "GaudiKernel/IAddressCreator.h"
33 #include "GaudiKernel/IDataProviderSvc.h"
34 #include "GaudiKernel/IPartitionControl.h"
42 typedef const std::string
CSTR;
49 struct Partition final {
106 template <
typename... Args,
typename... UArgs>
109 return m_current.dataProvider ? (m_current.dataProvider->*pmf)(std::forward<UArgs>(
args)...)
112 template <
typename... Args,
typename... UArgs>
115 return m_current.dataManager ? (m_current.dataManager->*pmf)(std::forward<UArgs>(
args)...)
179 for(
auto &
i : m_partitions) {
180 i.second.dataManager->clearStore().ignore();
226 return activate(m_defaultPartition);
248 return activate(m_defaultPartition);
254 m_dataLoader = pDataLoader;
255 if ( m_dataLoader ) m_dataLoader->
setDataProvider(dpsvc ? dpsvc :
this);
256 for(
auto&
i : m_partitions) {
257 i.second.dataManager->setDataLoader(m_dataLoader.
get()).ignore();
433 return create(nam, typ, pPartition);
437 if (
get(nam, pPartition).isSuccess() )
return PARTITION_EXISTS;
439 auto isvc = serviceLocator()->service<
IService>(typ);
440 if (!isvc)
return NO_INTERFACE;
443 if ( !dataMgr || !dataProv )
return NO_INTERFACE;
444 m_partitions.emplace( nam, Partition{ dataProv, dataMgr, nam } );
450 auto i = m_partitions.find(nam);
451 if (
i == m_partitions.end() )
return PARTITION_NOT_PRESENT;
452 if (
i->second.dataManager == m_current.dataManager ) {
453 m_current = Partition();
455 i->second.dataManager->clearStore().ignore();
456 m_partitions.erase(
i);
463 if ( !provider )
return NO_INTERFACE;
465 [&](Partitions::const_reference p) {
466 return p.second.dataProvider == provider;
468 if (
i==
std::end(m_partitions))
return PARTITION_NOT_PRESENT;
469 i->second.dataManager->clearStore().ignore();
470 m_partitions.erase(
i);
476 auto i = m_partitions.find(nam);
477 if (
i != m_partitions.end() ) {
478 m_current =
i->second;
481 m_current = Partition();
482 return PARTITION_NOT_PRESENT;
488 m_current = Partition();
489 if ( !provider )
return NO_INTERFACE;
491 [&](Partitions::const_reference p) {
492 return p.second.dataProvider == provider;
494 if (
i ==
std::end(m_partitions))
return PARTITION_NOT_PRESENT;
495 m_current =
i->second;
501 auto i = m_partitions.find(nam);
502 if (
i != m_partitions.end() ) {
503 pPartition =
i->second.dataProvider;
506 pPartition =
nullptr;
507 return PARTITION_NOT_PRESENT;
512 if ( m_current.dataProvider ) {
513 nam = m_current.name;
514 pPartition = m_current.dataProvider;
518 pPartition =
nullptr;
519 return NO_ACTIVE_PARTITION;
525 m_addrCreator = service(m_loader,
true);
526 if (!m_addrCreator) {
528 <<
"Failed to retrieve data loader "
529 <<
"\"" << m_loader <<
"\"" <<
endmsg;
533 auto dataLoader = service<IConversionSvc>(
m_loader,
true);
535 log <<
MSG::ERROR <<
"Failed to retrieve data loader "
536 <<
"\"" << m_loader <<
"\"" <<
endmsg;
540 if (!
sc.isSuccess()) {
541 log <<
MSG::ERROR <<
"Failed to set data loader "
542 <<
"\"" << m_loader <<
"\"" <<
endmsg;
548 m_addrCreator.
reset();
549 m_dataLoader.
reset();
561 log <<
MSG::ERROR <<
"Failed to connect to all store partitions." <<
endmsg;
572 log <<
MSG::ERROR <<
"Enable to reinitialize base class"
596 m_current = Partition();
608 declareProperty(
"RootCLID", m_rootCLID = 110);
609 declareProperty(
"RootName", m_rootName =
"/Event");
610 declareProperty(
"Partitions", m_partitionDefs);
611 declareProperty(
"DataLoader", m_loader=
"EventPersistencySvc");
612 declareProperty(
"DefaultPartition", m_defaultPartition=
"Default");
626 for(
auto&
i : m_partitions) {
639 sc =
i.second.dataManager->setRoot(
m_root.
path, pAdd);
661 for(
auto &
i : m_partitions)
i.second.dataManager->clearStore().ignore();
662 m_partitions.clear();
668 using Parser = Gaudi::Utils::AttribStringParser;
669 std::string typ, nam;
671 for(
auto part: m_partitionDefs) {
672 for(
auto attrib: Parser(std::move(part))) {
673 switch( ::
toupper(attrib.tag[0]) ) {
675 nam = std::move(attrib.value);
678 typ = std::move(attrib.value);
684 if ( m_defaultPartition.empty() ) m_defaultPartition = nam;
virtual StatusCode objectParent(const DataObject *pObject, IRegistry *&refpParent)=0
IDataManagerSvc: Explore the object store: retrieve the object's parent.
STATUS objectLeaves(const IRegistry *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
StatusCode initialize() override
STATUS clearSubTree(CSTR &path) override
Remove all data objects below the sub tree identified.
STATUS unregisterObject(CSTR &path) override
Unregister object from the data store.
STATUS removePreLoadItem(CSTR &item) override
Add an item to the preload list.
STATUS preLoad() override
load all preload items of the list
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Partitions m_partitions
Datastore partitions.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
STATUS unlinkObject(CSTR &path) override
Remove a link to another object.
STATUS finalize() override
Service initialisation.
STATUS registerAddress(CSTR &path, ADDRESS *pAddr) override
IDataManagerSvc: Register object address with the data store.
PartitionDefs m_partitionDefs
Datastore partition definitions.
StatusCode finalize() override
virtual StatusCode addPreLoadItem(const DataStoreItem &item)=0
Add an item to the preload list.
STATUS updateObject(OBJECT *pObj) override
Update object.
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ipar, IOpaqueAddress *&refpAddress)=0
Create a Generic address using explicit arguments to identify a single object.
virtual StatusCode clearSubTree(const std::string &sub_path)=0
Remove all data objects below the sub tree identified by its full path name.
STATUS objectParent(const OBJECT *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
STATUS findObject(OBJECT *parent, int item, OBJECT *&pObject) override
Find object in the data store.
bool isSuccess() const
Test for a status code of SUCCESS.
auto begin(reverse_wrapper< T > &w)
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
virtual StatusCode preLoad()=0
Load all preload items of the list.
STATUS registerObject(CSTR &parent, CSTR &obj, OBJECT *pObj) override
Register object with the data store.
virtual StatusCode resetPreLoad()=0
Clear the preload list.
STATUS unregisterAddress(OBJECT *pParent, CSTR &path) override
IDataManagerSvc: Unregister object address from the data store.
STATUS unregisterObject(CSTR &parent, CSTR &obj) override
Unregister object from the data store.
STATUS unlinkObject(OBJECT *from, CSTR &objPath) override
Remove a link to another object.
virtual unsigned long release()=0
release reference to object
Invalid root path object cannot be retrieved or stored.
STATUS create(CSTR &nam, CSTR &typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
virtual StatusCode unregisterAddress(const std::string &fullPath)=0
Unregister object address from the data store.
STATUS findObject(CSTR &parent, int item, OBJECT *&pObject) override
Find object in the data store.
STATUS reinitialize() override
Service initialisation.
Data provider interface definition.
STATUS removePreLoadItem(const DataStoreItem &item) override
Remove an item from the preload list.
Description of the DataStoreItem class.
virtual long svcType() const =0
Retrieve service type.
STATUS linkObject(OBJECT *from, CSTR &objPath, OBJECT *to) override
Add a link to another object.
std::string m_rootName
Name of root event.
SmartIF< IConversionSvc > m_dataLoader
Pointer to data loader service.
STATUS traverseSubTree(CSTR &path, AGENT *pAgent) override
Analyze by traversing all data objects below the sub tree.
STATUS create(CSTR &nam, CSTR &typ) override
Create a partition object. The name identifies the partition uniquely.
STATUS linkObject(CSTR &from, CSTR &objPath, OBJECT *to) override
Add a link to another object.
STATUS setDataLoader(IConversionSvc *pDataLoader, IDataProviderSvc *dpsvc=nullptr) override
IDataManagerSvc: Pass a default data loader to the service.
STATUS updateObject(CSTR &parent, CSTR &updatePath) override
Update object.
std::vector< std::string > PartitionDefs
virtual StatusCode removePreLoadItem(const DataStoreItem &item)=0
Remove an item from the preload list.
TYPE * get() const
Get interface pointer.
STATUS updateObject(OBJECT *parent, CSTR &updatePath) override
Update object.
STATUS makePartitions()
Create all partitions according to job options.
STATUS retrieveObject(CSTR &path, OBJECT *&pObj) override
Retrieve object identified by its full path from the data store.
STATUS unlinkObject(IRegistry *from, CSTR &objPath) override
Remove a link to another object.
STATUS unregisterAddress(IRegistry *pParent, CSTR &path) override
IDataManagerSvc: Unregister object address from the data store.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
virtual StatusCode findObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Find object identified by its directory entry.
STATUS setRoot(std::string path, OBJECT *pObj) override
Initialize data store for new event by giving new event path and root object.
virtual const CLID & clID() const =0
Retrieve class information from link.
virtual StatusCode traverseTree(IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects in the data store.
STATUS addPreLoadItem(const DataStoreItem &item) override
Add an item to the preload list.
STATUS findObject(IRegistry *parent, CSTR &path, OBJECT *&pObj) override
Find object identified by its full path in the data store.
virtual StatusCode unregisterObject(const std::string &fullPath)=0
Unregister object from the data store.
STATUS retrieveObject(IRegistry *parent, CSTR &path, OBJECT *&pObj) override
Retrieve object from data store.
virtual StatusCode linkObject(IRegistry *from, const std::string &objPath, DataObject *toObj)=0
Add a link to another object.
General service interface definition.
STATUS clearSubTree(OBJECT *pObject) override
Remove all data objects below the sub tree identified.
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
STATUS activate(CSTR &nam) override
Activate a partition object. The name identifies the partition uniquely.
#define DECLARE_COMPONENT(type)
Definition of the basic interface.
struct MultiStoreSvc::tagROOT m_root
STATUS registerObject(CSTR &path, OBJECT *pObj) override
Register object with the data store.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
STATUS findObject(CSTR &parent, CSTR &path, OBJECT *&pObj) override
Find object in the data store.
MultiStoreSvc(CSTR &name, ISvcLocator *svc)
Standard Constructor.
StatusCode reinitialize() override
STATUS retrieveObject(CSTR &parent, int item, OBJECT *&pObj) override
Retrieve object from data store.
STATUS unregisterObject(OBJECT *pObj, CSTR &path) override
Unregister object from the data store.
STATUS linkObject(CSTR &fullPath, OBJECT *to) override
Add a link to another object.
STATUS clearPartitions()
Clear all partitions.
STATUS call_(STATUS(IDataProviderSvc::*pmf)(Args...), UArgs &&...args)
union MultiStoreSvc::tagROOT::@1 root
std::string m_loader
Data loader name.
CLID rootCLID() const override
IDataManagerSvc: Accessor for root event CLID.
const std::string & rootName() const override
Name for root Event.
Partition m_current
Current partition.
STATUS unregisterAddress(CSTR &path) override
IDataManagerSvc: Unregister object address from the data store.
STATUS retrieveObject(OBJECT *parent, CSTR &path, OBJECT *&pObj) override
Retrieve object from data store.
STATUS preparePartitions()
Prepare partition for usage.
STATUS objectLeaves(const OBJECT *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
STATUS unregisterObject(OBJECT *pObj) override
Unregister object from the data store.
STATUS setRoot(std::string path, ADDRESS *pAddr) override
Initialize data store for new event by giving new event path and address of root object.
virtual StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves)=0
Explore the object store: retrieve all leaves attached to the object The object is identified by its ...
virtual unsigned long release()
release reference to object
STATUS resetPreLoad() override
Clear the preload list.
STATUS unregisterObject(OBJECT *pObj, int item) override
Unregister object from the data store.
STATUS initialize() override
Service initialisation.
Generic data agent interface.
STATUS drop(CSTR &nam) override
Drop a partition object. The name identifies the partition uniquely.
Base class used to extend a class implementing other interfaces.
virtual StatusCode unlinkObject(IRegistry *from, const std::string &objPath)=0
Remove a link to another object.
STATUS activate(IInterface *pPartition) override
Activate a partition object.
STATUS addPreLoadItem(CSTR &item) override
Add an item to the preload list.
StatusCode activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
SmartIF< IAddressCreator > m_addrCreator
Reference to address creator.
STATUS registerObject(OBJECT *parent, CSTR &obj, OBJECT *pObj) override
Register object with the data store.
CLID m_rootCLID
Integer Property corresponding to CLID of root entry.
STATUS retrieveObject(OBJECT *parent, int item, OBJECT *&pObj) override
Retrieve object from data store.
STATUS findObject(CSTR &path, OBJECT *&pObj) override
Find object identified by its full path in the data store.
STATUS retrieveObject(CSTR &parent, CSTR &path, OBJECT *&pObj) override
Retrieve object from data store.
STATUS linkObject(IRegistry *from, CSTR &objPath, OBJECT *to) override
Add a link to another object.
STATUS updateObject(CSTR &path) override
Update object.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
virtual StatusCode registerAddress(const std::string &fullPath, IOpaqueAddress *pAddress)=0
Register object address with the data store.
Opaque address interface definition.
STATUS unregisterObject(CSTR &parent, int obj) override
Unregister object from the data store.
unsigned int CLID
Class ID definition.
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
STATUS traverseSubTree(OBJECT *pObject, AGENT *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects below the sub tree.
virtual StatusCode traverseSubTree(const std::string &sub_path, IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects below the sub tree identified by its full path name...
STATUS call_(STATUS(IDataManagerSvc::*pmf)(Args...), UArgs &&...args)
std::map< std::string, Partition > Partitions
A DataObject is the base class of any identifiable object on any data store.
STATUS clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
std::string m_defaultPartition
Default partition.
STATUS registerObject(CSTR &parent, int item, OBJECT *pObj) override
Register object with the data store.
STATUS registerAddress(OBJECT *parent, CSTR &path, ADDRESS *pAddr) override
IDataManagerSvc: Register object address with the data store.
STATUS registerAddress(IRegistry *parent, CSTR &path, ADDRESS *pAdd) override
IDataManagerSvc: Register object address with the data store.
STATUS updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
STATUS unlinkObject(CSTR &from, CSTR &objPath) override
Remove a link to another object.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
STATUS findObject(OBJECT *parent, CSTR &path, OBJECT *&pObject) override
Find object in the data store.
void toupper(std::string &s)
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
STATUS traverseTree(AGENT *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
STATUS objectParent(const IRegistry *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
STATUS registerObject(OBJECT *parent, int obj, OBJECT *pObj) override
Register object with the data store.
~MultiStoreSvc() override
Standard Destructor.
virtual unsigned long addRef()=0
Add reference to object.
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.