| The Gaudi Framework v32r1 (f65d50dc)

DataHandleHolderBase.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_DATAHANDLEHOLDERBASE
2 #define GAUDIKERNEL_DATAHANDLEHOLDERBASE 1
3
4 #include "GaudiKernel/DataHandle.h"
5 #include "GaudiKernel/DataObjID.h"
6 #include "GaudiKernel/GaudiException.h"
7 #include "GaudiKernel/IDataHandleHolder.h"
8 #include "GaudiKernel/Property.h"
9
10 #include <algorithm>
11 #include <unordered_set>
12
13 namespace {
14 template <typename Container>
15 std::vector<Gaudi::DataHandle*> handles( Container& c, Gaudi::DataHandle::Mode mode ) {
16 std::vector<Gaudi::DataHandle*> h;
17 std::copy_if( std::begin( c ), std::end( c ), std::back_inserter( h ),
18 [&]( const Gaudi::DataHandle* hndl ) -> bool { return hndl->mode() & mode; } );
19 return h;
20 }
21 } // namespace
22
23 template <class BASE>
24 class GAUDI_API DataHandleHolderBase : public extends<BASE, IDataHandleHolder> {
25 public:
26 using extends<BASE, IDataHandleHolder>::extends;
27
28 std::vector<Gaudi::DataHandle*> inputHandles() const override {
29 return handles( m_handles, Gaudi::DataHandle::Reader );
30 }
31 std::vector<Gaudi::DataHandle*> outputHandles() const override {
32 return handles( m_handles, Gaudi::DataHandle::Writer );
33 }
34
35 virtual const DataObjIDColl& extraInputDeps() const override { return m_extInputDataObjs; }
36 virtual const DataObjIDColl& extraOutputDeps() const override { return m_extOutputDataObjs; }
37
38 void declare( Gaudi::DataHandle& handle ) override {
39 if ( !handle.owner() ) handle.setOwner( this );
40
41 if ( handle.owner() != this ) {
42 throw GaudiException( "Attempt to declare foreign handle with algorithm!", this->name(), StatusCode::FAILURE );
43 }
44
45 m_handles.insert( &handle );
46 }
47
48 void renounce( Gaudi::DataHandle& handle ) override {
49 if ( handle.owner() != this ) {
50 throw GaudiException( "Attempt to renounce foreign handle with algorithm!", this->name(), StatusCode::FAILURE );
51 }
52 m_handles.erase( &handle );
53 }
54
55 const DataObjIDColl& inputDataObjs() const override { return m_inputDataObjs; }
56 const DataObjIDColl& outputDataObjs() const override { return m_outputDataObjs; }
57
58 void addDependency( const DataObjID& id, const Gaudi::DataHandle::Mode& mode ) override {
59 if ( mode & Gaudi::DataHandle::Reader ) m_inputDataObjs.emplace( id );
60 if ( mode & Gaudi::DataHandle::Writer ) m_outputDataObjs.emplace( id );
61 }
62
63 private:
64 protected:
67 void initDataHandleHolder() {
68 for ( auto h : m_handles ) h->init();
69 }
70
71 DataObjIDColl m_inputDataObjs, m_outputDataObjs;
72
73 private:
74 std::unordered_set<Gaudi::DataHandle*> m_handles;
75
76 Gaudi::Property<DataObjIDColl> m_extInputDataObjs{this, "ExtraInputs", DataObjIDColl{}};
77 Gaudi::Property<DataObjIDColl> m_extOutputDataObjs{this, "ExtraOutputs", DataObjIDColl{}};
78 };
79
80 #endif // !GAUDIKERNEL_DATAHANDLEHOLDERBASE
DataHandleHolderBase::inputHandles
std::vector< Gaudi::DataHandle * > inputHandles() const override
Definition: DataHandleHolderBase.h:28
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:42
IDataHandleHolder.h
std::copy_if
T copy_if(T... args)
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
gaudirun.c
c
Definition: gaudirun.py:487
Gaudi::DataHandle::setOwner
virtual void setOwner(IDataHandleHolder *o)
Definition: DataHandle.h:39
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
DataObjID
Definition: DataObjID.h:37
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:40
DataHandleHolderBase::initDataHandleHolder
void initDataHandleHolder()
initializes all handles - called by the sysInitialize method of any descendant of this
Definition: DataHandleHolderBase.h:67
DataHandleHolderBase::renounce
void renounce(Gaudi::DataHandle &handle) override
Definition: DataHandleHolderBase.h:48
std::end
T end(T... args)
Gaudi::DataHandle::Reader
Definition: DataHandle.h:29
DataHandleHolderBase::declare
void declare(Gaudi::DataHandle &handle) override
Definition: DataHandleHolderBase.h:38
GaudiException.h
DataHandleHolderBase
Definition: DataHandleHolderBase.h:24
Gaudi::DataHandle
Definition: DataHandle.h:27
DataHandleHolderBase::extraOutputDeps
virtual const DataObjIDColl & extraOutputDeps() const override
Definition: DataHandleHolderBase.h:36
std::unordered_set< DataObjID, DataObjID_Hasher >
DataObjID.h
DataHandleHolderBase::addDependency
void addDependency(const DataObjID &id, const Gaudi::DataHandle::Mode &mode) override
Definition: DataHandleHolderBase.h:58
DataHandleHolderBase::outputDataObjs
const DataObjIDColl & outputDataObjs() const override
Definition: DataHandleHolderBase.h:56
std::vector
STL class.
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
std::begin
T begin(T... args)
DataHandleHolderBase::extraInputDeps
virtual const DataObjIDColl & extraInputDeps() const override
Definition: DataHandleHolderBase.h:35
std::back_inserter
T back_inserter(T... args)
Property.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::DataHandle::Writer
Definition: DataHandle.h:29
DataHandleHolderBase::inputDataObjs
const DataObjIDColl & inputDataObjs() const override
Definition: DataHandleHolderBase.h:55
Gaudi::DataHandle::Mode
Mode
Definition: DataHandle.h:29
DataHandle.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
DataHandleHolderBase::outputHandles
std::vector< Gaudi::DataHandle * > outputHandles() const override
Definition: DataHandleHolderBase.h:31
DataHandleHolderBase::m_outputDataObjs
DataObjIDColl m_outputDataObjs
Definition: DataHandleHolderBase.h:71
DataHandleHolderBase::m_handles
std::unordered_set< Gaudi::DataHandle * > m_handles
Definition: DataHandleHolderBase.h:74