ATLAS Offline Software
Loading...
Searching...
No Matches
SysWriteDecorHandle.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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 <AsgMessaging/StatusCode.h>
14
15#include <regex>
16
17//
18// method implementations
19//
20
21namespace CP
22{
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)
28 {
29 owner->declareProperty (propertyName, m_decorName, propertyDescription);
30 }
31
32 template<typename T> template<typename T2> SysWriteDecorHandle<T> ::
33 SysWriteDecorHandle (const std::string& decorName, T2 *owner)
34 : AsgMessagingForward (owner), m_decorName(decorName)
35 {}
36
37
38
39 template<typename T> bool SysWriteDecorHandle<T> ::
40 empty () const noexcept
41 {
42 return m_decorName.empty();
43 }
44
45
46
47 template<typename T> SysWriteDecorHandle<T> ::
48 operator bool () const noexcept
49 {
50 return !m_decorName.empty();
51 }
52
53
54
55 template<typename T> std::string SysWriteDecorHandle<T> ::
56 getNamePattern () const
57 {
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.
61 return "";
62 }
63
64
65
66 template<typename T> StatusCode SysWriteDecorHandle<T> ::
67 initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle)
68 {
69 if (m_objectHandle != nullptr)
70 {
71 ANA_MSG_ERROR ("trying to initialize handle twice");
72 return StatusCode::FAILURE;
73 }
74 m_objectHandle = &objectHandle;
75 return sysListHandle.addHandle (*this);
76 }
77
78
79
80 template<typename T> StatusCode SysWriteDecorHandle<T> ::
81 initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle, SG::AllowEmptyEnum)
82 {
83 if (!empty())
84 return initialize (sysListHandle, objectHandle);
85 else
86 return StatusCode::SUCCESS;
87 }
88
89
90
91 template<typename T> const std::string& SysWriteDecorHandle<T> ::
92 getName (const CP::SystematicSet& sys) const
93 {
94 const auto& data = getData (sys);
95 return std::get<0> (data);
96 }
97
98
99
100 template<typename T> void SysWriteDecorHandle<T> ::
101 set (const SG::AuxElement& object, const T& value,
102 const CP::SystematicSet& sys) const
103 {
104 const auto& data = getData (sys);
105 std::get<1> (data) (object) = value;
106 }
107
108
109
110 template<typename T> void SysWriteDecorHandle<T> ::
111 lock (const SG::AuxElement& object,
112 const CP::SystematicSet& sys) const
113 {
114 const auto& data = getData (sys);
115 SG::AuxVectorData* cont_nc ATLAS_THREAD_SAFE =
116 const_cast<SG::AuxVectorData*> (object.container());
117 cont_nc->lockDecoration (std::get<1> (data).auxid());
118 }
119
120
121
122 template<typename T> CP::SystematicSet SysWriteDecorHandle<T> ::
123 getInputAffecting (const ISystematicsSvc& /*svc*/) const
124 {
125 return CP::SystematicSet ();
126 }
127
128
129
130 template<typename T> StatusCode SysWriteDecorHandle<T> ::
131 fillSystematics (const ISystematicsSvc& svc,
132 const CP::SystematicSet& fullAffecting,
133 const std::vector<CP::SystematicSet>& sysList)
134 {
135 for (auto& sys : sysList)
136 {
137 std::string newName;
138 ANA_CHECK (svc.makeSystematicsName (newName, m_decorName, sys));
139 ANA_MSG_DEBUG ("SysWriteDecorHandle: " << newName << " (" << sys.name() << ")");
140 m_dataCache.emplace (sys, std::make_tuple (newName, newName));
141 }
142 ANA_CHECK (svc.setDecorSystematics (m_objectHandle->getNamePattern(), m_decorName, fullAffecting));
143 return StatusCode::SUCCESS;
144 }
145
146
147
148 template<typename T> const auto&
149 SysWriteDecorHandle<T> ::
150 getData (const CP::SystematicSet& sys) const
151 {
152 auto cache = m_dataCache.find (sys);
153 if (cache == m_dataCache.end())
154 {
155 if (m_dataCache.empty())
156 throw std::logic_error ("uninitialized SysWriteDecorHandle (" + m_decorName + ")");
157 else
158 throw std::logic_error ("unsupported systematic in SysWriteDecorHandle (" + m_decorName + "): (" + sys.name() + ")");
159 }
160 return cache->second;
161 }
162}