ATLAS Offline Software
SysWriteHandle.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 
14 //
15 // method implementations
16 //
17 
18 namespace CP
19 {
20  template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
21  SysWriteHandle (T2 *owner, const std::string& propertyName,
22  const std::string& propertyValue,
23  const std::string& propertyDescription)
24  : AsgMessagingForward (owner), m_outputName (propertyValue)
25  , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
26  {
27  owner->declareProperty (propertyName, m_outputName, propertyDescription);
28  }
29 
30 
31  template<typename T,typename Aux> template<typename T2> SysWriteHandle<T,Aux> ::
32  SysWriteHandle (const std::string &outputName, T2 *owner)
33  : AsgMessagingForward (owner), m_outputName (outputName)
34  , m_evtStoreGetter ([owner] () {return &*owner->evtStore();})
35  {
36  }
37 
38 
39 
40  template<typename T,typename Aux> bool SysWriteHandle<T,Aux> ::
41  empty () const noexcept
42  {
43  return m_outputName.empty();
44  }
45 
46 
47 
48  template<typename T,typename Aux> SysWriteHandle<T,Aux> ::
49  operator bool () const noexcept
50  {
51  return !m_outputName.empty();
52  }
53 
54 
55 
56  template<typename T,typename Aux> std::string SysWriteHandle<T,Aux> ::
57  getNamePattern () const
58  {
59  return m_outputName;
60  }
61 
62 
63 
64  template<typename T,typename Aux>
65  StatusCode SysWriteHandle<T,Aux> ::
66  initialize (SysListHandle& sysListHandle)
67  {
68  return sysListHandle.addHandle (*this);
69  }
70 
71 
72 
73  template<typename T,typename Aux>
74  StatusCode SysWriteHandle<T,Aux> ::
75  initialize (SysListHandle& sysListHandle, SG::AllowEmptyEnum)
76  {
77  if (!empty())
78  return initialize (sysListHandle);
79  else
80  return StatusCode::SUCCESS;
81  }
82 
83 
84 
85  template<typename T,typename Aux>
86  const std::string& SysWriteHandle<T,Aux> ::
87  getName (const CP::SystematicSet& sys) const
88  {
89  auto cache = m_outputNameCache.find (sys);
90  if (cache == m_outputNameCache.end())
91  {
92  if (m_outputName.empty())
93  throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
94  else
95  throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
96  }
97  return cache->second;
98  }
99 
100 
101 
102  template<typename T,typename Aux>
103  template<typename,typename>
104  ::StatusCode SysWriteHandle<T,Aux> ::
105  record (std::unique_ptr<T> object, const CP::SystematicSet& sys) const
106  {
107  const std::string& name = getName (sys);
108  assert (m_evtStore);
109  return m_evtStore->record (object.release(), name);
110  }
111 
112 
113 
114  template<typename T,typename Aux>
115  template<typename,typename>
116  ::StatusCode SysWriteHandle<T,Aux> ::
117  record (std::unique_ptr<T> object, std::unique_ptr<Aux> aux,
118  const CP::SystematicSet& sys) const
119  {
120  auto cache = m_outputNameCache.find (sys);
121  if (cache == m_outputNameCache.end())
122  {
123  if (m_outputName.empty())
124  throw std::logic_error ("uninitialized SysWriteHandle(" + m_outputName + ")");
125  else
126  throw std::logic_error ("unknown systematic in SysWriteHandle(" + m_outputName + "): (" + sys.name() + ")");
127  }
128  assert (m_evtStore);
129  if (m_evtStore->record (aux.release(), cache->second + "Aux.").isFailure())
130  return StatusCode::FAILURE;
131  if (m_evtStore->record (object.release(), cache->second).isFailure())
132  return StatusCode::FAILURE;
133  return StatusCode::SUCCESS;
134  }
135 
136 
137 
138  template<typename T,typename Aux>
139  CP::SystematicSet SysWriteHandle<T,Aux> ::
140  getInputAffecting (const ISystematicsSvc& /*svc*/) const
141  {
142  return CP::SystematicSet ();
143  }
144 
145 
146 
147  template<typename T,typename Aux>
148  StatusCode SysWriteHandle<T,Aux> ::
149  fillSystematics (const ISystematicsSvc& svc,
150  const CP::SystematicSet& fullAffecting,
151  const std::vector<CP::SystematicSet>& sysList)
152  {
153  if (!m_evtStore)
154  m_evtStore = m_evtStoreGetter();
155  for (auto& sys : sysList)
156  {
157  std::string newName;
158  ANA_CHECK (svc.makeSystematicsName (newName, m_outputName, sys));
159  ANA_MSG_DEBUG ("SysWriteHandle: " << newName << " (" << sys.name() << ")");
160  m_outputNameCache.emplace (sys, newName);
161  }
162  ANA_CHECK (svc.setObjectSystematics (m_outputName, fullAffecting));
163  return StatusCode::SUCCESS;
164  }
165 }