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>
14 #include <SystematicsHandles/ISystematicsSvc.h>
15 #include <SystematicsHandles/SysListHandle.h>
18 // method implementations
23 template<typename T> template<typename T2> SysReadHandle<T> ::
24 SysReadHandle (T2 *owner, const std::string& propertyName,
25 const std::string& propertyValue,
26 const std::string& propertyDescription)
27 : AsgMessagingForward (owner), m_inputName (propertyValue)
28 , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
30 owner->declareProperty (propertyName, m_inputName, propertyDescription);
33 template<typename T> template<typename T2> SysReadHandle<T> ::
34 SysReadHandle (const std::string &inputName, T2 *owner)
35 : AsgMessagingForward (owner), m_inputName(inputName)
36 , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
40 template<typename T> bool SysReadHandle<T> ::
41 empty () const noexcept
43 return m_inputName.empty();
48 template<typename T> SysReadHandle<T> ::
49 operator bool () const noexcept
51 return !m_inputName.empty();
56 template<typename T> std::string SysReadHandle<T> ::
57 getNamePattern () const
64 template<typename T> StatusCode SysReadHandle<T> ::
65 initialize (SysListHandle& sysListHandle)
67 return sysListHandle.addHandle (*this);
72 template<typename T> StatusCode SysReadHandle<T> ::
73 initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
76 return initialize (sysListHandle);
78 return StatusCode::SUCCESS;
83 template<typename T> const std::string& SysReadHandle<T> ::
84 getName (const CP::SystematicSet& sys) const
86 auto cache = m_inputNameCache.find (sys);
87 if (cache == m_inputNameCache.end())
89 if (m_inputNameCache.empty())
90 throw std::logic_error ("uninitialized SysReadHandle (" + m_inputName + ")");
92 throw std::logic_error ("unsupported systematic in SysReadHandle (" + m_inputName + "): (" + sys.name() + ")");
99 template<typename T> ::StatusCode SysReadHandle<T> ::
100 retrieve (const T*& object, const CP::SystematicSet& sys) const
102 const std::string& name = getName (sys);
104 return m_evtStore->retrieve (object, name);
109 template<typename T> bool SysReadHandle<T> ::
110 isValid (const CP::SystematicSet& sys) const
112 const std::string& name = getName (sys);
114 return m_evtStore->contains<T> (name);
119 template<typename T> CP::SystematicSet SysReadHandle<T> ::
120 getInputAffecting (const ISystematicsSvc& svc) const
122 return svc.getObjectSystematics (m_inputName);
127 template<typename T> StatusCode SysReadHandle<T> ::
128 fillSystematics (const ISystematicsSvc& svc,
129 const CP::SystematicSet& /*fullAffecting*/,
130 const std::vector<CP::SystematicSet>& sysList)
132 const CP::SystematicSet affecting = svc.getObjectSystematics (m_inputName);
133 for (auto& sys : sysList)
135 CP::SystematicSet inputSys;
136 ANA_CHECK (SystematicSet::filterForAffectingSystematics (sys, affecting, inputSys));
137 std::string inputName;
138 ANA_CHECK (svc.makeSystematicsName (inputName, m_inputName, inputSys));
139 m_inputNameCache.emplace (sys, inputName);
142 // retrieving this here, just so it exists
144 m_evtStore = m_evtStoreGetter();
146 return StatusCode::SUCCESS;