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> SysReadDecorHandle<T> ::
24 SysReadDecorHandle (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);
33 template<typename T> template<typename T2> SysReadDecorHandle<T> ::
34 SysReadDecorHandle (const std::string& decorName, T2 *owner)
35 : AsgMessagingForward (owner), m_decorName(decorName)
40 template<typename T> bool SysReadDecorHandle<T> ::
41 empty () const noexcept
43 return m_decorName.empty();
48 template<typename T> SysReadDecorHandle<T> ::
49 operator bool () const noexcept
51 return !m_decorName.empty();
56 template<typename T> std::string SysReadDecorHandle<T> ::
57 getNamePattern () const
59 // So far it is undefined what to return here, it could either be
60 // "decorName" or "objectName.decorName". I'll fill this in once
61 // there is a reason for it to be one or the other.
67 template<typename T> StatusCode SysReadDecorHandle<T> ::
68 initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle)
70 if (m_objectHandle != nullptr)
72 ANA_MSG_ERROR ("trying to initialize handle twice");
73 return StatusCode::FAILURE;
75 m_objectHandle = &objectHandle;
76 return sysListHandle.addHandle (*this);
81 template<typename T> StatusCode SysReadDecorHandle<T> ::
82 initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle, SG::AllowEmptyEnum)
85 return initialize (sysListHandle, objectHandle);
87 return StatusCode::SUCCESS;
92 template<typename T> const std::string& SysReadDecorHandle<T> ::
93 getName (const CP::SystematicSet& sys) const
95 const auto& data = getData (sys);
96 return std::get<0> (data);
101 template<typename T> const T& SysReadDecorHandle<T> ::
102 get (const SG::AuxElement& object,
103 const CP::SystematicSet& sys) const
105 const auto& data = getData (sys);
106 return std::get<1> (data) (object);
111 template<typename T> CP::SystematicSet SysReadDecorHandle<T> ::
112 getInputAffecting (const ISystematicsSvc& svc) const
114 return svc.getDecorSystematics (m_objectHandle->getNamePattern(), m_decorName);
119 template<typename T> StatusCode SysReadDecorHandle<T> ::
120 fillSystematics (const ISystematicsSvc& svc,
121 const CP::SystematicSet& /*fullAffecting*/,
122 const std::vector<CP::SystematicSet>& sysList)
124 const CP::SystematicSet affecting
125 = svc.getDecorSystematics (m_objectHandle->getNamePattern(), m_decorName);
126 for (auto& sys : sysList)
128 CP::SystematicSet inputSys;
129 ANA_CHECK (SystematicSet::filterForAffectingSystematics (sys, affecting, inputSys));
130 std::string decorName;
131 ANA_CHECK (svc.makeSystematicsName (decorName, m_decorName, inputSys));
132 ANA_MSG_DEBUG ("SysReadDecorHandle: " << decorName << " (" << sys.name() << ")");
133 m_dataCache.emplace (sys, std::make_tuple (decorName, decorName));
135 return StatusCode::SUCCESS;
140 template<typename T> const auto&
141 SysReadDecorHandle<T> ::
142 getData (const CP::SystematicSet& sys) const
144 auto cache = m_dataCache.find (sys);
145 if (cache == m_dataCache.end())
147 if (m_dataCache.empty())
148 throw std::logic_error ("uninitialized SysReadDecorHandle (" + m_decorName + ")");
150 throw std::logic_error ("unsupported systematic in SysReadDecorHandle (" + m_decorName + "): (" + sys.name() + ")");
152 return cache->second;