ATLAS Offline Software
Loading...
Searching...
No Matches
SysReadHandle.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4
5/// @author Nils Krumnack
6
7
8//
9// includes
10//
11
12#include <AsgMessaging/MessageCheck.h>
13#include <AsgMessaging/StatusCode.h>
14#include <SystematicsHandles/AthenaDependencyHelpers.h>
15#include <SystematicsHandles/ISystematicsSvc.h>
16#include <SystematicsHandles/SysListHandle.h>
17
18//
19// method implementations
20//
21
22namespace CP
23{
24 template<typename T> template<typename T2> SysReadHandle<T> ::
25 SysReadHandle (T2 *owner, const std::string& propertyName,
26 const std::string& propertyValue,
27 const std::string& propertyDescription)
28 : SysReadHandle (propertyValue, owner)
29 {
30 owner->declareProperty (propertyName, m_inputName, propertyDescription);
31 }
32
33 template<typename T> template<typename T2> SysReadHandle<T> ::
34 SysReadHandle (const std::string &inputName, T2 *owner)
35 : AsgMessagingForward (owner), m_inputName(inputName)
36 , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
37 {
38#ifndef XAOD_STANDALONE
39 m_addAlgDependency = [owner](const DataObjID& id, Gaudi::DataHandle::Mode mode) {
40 owner->addDependency(id, mode);
41 };
42#endif
43 }
44
45
46 template<typename T> bool SysReadHandle<T> ::
47 empty () const noexcept
48 {
49 return m_inputName.empty();
50 }
51
52
53
54 template<typename T> SysReadHandle<T> ::
55 operator bool () const noexcept
56 {
57 return !m_inputName.empty();
58 }
59
60
61
62 template<typename T> std::string SysReadHandle<T> ::
63 getNamePattern () const
64 {
65 return m_inputName;
66 }
67
68
69
70 template<typename T> StatusCode SysReadHandle<T> ::
71 initialize (SysListHandle& sysListHandle)
72 {
73 return sysListHandle.addHandle (*this);
74 }
75
76
77
78 template<typename T> StatusCode SysReadHandle<T> ::
79 initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
80 {
81 if (!empty())
82 return initialize (sysListHandle);
83 else
84 return StatusCode::SUCCESS;
85 }
86
87
88
89 template<typename T> const std::string& SysReadHandle<T> ::
90 getName (const CP::SystematicSet& sys) const
91 {
92 auto cache = m_inputNameCache.find (sys);
93 if (cache == m_inputNameCache.end())
94 {
95 if (m_inputNameCache.empty())
96 throw std::logic_error ("uninitialized SysReadHandle (" + m_inputName + ")");
97 else
98 throw std::logic_error ("unsupported systematic in SysReadHandle (" + m_inputName + "): (" + sys.name() + ")");
99 }
100 return cache->second;
101 }
102
103
104
105 template<typename T> ::StatusCode SysReadHandle<T> ::
106 retrieve (const T*& object, const CP::SystematicSet& sys) const
107 {
108 const std::string& name = getName (sys);
109 assert (m_evtStore);
110 return m_evtStore->retrieve (object, name);
111 }
112
113
114
115 template<typename T> bool SysReadHandle<T> ::
116 isValid (const CP::SystematicSet& sys) const
117 {
118 const std::string& name = getName (sys);
119 assert (m_evtStore);
120 return m_evtStore->contains<T> (name);
121 }
122
123
124
125 template<typename T> CP::SystematicSet SysReadHandle<T> ::
126 getInputAffecting (const ISystematicsSvc& svc) const
127 {
128 return svc.getObjectSystematics (m_inputName);
129 }
130
131
132
133 template<typename T> StatusCode SysReadHandle<T> ::
134 fillSystematics (const ISystematicsSvc& svc,
135 const CP::SystematicSet& /*fullAffecting*/,
136 const std::vector<CP::SystematicSet>& sysList)
137 {
138 const CP::SystematicSet affecting = svc.getObjectSystematics (m_inputName);
139 for (auto& sys : sysList)
140 {
141 CP::SystematicSet inputSys;
142 ANA_CHECK (SystematicSet::filterForAffectingSystematics (sys, affecting, inputSys));
143 std::string inputName;
144 ANA_CHECK (svc.makeSystematicsName (inputName, m_inputName, inputSys));
145 m_inputNameCache.emplace (sys, inputName);
146 }
147
148 // retrieving this here, just so it exists
149 if (!m_evtStore)
150 m_evtStore = m_evtStoreGetter();
151
152 ANA_CHECK (addDecorationDependency(svc, "", false));
153
154 return StatusCode::SUCCESS;
155 }
156
157
158
159 template<typename T> StatusCode SysReadHandle<T> ::
160 addDecorationDependency (const ISystematicsSvc& svc, const std::string& decoName, bool decoWrite)
161 {
162#ifdef XAOD_STANDALONE
163 (void) svc;
164 (void) decoName;
165 (void) decoWrite;
166 return StatusCode::SUCCESS;
167#else
168 const CLID clid = detail::getClidForDependency<T>("", decoName, decoWrite);
169 ANA_CHECK (detail::addSysDependency(msg(), svc, m_addAlgDependency, clid, m_inputName, Gaudi::DataHandle::Reader, decoName, decoWrite));
170 return StatusCode::SUCCESS;
171#endif
172 }
173}