ATLAS Offline Software
Loading...
Searching...
No Matches
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 */
12
13
15#include "GaudiKernel/IAlgTool.h"
16#include "GaudiKernel/IDataHandleHolder.h"
17#include "GaudiKernel/Algorithm.h"
18
19
20namespace SG {
21namespace detail {
22
23
30bool 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
58const 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
82 : public IDataHandleVisitor
83{
84public:
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
117void 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
154void 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
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.