ATLAS Offline Software
SysReadHandle.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 #include <SystematicsHandles/ISystematicsSvc.h>
15 #include <SystematicsHandles/SysListHandle.h>
16 
17 //
18 // method implementations
19 //
20 
21 namespace CP
22 {
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();})
29  {
30  owner->declareProperty (propertyName, m_inputName, propertyDescription);
31  }
32 
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();})
37  {}
38 
39 
40  template<typename T> bool SysReadHandle<T> ::
41  empty () const noexcept
42  {
43  return m_inputName.empty();
44  }
45 
46 
47 
48  template<typename T> SysReadHandle<T> ::
49  operator bool () const noexcept
50  {
51  return !m_inputName.empty();
52  }
53 
54 
55 
56  template<typename T> std::string SysReadHandle<T> ::
57  getNamePattern () const
58  {
59  return m_inputName;
60  }
61 
62 
63 
64  template<typename T> StatusCode SysReadHandle<T> ::
65  initialize (SysListHandle& sysListHandle)
66  {
67  return sysListHandle.addHandle (*this);
68  }
69 
70 
71 
72  template<typename T> StatusCode SysReadHandle<T> ::
73  initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
74  {
75  if (!empty())
76  return initialize (sysListHandle);
77  else
78  return StatusCode::SUCCESS;
79  }
80 
81 
82 
83  template<typename T> const std::string& SysReadHandle<T> ::
84  getName (const CP::SystematicSet& sys) const
85  {
86  auto cache = m_inputNameCache.find (sys);
87  if (cache == m_inputNameCache.end())
88  {
89  if (m_inputNameCache.empty())
90  throw std::logic_error ("uninitialized SysReadHandle (" + m_inputName + ")");
91  else
92  throw std::logic_error ("unsupported systematic in SysReadHandle (" + m_inputName + "): (" + sys.name() + ")");
93  }
94  return cache->second;
95  }
96 
97 
98 
99  template<typename T> ::StatusCode SysReadHandle<T> ::
100  retrieve (const T*& object, const CP::SystematicSet& sys) const
101  {
102  const std::string& name = getName (sys);
103  assert (m_evtStore);
104  return m_evtStore->retrieve (object, name);
105  }
106 
107 
108 
109  template<typename T> bool SysReadHandle<T> ::
110  isValid (const CP::SystematicSet& sys) const
111  {
112  const std::string& name = getName (sys);
113  assert (m_evtStore);
114  return m_evtStore->contains<T> (name);
115  }
116 
117 
118 
119  template<typename T> CP::SystematicSet SysReadHandle<T> ::
120  getInputAffecting (const ISystematicsSvc& svc) const
121  {
122  return svc.getObjectSystematics (m_inputName);
123  }
124 
125 
126 
127  template<typename T> StatusCode SysReadHandle<T> ::
128  fillSystematics (const ISystematicsSvc& svc,
129  const CP::SystematicSet& /*fullAffecting*/,
130  const std::vector<CP::SystematicSet>& sysList)
131  {
132  const CP::SystematicSet affecting = svc.getObjectSystematics (m_inputName);
133  for (auto& sys : sysList)
134  {
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);
140  }
141 
142  // retrieving this here, just so it exists
143  if (!m_evtStore)
144  m_evtStore = m_evtStoreGetter();
145 
146  return StatusCode::SUCCESS;
147  }
148 }