16 #include "ThreadLocalStorage.h" 17 #include "boost/callable_traits.hpp" 18 #include "tbb/concurrent_queue.h" 19 #include "tbb/mutex.h" 20 #include "tbb/recursive_mutex.h" 36 struct Partition final {
47 return dataProvider.get();
51 return dataManager.get();
57 template <
typename T,
typename Mutex = tbb::recursive_mutex,
typename ReadLock =
typename Mutex::scoped_lock,
58 typename WriteLock = ReadLock>
65 decltype(
auto ) with_lock( F&& f ) {
66 WriteLock
lock{m_mtx};
70 decltype(
auto ) with_lock( F&& f )
const {
76 template <
typename Fun>
77 auto with_lock( Fun&& f ) {
78 return [f = std::forward<Fun>( f )](
auto& p ) -> decltype(
auto ) {
return p.with_lock( f ); };
81 template <
typename ContainerOfSynced,
typename Fun>
82 void for_( ContainerOfSynced&
c, Fun&& f ) {
87 TTHREAD_TLS( Synced<Partition>* ) s_current =
nullptr;
94 using argument_t = std::tuple_element_t<0, boost::callable_traits::args_t<F>>;
97 template <
typename Fun>
100 return s_current->with_lock( [&]( Partition& p ) {
101 auto* svc = p.get<std::decay_t<detail::argument_t<Fun>>>();
125 Gaudi::Property<bool> m_forceLeaves{
this,
"ForceLeaves",
false,
"force creation of default leaves on registerObject"};
127 "enable incidents on data creation requests"};
140 using extends::extends;
144 setDataLoader( 0 ).ignore();
145 resetPreLoad().ignore();
146 clearStore().ignore();
147 for_( m_partitions, []( Partition& p ) {
148 p.dataManager->release();
149 p.dataProvider->release();
151 m_partitions.
clear();
155 size_t freeSlots()
override {
return m_freeSlots.unsafe_size(); }
204 for_( m_partitions, []( Partition& p ) { p.dataManager->clearStore().ignore(); } );
239 if ( pDataLoader ) pDataLoader->
addRef();
240 if ( m_dataLoader ) m_dataLoader->
release();
242 m_dataLoader = pDataLoader;
243 for_( m_partitions, [&]( Partition& p ) { p.dataManager->setDataLoader( m_dataLoader,
this ).ignore(); } );
248 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->addPreLoadItem( item ); } );
253 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->removePreLoadItem( item ); } );
258 for_( m_partitions, [&]( Partition& p ) { p.dataProvider->resetPreLoad(); } );
332 return m_partitions[partition].with_lock( []( Partition& p ) {
return p.dataManager->clearStore(); } );
337 s_current = &m_partitions[partition];
344 warning() <<
"Too late to change the number of slots!" <<
endmsg;
358 return findObject(
id.fullKey(), pObject ).isSuccess();
364 size_t slot = std::string::npos;
365 if ( m_freeSlots.try_pop( slot ) ) {
366 assert( slot != std::string::npos );
367 assert( slot < m_partitions.
size() );
368 m_partitions[slot].with_lock( [evtnumber]( Partition& p ) {
369 assert( p.eventNumber == -1 );
370 p.eventNumber = evtnumber;
378 assert( partition < m_partitions.
size() );
379 auto prev = m_partitions[partition].with_lock( []( Partition& p ) {
return std::exchange( p.eventNumber, -1 ); } );
381 m_freeSlots.push( partition );
388 with_lock( [eventnumber](
const Partition& p ) {
return p.eventNumber == eventnumber; } ) );
393 StatusCode sc = service( m_loader, m_addrCreator,
true );
395 error() <<
"Failed to retrieve data loader " 396 <<
"\"" << m_loader <<
"\"" <<
endmsg;
400 sc = service( m_loader, dataLoader,
true );
402 error() <<
MSG::ERROR <<
"Failed to retrieve data loader " 403 <<
"\"" << m_loader <<
"\"" <<
endmsg;
406 sc = setDataLoader( dataLoader );
409 error() <<
MSG::ERROR <<
"Failed to set data loader " 410 <<
"\"" << m_loader <<
"\"" <<
endmsg;
417 if ( m_addrCreator ) m_addrCreator->
release();
418 if ( m_dataLoader ) m_dataLoader->
release();
419 m_addrCreator =
nullptr;
420 m_dataLoader =
nullptr;
432 error() <<
"Unable to initialize base class" <<
endmsg;
435 if ( m_slots < (
size_t)1 ) {
436 error() <<
"Invalid number of slots (" << m_slots <<
")" <<
endmsg;
440 if ( !setNumberOfStores( m_slots ).isSuccess() ) {
441 error() <<
"Cannot set number of slots" <<
endmsg;
446 for (
size_t i = 0; i < m_slots; i++ ) {
458 error() <<
"Failed to instantiate DataSvc as store partition" <<
endmsg;
461 m_partitions[i].with_lock( [&]( Partition& p ) {
462 p.dataProvider = svc;
465 m_freeSlots.push( i );
467 selectStore( 0 ).ignore();
468 return attachServices();
475 error() <<
"Unable to reinitialize base class" <<
endmsg;
479 sc = attachServices();
481 error() <<
"Failed to attach necessary services." <<
endmsg;
489 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.
StatusCode initialize() override
StatusCode unregisterObject(DataObject *pObj) override
Unregister object from the data store.
StatusCode registerAddress(std::string_view path, IOpaqueAddress *pAddr) override
IDataManagerSvc: Register object address with the data store.
StatusCode retrieveObject(IRegistry *parent, std::string_view path, DataObject *&pObj) override
Retrieve object from 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 ...
virtual StatusCode registerAddress(std::string_view fullPath, IOpaqueAddress *pAddress)=0
Register object address with the data store.
virtual StatusCode linkObject(IRegistry *from, std::string_view objPath, DataObject *toObj)=0
Add a link to another object.
StatusCode finalize() override
Implementation of property with value of concrete type.
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
virtual StatusCode traverseSubTree(std::string_view sub_tree_path, IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects below the sub tree identified by its full path name...
StatusCode freeStore(size_t partition) override
Free a store partition.
StatusCode registerObject(std::string_view parent, std::string_view obj, DataObject *pObj) override
Register object with the data store.
StatusCode traverseSubTree(std::string_view path, IDataStoreAgent *pAgent) override
Analyze by traversing all data objects below the sub tree.
StatusCode unregisterObject(std::string_view path) override
Unregister object from the data store.
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 linkObject(std::string_view fullPath, DataObject *to) override
Add a link to another object.
StatusCode linkObject(IRegistry *from, std::string_view objPath, DataObject *to) override
Add a link to another object.
StatusCode unregisterObject(DataObject *pObj, std::string_view path) override
Unregister object from the data store.
virtual StatusCode setRoot(std::string root_name, DataObject *pObject)=0
Initialize data store for new event by giving new event path.
virtual StatusCode unregisterAddress(std::string_view fullPath)=0
Unregister object address from the data store.
IAddressCreator interface definition.
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
StatusCode unregisterAddress(IRegistry *pParent, std::string_view path) override
IDataManagerSvc: Unregister object address from the data store.
constexpr static const auto SUCCESS
virtual StatusCode preLoad()=0
Load all preload items of the list.
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 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.
StatusCode clearSubTree(std::string_view path) override
Remove all data objects below the sub tree identified.
Data provider interface definition.
StatusCode preLoad() override
load all preload items of the list
Description of the DataStoreItem class.
StatusCode unregisterAddress(std::string_view path) override
IDataManagerSvc: Unregister object address from the data store.
StatusCode unlinkObject(std::string_view path) 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.
virtual StatusCode unlinkObject(IRegistry *from, std::string_view objPath)=0
Remove a link to another object.
StatusCode selectStore(size_t partition) override
Activate a partition object. The identifies the partition uniquely.
Invalid root path object cannot be retrieved or stored.
#define DECLARE_COMPONENT(type)
StatusCode registerAddress(IRegistry *parent, std::string_view path, IOpaqueAddress *pAdd) override
IDataManagerSvc: Register object address with the data store.
virtual StatusCode unregisterObject(std::string_view fullPath)=0
Unregister object from the data store.
virtual StatusCode clearSubTree(std::string_view sub_path)=0
Remove 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 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(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
unsigned int CLID
Class ID definition.
TTHREAD_TLS(Synced< Partition > *) s_current
StatusCode attachServices()
StatusCode traverseSubTree(DataObject *pObject, IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects below the sub tree.
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.
StatusCode unlinkObject(DataObject *from, std::string_view objPath) override
Remove a link to another object.
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
virtual unsigned long release()=0
Release Interface instance.
Generic data agent interface.
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
Base class used to extend a class implementing other interfaces.
StatusCode initialize() override
Service initialization.
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.
StatusCode setDataLoader(IConversionSvc *pDataLoader, IDataProviderSvc *=nullptr) override
IDataManagerSvc: Pass a default data loader to the service.
constexpr static const auto FAILURE
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
StatusCode initialize() override
Service initialisation.
StatusCode traverseTree(IDataStoreAgent *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Opaque address interface definition.
StatusCode findObject(std::string_view path, DataObject *&pObj) override
Find object identified by its full path in the data store.
A DataObject is the base class of any identifiable object on any data store.
StatusCode findObject(IRegistry *parent, std::string_view path, DataObject *&pObj) override
Find object identified by its full path in the data store.
tbb::concurrent_queue< size_t > m_freeSlots
fifo queue of free slots
StatusCode unlinkObject(IRegistry *from, std::string_view objPath) override
Remove a link to another object.
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.
static GAUDI_API void setNumConcEvents(const std::size_t &nE)
StatusCode reinitialize() override
Service initialisation.
StatusCode setNumberOfStores(size_t slots) override
Set the number of event slots (copies of DataSvc objects).
~HiveWhiteBoard() override
Standard Destructor.
StatusCode registerObject(DataObject *parent, std::string_view obj, DataObject *pObj) override
Register object with the data store.