9 #include "GaudiKernel/Service.h"
10 #include "GaudiKernel/SmartIF.h"
11 #include "GaudiKernel/TypeNameString.h"
12 #include "GaudiKernel/MsgStream.h"
13 #include "GaudiKernel/SvcFactory.h"
14 #include "GaudiKernel/DataObject.h"
15 #include "GaudiKernel/DataSvc.h"
16 #include "GaudiKernel/ThreadLocalPtr.h"
17 #include "tbb/spin_mutex.h"
18 #include "tbb/recursive_mutex.h"
22 #include "GaudiKernel/ISvcLocator.h"
23 #include "GaudiKernel/ISvcManager.h"
24 #include "GaudiKernel/IOpaqueAddress.h"
25 #include "GaudiKernel/IConversionSvc.h"
26 #include "GaudiKernel/IDataManagerSvc.h"
27 #include "GaudiKernel/IAddressCreator.h"
28 #include "GaudiKernel/IDataProviderSvc.h"
29 #include "GaudiKernel/IDataStoreAgent.h"
30 #include "GaudiKernel/IHiveWhiteBoard.h"
31 #include "GaudiKernel/IRegistry.h"
44 std::vector<std::string> newDataObjects;
46 Partition() : dataProvider(0), dataManager(0), eventNumber(-1) {}
48 Partition(
const Partition& entry) : dataProvider(entry.dataProvider), dataManager(entry.dataManager), eventNumber(entry.eventNumber) {}
49 Partition& operator=(
const Partition& entry) {
50 dataProvider = entry.dataProvider;
51 dataManager = entry.dataManager;
57 std::vector<std::string>& m_dataObjects;
59 DataAgent(std::vector<std::string>& objs) : m_dataObjects(objs) {}
60 virtual ~DataAgent() {}
63 m_dataObjects.emplace_back(pReg->
identifier());
125 #define _CALL(P,F,ARGS) if(s_current) { \
126 wbMutex::scoped_lock lock; lock.acquire(s_current->storeMutex);\
127 return s_current->P ? s_current->P->F ARGS : IDataProviderSvc::INVALID_ROOT; }\
128 return IDataProviderSvc::INVALID_ROOT;
180 for(
auto& p: m_partitions) p.dataManager->clearStore().
ignore();
214 if ( 0 != pDataLoader ) pDataLoader->
addRef();
215 if ( 0 != m_dataLoader ) m_dataLoader->
release();
216 if ( 0 != pDataLoader ) {
219 m_dataLoader = pDataLoader;
220 for(
auto& p: m_partitions) {
221 p.dataManager->setDataLoader(m_dataLoader,
this).ignore();
227 for(
auto& p: m_partitions) p.dataProvider->addPreLoadItem(item);
232 for(
auto& p: m_partitions) p.dataProvider->addPreLoadItem(item);
237 for(
auto& p: m_partitions) p.dataProvider->removePreLoadItem(item);
242 for(
auto& p: m_partitions) p.dataProvider->removePreLoadItem(item);
247 for(
auto& p: m_partitions) p.dataProvider->resetPreLoad();
252 wbMutex::scoped_lock
lock; lock.acquire(
s_current->storeMutex);
255 s_current->dataManager->traverseTree(&da);
260 wbMutex::scoped_lock
lock; lock.acquire(
s_current->storeMutex);
263 s_current->newDataObjects.push_back(path);
414 return m_partitions[partition].dataManager->clearStore();
425 if((
int)slots != m_slots and
427 warning() <<
"Too late to change the number of slots!" <<
endmsg;
441 wbMutex::scoped_lock
lock; lock.acquire(
s_current->storeMutex);
449 wbMutex::scoped_lock
lock; lock.acquire(
s_current->storeMutex);
450 return s_current->newDataObjects.size()!=0;
457 for (
auto& p : m_partitions ) {
458 if( p.eventNumber == evtnumber) {
459 error() <<
"Attempt to allocate a store partition for an event that is still active" <<
endmsg;
460 return std::string::npos;
461 }
else if (p.eventNumber == -1) {
462 p.eventNumber = evtnumber;
468 return std::string::npos;
473 m_partitions[partition].eventNumber = -1;
482 for (
auto& p : m_partitions) {
483 if (p.eventNumber == eventnumber)
return index;
486 return std::string::npos;
492 error() <<
"Failed to retrieve data loader " <<
"\"" << m_loader <<
"\"" <<
endmsg;
496 sc = service(m_loader, dataLoader,
true);
498 error() <<
MSG::ERROR <<
"Failed to retrieve data loader " <<
"\"" << m_loader <<
"\"" <<
endmsg;
504 error() <<
MSG::ERROR <<
"Failed to set data loader " <<
"\"" << m_loader <<
"\"" <<
endmsg;
511 if ( m_addrCreator ) m_addrCreator->
release();
512 if ( m_dataLoader ) m_dataLoader->
release();
526 error() <<
"Unable to initialize base class" <<
endmsg;
531 error() <<
"Invalid number of slots (" << m_slots <<
")" <<
endmsg;
536 std::ostringstream oss;
537 oss <<
name() <<
"_" <<
i;
541 svc->setProperty(
"RootName", m_rootName);
543 svc->setProperty(
"EnableFaultHandler",
std::to_string(m_enableFaultHdlr));
547 error() <<
"Failed to instantiate DataSvc as store partition" <<
endmsg;
550 m_partitions.push_back(Partition(svc, svc));
560 error() <<
"Unable to reinitialize base class" <<
endmsg;
566 error() <<
"Failed to attach necessary services." <<
endmsg;
584 :
base_class(name,svc), m_rootCLID(110), m_rootName(
"/Event"),
585 m_dataLoader(0), m_addrCreator(0)
588 declareProperty(
"RootCLID", m_rootCLID);
589 declareProperty(
"RootName", m_rootName);
590 declareProperty(
"DataLoader", m_loader=
"EventPersistencySvc");
591 declareProperty(
"EventSlots", m_slots = 1);
592 declareProperty(
"ForceLeaves", m_forceLeaves = 1);
593 declareProperty(
"EnableFaultHandler", m_enableFaultHdlr = 0);
602 for(Partitions::iterator
i = m_partitions.begin();
i != m_partitions.end(); ++
i) {
603 (*i).dataManager->release();
604 (*i).dataProvider->release();
606 m_partitions.clear();
StatusCode unlinkObject(const std::string &path) override
Remove a link to another object.
StatusCode unlinkObject(IRegistry *from, const std::string &objPath) override
Remove a link to another object.
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
StatusCode retrieveObject(const std::string &parent, const std::string &path, DataObject *&pObj) override
Retrieve object from data store.
StatusCode registerAddress(IRegistry *parent, const std::string &path, IOpaqueAddress *pAdd) override
IDataManagerSvc: Register object address with the data store.
StatusCode linkObject(DataObject *from, const std::string &objPath, DataObject *to) override
Add a link to another object.
#define _CALL(P, F, ARGS)
StatusCode retrieveObject(const std::string &parent, int item, DataObject *&pObj) override
Retrieve object from data store.
StatusCode registerObject(const std::string &path, DataObject *pObj) override
Register object with the data store. (The most common one is the only monitored one for the time bein...
StatusCode initialize() override
StatusCode registerObject(const std::string &parent, int item, DataObject *pObj) override
Register object with the data store.
StatusCode unregisterObject(DataObject *pObj) override
Unregister object from the data store.
string to_string(const T &value)
size_t allocateStore(int evtnumber) override
Allocate a store partition for a given event number.
StatusCode traverseSubTree(const std::string &path, IDataStoreAgent *pAgent) override
Analyze by traversing all data objects below the sub tree.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
StatusCode getNewDataObjects(std::vector< std::string > &products) override
Get the list of new DataObjects in the current store.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode unregisterAddress(const std::string &path) override
IDataManagerSvc: Unregister object address from the data store.
StatusCode setDataLoader(IConversionSvc *pDataLoader, IDataProviderSvc *dpsvc __attribute__((unused))=nullptr) override
IDataManagerSvc: Pass a default data loader to the service.
StatusCode registerAddress(const std::string &path, IOpaqueAddress *pAddr) override
IDataManagerSvc: Register object address with the data store.
StatusCode finalize() override
StatusCode retrieveObject(DataObject *parent, const std::string &path, DataObject *&pObj) override
Retrieve object from data store.
StatusCode freeStore(size_t partition) override
Free a store partition.
StatusCode clearStore(size_t partition) override
Remove all data objects in one 'slot' of the data store.
bool isSuccess() const
Test for a status code of SUCCESS.
virtual bool analyse(IRegistry *pObject, int level)=0
Analyse the data object.
StatusCode retrieveObject(const std::string &path, DataObject *&pObj) override
Retrieve object identified by its full path from the data store.
StatusCode registerObject(const std::string &parent, const std::string &obj, DataObject *pObj) override
Register object with the data store.
StatusCode findObject(DataObject *parent, int item, DataObject *&pObject) override
Find object in the data store.
StatusCode unregisterObject(const std::string &parent, const std::string &obj) override
Unregister object from the data store.
IAddressCreator interface definition.
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
StatusCode unregisterObject(DataObject *pObj, const std::string &path) override
Unregister object from the data store.
StatusCode resetPreLoad() override
Clear the preload list.
StatusCode addPreLoadItem(const std::string &item) override
Add an item to the preload list.
StatusCode finalize() override
Service initialisation.
StatusCode clearSubTree(DataObject *pObject) override
Remove all data objects below the sub tree identified.
StatusCode clearSubTree(const std::string &path) override
Remove all data objects below the sub tree identified.
StatusCode objectParent(const IRegistry *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
StatusCode addPreLoadItem(const DataStoreItem &item) override
Add an item to the preload list.
StatusCode updateObject(DataObject *pObj) override
Update object.
StatusCode registerAddress(DataObject *parent, const std::string &path, IOpaqueAddress *pAddr) override
IDataManagerSvc: Register object address with the data store.
Data provider interface definition.
StatusCode preLoad() override
load all preload items of the list
Description of the DataStoreItem class.
StatusCode unregisterObject(DataObject *pObj, int item) override
Unregister object from the data store.
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
size_t getPartitionNumber(int eventnumber) const override
Get the partition number corresponding to a given event.
StatusCode selectStore(size_t partition) override
Activate a partition object. The identifies the partition uniquely.
bool m_enableFaultHdlr
Flag to enable interrupts on data creation requests.
tbb::recursive_mutex wbMutex
StatusCode removePreLoadItem(const std::string &item) override
Add an item to the preload list.
std::string m_rootName
Name of root event.
StatusCode detachServices()
StatusCode findObject(DataObject *parent, const std::string &path, DataObject *&pObject) override
Find object in the data store.
std::string m_loader
Data loader name.
StatusCode linkObject(const std::string &from, const std::string &objPath, DataObject *to) override
Add a link to another object.
StatusCode findObject(const std::string &path, DataObject *&pObj) override
Find object identified by its full path in the data store.
StatusCode objectLeaves(const IRegistry *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
StatusCode updateObject(const std::string &path) override
Update object.
This class is used for returning status codes from appropriate routines.
StatusCode linkObject(const std::string &fullPath, DataObject *to) override
Add a link to another object.
bool m_forceLeaves
Allow forced creation of default leaves on registerObject.
StatusCode unregisterObject(const std::string &path) override
Unregister object from the data store.
CLID rootCLID() const override
IDataManagerSvc: Accessor for root event CLID.
StatusCode updateObject(const std::string &parent, const std::string &updatePath) override
Update object.
StatusCode removePreLoadItem(const DataStoreItem &item) override
Remove an item from the preload list.
bool newDataObjectsPresent() override
Check if new DataObjects are in the current store.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
StatusCode reinitialize() override
#define DECLARE_SERVICE_FACTORY(x)
CLID m_rootCLID
Integer Property corresponding to CLID of root entry.
StatusCode linkObject(IRegistry *from, const std::string &objPath, DataObject *to) override
Add a link to another object.
StatusCode registerObject(DataObject *parent, int obj, DataObject *pObj) override
Register object with the data store.
StatusCode unlinkObject(DataObject *from, const std::string &objPath) override
Remove a link to another object.
const std::string & rootName() const override
Name for root Event.
virtual DataObject * object() const =0
Retrieve object behind the link.
size_t getNumberOfStores() override
Get the number of event slots (copies of DataSvc objects).
StatusCode attachServices()
StatusCode traverseSubTree(DataObject *pObject, IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects below the sub tree.
StatusCode registerObject(DataObject *parent, const std::string &obj, DataObject *pObj) override
Register object with the data store.
StatusCode objectParent(const DataObject *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
StatusCode setRoot(std::string path, IOpaqueAddress *pAddr) override
Initialize data store for new event by giving new event path and address of root object.
Partitions m_partitions
Datastore partitions.
StatusCode findObject(IRegistry *parent, const std::string &path, DataObject *&pObj) override
Find object identified by its full path in the data store.
virtual unsigned long release()=0
Release Interface instance.
IAddressCreator * m_addrCreator
Reference to address creator.
Generic data agent interface.
virtual ~HiveWhiteBoard()
Standard Destructor.
Base class used to extend a class implementing other interfaces.
StatusCode initialize() override
Service initialization.
StatusCode unregisterAddress(IRegistry *pParent, const std::string &path) override
IDataManagerSvc: Unregister object address from the data store.
HiveWhiteBoard(const std::string &name, ISvcLocator *svc)
Standard Constructor.
StatusCode setRoot(std::string path, DataObject *pObj) override
Initialize data store for new event by giving new event path and root object.
StatusCode retrieveObject(DataObject *parent, int item, DataObject *&pObj) override
Retrieve object from data store.
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
int m_slots
Datastore slots.
StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
StatusCode unregisterObject(const std::string &parent, int obj) override
Unregister object from the data store.
StatusCode initialize() override
Service initialisation.
StatusCode updateObject(DataObject *parent, const std::string &updatePath) override
Update object.
StatusCode findObject(const std::string &parent, const std::string &path, DataObject *&pObj) override
Find object in the data store.
virtual const id_type & identifier() const =0
Full identifier (or key)
StatusCode unlinkObject(const std::string &from, const std::string &objPath) override
Remove a link to another object.
StatusCode traverseTree(IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
Opaque address interface definition.
IConversionSvc * m_dataLoader
Pointer to data loader service.
unsigned int CLID
Class ID definition.
StatusCode findObject(const std::string &parent, int item, DataObject *&pObject) override
Find object in the data store.
std::vector< Partition > Partitions
A DataObject is the base class of any identifiable object on any data store.
THREAD_LOCAL_PTR Partition * s_current(0)
StatusCode retrieveObject(IRegistry *parent, const std::string &path, DataObject *&pObj) override
Retrieve object from data store.
StatusCode unregisterAddress(DataObject *pParent, const std::string &path) override
IDataManagerSvc: Unregister object address from the data store.
StatusCode reinitialize() override
Service initialisation.
StatusCode setNumberOfStores(size_t slots) override
Set the number of event slots (copies of DataSvc objects).