ATLAS Offline Software
Loading...
Searching...
No Matches
SysWriteHandle.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 <SystematicsHandles/AthenaDependencyHelpers.h>
14
15//
16// method implementations
17//
18
19namespace CP
20{
21 template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
22 SysWriteHandle (T2 *owner, const std::string& propertyName,
23 const std::string& propertyValue,
24 const std::string& propertyDescription)
25 : SysWriteHandle (propertyValue, owner)
26 {
27 owner->declareProperty (propertyName, m_outputName, propertyDescription);
28 }
29
30
31 template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
32 SysWriteHandle (const std::string &outputName, T2 *owner)
33 : AsgMessagingForward (owner), m_outputName (outputName)
34 , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
35 {
36#ifndef XAOD_STANDALONE
37 m_addDependency = [owner] (const std::string& name,const std::string& decoName,bool decoWrite) -> StatusCode
38 {
39 return detail::addDependency<T,true>(*owner, name, decoName, decoWrite);
40 };
41#endif
42 }
43
44
45
46 template<typename T,typename Aux> bool SysWriteHandle<T,Aux> ::
47 empty () const noexcept
48 {
49 return m_outputName.empty();
50 }
51
52
53
54 template<typename T,typename Aux> SysWriteHandle<T,Aux> ::
55 operator bool () const noexcept
56 {
57 return !m_outputName.empty();
58 }
59
60
61
62 template<typename T,typename Aux> std::string SysWriteHandle<T,Aux> ::
63 getNamePattern () const
64 {
65 return m_outputName;
66 }
67
68
69
70 template<typename T,typename Aux>
71 StatusCode SysWriteHandle<T,Aux> ::
72 initialize (SysListHandle& sysListHandle)
73 {
74 return sysListHandle.addHandle (*this);
75 }
76
77
78
79 template<typename T,typename Aux>
80 StatusCode SysWriteHandle<T,Aux> ::
81 initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
82 {
83 if (!empty())
84 return initialize (sysListHandle);
85 else
86 return StatusCode::SUCCESS;
87 }
88
89
90
91 template<typename T,typename Aux>
92 const std::string& SysWriteHandle<T,Aux> ::
93 getName (const CP::SystematicSet& sys) const
94 {
95 auto cache = m_outputNameCache.find (sys);
96 if (cache == m_outputNameCache.end())
97 {
98 if (m_outputName.empty())
99 throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
100 else
101 throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
102 }
103 return cache->second;
104 }
105
106
107
108 template<typename T,typename Aux>
109 template<typename,typename>
110 ::StatusCode SysWriteHandle<T,Aux> ::
111 record (std::unique_ptr<T> object, const CP::SystematicSet& sys) const
112 {
113 const std::string& name = getName (sys);
114 assert (m_evtStore);
115 return m_evtStore->record (object.release(), name);
116 }
117
118
119
120 template<typename T,typename Aux>
121 template<typename,typename>
122 ::StatusCode SysWriteHandle<T,Aux> ::
123 record (std::unique_ptr<T> object, std::unique_ptr<Aux> aux,
124 const CP::SystematicSet& sys) const
125 {
126 auto cache = m_outputNameCache.find (sys);
127 if (cache == m_outputNameCache.end())
128 {
129 if (m_outputName.empty())
130 throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
131 else
132 throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
133 }
134 assert (m_evtStore);
135 if (m_evtStore->record (aux.release(), cache->second + "Aux.").isFailure())
136 return StatusCode::FAILURE;
137 if (m_evtStore->record (object.release(), cache->second).isFailure())
138 return StatusCode::FAILURE;
139 return StatusCode::SUCCESS;
140 }
141
142
143
144 template<typename T,typename Aux>
145 CP::SystematicSet SysWriteHandle<T,Aux> ::
146 getInputAffecting (const ISystematicsSvc& /*svc*/) const
147 {
148 return CP::SystematicSet ();
149 }
150
151
152
153 template<typename T,typename Aux>
154 StatusCode SysWriteHandle<T,Aux> ::
155 fillSystematics (const ISystematicsSvc& svc,
156 const CP::SystematicSet& fullAffecting,
157 const std::vector<CP::SystematicSet>& sysList)
158 {
159 if (!m_evtStore)
160 m_evtStore = m_evtStoreGetter();
161 for (auto& sys : sysList)
162 {
163 std::string newName;
164 ANA_CHECK (svc.makeSystematicsName (newName, m_outputName, sys));
165 ANA_MSG_DEBUG ("SysWriteHandle: " << newName << " (" << sys.name() << ")");
166 m_outputNameCache.emplace (sys, newName);
167 }
168 ANA_CHECK (svc.setObjectSystematics (m_outputName, fullAffecting));
169
170 if (m_addDependency)
171 {
172 /// I'm only adding a dependency for nominal here, as there are
173 /// currently no use cases in which a downstream user would only
174 /// read a systematic, but not the nominal. The concern is that we
175 /// might add dozens (or in extreme cases hundreds) of
176 /// dependencies, without those adding providing any value.
177 ANA_CHECK (m_addDependency(getName (CP::SystematicSet{}), "", false));
178 }
179
180 return StatusCode::SUCCESS;
181 }
182
183
184
185 template<typename T,typename Aux>
186 StatusCode SysWriteHandle<T,Aux> ::
187 addDecorationDependency (const std::string& decoName, bool decoWrite)
188 {
189 if (m_addDependency)
190 return m_addDependency (getName (CP::SystematicSet{}), decoName, decoWrite);
191 else
192 return StatusCode::SUCCESS;
193 }
194}