ATLAS Offline Software
ShallowCopyDecorDeps.icc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
3  */
4 /**
5  * @file StoreGate/ShallowCopyDecorDeps.icc
6  * @author scott snyder <snyder@bnl.gov>
7  * @date Nov, 2020
8  * @brief Helper to propagate decoration dependencies to a shallow copy.
9  */
10 
11 
12 namespace SG {
13 
14 
15 /**
16  * @brief Auto-declaring Property constructor.
17  * @param owner Owning component.
18  * @param name Name of the Property.
19  * @param l Default list of decorations to propagate.
20  * @param doc Documentation string.
21  */
22 template <class T>
23 template <class OWNER>
24 ShallowCopyDecorDeps<T>::ShallowCopyDecorDeps (OWNER* owner,
25  const std::string& name,
26  std::initializer_list<std::string> l,
27  const std::string& doc /*= ""*/)
28  : m_readKeys (owner, name + "ReadKeys", {}, "[Internal property]"),
29  m_writeKeys (owner, name, l, doc)
30 {
31 }
32 
33 
34 /**
35  * @brief Initialize this property. Call this from initialize().
36  * @param origKey Key for the source of the shallow copy.
37  * @param copyKey Key for the result of the shallow copy.
38  * @param used If false, then this handle is not to be used.
39  * Instead of normal initialization, the keys will be cleared.
40  */
41 template <class T>
42 StatusCode
43 ShallowCopyDecorDeps<T>::initialize (const SG::ReadHandleKey<T>& origKey,
44  const SG::WriteHandleKey<T>& copyKey,
45  bool used /*= true*/)
46 {
47  m_readKeys.clear();
48  if (used) {
49  for (SG::WriteHandleKey<T>& k : m_writeKeys) {
50  m_readKeys.emplace_back (origKey.key() + '.' + k.key());
51  k = copyKey.key() + '.' + k.key();
52  }
53  CHECK( m_readKeys.initialize() );
54  CHECK( m_writeKeys.initialize() );
55  }
56  else {
57  m_writeKeys.clear();
58  }
59  return StatusCode::SUCCESS;
60 }
61 
62 
63 /**
64  * @brief Create alias for the decorations, linked to the shallow copy.
65  * @param origKey Key for the source of the shallow copy.
66  * @param ctx The current EventContext.
67  *
68  * Call this after the shallow copy has been recorded in SG.
69  */
70 template <class T>
71 StatusCode
72 ShallowCopyDecorDeps<T>::linkDecors (const SG::ReadHandleKey<T>& origKey,
73  const EventContext& ctx /*= Gaudi::Hive::currentContext()*/) const
74 {
75  SG::ReadHandle<T> orig (origKey, ctx);
76  for (const SG::WriteHandleKey<T>& k : m_writeKeys) {
77  CHECK( orig.alias (k) );
78  }
79  return StatusCode::SUCCESS;
80 }
81 
82 
83 } // namespace SG