15 #include "ThreadLocalStorage.h" 16 #include "tbb/concurrent_queue.h" 17 #include "tbb/mutex.h" 18 #include "tbb/recursive_mutex.h" 35 struct Partition final {
48 return dataProvider.get();
53 return dataManager.get();
59 template <
typename T,
typename Mutex = tbb::recursive_mutex,
typename ReadLock =
typename Mutex::scoped_lock,
60 typename WriteLock = ReadLock>
68 auto with_lock( F&& f ) -> decltype(
auto )
70 WriteLock
lock{m_mtx};
74 auto with_lock( F&& f ) const -> decltype( auto )
81 template <
typename Fun>
82 auto with_lock( Fun&& f )
84 return [f = std::forward<Fun>( f )](
auto& p )->decltype(
auto ) {
return p.with_lock( f ); };
87 template <
typename ContainerOfSynced,
typename Fun>
88 void for_( ContainerOfSynced&
c, Fun&& f )
99 bool analyse(
IRegistry* pReg,
int )
override 101 if ( !pReg->
object() )
return false;
108 TTHREAD_TLS( Synced<Partition>* ) s_current =
nullptr;
114 template <
typename lambda>
115 struct arg_helper :
public arg_helper<decltype( &lambda::operator() )> {
117 template <
typename T,
typename Ret,
typename Arg>
118 struct arg_helper<Ret ( T::* )( Arg ) const> {
124 template <
typename lambda>
128 template <
typename Fun>
132 return s_current->with_lock( [&]( Partition& p ) {
133 auto* svc = p.get<std::decay_t<detail::argument_t<Fun>>>();
158 Gaudi::Property<bool> m_forceLeaves{
this,
"ForceLeaves",
false,
"force creation of default leaves on registerObject"};
160 "enable incidents on data creation requests"};
173 using extends::extends;
178 setDataLoader( 0 ).ignore();
179 resetPreLoad().ignore();
180 clearStore().ignore();
181 for_( m_partitions, []( Partition& p ) {
182 p.dataManager->release();
183 p.dataProvider->release();
185 m_partitions.
clear();
189 size_t freeSlots()
override {
return m_freeSlots.unsafe_size(); }
259 for_( m_partitions, []( Partition& p ) { p.dataManager->clearStore().ignore(); } );
301 if ( pDataLoader ) pDataLoader->
addRef();
302 if ( m_dataLoader ) m_dataLoader->
release();
304 m_dataLoader = pDataLoader;
305 for_( m_partitions, [&]( Partition& p ) { p.dataManager->setDataLoader( m_dataLoader,
this ).ignore(); } );
311 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->addPreLoadItem( item ); } );
317 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->addPreLoadItem( item ); } );
323 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->removePreLoadItem( item ); } );
329 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->removePreLoadItem( item ); } );
335 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->resetPreLoad(); } );
341 return s_current->with_lock( []( Partition& p ) {
343 DataAgent da( p.newDataObjects );
344 p.dataManager->traverseTree( &da );
351 return s_current->with_lock( [&]( Partition& p ) {
352 StatusCode sc = p.dataProvider->registerObject( path, pObj );
542 return m_partitions[partition].with_lock( []( Partition& p ) {
return p.dataManager->clearStore(); } );
548 s_current = &m_partitions[partition];
556 warning() <<
"Too late to change the number of slots!" <<
endmsg;
569 return s_current->with_lock( [&]( Partition& p ) {
return std::exchange( p.newDataObjects, {} ); } );
575 s_current->with_lock( [&]( Partition& p ) { p.newDataObjects.insert(
begin( products ),
end( products ) ); } );
582 return findObject(
id.fullKey(), pObject ).isSuccess();
589 size_t slot = std::string::npos;
590 if ( m_freeSlots.try_pop( slot ) ) {
591 assert( slot != std::string::npos );
592 assert( slot < m_partitions.
size() );
593 m_partitions[slot].with_lock( [evtnumber]( Partition& p ) {
594 assert( p.eventNumber == -1 );
595 p.eventNumber = evtnumber;
604 assert( partition < m_partitions.
size() );
605 m_partitions[partition].with_lock( []( Partition& p ) { p.eventNumber = -1; } );
606 m_freeSlots.push( partition );
614 with_lock( [eventnumber](
const Partition& p ) {
return p.eventNumber == eventnumber; } ) );
620 StatusCode sc = service( m_loader, m_addrCreator,
true );
622 error() <<
"Failed to retrieve data loader " 623 <<
"\"" << m_loader <<
"\"" <<
endmsg;
627 sc = service( m_loader, dataLoader,
true );
629 error() <<
MSG::ERROR <<
"Failed to retrieve data loader " 630 <<
"\"" << m_loader <<
"\"" <<
endmsg;
633 sc = setDataLoader( dataLoader );
636 error() <<
MSG::ERROR <<
"Failed to set data loader " 637 <<
"\"" << m_loader <<
"\"" <<
endmsg;
645 if ( m_addrCreator ) m_addrCreator->
release();
646 if ( m_dataLoader ) m_dataLoader->
release();
647 m_addrCreator =
nullptr;
648 m_dataLoader =
nullptr;
661 error() <<
"Unable to initialize base class" <<
endmsg;
664 if ( m_slots < (
size_t)1 ) {
665 error() <<
"Invalid number of slots (" << m_slots <<
")" <<
endmsg;
670 for (
size_t i = 0; i < m_slots; i++ ) {
682 error() <<
"Failed to instantiate DataSvc as store partition" <<
endmsg;
685 m_partitions[i].with_lock( [&]( Partition& p ) {
686 p.dataProvider = svc;
689 m_freeSlots.push( i );
691 selectStore( 0 ).ignore();
692 return attachServices();
700 error() <<
"Unable to reinitialize base class" <<
endmsg;
704 sc = attachServices();
706 error() <<
"Failed to attach necessary services." <<
endmsg;
715 setDataLoader( 0 ).
ignore();
virtual StatusCode traverseTree(IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects in the data store.
StatusCode updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
constexpr static const auto FAILURE
StatusCode initialize() override
StatusCode unregisterObject(DataObject *pObj) override
Unregister object from the data store.
size_t allocateStore(int evtnumber) override
Allocate a store partition for a given event number.
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 ...
StatusCode findObject(boost::string_ref parent, int item, DataObject *&pObject) override
Find object in the data store.
virtual StatusCode unlinkObject(IRegistry *from, boost::string_ref objPath)=0
Remove a link to another object.
StatusCode updateObject(boost::string_ref parent, boost::string_ref updatePath) override
Update object.
StatusCode setDataLoader(IConversionSvc *pDataLoader, IDataProviderSvc *dpsvc __attribute__((unused))=nullptr) override
IDataManagerSvc: Pass a default data loader to the service.
StatusCode finalize() override
StatusCode linkObject(boost::string_ref fullPath, DataObject *to) override
Add a link to another object.
Implementation of property with value of concrete type.
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
StatusCode freeStore(size_t partition) override
Free a store partition.
DataObjIDColl getNewDataObjects() override
Get the list of new DataObjects in the current store.
StatusCode unlinkObject(IRegistry *from, boost::string_ref objPath) override
Remove a link to another object.
size_t getPartitionNumber(int eventnumber) const override
Get the partition number corresponding to a given event.
StatusCode clearStore(size_t partition) override
Remove all data objects in one 'slot' of the data store.
StatusCode registerObject(boost::string_ref path, DataObject *pObj) override
Register object with the data store. (The most common one is the only monitored one for the time bein...
virtual StatusCode findObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Find object identified by its directory entry.
StatusCode retrieveObject(boost::string_ref path, DataObject *&pObj) override
Retrieve object identified by its full path from the data store.
StatusCode registerAddress(boost::string_ref path, IOpaqueAddress *pAddr) override
IDataManagerSvc: Register object address with the data store.
virtual StatusCode setRoot(std::string root_name, DataObject *pObject)=0
Initialize data store for new event by giving new event path.
StatusCode retrieveObject(DataObject *parent, boost::string_ref path, DataObject *&pObj) override
Retrieve object from data store.
StatusCode findObject(DataObject *parent, int item, DataObject *&pObject) override
Find object in the data store.
IAddressCreator interface definition.
StatusCode unlinkObject(boost::string_ref path) override
Remove a link to another object.
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
StatusCode findObject(IRegistry *parent, boost::string_ref path, DataObject *&pObj) override
Find object identified by its full path in the data store.
StatusCode unregisterAddress(boost::string_ref path) override
IDataManagerSvc: Unregister object address from the data store.
StatusCode resetPreLoad() override
Clear the preload list.
StatusCode finalize() override
Service initialisation.
StatusCode clearSubTree(DataObject *pObject) override
Remove all data objects below the sub tree identified.
size_t getNumberOfStores() const override
Get the number of event slots (copies of DataSvc objects).
StatusCode objectParent(const IRegistry *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
StatusCode linkObject(DataObject *from, boost::string_ref objPath, DataObject *to) override
Add a link to another object.
StatusCode addPreLoadItem(const DataStoreItem &item) override
Add an item to the preload list.
StatusCode updateObject(DataObject *pObj) override
Update object.
std::vector< Synced< Partition > > m_partitions
Datastore partitions.
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 unlinkObject(DataObject *from, boost::string_ref objPath) override
Remove a link to another object.
size_t freeSlots() override
Get free slots number.
virtual StatusCode objectParent(const DataObject *pObject, IRegistry *&refpParent)=0
IDataManagerSvc: Explore the object store: retrieve the object's parent.
StatusCode clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
StatusCode unregisterObject(boost::string_ref parent, boost::string_ref obj) override
Unregister object from the data store.
StatusCode selectStore(size_t partition) override
Activate a partition object. The identifies the partition uniquely.
Invalid root path object cannot be retrieved or stored.
virtual StatusCode linkObject(IRegistry *from, boost::string_ref objPath, DataObject *toObj)=0
Add a link to another object.
#define DECLARE_COMPONENT(type)
virtual StatusCode traverseSubTree(boost::string_ref sub_path, IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects below the sub tree identified by its full path name...
StatusCode detachServices()
TupleObj.h GaudiAlg/TupleObj.h namespace with few technical implementations.
StatusCode unregisterAddress(IRegistry *pParent, boost::string_ref path) override
IDataManagerSvc: Unregister object address from the data store.
virtual const id_type & identifier() const =0
Full identifier (or key)
StatusCode objectLeaves(const IRegistry *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
This class is used for returning status codes from appropriate routines.
typename arg_helper< lambda >::type argument_t
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
StatusCode removePreLoadItem(std::string item) override
Add an item to the preload list.
StatusCode addPreLoadItem(std::string item) override
Add an item to the preload list.
StatusCode retrieveObject(boost::string_ref parent, int item, DataObject *&pObj) override
Retrieve object from data store.
StatusCode linkObject(IRegistry *from, boost::string_ref objPath, DataObject *to) override
Add a link to another object.
StatusCode unregisterObject(boost::string_ref path) override
Unregister object from the data store.
StatusCode removePreLoadItem(const DataStoreItem &item) override
Remove an item from the preload list.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
StatusCode reinitialize() override
StatusCode traverseSubTree(boost::string_ref path, IDataStoreAgent *pAgent) override
Analyze by traversing all data objects below the sub tree.
virtual StatusCode retrieveObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
unsigned int CLID
Class ID definition.
StatusCode registerObject(DataObject *parent, int obj, DataObject *pObj) override
Register object with the data store.
virtual StatusCode clearSubTree(boost::string_ref sub_path)=0
Remove all data objects below the sub tree identified by its full path name.
StatusCode clearSubTree(boost::string_ref path) override
Remove all data objects below the sub tree identified.
StatusCode unlinkObject(boost::string_ref from, boost::string_ref objPath) override
Remove a link to another object.
constexpr static const auto SUCCESS
virtual DataObject * object() const =0
Retrieve object behind the link.
TTHREAD_TLS(Synced< Partition > *) s_current
StatusCode findObject(boost::string_ref parent, boost::string_ref path, DataObject *&pObj) override
Find object in the data store.
StatusCode attachServices()
StatusCode traverseSubTree(DataObject *pObject, IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects below the sub tree.
virtual StatusCode unregisterAddress(boost::string_ref fullPath)=0
Unregister object address from the data store.
virtual StatusCode unregisterObject(boost::string_ref fullPath)=0
Unregister object from the data store.
StatusCode registerObject(boost::string_ref parent, int item, 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.
virtual unsigned long release()=0
Release Interface instance.
Generic data agent interface.
Base class used to extend a class implementing other interfaces.
StatusCode initialize() override
Service initialization.
StatusCode unregisterObject(DataObject *pObj, boost::string_ref path) override
Unregister object from the data store.
virtual StatusCode registerObject(boost::string_ref fullPath, DataObject *pObject)=0
Register object with the data store.
const StatusCode & ignore() const
Ignore/check StatusCode.
StatusCode setRoot(std::string path, DataObject *pObj) override
Initialize data store for new event by giving new event path and root object.
CLID rootCLID() const override
IDataManagerSvc: Accessor for root event CLID.
virtual StatusCode registerAddress(boost::string_ref fullPath, IOpaqueAddress *pAddress)=0
Register object address with the data store.
StatusCode registerAddress(IRegistry *parent, boost::string_ref path, IOpaqueAddress *pAdd) override
IDataManagerSvc: Register object address with the data store.
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.
StatusCode unregisterObject(boost::string_ref parent, int obj) override
Unregister object from the data store.
StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
StatusCode registerObject(DataObject *parent, boost::string_ref obj, DataObject *pObj) override
Register object with the data store.
StatusCode initialize() override
Service initialisation.
StatusCode linkObject(boost::string_ref from, boost::string_ref objPath, DataObject *to) override
Add a link to another object.
StatusCode updateObject(boost::string_ref path) override
Update object.
StatusCode traverseTree(IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
void addNewDataObjects(DataObjIDColl &products) override
add to the list of new DataObjects in the current store.
StatusCode findObject(boost::string_ref path, DataObject *&pObj) override
Find object identified by its full path in the data store.
Opaque address interface definition.
StatusCode findObject(DataObject *parent, boost::string_ref path, DataObject *&pObject) override
Find object in the data store.
StatusCode registerObject(boost::string_ref parent, boost::string_ref obj, DataObject *pObj) override
Register object with the data store.
StatusCode retrieveObject(boost::string_ref parent, boost::string_ref path, DataObject *&pObj) override
Retrieve object from data store.
A DataObject is the base class of any identifiable object on any data store.
tbb::concurrent_queue< size_t > m_freeSlots
fifo queue of free slots
StatusCode updateObject(DataObject *parent, boost::string_ref updatePath) override
Update object.
StatusCode unregisterAddress(DataObject *pParent, boost::string_ref path) override
IDataManagerSvc: Unregister object address from the data store.
bool exists(const DataObjID &id) override
check if a data object exists in the current store
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
const std::string & rootName() const override
Name for root Event.
StatusCode reinitialize() override
Service initialisation.
StatusCode retrieveObject(IRegistry *parent, boost::string_ref path, DataObject *&pObj) override
Retrieve object from data store.
StatusCode setNumberOfStores(size_t slots) override
Set the number of event slots (copies of DataSvc objects).
~HiveWhiteBoard() override
Standard Destructor.
StatusCode registerAddress(DataObject *parent, boost::string_ref path, IOpaqueAddress *pAddr) override
IDataManagerSvc: Register object address with the data store.