ATLAS Offline Software
WriteDecorHandleKey.cxx
Go to the documentation of this file.
1 // $Id$
2 /*
3  * Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration.
4  */
15 #include "GaudiKernel/IAlgTool.h"
16 #include "GaudiKernel/IDataHandleHolder.h"
17 #include "GaudiKernel/Algorithm.h"
18 
19 
20 namespace SG {
21 namespace detail {
22 
23 
30 bool handleInHolder (const DataObjID& contHandleKey,
31  const IDataHandleHolder& holder)
32 {
33  for (const Gaudi::DataHandle* h : holder.inputHandles()) {
34  if (h->fullKey() == contHandleKey) {
35  return true;
36  }
37  }
38 
39  for (const Gaudi::DataHandle* h : holder.outputHandles()) {
40  if (h->fullKey() == contHandleKey) {
41  return true;
42  }
43  }
44 
45  return false;
46 }
47 
48 
58 const IDataHandleHolder* findParent (const IDataHandleHolder* h)
59 {
60  while (true) {
61  const IAlgTool* astool = dynamic_cast<const IAlgTool*> (h);
62  if (!astool) return h;
63  const IInterface* parent = astool->parent();
64  if (!parent) return h;
65  auto pdh = dynamic_cast<const IDataHandleHolder*> (parent);
66  if (!pdh) return h;
67  if (dynamic_cast<const Gaudi::Algorithm*> (parent)) return pdh;
68  h = pdh;
69  }
70 }
71 
72 
81 class WDHScan
82  : public IDataHandleVisitor
83 {
84 public:
90  WDHScan (const DataObjID& contHandleKey, const IDataHandleHolder* owner)
91  : m_contHandleKey (contHandleKey),
92  m_owner (owner)
93  {
94  }
95 
97  virtual void visit (const IDataHandleHolder* h) override;
98 
100  const DataObjID& m_contHandleKey;
101 
103  const IDataHandleHolder* m_owner;
104 
106  bool m_found = false;
107 
109  bool m_sawOwner = false;
110 };
111 
112 
117 void WDHScan::visit (const IDataHandleHolder* h)
118 {
119  // Don't do anything if we've already found the key, or if we've seen m_owner.
120  if (m_found || m_sawOwner) return;
121  if (h == m_owner) {
122  m_sawOwner = true;
123  return;
124  }
125 
126  // Test to see if this component has a key matching the one we're looking for.
128 }
129 
130 
154 void registerWriteDecorHandleKey (IDataHandleHolder* owner,
155  const DataObjID& contHandleKey)
156 {
157  if (!owner) return;
158 
159  // Does this component already have a key matching @c contHandleKey?
160  bool found = handleInHolder (contHandleKey, *owner);
161 
162  if (!found) {
163  // No --- now search the complete component tree up to @c owner for a match.
164  const IDataHandleHolder* parent = findParent (owner);
165  if (parent && parent != owner) {
166  WDHScan scan (contHandleKey, owner);
167  parent->acceptDHVisitor (&scan);
168  found = scan.m_found;
169  }
170  }
171 
172  if (!found) {
173  owner->addDependency (contHandleKey, Gaudi::DataHandle::Reader);
174  }
175 }
176 
177 
178 } // namespace detail
179 } // namespace SG
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::detail::WDHScan::WDHScan
WDHScan(const DataObjID &contHandleKey, const IDataHandleHolder *owner)
Constructor.
Definition: WriteDecorHandleKey.cxx:90
SG::detail::findParent
const IDataHandleHolder * findParent(const IDataHandleHolder *h)
Find the top-level Gaudi component for H.
Definition: WriteDecorHandleKey.cxx:58
python.FakeAthena.Algorithm
def Algorithm(name)
Definition: FakeAthena.py:41
SG::detail::WDHScan::m_contHandleKey
const DataObjID & m_contHandleKey
The key we're searching for.
Definition: WriteDecorHandleKey.cxx:100
detail
Definition: extract_histogram_tag.cxx:14
WriteDecorHandleKey.h
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
SG::detail::WDHScan::m_owner
const IDataHandleHolder * m_owner
Stop the search when we reach this component.
Definition: WriteDecorHandleKey.cxx:103
extractSporadic.h
list h
Definition: extractSporadic.py:97
LHEF::Reader
Pythia8::Reader Reader
Definition: Prophecy4fMerger.cxx:11
test_pyathena.parent
parent
Definition: test_pyathena.py:15
SG::detail::WDHScan::visit
virtual void visit(const IDataHandleHolder *h) override
Called for each component in the tree.
Definition: WriteDecorHandleKey.cxx:117
SG::detail::handleInHolder
bool handleInHolder(const DataObjID &contHandleKey, const IDataHandleHolder &holder)
Test to see if HOLDER has registered a handle key matching CONTHANDLEKEY, as either input or output.
Definition: WriteDecorHandleKey.cxx:30
SG::detail::WDHScan::m_sawOwner
bool m_sawOwner
Have we reached m_owner yet?
Definition: WriteDecorHandleKey.cxx:109
h
scan
void scan(TDirectory *td=0, int depth=0)
Definition: listroot.cxx:440
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
SG::detail::WDHScan
Helper to scan a tree of components to search for another handle key potentially conflicting with the...
Definition: WriteDecorHandleKey.cxx:83
SG::detail::registerWriteDecorHandleKey
void registerWriteDecorHandleKey(IDataHandleHolder *owner, const DataObjID &contHandleKey)
Optionally register read dependency of a WriteDecorHandleKey.
Definition: WriteDecorHandleKey.cxx:154
SG::detail::WDHScan::m_found
bool m_found
Did we find the key?
Definition: WriteDecorHandleKey.cxx:106