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