The Gaudi Framework  v33r0 (d5ea422b)
DataHandleHolderBase.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_DATAHANDLEHOLDERBASE
12 #define GAUDIKERNEL_DATAHANDLEHOLDERBASE 1
13 
14 #include "GaudiKernel/DataHandle.h"
15 #include "GaudiKernel/DataObjID.h"
18 #include "GaudiKernel/Property.h"
19 
20 #include <algorithm>
21 #include <unordered_set>
22 
23 namespace {
24  template <typename Container>
25  std::vector<Gaudi::DataHandle*> handles( Container& c, Gaudi::DataHandle::Mode mode ) {
28  [&]( const Gaudi::DataHandle* hndl ) -> bool { return hndl->mode() & mode; } );
29  return h;
30  }
31 } // namespace
32 
33 template <class BASE>
34 class GAUDI_API DataHandleHolderBase : public extends<BASE, IDataHandleHolder> {
35 public:
37 
39  return handles( m_handles, Gaudi::DataHandle::Reader );
40  }
42  return handles( m_handles, Gaudi::DataHandle::Writer );
43  }
44 
45  virtual const DataObjIDColl& extraInputDeps() const override { return m_extInputDataObjs; }
46  virtual const DataObjIDColl& extraOutputDeps() const override { return m_extOutputDataObjs; }
47 
48  void declare( Gaudi::DataHandle& handle ) override {
49  if ( !handle.owner() ) handle.setOwner( this );
50 
51  if ( handle.owner() != this ) {
52  throw GaudiException( "Attempt to declare foreign handle with algorithm!", this->name(), StatusCode::FAILURE );
53  }
54 
55  m_handles.insert( &handle );
56  }
57 
58  void renounce( Gaudi::DataHandle& handle ) override {
59  if ( handle.owner() != this ) {
60  throw GaudiException( "Attempt to renounce foreign handle with algorithm!", this->name(), StatusCode::FAILURE );
61  }
62  m_handles.erase( &handle );
63  }
64 
65  const DataObjIDColl& inputDataObjs() const override { return m_inputDataObjs; }
66  const DataObjIDColl& outputDataObjs() const override { return m_outputDataObjs; }
67 
68  void addDependency( const DataObjID& id, const Gaudi::DataHandle::Mode& mode ) override {
69  if ( mode & Gaudi::DataHandle::Reader ) m_inputDataObjs.emplace( id );
70  if ( mode & Gaudi::DataHandle::Writer ) m_outputDataObjs.emplace( id );
71  }
72 
73 private:
74 protected:
78  for ( auto h : m_handles ) h->init();
79  }
80 
81  DataObjIDColl m_inputDataObjs, m_outputDataObjs;
82 
83 private:
85 
86  Gaudi::Property<DataObjIDColl> m_extInputDataObjs{this, "ExtraInputs", DataObjIDColl{}};
87  Gaudi::Property<DataObjIDColl> m_extOutputDataObjs{this, "ExtraOutputs", DataObjIDColl{}};
88 };
89 
90 #endif // !GAUDIKERNEL_DATAHANDLEHOLDERBASE
std::vector< Gaudi::DataHandle * > inputHandles() const override
virtual Mode mode() const
Definition: DataHandle.h:52
T copy_if(T... args)
Define general base for Gaudi exception.
virtual void setOwner(IDataHandleHolder *o)
Definition: DataHandle.h:49
Implementation of property with value of concrete type.
Definition: Property.h:370
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:50
void initDataHandleHolder()
initializes all handles - called by the sysInitialize method of any descendant of this
void renounce(Gaudi::DataHandle &handle) override
T end(T... args)
void declare(Gaudi::DataHandle &handle) override
virtual const DataObjIDColl & extraOutputDeps() const override
void addDependency(const DataObjID &id, const Gaudi::DataHandle::Mode &mode) override
const DataObjIDColl & outputDataObjs() const override
STL class.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
T begin(T... args)
virtual const DataObjIDColl & extraInputDeps() const override
T back_inserter(T... args)
constexpr static const auto FAILURE
Definition: StatusCode.h:97
const DataObjIDColl & inputDataObjs() const override
#define GAUDI_API
Definition: Kernel.h:81
std::vector< Gaudi::DataHandle * > outputHandles() const override
DataObjIDColl m_outputDataObjs
std::unordered_set< Gaudi::DataHandle * > m_handles