ATLAS Offline Software
Loading...
Searching...
No Matches
StoreGate/StoreGate/WriteHandle.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2/*
3 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4*/
11
12#ifndef STOREGATE_SG_WRITEHANDLE_H
13#define STOREGATE_SG_WRITEHANDLE_H 1
14
15
18#include "StoreGate/StoreGateSvc.h" /* needed by clients */
19#include "GaudiKernel/EventContext.h"
20#include <string>
21#include <memory> /*unique_ptr*/
22
23
24template <class DV> class ConstDataVector;
25
26
27namespace SG {
28
29
68template <class T>
70 : public SG::VarHandleBase
71{
72public:
73 typedef T* pointer_type; // FIXME: better handling of
74 typedef const T* const_pointer_type; // qualified T type ?
75 typedef T& reference_type;
76 typedef const T& const_reference_type;
77
78
79 //************************************************************************
80 // Constructors, etc.
81 //
82
83
90
91
97 explicit WriteHandle(const std::string& sgkey,
98 const std::string& storename = StoreID::storeName(StoreID::EVENT_STORE));
99
100
106 explicit WriteHandle(const std::string& sgkey,
107 const EventContext& ctx);
108
109
116 explicit WriteHandle(const std::string& sgkey,
117 const std::string& storename,
118 const EventContext& ctx);
119
120
129
130
142 explicit WriteHandle (const WriteHandleKey<T>& key, const EventContext& ctx);
143
144
145 // Disallow initialization from a temporary Key object.
146 explicit WriteHandle (SG::WriteHandleKey<T>&& key) = delete; // Not allowed from a temporary.
148 const EventContext& ctx) = delete; // Not allowed from a temporary.
149
150
155
156
160 WriteHandle( WriteHandle&& rhs ) noexcept;
161
162
167
168
173
174
181
182
183 //************************************************************************
184 // Deference. These all return only the cached pointer.
185 //
186
187
193
194
200
201
207
208
214
215
220
221
225 virtual bool isValid() override final;
226
227
228 //************************************************************************
229 // Record.
230 //
231
232
237 StatusCode record (std::unique_ptr<T> data);
238
239
244 StatusCode recordNonConst (std::unique_ptr<T> data);
245
246
252 template <class AUXSTORE>
253 StatusCode record (std::unique_ptr<T> data,
254 std::unique_ptr<AUXSTORE> store);
255
256
262 template <class AUXSTORE>
263 StatusCode recordNonConst (std::unique_ptr<T> data,
264 std::unique_ptr<AUXSTORE> store);
265
266
273 template <std::derived_from<DataObject> DOBJ>
274 requires std::convertible_to<DOBJ*, T*>
275 StatusCode record (SG::DataObjectSharedPtr<DOBJ> data);
276
277
284 template <std::derived_from<DataObject> DOBJ>
285 requires std::convertible_to<DOBJ*, T*>
286 StatusCode recordNonConst (SG::DataObjectSharedPtr<DOBJ> data);
287
288
304 bool returnExisting = false) const;
305
306
322 bool returnExisting = false) const;
323
324
340 bool returnExisting = false) const;
341
342
358 const_pointer_type put (const EventContext& ctx,
360 bool returnExisting = false) const;
361
362
378 const_pointer_type put (const EventContext& ctx,
379 std::unique_ptr<T> data,
380 bool returnExisting = false) const;
381
382
398 const_pointer_type put (const EventContext& ctx,
399 std::unique_ptr<const T> data,
400 bool returnExisting = false) const;
401
402
415 template <std::derived_from<DataObject> DOBJ>
416 requires std::convertible_to<DOBJ*, T*>
418
419
433 template <std::derived_from<DataObject> DOBJ>
434 requires std::convertible_to<DOBJ*, T*>
435 const_pointer_type put (const EventContext& ctx,
436 SG::DataObjectSharedPtr<DOBJ> data) const;
437
438
452 template <class AUXSTORE>
454 put (std::unique_ptr<T> data,
455 std::unique_ptr<AUXSTORE> auxstore) const;
456
457
474 template <class AUXSTORE>
477 std::unique_ptr<const AUXSTORE> auxstore) const;
478
479
494 template <class AUXSTORE>
496 put (const EventContext& ctx,
497 std::unique_ptr<T> data,
498 std::unique_ptr<AUXSTORE> auxstore) const;
499
500
518 template <class AUXSTORE>
520 put (const EventContext& ctx,
521 std::unique_ptr<const T> data,
522 std::unique_ptr<const AUXSTORE> auxstore) const;
523
524
531 WriteHandle& operator=( std::unique_ptr<T> data );
532
533
543 StatusCode alias (const WriteHandleKey<T>& key);
544
545
573 template <class U>
574 StatusCode symLink (const WriteHandleKey<U>& key);
575
576
577private:
584
585
592 template <class U>
593 StatusCode doRecord (U data,
594 bool isConst,
595 bool returnExisting);
596
597
614 template <class U>
615 const_pointer_type doPut (const EventContext* ctx,
616 U data,
617 bool returnExisting,
619
620
635 template <class AUXSTORE>
637 doPut (const EventContext* ctx,
638 std::unique_ptr<T> data,
639 std::unique_ptr<AUXSTORE> auxstore) const;
640
641
656 template <class AUXSTORE>
658 doPut (const EventContext* ctx,
659 std::unique_ptr<const T> data,
660 std::unique_ptr<const AUXSTORE> auxstore) const;
661
662
669 template <class AUXSTORE>
670 StatusCode
672 std::unique_ptr<AUXSTORE> auxstore,
673 bool isConst);
674
675
676private:
692};
693
694
702template <class T>
704
705
717template <class T>
719 const EventContext& ctx);
720
721
722} /* namespace SG */
723
724
725#include "StoreGate/WriteHandle.icc"
726
727
728#endif //> !STOREGATE_SG_WRITEHANDLE_H
Base class for VarHandle classes.
Property holding a SG store/key/clid from which a WriteHandle is made.
DataVector adapter that acts like it holds const pointers.
Base class for VarHandle types.
Property holding a SG store/key/clid from which a WriteHandle is made.
WriteHandle & operator=(WriteHandle &&rhs) noexcept
Move operator.
WriteHandle(const WriteHandle &rhs)
Copy constructor.
WriteHandle(const WriteHandleKey< T > &key)
Constructor from a WriteHandleKey.
const_pointer_type doPut(const EventContext *ctx, U data, bool returnExisting, IProxyDict *&store) const
const_pointer_type cptr() const
Dereference the pointer.
WriteHandle(SG::WriteHandleKey< T > &&key)=delete
WriteHandle(const std::string &sgkey, const EventContext &ctx)
Constructor specifying the key as a string, with context.
StatusCode symLink(const WriteHandleKey< U > &key)
WriteHandle(WriteHandle &&rhs) noexcept
Move constructor.
WriteHandle()
Default constructor.
WriteHandle & operator=(const WriteHandle &rhs)
Assignment operator.
WriteHandle(const std::string &sgkey, const std::string &storename=StoreID::storeName(StoreID::EVENT_STORE))
Constructor specifying the key as a string.
~WriteHandle()
Destructor.
WriteHandle(SG::WriteHandleKey< T > &&key, const EventContext &ctx)=delete
pointer_type cachedPtr()
Return the cached pointer directly; no lookup.
WriteHandle(const std::string &sgkey, const std::string &storename, const EventContext &ctx)
Constructor specifying the key as a string, with context.
StatusCode record(std::unique_ptr< xAOD::CaloClusterContainer > data)
const_pointer_type put(std::unique_ptr< xAOD::CaloClusterContainer > data, bool returnExisting=false) const
StatusCode recordNonConst(std::unique_ptr< xAOD::CaloClusterContainer > data)
pointer_type operator->()
Dereference the pointer.
WriteHandle(const WriteHandleKey< T > &key, const EventContext &ctx)
Constructor from a WriteHandleKey and an explicit event context.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode doRecord(U data, bool isConst, bool returnExisting)
reference_type operator*()
Dereference the pointer.
StatusCode alias(const WriteHandleKey< xAOD::CaloClusterContainer > &key)
pointer_type ptr()
Dereference the pointer.
@ EVENT_STORE
Definition StoreID.h:26
static const std::string & storeName(const StoreID::type &s)
Definition StoreID.cxx:77
STL class.
Forward declaration.
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
STL namespace.
#define private
Definition testRead.cxx:27