ATLAS Offline Software
SysWriteDecorHandle.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 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 
21 namespace 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> CP::SystematicSet SysWriteDecorHandle<T> ::
111  getInputAffecting (const ISystematicsSvc& /*svc*/) const
112  {
113  return CP::SystematicSet ();
114  }
115 
116 
117 
118  template<typename T> StatusCode SysWriteDecorHandle<T> ::
119  fillSystematics (const ISystematicsSvc& svc,
120  const CP::SystematicSet& fullAffecting,
121  const std::vector<CP::SystematicSet>& sysList)
122  {
123  for (auto& sys : sysList)
124  {
125  std::string newName;
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));
129  }
130  ANA_CHECK (svc.setDecorSystematics (m_objectHandle->getNamePattern(), m_decorName, fullAffecting));
131  return StatusCode::SUCCESS;
132  }
133 
134 
135 
136  template<typename T> const auto&
137  SysWriteDecorHandle<T> ::
138  getData (const CP::SystematicSet& sys) const
139  {
140  auto cache = m_dataCache.find (sys);
141  if (cache == m_dataCache.end())
142  {
143  if (m_dataCache.empty())
144  throw std::logic_error ("uninitialized SysWriteDecorHandle (" + m_decorName + ")");
145  else
146  throw std::logic_error ("unsupported systematic in SysWriteDecorHandle (" + m_decorName + "): (" + sys.name() + ")");
147  }
148  return cache->second;
149  }
150 }