ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
Athena::RecyclableDataObject< DOBJ > Class Template Reference

Helper for recycling objects from event to event. More...

#include <RecyclableDataObject.h>

Inheritance diagram for Athena::RecyclableDataObject< DOBJ >:
Collaboration diagram for Athena::RecyclableDataObject< DOBJ >:

Public Types

typedef tbb::concurrent_queue< DOBJ * > queue_t
 Underlying queue type holding these objects. More...
 

Public Member Functions

template<typename... ARGS>
 RecyclableDataObject (std::shared_ptr< queue_t > queue, ARGS &&... args)
 Constructor. More...
 
virtual unsigned long release () override
 DataObject release method. More...
 

Private Attributes

std::shared_ptr< queue_tm_queue
 The queue on which this object will be placed when it is recycled. More...
 

Detailed Description

template<class DOBJ>
class Athena::RecyclableDataObject< DOBJ >

Helper for recycling objects from event to event.

In some cases, one wants to reuse already-allocated objects from event to event, rather than deleting and recreating them each time. This has typically been done for complicated objects, such as classes deriving from IdentfiableContainer.

Some care is obviously needed for this to work in a MT job. Rather than holding a pointer to a specific object from a class member, we instead maintain a concurrent_queue of pointers to objects. When we want an object, we get one from the queue; if the queue is empty, then we allocate a new one.

The object used should derive from DataObject. We bump the reference count by 1 when the object is allocated so that it won't get deleted by StoreGate. We also override release() so that when the reference count goes back to 1 it is ‘recycled’. When this happens, we call the recycle() method on the object (which should probably be protected) and put the object back on the queue to be allocated again.

Example use:

class MyDataObj : public DataObject { ...
public:
MyDataObj (bool createColl); ...
protected:
void recycle();
... };
class MyConverter { ...
private:
RecyclableDataQueue<MyDataObj> m_queue;
... };
StatusCode MyConverter::createObj (...) { ...
MyDataObj* obj = m_queue.get (true);

DOBJ should derive from DataObject and should provide a member recycle().

Implementation note: one needs to be careful about the order in which objects are deleted during finalization. In particular, it is possible for a Gaudi component that holds a RecyclableDataQueue as a member to be deleted while there are still associated data objects registered in the event store. To be robust against this, we allocate the actual queue object separately from RecyclableDataQueue and manage it with shared_ptr; RecyclableDataObject then references the queue with a shared_ptr.

Definition at line 87 of file RecyclableDataObject.h.

Member Typedef Documentation

◆ queue_t

template<class DOBJ >
typedef tbb::concurrent_queue<DOBJ*> Athena::RecyclableDataObject< DOBJ >::queue_t

Underlying queue type holding these objects.

Definition at line 91 of file RecyclableDataObject.h.

Constructor & Destructor Documentation

◆ RecyclableDataObject()

template<class DOBJ >
template<typename... ARGS>
Athena::RecyclableDataObject< DOBJ >::RecyclableDataObject ( std::shared_ptr< queue_t queue,
ARGS &&...  args 
)

Constructor.

Parameters
queueQueue on which this object will be entered when it is released.
args...Additional arguments to pass to the DOBJ constructor.

Member Function Documentation

◆ release()

template<class DOBJ >
virtual unsigned long Athena::RecyclableDataObject< DOBJ >::release ( )
overridevirtual

DataObject release method.

This overrides the release() method of DataObject. Once the reference count falls back to 1 (meaning that the object is no longer referenced from StoreGate), we recycle the object back to the queue.

Member Data Documentation

◆ m_queue

template<class DOBJ >
std::shared_ptr<queue_t> Athena::RecyclableDataObject< DOBJ >::m_queue
private

The queue on which this object will be placed when it is recycled.

Definition at line 115 of file RecyclableDataObject.h.


The documentation for this class was generated from the following file:
MyDataObj
Definition: AthExStoreGateExample/MyDataObj.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Athena::RecyclableDataObject::m_queue
std::shared_ptr< queue_t > m_queue
The queue on which this object will be placed when it is recycled.
Definition: RecyclableDataObject.h:115
python.PyAthena.obj
obj
Definition: PyAthena.py:135