2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
5/// @author Nils Krumnack
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>
20// method implementations
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)
31 owner->declareProperty (propertyName, m_outputName, propertyDescription);
32 owner->declareProperty (propertyName + "Type", m_outputType,
33 "an explicit type name for output dependencies");
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)
41#ifndef XAOD_STANDALONE
42 m_addAlgDependency = [owner](const DataObjID& id, Gaudi::DataHandle::Mode mode) {
43 owner->addDependency(id, mode);
50 template<typename T,typename Aux> bool SysWriteHandle<T,Aux> ::
51 empty () const noexcept
53 return m_outputName.empty();
58 template<typename T,typename Aux> SysWriteHandle<T,Aux> ::
59 operator bool () const noexcept
61 return !m_outputName.empty();
66 template<typename T,typename Aux> std::string SysWriteHandle<T,Aux> ::
67 getNamePattern () const
74 template<typename T,typename Aux> StatusCode SysWriteHandle<T,Aux> ::
75 initialize (SysListHandle& sysListHandle)
77 return sysListHandle.addHandle (*this);
82 template<typename T,typename Aux> StatusCode SysWriteHandle<T,Aux> ::
83 initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
86 return initialize (sysListHandle);
88 return StatusCode::SUCCESS;
93 template<typename T,typename Aux> const std::string& SysWriteHandle<T,Aux> ::
94 getName (const CP::SystematicSet& sys) const
96 return getWriteHandle (sys).key();
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
106 SG::WriteHandle<T> handle (getWriteHandle (sys), ctx);
107 return handle.recordNonConst (std::move (object));
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
118 SG::WriteHandle<T> handle (getWriteHandle (sys), ctx);
119 return handle.recordNonConst (std::move (object), std::move (aux));
124 template<typename T,typename Aux> CP::SystematicSet SysWriteHandle<T,Aux> ::
125 getInputAffecting (const ISystematicsSvc& /*svc*/) const
127 return CP::SystematicSet ();
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)
139 for (auto& sys : sysList)
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)});
149 ANA_CHECK (svc.setObjectSystematics (m_outputName, fullAffecting));
151 ANA_CHECK (addDecorationDependency(svc, "", false));
153 return StatusCode::SUCCESS;
158 template<typename T,typename Aux> StatusCode SysWriteHandle<T,Aux> ::
159 addDecorationDependency (const ISystematicsSvc& svc, const std::string& decoName, bool decoWrite)
161#ifdef XAOD_STANDALONE
165 return StatusCode::SUCCESS;
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;
175 template<typename T,typename Aux> const SG::WriteHandleKey<T>& SysWriteHandle<T,Aux> ::
176 getWriteHandle (const CP::SystematicSet& sys) const
178 auto cache = m_sysData.find (sys);
179 if (cache == m_sysData.end())
181 if (m_sysData.empty())
182 throw std::logic_error ("uninitialized SysWriteHandle (" + m_outputName + ")");
184 throw std::logic_error ("unsupported systematic in SysWriteHandle (" + m_outputName + "): (" + sys.name() + ")");
186 return cache->second.writeHandle;