Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DataHandleHolderBase.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 
13 #include <Gaudi/Property.h>
14 #include <GaudiKernel/DataHandle.h>
15 #include <GaudiKernel/DataObjID.h>
18 
19 #include <algorithm>
20 #include <unordered_set>
21 
22 namespace {
23  template <typename Container>
24  std::vector<Gaudi::DataHandle*> handles( Container& c, Gaudi::DataHandle::Mode mode ) {
25  std::vector<Gaudi::DataHandle*> h;
26  std::copy_if( std::begin( c ), std::end( c ), std::back_inserter( h ),
27  [&]( const Gaudi::DataHandle* hndl ) -> bool { return hndl->mode() & mode; } );
28  return h;
29  }
30 } // namespace
31 
32 template <class BASE>
33 class GAUDI_API DataHandleHolderBase : public extends<BASE, IDataHandleHolder> {
34 public:
36 
37  std::vector<Gaudi::DataHandle*> inputHandles() const override {
38  return handles( m_handles, Gaudi::DataHandle::Reader );
39  }
40  std::vector<Gaudi::DataHandle*> outputHandles() const override {
41  return handles( m_handles, Gaudi::DataHandle::Writer );
42  }
43 
44  virtual const DataObjIDColl& extraInputDeps() const override { return m_extInputDataObjs; }
45  virtual const DataObjIDColl& extraOutputDeps() const override { return m_extOutputDataObjs; }
46 
47  void declare( Gaudi::DataHandle& handle ) override {
48  if ( !handle.owner() ) handle.setOwner( this );
49 
50  if ( handle.owner() != this ) {
51  throw GaudiException( "Attempt to declare foreign handle with algorithm!", this->name(), StatusCode::FAILURE );
52  }
53 
54  m_handles.insert( &handle );
55  }
56 
57  void renounce( Gaudi::DataHandle& handle ) override {
58  if ( handle.owner() != this ) {
59  throw GaudiException( "Attempt to renounce foreign handle with algorithm!", this->name(), StatusCode::FAILURE );
60  }
61  m_handles.erase( &handle );
62  }
63 
64  bool renounceInput( const DataObjID& id ) override {
65  bool renounced = false;
66  // TODO: C++20: use std::erase_if
67  for ( auto i = m_handles.begin(), last = m_handles.end(); i != last; ) {
68  if ( ( *i )->mode() == Gaudi::DataHandle::Reader && ( *i )->fullKey() == id ) {
69  i = m_handles.erase( i );
70  renounced = true;
71  } else {
72  ++i;
73  }
74  }
75  if ( auto elm = m_inputDataObjs.find( id ); elm != m_inputDataObjs.end() ) {
76  m_inputDataObjs.erase( elm );
77  renounced = true;
78  }
79  return renounced;
80  }
81 
82  const DataObjIDColl& inputDataObjs() const override { return m_inputDataObjs; }
83  const DataObjIDColl& outputDataObjs() const override { return m_outputDataObjs; }
84 
85  void addDependency( const DataObjID& id, const Gaudi::DataHandle::Mode& mode ) override {
86  if ( mode & Gaudi::DataHandle::Reader ) m_inputDataObjs.emplace( id );
87  if ( mode & Gaudi::DataHandle::Writer ) m_outputDataObjs.emplace( id );
88  }
89 
90 protected:
94  for ( auto h : m_handles ) h->init();
95  }
96 
97  DataObjIDColl m_inputDataObjs, m_outputDataObjs;
98 
99 private:
100  std::unordered_set<Gaudi::DataHandle*> m_handles;
101 
102  Gaudi::Property<DataObjIDColl> m_extInputDataObjs{ this, "ExtraInputs", DataObjIDColl{} };
103  Gaudi::Property<DataObjIDColl> m_extOutputDataObjs{ this, "ExtraOutputs", DataObjIDColl{} };
104 };
DataHandleHolderBase
Definition: DataHandleHolderBase.h:33
DataHandleHolderBase::renounceInput
bool renounceInput(const DataObjID &id) override
Definition: DataHandleHolderBase.h:64
GaudiException.h
Gaudi::DataHandle::setOwner
virtual void setOwner(IDataHandleHolder *o)
Definition: DataHandle.h:51
GaudiException
Definition: GaudiException.h:29
DataHandleHolderBase::addDependency
void addDependency(const DataObjID &id, const Gaudi::DataHandle::Mode &mode) override
Definition: DataHandleHolderBase.h:85
Gaudi::DataHandle
Definition: DataHandle.h:37
DataHandleHolderBase::outputHandles
std::vector< Gaudi::DataHandle * > outputHandles() const override
Definition: DataHandleHolderBase.h:40
gaudirun.c
c
Definition: gaudirun.py:525
DataObjID.h
Gaudi::DataHandle::Writer
@ Writer
Definition: DataHandle.h:39
DataHandleHolderBase::m_outputDataObjs
DataObjIDColl m_outputDataObjs
Definition: DataHandleHolderBase.h:97
DataHandleHolderBase::declare
void declare(Gaudi::DataHandle &handle) override
Definition: DataHandleHolderBase.h:47
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:135
DataHandleHolderBase::initDataHandleHolder
void initDataHandleHolder()
initializes all handles - called by the sysInitialize method of any descendant of this
Definition: DataHandleHolderBase.h:93
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition: DataHandle.h:52
AlgSequencer.h
h
Definition: AlgSequencer.py:31
DataHandleHolderBase::extraOutputDeps
virtual const DataObjIDColl & extraOutputDeps() const override
Definition: DataHandleHolderBase.h:45
DataHandleHolderBase::extraInputDeps
virtual const DataObjIDColl & extraInputDeps() const override
Definition: DataHandleHolderBase.h:44
DataHandleHolderBase::renounce
void renounce(Gaudi::DataHandle &handle) override
Definition: DataHandleHolderBase.h:57
DataObjIDColl
std::unordered_set< DataObjID, DataObjID_Hasher > DataObjIDColl
Definition: DataObjID.h:122
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:19
DataObjID
Definition: DataObjID.h:47
Gaudi::DataHandle::Mode
Mode
Definition: DataHandle.h:39
DataHandleHolderBase::inputHandles
std::vector< Gaudi::DataHandle * > inputHandles() const override
Definition: DataHandleHolderBase.h:37
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
DataHandleHolderBase::outputDataObjs
const DataObjIDColl & outputDataObjs() const override
Definition: DataHandleHolderBase.h:83
IDataHandleHolder.h
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition: DataHandle.h:54
DataHandle.h
Gaudi::DataHandle::Reader
@ Reader
Definition: DataHandle.h:39
DataHandleHolderBase::inputDataObjs
const DataObjIDColl & inputDataObjs() const override
Definition: DataHandleHolderBase.h:82
IOTest.end
end
Definition: IOTest.py:125
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:100
DataHandleHolderBase::m_handles
std::unordered_set< Gaudi::DataHandle * > m_handles
Definition: DataHandleHolderBase.h:100
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
Gaudi::Property< DataObjIDColl >
Property.h