25#include "GaudiKernel/MsgStream.h"
30#include "GaudiKernel/ThreadLocalContext.h"
37#include <boost/core/demangle.hpp>
42template <
class...
Args>
void print(std::FILE* stream, std::format_string<Args...>
fmt, Args&&... args)
44 std::fputs(std::format(
fmt, std::forward<Args>(args)...), stream);
47template <
class T>
void*
ptr(T* p) {
return static_cast<void*
>(
p); }
49std::string
proxy(SG::DataProxy* proxy)
54std::string
store(IProxyDict* store)
72 return std::format(
"VarHandle({}+{}[{}])", context->
storeHandle().name(), context->
key(), context->
clid());
94 virtual const std::type_info&
tinfo()
const override {
return typeid(void); }
99 virtual void lock()
override { }
138 const std::string& sgkey,
139 Gaudi::DataHandle::Mode
mode,
140 const std::string& storename,
141 const EventContext* ctx) :
167 const EventContext* ctx)
172 m_storeWasSet(false),
175 if (
key.storeHandle().get() ==
nullptr) {
176 throw SG::ExcUninitKey (key.clid(), key.key(),
177 key.storeHandle().name());
182 key.storeHandle().name());
195 Gaudi::DataHandle::Mode
mode)
223 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
224 m_ownedKey->setOwningHandle (this);
225 m_key = m_ownedKey.get();
231 dbg::print(stderr,
"::VHB::copy constr from {} to {} with proxy={} => {}, key={}, store={}\n",
dbg::ptr(&rhs),
dbg::ptr(
this), dbg::proxy(this->m_proxy), dbg::proxy(rhs.
m_proxy), this->key(), dbg::store(this->m_store));
264 dbg::print(stderr,
"::VHB::move constr from {} to {} with proxy={}, key={}, store={}\n",
dbg::ptr(&rhs),
dbg::ptr(
this), dbg::proxy(this->m_proxy), this->key(), dbg::store(this->m_store));
464 return StatusCode::SUCCESS;
476 return StatusCode::FAILURE;
479 return StatusCode::SUCCESS;
502 dbg::print(stderr,
"::VHB:: setState() on {} with key={} ({}) and store={} (CLID: {})\n",
dbg::ptr(
this), this->
key(),
m_key->hashedKey(), dbg::store(
m_store), this->clid());
515 dbg::print(stderr,
"::VHB:: setState() on {} ==> STILL null proxy!\n",
dbg::ptr(
this));
518 else if (!proxy->isValid()) {
520 dbg::print(stderr,
"::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n",
dbg::ptr(
this));
522 dbg::print(stderr,
"::VHB:: setState() on {} ==> m_store is a nullptr\n",
dbg::ptr(
this));
527 dbg::print(stderr,
"::VHB:: setState() on {} ==> m_store points not to an SGImplSvc but to a {}\n",
dbg::ptr(
this), boost::core::demangle(
typeid(*m_store).name()));
539 if (
sc.isFailure() &&
mode() == Gaudi::DataHandle::Writer &&
m_ptr ==
nullptr)
540 return StatusCode::SUCCESS;
562 return StatusCode::SUCCESS;
616 return StatusCode::SUCCESS;
618 return StatusCode::FAILURE;
633 m_key->storeHandle().name());
669 dbg::print(stderr,
"::VHB::setState({}, proxy={}) const\n",
dbg::ptr(
this), dbg::proxy(proxy));
671 if (0 == proxy || !proxy->isValid()) {
672 return StatusCode::FAILURE;
682 return StatusCode::SUCCESS;
695 return StatusCode::FAILURE;
733 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record an object with a null key";
734 return StatusCode::FAILURE;
737 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record null pointer";
738 return StatusCode::FAILURE;
742 unsigned int initRefCount = sptr->refCount();
744 m_store->recordObject (sptr, this->
name(), allowMods, returnExisting);
746 REPORT_ERROR (StatusCode::FAILURE) <<
"recordObject failed";
748 return StatusCode::FAILURE;
754 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->
isValid()) {
760 <<
"Found an existing const object from recordOrRetrieve.";
761 return StatusCode::FAILURE;
768 m_ptr=(
void*)dataPtr;
770 return StatusCode::SUCCESS;
793 std::unique_ptr<DataObject> dobj,
800 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record an object with a null key";
810 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record null pointer.";
815 unsigned int initRefCount = sptr->refCount();
817 store->recordObject (sptr, this->
name(), allowMods, returnExisting);
819 REPORT_ERROR (StatusCode::FAILURE) <<
"recordObject failed";
823 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->
isValid()) {
841 dbg::print(stderr,
"::VHB::typeless_dataPointer_impl({}, ptr={}, proxy={}, key={}, store={})\n",
dbg::ptr(
this),
dbg::ptr(this->
m_ptr), dbg::proxy(this->
m_proxy), this->
key(), dbg::store(this->
m_store));
853 <<
"could not get proxy for key " <<
key();
854 if (this->
mode() != Gaudi::DataHandle::Reader) {
893 if (this->
mode() != Gaudi::DataHandle::Reader) {
896 <<
"get_impl called for a non-read handle.";
903 <<
"Cannot initialize a Read/Write/Update handle with a null key.";
920 <<
"Cannot find proxy for "
921 << this->
clid() <<
"/" << this->
key();
941 const std::string& newKey)
944 REPORT_ERROR (StatusCode::FAILURE) <<
"symlink: Handle not valid.";
945 return StatusCode::FAILURE;
951 return StatusCode::FAILURE;
952 return StatusCode::SUCCESS;
973 if (
m_key->isEventStore()) {
1040 proxy->bindHandle (
this);
1058 if (!proxy || !proxy->isValid()) {
1063 <<
" [" << (proxy != 0 ? proxy->clID() : 0)
1064 <<
"/" << (proxy != 0
1066 : std::string(
"<N/A>"))
1067 <<
"] is in an invalid state";
1072 DataObject* dobj = proxy->accessData();
1077 <<
"this proxy " << MSG::hex << proxy
1078 << MSG::dec <<
" has a NULL data object ptr";
1092 if (proxy->transientID(
clid) &&
1096 ptr =
static_cast<void*
>(dbb->
object());
1100 <<
"Request for an invalid object; requested CLID = "
1102 <<
", proxy primary ID is " << proxy->clID();
1123 proxy =
store->proxy(this->
clid(), key);
1126 return proxy->isValid();
1144 out <<
"VarHandleBase @" << &o
1145 <<
" store=" <<o.
store()
1146 <<
", clid=" <<o.
clid()
1147 <<
", key=" <<o.
key()
1148 <<
"----------- ptr@" << o.
m_ptr
1151 out <<
", DataObject@" << o.
m_proxy->object();
1159 bool operator==(
const VarHandleBase& l,
const VarHandleBase&
r)
1161 return (l.clid() ==
r.clid() &&
1162 l.mode() ==
r.mode() &&
1163 l.name() ==
r.name() &&
1164 l.store() ==
r.store());
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define REPORT_ERROR(SC)
Report an error.
#define CHECK(...)
Evaluate an expression and check for errors.
Exceptions that can be thrown from StoreGate.
uint32_t CLID
The Class ID type.
convert to and from a SG storable
Base class for VarHandle classes.
static const Attributes_t empty
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
virtual void * object()=0
T * cast(SG::IRegisterTransient *irt=0, bool isConst=true)
Return the contents of the DataBucket, converted to type T.
virtual IProxyDict * hiveProxyDict() override
Return the current event-slot-specific store.
The Athena Transient Store API.
std::string dump() const
dump objects in store.
bool isValid() const
called by destructor
void unbindHandle(IResetable *ir)
bool bindHandle(IResetable *ir)
Exception — Tried to retrieve non-const pointer to const object.
Exception — Error initializing VarHandle from VarHandleKey.
Interface for registering a transient object in t2p map.
virtual void * cast(const std::type_info &, SG::IRegisterTransient *, bool) override
Return the contents of the DataBucket, converted to type given by std::type_info.
virtual void * cast(CLID, SG::IRegisterTransient *, bool) override
Return the contents of the DataBucket, converted to type given by clid.
virtual const CLID & clID() const override
virtual void relinquish() override
Give up ownership of the DataBucket contents.
virtual void * object() override
SymlinkDataObject(CLID clid, void *obj)
virtual const std::type_info & tinfo() const override
Return the type_info for the stored object.
virtual void lock() override
If the held object derives from ILockable, call lock() on it.
Base class for VarHandle types.
void * typeless_ptr(bool quiet=defaultQuiet)
Retrieve an object from StoreGate as non-const pointer.
StatusCode assign(const std::string &sgkey)
Update the underlying key from a string.
VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode)
Constructor with default key.
virtual void reset(bool hard) override
Reset this handle.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
std::unique_ptr< VarHandleKey > m_ownedKey
An owned VarHandleKey.
bool isPresent_impl(const std::string &key) const
Is the referenced object present in SG?
IProxyDict * storeFromHandle(const EventContext *ctx) const
Return the store instance to use.
StatusCode symLink_impl(CLID newClid, const std::string &newKey)
Make a symlink or alias to the object currently referenced by this handle.
StatusCode setState()
Retrieve and cache all information managed by a handle.
bool isPresent() const
Is the referenced object present in SG?
void setProxy(SG::DataProxy *proxy)
Set a new proxy.
bool m_storeWasSet
True if the store was set explicitly via setProxyDict.
void * typeless_dataPointer_fromProxy(SG::DataProxy *proxy, bool quiet) const
Retrieve a pointer from a proxy.
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
const void * get_impl(const EventContext *ctx, bool quiet=defaultQuiet) const
virtual void finalReset() override final
Reset this handle at the end of processing.
virtual bool isSet() const override final
Has a proxy been retrieved from SG?
const void * put_impl(const EventContext *ctx, std::unique_ptr< DataObject > dobj, const void *dataPtr, bool allowMods, bool returnExisting, IProxyDict *&store) const
Helper to record an object in the event store.
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
IProxyDict * m_store
Pointer to the store that owns the object.
void * m_ptr
The object to which we are bound.
StatusCode record_impl(std::unique_ptr< DataObject > dobj, void *dataPtr, bool allowMods, bool returnExisting)
Helper to record an object in the event store.
Gaudi::DataHandle::Mode mode() const
Return the mode (read/write/update) for this handle.
void * typeless_dataPointer(bool quiet=defaultQuiet)
Retrieve an object from StoreGate.
const VarHandleKey * m_key
The associated key object.
SG::DataProxy * m_proxy
Proxy holding the object to which we are bound.
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
void * typeless_dataPointer_impl(bool quiet)
Retrieve an object from StoreGate.
VarHandleBase & operator=(const VarHandleBase &rhs)
Assignment operator.
std::string store() const
Return the name of the store holding the object we are proxying.
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
bool isInitialized() const
Has a proxy been retrieved from SG?
bool isConst() const
True if this handle has a proxy, and the proxy is const.
StatusCode initialize(bool used=true)
Verify that the handle has been configured properly.
bool setStoreFromHandle(const EventContext *ctx)
Initialize the store pointer from the store handle.
void resetProxy()
Clear the m_proxy field and release the old proxy.
CLID clid() const
Return the class ID for the referenced object.
virtual ~VarHandleBase() override
Destructor.
const std::string & name() const
Return the StoreGate ID for the referenced object.
A property holding a SG store/key/clid from which a VarHandle is made.
virtual StatusCode assign(const std::string &sgkey)
Change the key of the object to which we're referring.
holding In fact this class is here in order to allow STL container for all features This class is sho...
singleton-like access to IMessageSvc via open function and helper
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
::StatusCode StatusCode
StatusCode definition for legacy code.
l
Printing final latex table to .tex output file.
bool operator==(const VarHandleBase &l, const VarHandleBase &r)
Equality comparison.
T * Storable_cast(DataObject *pDObj, bool quiet=true, IRegisterTransient *irt=0, bool isConst=true)
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
void throwExcNonConstHandleKey(CLID clid, const std::string &sgkey, const std::string &storename)
Throw a SG::ExcNonConstHandleKey exception.
bool operator!=(const VarHandleBase &l, const VarHandleBase &r)
Inequality comparison.
std::ostream & operator<<(std::ostream &os, const ArenaAllocatorBase::Stats::Stat &stat)
Format a statistic structure.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
std::string context_name(const INamedInterface *context)
Return the context name from a context (this) pointer.