ATLAS Offline Software
SysReadDecorHandle.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> 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)
28  {
29  owner->declareProperty (propertyName, m_decorName, propertyDescription);
30  }
31 
32 
33  template<typename T> template<typename T2> SysReadDecorHandle<T> ::
34  SysReadDecorHandle (const std::string& decorName, T2 *owner)
35  : AsgMessagingForward (owner), m_decorName(decorName)
36  {}
37 
38 
39 
40  template<typename T> bool SysReadDecorHandle<T> ::
41  empty () const noexcept
42  {
43  return m_decorName.empty();
44  }
45 
46 
47 
48  template<typename T> SysReadDecorHandle<T> ::
49  operator bool () const noexcept
50  {
51  return !m_decorName.empty();
52  }
53 
54 
55 
56  template<typename T> std::string SysReadDecorHandle<T> ::
57  getNamePattern () const
58  {
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.
62  return "";
63  }
64 
65 
66 
67  template<typename T> StatusCode SysReadDecorHandle<T> ::
68  initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle)
69  {
70  if (m_objectHandle != nullptr)
71  {
72  ANA_MSG_ERROR ("trying to initialize handle twice");
73  return StatusCode::FAILURE;
74  }
75  m_objectHandle = &objectHandle;
76  return sysListHandle.addHandle (*this);
77  }
78 
79 
80 
81  template<typename T> StatusCode SysReadDecorHandle<T> ::
82  initialize (SysListHandle& sysListHandle, const ISysHandleBase& objectHandle, SG::AllowEmptyEnum)
83  {
84  if (!empty())
85  return initialize (sysListHandle, objectHandle);
86  else
87  return StatusCode::SUCCESS;
88  }
89 
90 
91 
92  template<typename T> const std::string& SysReadDecorHandle<T> ::
93  getName (const CP::SystematicSet& sys) const
94  {
95  const auto& data = getData (sys);
96  return std::get<0> (data);
97  }
98 
99 
100 
101  template<typename T> const T& SysReadDecorHandle<T> ::
102  get (const SG::AuxElement& object,
103  const CP::SystematicSet& sys) const
104  {
105  const auto& data = getData (sys);
106  return std::get<1> (data) (object);
107  }
108 
109 
110 
111  template<typename T> CP::SystematicSet SysReadDecorHandle<T> ::
112  getInputAffecting (const ISystematicsSvc& svc) const
113  {
114  return svc.getDecorSystematics (m_objectHandle->getNamePattern(), m_decorName);
115  }
116 
117 
118 
119  template<typename T> StatusCode SysReadDecorHandle<T> ::
120  fillSystematics (const ISystematicsSvc& svc,
121  const CP::SystematicSet& /*fullAffecting*/,
122  const std::vector<CP::SystematicSet>& sysList)
123  {
124  const CP::SystematicSet affecting
125  = svc.getDecorSystematics (m_objectHandle->getNamePattern(), m_decorName);
126  for (auto& sys : sysList)
127  {
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));
134  }
135  return StatusCode::SUCCESS;
136  }
137 
138 
139 
140  template<typename T> const auto&
141  SysReadDecorHandle<T> ::
142  getData (const CP::SystematicSet& sys) const
143  {
144  auto cache = m_dataCache.find (sys);
145  if (cache == m_dataCache.end())
146  {
147  if (m_dataCache.empty())
148  throw std::logic_error ("uninitialized SysReadDecorHandle (" + m_decorName + ")");
149  else
150  throw std::logic_error ("unsupported systematic in SysReadDecorHandle (" + m_decorName + "): (" + sys.name() + ")");
151  }
152  return cache->second;
153  }
154 }