ATLAS Offline Software
SysReadHandleArray.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/Helpers.h>
15 
16 //
17 // method implementations
18 //
19 
20 namespace CP
21 {
22  template<typename T> template<typename T2> SysReadHandleArray<T> ::
23  SysReadHandleArray (T2 *owner, const std::string& propertyName,
24  const std::string& propertyDescription)
25  : AsgMessagingForward (owner)
26  , m_propertyName (propertyName)
27  , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
28  {
29  owner->declareProperty (propertyName, m_inputName, propertyDescription);
30  owner->declareProperty (propertyName + "Regex", m_affectingRegex, "affecting systematics for " + propertyDescription);
31  }
32 
33 
34 
35  template<typename T> StatusCode SysReadHandleArray<T> ::
36  initialize ()
37  {
38  assert (m_isInitialized == false);
39  if (m_inputName.size() != m_affectingRegex.size())
40  {
41  ANA_MSG_ERROR ("array sizes for property " << m_propertyName << " and " << m_propertyName << "Regex do not match");
42  return StatusCode::FAILURE;
43  }
44  m_isInitialized = true;
45  return StatusCode::SUCCESS;
46  }
47 
48 
49 
50  template<typename T> std::size_t SysReadHandleArray<T> ::
51  size () const noexcept
52  {
53  assert (m_isInitialized);
54  return m_inputName.size();
55  }
56 
57 
58 
59  template<typename T> const std::string& SysReadHandleArray<T> ::
60  getName (const CP::SystematicSet& sys,
61  std::size_t index) const
62  {
63  assert (m_isInitialized);
64  assert (index < size());
65  auto cache = m_inputNameCache.find (std::make_pair (sys, index));
66  if (cache == m_inputNameCache.end())
67  {
68  std::string newName = makeSystematicsName
69  (m_inputName[index], m_affectingRegex[index], sys);
70  ANA_MSG_DEBUG ("SysReadHandleArray: " << newName << " (" << sys.name() << ")");
71  m_inputNameCache.insert (std::make_pair (std::make_pair (sys, index), newName));
72  cache = m_inputNameCache.find (std::make_pair (sys, index));
73  assert (cache != m_inputNameCache.end());
74 
75  // retrieving this here, just so it exists
76  if (!m_evtStore)
77  m_evtStore = m_evtStoreGetter();
78  }
79  return cache->second;
80  }
81 
82 
83 
84  template<typename T> ::StatusCode SysReadHandleArray<T> ::
85  retrieve (const T*& object, const CP::SystematicSet& sys,
86  std::size_t index) const
87  {
88  assert (m_isInitialized);
89  assert (index < size());
90  const std::string& name = getName (sys, index);
91  assert (m_evtStore);
92  return m_evtStore->retrieve (object, name);
93  }
94 
95 
96 
97  template<typename T> std::string SysReadHandleArray<T> ::
98  getInputAffecting () const
99  {
100  assert (m_isInitialized);
101  std::string result;
102  for (const std::string& regex : m_affectingRegex)
103  {
104  if (!regex.empty())
105  {
106  if (!result.empty())
107  result += "|";
108  result += regex;
109  }
110  }
111  return result;
112  }
113 }