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, const EventContext& ctx);
107
108
114 explicit WriteHandle(const std::string& sgkey, IProxyDict* sg);
115
116
123 explicit WriteHandle(const std::string& sgkey,
124 const std::string& storename,
125 const EventContext& ctx);
126
127
136
137
149 explicit WriteHandle (const WriteHandleKey<T>& key, const EventContext& ctx);
150
151
152 // Disallow initialization from a temporary Key object.
153 explicit WriteHandle (SG::WriteHandleKey<T>&& key) = delete; // Not allowed from a temporary.
155 const EventContext& ctx) = delete; // Not allowed from a temporary.
156
157
162
163
167 WriteHandle( WriteHandle&& rhs ) noexcept;
168
169
174
175
180
181
188
189
190 //************************************************************************
191 // Deference. These all return only the cached pointer.
192 //
193
194
200
201
207
208
214
215
221
222
227
228
232 virtual bool isValid() override final;
233
234
235 //************************************************************************
236 // Record.
237 //
238
239
244 StatusCode record (std::unique_ptr<T> data);
245
246
251 StatusCode recordNonConst (std::unique_ptr<T> data);
252
253
259 template <class AUXSTORE>
260 StatusCode record (std::unique_ptr<T> data,
261 std::unique_ptr<AUXSTORE> store);
262
263
269 template <class AUXSTORE>
270 StatusCode recordNonConst (std::unique_ptr<T> data,
271 std::unique_ptr<AUXSTORE> store);
272
273
280 template <std::derived_from<DataObject> DOBJ>
281 requires std::convertible_to<DOBJ*, T*>
282 StatusCode record (SG::DataObjectSharedPtr<DOBJ> data);
283
284
291 template <std::derived_from<DataObject> DOBJ>
292 requires std::convertible_to<DOBJ*, T*>
293 StatusCode recordNonConst (SG::DataObjectSharedPtr<DOBJ> data);
294
295
311 bool returnExisting = false) const;
312
313
329 bool returnExisting = false) const;
330
331
347 bool returnExisting = false) const;
348
349
365 const_pointer_type put (const EventContext& ctx,
367 bool returnExisting = false) const;
368
369
385 const_pointer_type put (const EventContext& ctx,
386 std::unique_ptr<T> data,
387 bool returnExisting = false) const;
388
389
405 const_pointer_type put (const EventContext& ctx,
406 std::unique_ptr<const T> data,
407 bool returnExisting = false) const;
408
409
422 template <std::derived_from<DataObject> DOBJ>
423 requires std::convertible_to<DOBJ*, T*>
425
426
440 template <std::derived_from<DataObject> DOBJ>
441 requires std::convertible_to<DOBJ*, T*>
442 const_pointer_type put (const EventContext& ctx,
443 SG::DataObjectSharedPtr<DOBJ> data) const;
444
445
459 template <class AUXSTORE>
461 put (std::unique_ptr<T> data,
462 std::unique_ptr<AUXSTORE> auxstore) const;
463
464
481 template <class AUXSTORE>
484 std::unique_ptr<const AUXSTORE> auxstore) const;
485
486
501 template <class AUXSTORE>
503 put (const EventContext& ctx,
504 std::unique_ptr<T> data,
505 std::unique_ptr<AUXSTORE> auxstore) const;
506
507
525 template <class AUXSTORE>
527 put (const EventContext& ctx,
528 std::unique_ptr<const T> data,
529 std::unique_ptr<const AUXSTORE> auxstore) const;
530
531
538 WriteHandle& operator=( std::unique_ptr<T> data );
539
540
550 StatusCode alias (const WriteHandleKey<T>& key);
551
552
580 template <class U>
581 StatusCode symLink (const WriteHandleKey<U>& key);
582
583
584private:
591
592
599 template <class U>
600 StatusCode doRecord (U data,
601 bool isConst,
602 bool returnExisting);
603
604
621 template <class U>
622 const_pointer_type doPut (const EventContext* ctx,
623 U data,
624 bool returnExisting,
626
627
642 template <class AUXSTORE>
644 doPut (const EventContext* ctx,
645 std::unique_ptr<T> data,
646 std::unique_ptr<AUXSTORE> auxstore) const;
647
648
663 template <class AUXSTORE>
665 doPut (const EventContext* ctx,
666 std::unique_ptr<const T> data,
667 std::unique_ptr<const AUXSTORE> auxstore) const;
668
669
676 template <class AUXSTORE>
677 StatusCode
679 std::unique_ptr<AUXSTORE> auxstore,
680 bool isConst);
681
682
683private:
699};
700
701
709template <class T>
711
712
724template <class T>
726 const EventContext& ctx);
727
728
729} /* namespace SG */
730
731
732#include "StoreGate/WriteHandle.icc"
733
734
735#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(const std::string &sgkey, IProxyDict *sg)
Constructor specifying the key as a string, with data store.
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