ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
23namespace 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>
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;
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 {
283 m_range = EventIDRange::intersect(m_range, range);
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
#define endmsg
Hold mappings of ranges to condition objects.
static Double_t sc
static bool isOverlap(code_t code)
Helper to test whether a code is OVERLAP.
Definition CondCont.cxx:242
Base class for all conditions containers.
Definition CondCont.h:140
KeyType
Type of key used for this container.
Definition CondCont.h:180
void addDep(CondContBase *dep)
Declare another conditions container that depends on this one.
Definition CondCont.cxx:696
Hold mapping of ranges to condition objects.
Definition CondCont.h:889
CondCont< T > * getCC()
const EventIDRange & getRange()
StatusCode extendLastRange(const EventIDRange &range, const EventContext &ctx=Gaudi::Hive::currentContext())
Extend the range of the last IOV.
const std::string & key() const
StatusCode record(T *t)
bool isValid(EventIDRange &range) const
const std::string & dbKey() const
void addDependency(ReadCondHandle< R > &rch, Args... args)
StatusCode record(std::unique_ptr< T > t)
record handle, range must have been set by addDependency(...)
WriteCondHandle(SG::WriteCondHandleKey< T > &&key)=delete
void addDependency(SG::ReadCondHandle< R > &rch)
bool isValid(const EventIDBase &t, EventIDRange &range) const
void addDependency(const EventIDRange &range)
bool isValid(const EventIDBase &t) const
const EventIDRange & getRange() const
const SG::WriteCondHandleKey< CscCondDbData > & m_hkey
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
WriteCondHandle(const WriteCondHandleKey< T > &key, const EventContext &ctx)
WriteCondHandle(SG::WriteCondHandleKey< T > &&key, const EventContext &ctx)=delete
StatusCode record(const EventIDRange &range, std::unique_ptr< T > t)
const T & const_reference_type
CondCont< CscCondDbData > * m_cc
const DataObjID & fullKey() const
WriteCondHandle(const WriteCondHandleKey< T > &key)
singleton-like access to IMessageSvc via open function and helper
int r
Definition globals.cxx:22
IMessageSvc * getMessageSvc(bool quiet=false)
=============================================================================
Forward declaration.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
MsgStream & msg
Definition testRead.cxx:32