2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
5 /// @author Nils Krumnack
12 #include <AsgMessaging/MessageCheck.h>
13 #include <AsgMessaging/StatusCode.h>
18 // method implementations
23 template<typename T> template<typename T2> SysWriteDecorHandle<T> ::
24 SysWriteDecorHandle (T2 *owner, const std::string& propertyName,
25 const std::string& propertyValue,
26 const std::string& propertyDescription)
27 : AsgMessagingForward (owner), m_decorName (propertyValue)
29 owner->declareProperty (propertyName, m_decorName, propertyDescription);
32 template<typename T> template<typename T2> SysWriteDecorHandle<T> ::
33 SysWriteDecorHandle (const std::string& decorName, T2 *owner)
34 : AsgMessagingForward (owner), m_decorName(decorName)
39 template<typename T> bool SysWriteDecorHandle<T> ::
40 empty () const noexcept
42 return m_decorName.empty();
47 template<typename T> SysWriteDecorHandle<T> ::
48 operator bool () const noexcept
50 return !m_decorName.empty();
55 template<typename T> std::string SysWriteDecorHandle<T> ::
56 getNamePattern () const
58 // So far it is undefined what to return here, it could either be
59 // "decorName" or "objectName.decorName". I'll fill this in once
60 // there is a reason for it to be one or the other.
66 template<typename T> StatusCode SysWriteDecorHandle<T> ::
67 initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle)
69 if (m_objectHandle != nullptr)
71 ANA_MSG_ERROR ("trying to initialize handle twice");
72 return StatusCode::FAILURE;
74 m_objectHandle = &objectHandle;
75 return sysListHandle.addHandle (*this);
80 template<typename T> StatusCode SysWriteDecorHandle<T> ::
81 initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle, SG::AllowEmptyEnum)
84 return initialize (sysListHandle, objectHandle);
86 return StatusCode::SUCCESS;
91 template<typename T> const std::string& SysWriteDecorHandle<T> ::
92 getName (const CP::SystematicSet& sys) const
94 const auto& data = getData (sys);
95 return std::get<0> (data);
100 template<typename T> void SysWriteDecorHandle<T> ::
101 set (const SG::AuxElement& object, const T& value,
102 const CP::SystematicSet& sys) const
104 const auto& data = getData (sys);
105 std::get<1> (data) (object) = value;
110 template<typename T> CP::SystematicSet SysWriteDecorHandle<T> ::
111 getInputAffecting (const ISystematicsSvc& /*svc*/) const
113 return CP::SystematicSet ();
118 template<typename T> StatusCode SysWriteDecorHandle<T> ::
119 fillSystematics (const ISystematicsSvc& svc,
120 const CP::SystematicSet& fullAffecting,
121 const std::vector<CP::SystematicSet>& sysList)
123 for (auto& sys : sysList)
126 ANA_CHECK (svc.makeSystematicsName (newName, m_decorName, sys));
127 ANA_MSG_DEBUG ("SysWriteDecorHandle: " << newName << " (" << sys.name() << ")");
128 m_dataCache.emplace (sys, std::make_tuple (newName, newName));
130 ANA_CHECK (svc.setDecorSystematics (m_objectHandle->getNamePattern(), m_decorName, fullAffecting));
131 return StatusCode::SUCCESS;
136 template<typename T> const auto&
137 SysWriteDecorHandle<T> ::
138 getData (const CP::SystematicSet& sys) const
140 auto cache = m_dataCache.find (sys);
141 if (cache == m_dataCache.end())
143 if (m_dataCache.empty())
144 throw std::logic_error ("uninitialized SysWriteDecorHandle (" + m_decorName + ")");
146 throw std::logic_error ("unsupported systematic in SysWriteDecorHandle (" + m_decorName + "): (" + sys.name() + ")");
148 return cache->second;