Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
WriteCondHandle.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef STOREGATE_WRITECONDHANDLE_H
6 #define STOREGATE_WRITECONDHANDLE_H 1
7 
10 
11 #include "StoreGate/StoreGateSvc.h"
14 
15 #include "GaudiKernel/ServiceHandle.h"
16 #include "GaudiKernel/DataHandle.h"
17 #include "GaudiKernel/DataObjID.h"
18 #include "GaudiKernel/EventIDBase.h"
19 
20 #include <string>
21 #include <stdexcept>
22 
23 namespace SG {
24 
25  template <typename T>
27 
28  public:
29  typedef T* pointer_type; // FIXME: better handling of
30  typedef const T* const_pointer_type; // qualified T type ?
31  typedef T& reference_type;
32  typedef const T& const_reference_type;
33 
34  public:
36  WriteCondHandle(const WriteCondHandleKey<T>& key, const EventContext& ctx);
37 
38  WriteCondHandle(SG::WriteCondHandleKey<T>&& key) = delete; // Not allowed from a temporary.
40  const EventContext& ctx) = delete; // Not allowed from a temporary.
41 
43 
44  const std::string& key() const { return m_hkey.key(); }
45  const DataObjID& fullKey() const { return m_hkey.fullKey(); }
46 
47  bool isValid() const;
48  bool isValid(const EventIDBase& t) const;
49 
50  bool isValid(EventIDRange& range) const;
51  bool isValid(const EventIDBase& t, EventIDRange& range) const;
52 
53  void addDependency(const EventIDRange& range);
54 
55  template <typename R>
57 
58  template <typename R, typename... Args>
60 
61 
62 
68  StatusCode record(const EventIDRange& range, T* t);
69  StatusCode record(const EventIDRange& range, std::unique_ptr<T> t);
70 
75  StatusCode record(std::unique_ptr<T> t);
76  StatusCode record(T* t);
77 
88  StatusCode extendLastRange(const EventIDRange& range,
89  const EventContext& ctx = Gaudi::Hive::currentContext());
90 
91  const std::string& dbKey() const { return m_hkey.dbKey(); }
92 
93  const EventIDRange& getRange() const { return m_range; }
94 
95  private:
96 
97  const EventContext& m_ctx;
98  CondCont<T>* m_cc {nullptr};
99 
101 
102  EventIDRange m_range{};
103  bool m_rangeSet {false};
104  };
105 
106  //---------------------------------------------------------------------------
107 
108  template <typename T>
110  WriteCondHandle( key, Gaudi::Hive::currentContext() ) {}
111 
112  //---------------------------------------------------------------------------
113 
114  template <typename T>
116  const EventContext& ctx) :
117  m_ctx(ctx),
118  m_cc( key.getCC() ),
119  m_hkey(key)
120  {
121  if (m_cc == 0) {
122  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
123  msg << MSG::ERROR
124  << "WriteCondHandle : ptr to CondCont<T> is zero"
125  << endmsg;
126  }
127 
128  if (! m_hkey.isInit()) {
129  throw SG::ExcUninitKey (key.clid(), key.key(), key.storeHandle().name(),
130  "", "WriteCond");
131  }
132 
133  }
134 
135 
136  //---------------------------------------------------------------------------
137 
138  template <typename T>
139  StatusCode
140  WriteCondHandle<T>::record(const EventIDRange& r, std::unique_ptr<T> t)
141  {
142 
143  if (m_rangeSet) {
144  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
145  msg << MSG::ERROR
146  << "WriteCondHandle::record(EventIDRange, T*): for key "
147  << this->fullKey()
148  << " cannot use this method if range has already been set via dependencies"
149  << endmsg;
150  return StatusCode::FAILURE;
151  }
152 
153  m_range = r;
154  m_rangeSet = true;
155 
156  return record( std::move(t) );
157  }
158 
159  template <typename T>
160  StatusCode
161  WriteCondHandle<T>::record(const EventIDRange& r, T* t)
162  {
163  return record (r, std::unique_ptr<T> (t));
164  }
165 
166  template <typename T>
167  StatusCode
169  return record (std::unique_ptr<T> (t));
170  }
171 
172  template <typename T>
173  StatusCode
174  WriteCondHandle<T>::record(std::unique_ptr<T> t) {
175  if (! m_rangeSet) {
176  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
177  msg << MSG::ERROR
178  << "WriteCondHandle::record() : no range defined for key "
179  << this->fullKey()
180  << endmsg;
181  return StatusCode::FAILURE;
182  }
183 
184  #ifndef NDEBUG
185  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
186  if (msg.level() <= MSG::DEBUG) {
187  msg << MSG::DEBUG
188  << "WriteCondHandle::record() : obj at: " << t.get() << " range: "
189  << m_range << endmsg;
190  }
191  #endif
192 
193  StatusCode sc = m_cc->insert(m_range, std::move(t));
194  // Preserve sc for return, since it may be DUPLICATE.
195  if (sc.isFailure()) {
196  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
197  msg << MSG::ERROR
198  << "WriteCondHandle::record() : unable to insert obj in CondCont<T>"
199  << endmsg;
200  return StatusCode::FAILURE;
201  } else if (CondContBase::Category::isOverlap (sc)) {
202 #if 0
203  // Temporarily disable this check until caching issues with IOVDbSvc
204  // are sorted out.
205  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
206  msg << MSG::ERROR
207  << "WriteCondHandle::record() : IOV ranges overlap."
208  << endmsg;
209  return StatusCode::FAILURE;
210 #endif
211  sc = StatusCode::SUCCESS;
212  }
213 
214  return sc;
215  }
216 
217  //---------------------------------------------------------------------------
218 
219 
230  template <typename T>
231  StatusCode
232  WriteCondHandle<T>::extendLastRange (const EventIDRange& r, const EventContext& ctx)
233  {
234  return m_cc->extendLastRange (r, ctx);
235  }
236 
237 
238  //---------------------------------------------------------------------------
239 
240  template <typename T>
241  bool
242  WriteCondHandle<T>::isValid(const EventIDBase& t) const {
243 
244  return (m_cc->valid(t));
245  }
246 
247 
248  //---------------------------------------------------------------------------
249 
250  template <typename T>
251  bool
253 
254  return (m_cc->valid(m_ctx.eventID()));
255  }
256 
257  //---------------------------------------------------------------------------
258 
259  template <typename T>
260  bool
261  WriteCondHandle<T>::isValid(const EventIDBase& t, EventIDRange& range) const {
262 
263  return (m_cc->range(t, range));
264  }
265 
266 
267  //---------------------------------------------------------------------------
268 
269  template <typename T>
270  bool
271  WriteCondHandle<T>::isValid (EventIDRange& range) const {
272 
273  return (m_cc->range(m_ctx.eventID(), range));
274  }
275 
276  //---------------------------------------------------------------------------
277 
278  template <typename T>
279  void WriteCondHandle<T>::addDependency(const EventIDRange& range) {
280  if ( !m_rangeSet ) {
281  m_range = range;
282  } else {
284  }
285  m_rangeSet = true;
286  using KeyType = CondContBase::KeyType;
287  if (m_cc->keyType()==KeyType::RUNLBN && (range.start().isTimeStamp() || range.stop().isTimeStamp())) {
288  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
289  msg << MSG::ERROR << "Adding a time-stamp dependency on a run-lumi indexed CondCont. Consider a mixed ConditionsContainer for type " << fullKey() << endmsg;
290  }
291  if (m_cc->keyType()==KeyType::TIMESTAMP && (range.start().isRunLumi() || range.stop().isRunLumi())) {
292  MsgStream msg(Athena::getMessageSvc(), "WriteCondHandle");
293  msg << MSG::ERROR << "Adding a run-lumi dependency on a timestamp-indexed CondCont. Consider a mixed ConditionsContainer for type " << fullKey() << endmsg;
294  }
295  }
296 
297  // Can't take a const RCH, as RCH.range() can load the ptr.
298  template <typename T>
299  template< typename R>
300  void
302  CondContBase* dep_cc = rch.getCC();
303  dep_cc->addDep (m_cc);
304  return addDependency(rch.getRange());
305  }
306 
307  template< typename T>
308  template <typename R, typename... Args>
309  void
311  addDependency( rch );
312  return addDependency( args... );
313  }
314 
315  // helper methods to create a read cond handle from the corresponding key.
316  template <class T>
318  const EventContext& ctx = Gaudi::Hive::currentContext()) {
319  return SG::WriteCondHandle<T>(key, ctx);
320  }
321 
322 }
323 
324 #endif
325 
beamspotman.r
def r
Definition: beamspotman.py:676
SG::WriteCondHandle::pointer_type
T * pointer_type
Definition: WriteCondHandle.h:29
SG::WriteCondHandle::const_reference_type
const T & const_reference_type
Definition: WriteCondHandle.h:32
SG::ReadCondHandle::getRange
const EventIDRange & getRange()
Definition: ReadCondHandle.h:246
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
CondCont.h
Hold mappings of ranges to condition objects.
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:45
SG::ReadCondHandle::getCC
CondCont< T > * getCC()
Definition: ReadCondHandle.h:81
SG::WriteCondHandle::getRange
const EventIDRange & getRange() const
Definition: WriteCondHandle.h:93
WriteCondHandleKey.h
SG::WriteCondHandle::reference_type
T & reference_type
Definition: WriteCondHandle.h:31
CondContBase::KeyType
KeyType
Type of key used for this container.
Definition: CondCont.h:180
CondContBase::addDep
void addDep(CondContBase *dep)
Declare another conditions container that depends on this one.
Definition: CondCont.cxx:696
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Args
Definition: test_lwtnn_fastgraph.cxx:12
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition: WriteCondHandle.h:161
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
m_range
float m_range[NbCaloPart][2]
Definition: CellClusterLinkTool.h:55
ReadCondHandle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:274
SG::WriteCondHandle::~WriteCondHandle
~WriteCondHandle()
Definition: WriteCondHandle.h:42
SG::WriteCondHandle::m_range
EventIDRange m_range
Definition: WriteCondHandle.h:102
SG::WriteCondHandle::m_ctx
const EventContext & m_ctx
Definition: WriteCondHandle.h:97
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition: WriteCondHandle.h:45
SG::WriteCondHandle::m_cc
CondCont< T > * m_cc
Definition: WriteCondHandle.h:98
SG::WriteCondHandle::WriteCondHandle
WriteCondHandle(SG::WriteCondHandleKey< T > &&key, const EventContext &ctx)=delete
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CondContBase
Base class for all conditions containers.
Definition: CondCont.h:140
SG::WriteCondHandle::dbKey
const std::string & dbKey() const
Definition: WriteCondHandle.h:91
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
SG::WriteCondHandle::const_pointer_type
const T * const_pointer_type
Definition: WriteCondHandle.h:30
SG::WriteCondHandle::WriteCondHandle
WriteCondHandle(SG::WriteCondHandleKey< T > &&key)=delete
SG::WriteCondHandle::m_rangeSet
bool m_rangeSet
Definition: WriteCondHandle.h:103
SG::WriteCondHandle::key
const std::string & key() const
Definition: WriteCondHandle.h:44
SG::WriteCondHandle::WriteCondHandle
WriteCondHandle(const WriteCondHandleKey< T > &key)
Definition: WriteCondHandle.h:109
CondContBase::Category::isOverlap
static bool isOverlap(code_t code)
Helper to test whether a code is OVERLAP.
Definition: CondCont.cxx:242
CondCont
Hold mapping of ranges to condition objects.
Definition: CondCont.h:811
SG::ExcUninitKey
Exception — Tried to create a handle from an uninitialized key.
Definition: Control/StoreGate/StoreGate/exceptions.h:111
Amg::intersect
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the point B' along the line B that's closest to a second line A.
Definition: GeoPrimitivesHelpers.h:347
DEBUG
#define DEBUG
Definition: page_access.h:11
SG::WriteCondHandle::isValid
bool isValid() const
Definition: WriteCondHandle.h:252
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
SG::WriteCondHandle::extendLastRange
StatusCode extendLastRange(const EventIDRange &range, const EventContext &ctx=Gaudi::Hive::currentContext())
Extend the range of the last IOV.
Definition: WriteCondHandle.h:232
SG::WriteCondHandleKey
Definition: WriteCondHandleKey.h:20
SG::WriteCondHandle::m_hkey
const SG::WriteCondHandleKey< T > & m_hkey
Definition: WriteCondHandle.h:100
StoreGateSvc.h
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition: WriteCondHandle.h:279
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37