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 owner->declareProperty (propertyName + "Type", m_outputType,
29 "an explicit type name for output dependencies");
30 }
31
32
33 template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
34 SysWriteHandle (const std::string &outputName, T2 *owner)
35 : AsgMessagingForward (owner), m_outputName (outputName)
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
47 template<typename T,typename Aux> bool SysWriteHandle<T,Aux> ::
48 empty () const noexcept
49 {
50 return m_outputName.empty();
51 }
52
53
54
55 template<typename T,typename Aux> SysWriteHandle<T,Aux> ::
56 operator bool () const noexcept
57 {
58 return !m_outputName.empty();
59 }
60
61
62
63 template<typename T,typename Aux> std::string SysWriteHandle<T,Aux> ::
64 getNamePattern () const
65 {
66 return m_outputName;
67 }
68
69
70
71 template<typename T,typename Aux>
72 StatusCode SysWriteHandle<T,Aux> ::
73 initialize (SysListHandle& sysListHandle)
74 {
75 return sysListHandle.addHandle (*this);
76 }
77
78
79
80 template<typename T,typename Aux>
81 StatusCode SysWriteHandle<T,Aux> ::
82 initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
83 {
84 if (!empty())
85 return initialize (sysListHandle);
86 else
87 return StatusCode::SUCCESS;
88 }
89
90
91
92 template<typename T,typename Aux>
93 const std::string& SysWriteHandle<T,Aux> ::
94 getName (const CP::SystematicSet& sys) const
95 {
96 auto cache = m_outputNameCache.find (sys);
97 if (cache == m_outputNameCache.end())
98 {
99 if (m_outputName.empty())
100 throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
101 else
102 throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
103 }
104 return cache->second;
105 }
106
107
108
109 template<typename T,typename Aux>
110 template<typename,typename>
111 ::StatusCode SysWriteHandle<T,Aux> ::
112 record (std::unique_ptr<T> object, const CP::SystematicSet& sys) const
113 {
114 const std::string& name = getName (sys);
115 assert (m_evtStore);
116 return m_evtStore->record (object.release(), name);
117 }
118
119
120
121 template<typename T,typename Aux>
122 template<typename,typename>
123 ::StatusCode SysWriteHandle<T,Aux> ::
124 record (std::unique_ptr<T> object, std::unique_ptr<Aux> aux,
125 const CP::SystematicSet& sys) const
126 {
127 auto cache = m_outputNameCache.find (sys);
128 if (cache == m_outputNameCache.end())
129 {
130 if (m_outputName.empty())
131 throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
132 else
133 throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
134 }
135 assert (m_evtStore);
136 if (m_evtStore->record (aux.release(), cache->second + "Aux.").isFailure())
137 return StatusCode::FAILURE;
138 if (m_evtStore->record (object.release(), cache->second).isFailure())
139 return StatusCode::FAILURE;
140 return StatusCode::SUCCESS;
141 }
142
143
144
145 template<typename T,typename Aux>
146 CP::SystematicSet SysWriteHandle<T,Aux> ::
147 getInputAffecting (const ISystematicsSvc& /*svc*/) const
148 {
149 return CP::SystematicSet ();
150 }
151
152
153
154 template<typename T,typename Aux>
155 StatusCode SysWriteHandle<T,Aux> ::
156 fillSystematics (const ISystematicsSvc& svc,
157 const CP::SystematicSet& fullAffecting,
158 const std::vector<CP::SystematicSet>& sysList)
159 {
160 if (!m_evtStore)
161 m_evtStore = m_evtStoreGetter();
162 for (auto& sys : sysList)
163 {
164 std::string newName;
165 ANA_CHECK (svc.makeSystematicsName (newName, m_outputName, sys));
166 ANA_MSG_DEBUG ("SysWriteHandle: " << newName << " (" << sys.name() << ")");
167 m_outputNameCache.emplace (sys, newName);
168 }
169 ANA_CHECK (svc.setObjectSystematics (m_outputName, fullAffecting));
170
171 ANA_CHECK (addDecorationDependency(svc, "", false));
172
173 return StatusCode::SUCCESS;
174 }
175
176
177
178 template<typename T,typename Aux>
179 StatusCode SysWriteHandle<T,Aux> ::
180 addDecorationDependency (const ISystematicsSvc& svc, const std::string& decoName, bool decoWrite)
181 {
182#ifdef XAOD_STANDALONE
183 (void) svc;
184 (void) decoName;
185 (void) decoWrite;
186 return StatusCode::SUCCESS;
187#else
188 const CLID clid = detail::getClidForDependency<T>(m_outputType, decoName, decoWrite);
189 ANA_CHECK (detail::addSysDependency(msg(), svc, m_addAlgDependency, clid, m_outputName, Gaudi::DataHandle::Writer, decoName, decoWrite));
190 return StatusCode::SUCCESS;
191#endif
192 }
193}