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 <AsgDataHandles/WriteHandle.h>
13#include <AsgMessaging/MessageCheck.h>
14#include <AsgMessaging/StatusCode.h>
15#include <SystematicsHandles/AthenaDependencyHelpers.h>
16#include <SystematicsHandles/ISystematicsSvc.h>
17#include <SystematicsHandles/SysListHandle.h>
18
19//
20// method implementations
21//
22
23namespace CP
24{
25 template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
26 SysWriteHandle (T2 *owner, const std::string& propertyName,
27 const std::string& propertyValue,
28 const std::string& propertyDescription)
29 : SysWriteHandle (propertyValue, owner)
30 {
31 owner->declareProperty (propertyName, m_outputName, propertyDescription);
32 owner->declareProperty (propertyName + "Type", m_outputType,
33 "an explicit type name for output dependencies");
34 }
35
36
37 template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
38 SysWriteHandle (const std::string &outputName, T2 *owner)
39 : AsgMessagingForward (owner), m_outputName (outputName)
40 {
41#ifndef XAOD_STANDALONE
42 m_addAlgDependency = [owner](const DataObjID& id, Gaudi::DataHandle::Mode mode) {
43 owner->addDependency(id, mode);
44 };
45#endif
46 }
47
48
49
50 template<typename T,typename Aux> bool SysWriteHandle<T,Aux> ::
51 empty () const noexcept
52 {
53 return m_outputName.empty();
54 }
55
56
57
58 template<typename T,typename Aux> SysWriteHandle<T,Aux> ::
59 operator bool () const noexcept
60 {
61 return !m_outputName.empty();
62 }
63
64
65
66 template<typename T,typename Aux> std::string SysWriteHandle<T,Aux> ::
67 getNamePattern () const
68 {
69 return m_outputName;
70 }
71
72
73
74 template<typename T,typename Aux> StatusCode SysWriteHandle<T,Aux> ::
75 initialize (SysListHandle& sysListHandle)
76 {
77 return sysListHandle.addHandle (*this);
78 }
79
80
81
82 template<typename T,typename Aux> StatusCode SysWriteHandle<T,Aux> ::
83 initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
84 {
85 if (!empty())
86 return initialize (sysListHandle);
87 else
88 return StatusCode::SUCCESS;
89 }
90
91
92
93 template<typename T,typename Aux> const std::string& SysWriteHandle<T,Aux> ::
94 getName (const CP::SystematicSet& sys) const
95 {
96 return getWriteHandle (sys).key();
97 }
98
99
100
101 template<typename T,typename Aux> template<typename,typename>
102 ::StatusCode SysWriteHandle<T,Aux> ::
103 record (std::unique_ptr<T> object, const CP::SystematicSet& sys,
104 const EventContext& ctx) const
105 {
106 SG::WriteHandle<T> handle (getWriteHandle (sys), ctx);
107 return handle.recordNonConst (std::move (object));
108 }
109
110
111
112 template<typename T,typename Aux> template<typename,typename>
113 ::StatusCode SysWriteHandle<T,Aux> ::
114 record (std::unique_ptr<T> object, std::unique_ptr<Aux> aux,
115 const CP::SystematicSet& sys,
116 const EventContext& ctx) const
117 {
118 SG::WriteHandle<T> handle (getWriteHandle (sys), ctx);
119 return handle.recordNonConst (std::move (object), std::move (aux));
120 }
121
122
123
124 template<typename T,typename Aux> CP::SystematicSet SysWriteHandle<T,Aux> ::
125 getInputAffecting (const ISystematicsSvc& /*svc*/) const
126 {
127 return CP::SystematicSet ();
128 }
129
130
131
132 template<typename T,typename Aux> StatusCode SysWriteHandle<T,Aux> ::
133 fillSystematics (const ISystematicsSvc& svc,
134 const CP::SystematicSet& fullAffecting,
135 const std::vector<CP::SystematicSet>& sysList)
136 {
137 if (!empty())
138 {
139 for (auto& sys : sysList)
140 {
141 std::string newName;
142 ANA_CHECK (svc.makeSystematicsName (newName, m_outputName, sys));
143 ANA_MSG_DEBUG ("SysWriteHandle: " << newName << " (" << sys.name() << ")");
144 SG::WriteHandleKey<T> writeHandle (newName);
145 ANA_CHECK (writeHandle.initialize ());
146 m_sysData.emplace (sys, SysData{std::move (writeHandle)});
147 }
148 }
149 ANA_CHECK (svc.setObjectSystematics (m_outputName, fullAffecting));
150
151 ANA_CHECK (addDecorationDependency(svc, "", false));
152
153 return StatusCode::SUCCESS;
154 }
155
156
157
158 template<typename T,typename Aux> StatusCode SysWriteHandle<T,Aux> ::
159 addDecorationDependency (const ISystematicsSvc& svc, const std::string& decoName, bool decoWrite)
160 {
161#ifdef XAOD_STANDALONE
162 (void) svc;
163 (void) decoName;
164 (void) decoWrite;
165 return StatusCode::SUCCESS;
166#else
167 const CLID clid = detail::getClidForDependency<T>(m_outputType, decoName, decoWrite);
168 ANA_CHECK (detail::addSysDependency(msg(), svc, m_addAlgDependency, clid, m_outputName, Gaudi::DataHandle::Writer, decoName, decoWrite));
169 return StatusCode::SUCCESS;
170#endif
171 }
172
173
174
175 template<typename T,typename Aux> const SG::WriteHandleKey<T>& SysWriteHandle<T,Aux> ::
176 getWriteHandle (const CP::SystematicSet& sys) const
177 {
178 auto cache = m_sysData.find (sys);
179 if (cache == m_sysData.end())
180 {
181 if (m_sysData.empty())
182 throw std::logic_error ("uninitialized SysWriteHandle (" + m_outputName + ")");
183 else
184 throw std::logic_error ("unsupported systematic in SysWriteHandle (" + m_outputName + "): (" + sys.name() + ")");
185 }
186 return cache->second.writeHandle;
187 }
188}