25#include "GaudiKernel/MsgStream.h"
31#include "GaudiKernel/ThreadLocalContext.h"
38#include <boost/core/demangle.hpp>
43template <
class...
Args>
void print(std::FILE* stream, std::format_string<Args...>
fmt, Args&&... args)
45 std::fputs(std::format(
fmt, std::forward<Args>(args)...), stream);
48template <
class T>
void*
ptr(T* p) {
return static_cast<void*
>(
p); }
50std::string
proxy(SG::DataProxy* proxy)
55std::string
store(IProxyDict* store)
73 return std::format(
"VarHandle({}+{}[{}])", context->storeHandle().name(), context->key(), context->clid());
95 virtual const std::type_info&
tinfo()
const override {
return typeid(void); }
100 virtual void lock()
override { }
139 const std::string& sgkey,
140 Gaudi::DataHandle::Mode
mode,
141 const std::string& storename,
142 const EventContext* ctx) :
167 const std::string& sgkey,
168 Gaudi::DataHandle::Mode
mode,
191 const EventContext* ctx)
196 m_storeWasSet(false),
199 if (
key.storeHandle().get() ==
nullptr) {
200 throw SG::ExcUninitKey (key.clid(), key.key(),
201 key.storeHandle().name());
206 key.storeHandle().name());
219 Gaudi::DataHandle::Mode
mode)
247 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
248 m_ownedKey->setOwningHandle (this);
249 m_key = m_ownedKey.get();
255 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));
288 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));
488 return StatusCode::SUCCESS;
500 return StatusCode::FAILURE;
503 return StatusCode::SUCCESS;
526 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());
539 dbg::print(stderr,
"::VHB:: setState() on {} ==> STILL null proxy!\n",
dbg::ptr(
this));
542 else if (!proxy->isValid()) {
544 dbg::print(stderr,
"::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n",
dbg::ptr(
this));
546 dbg::print(stderr,
"::VHB:: setState() on {} ==> m_store is a nullptr\n",
dbg::ptr(
this));
551 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()));
563 if (
sc.isFailure() &&
mode() == Gaudi::DataHandle::Writer &&
m_ptr ==
nullptr)
564 return StatusCode::SUCCESS;
586 return StatusCode::SUCCESS;
640 return StatusCode::SUCCESS;
642 return StatusCode::FAILURE;
657 m_key->storeHandle().name());
684 std::format (
"VarHandleBase @{} store={}, clid={}, key{}----------- ptr@{}, proxy@{}",
685 static_cast<const void*
>(
this),
688 static_cast<const void*
>(
m_proxy));
690 s += std::format (
", DataObject@{}",
691 static_cast<const void*
>(
m_proxy->object()));
711 dbg::print(stderr,
"::VHB::setState({}, proxy={}) const\n",
dbg::ptr(
this), dbg::proxy(proxy));
713 if (0 == proxy || !proxy->isValid()) {
714 return StatusCode::FAILURE;
724 return StatusCode::SUCCESS;
737 return StatusCode::FAILURE;
774 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record an object with a null key";
775 return StatusCode::FAILURE;
778 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record null pointer";
779 return StatusCode::FAILURE;
783 unsigned int initRefCount = sptr->refCount();
785 m_store->recordObject (sptr, this->
name(), allowMods, returnExisting);
787 REPORT_ERROR (StatusCode::FAILURE) <<
"recordObject failed";
789 return StatusCode::FAILURE;
795 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->
isValid()) {
801 <<
"Found an existing const object from recordOrRetrieve.";
802 return StatusCode::FAILURE;
809 m_ptr=(
void*)dataPtr;
811 return StatusCode::SUCCESS;
834 std::unique_ptr<DataObject> dobj,
841 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record an object with a null key";
851 REPORT_ERROR (StatusCode::FAILURE) <<
"Attempt to record null pointer.";
856 unsigned int initRefCount = sptr->refCount();
858 store->recordObject (sptr, this->
name(), allowMods, returnExisting);
860 REPORT_ERROR (StatusCode::FAILURE) <<
"recordObject failed";
864 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->
isValid()) {
882 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));
894 <<
"could not get proxy for key " <<
key();
895 if (this->
mode() != Gaudi::DataHandle::Reader) {
934 if (this->
mode() != Gaudi::DataHandle::Reader) {
937 <<
"get_impl called for a non-read handle.";
944 <<
"Cannot initialize a Read/Write/Update handle with a null key.";
961 <<
"Cannot find proxy for "
962 << this->
clid() <<
"/" << this->
key();
982 const std::string& newKey)
985 REPORT_ERROR (StatusCode::FAILURE) <<
"symlink: Handle not valid.";
986 return StatusCode::FAILURE;
992 return StatusCode::FAILURE;
993 return StatusCode::SUCCESS;
1014 if (
m_key->isEventStore()) {
1022 return (ectx ? ectx->proxy() :
nullptr);
1080 proxy->bindHandle (
this);
1098 if (!proxy || !proxy->isValid()) {
1103 <<
" [" << (proxy != 0 ? proxy->clID() : 0)
1104 <<
"/" << (proxy != 0
1106 : std::string(
"<N/A>"))
1107 <<
"] is in an invalid state";
1112 DataObject* dobj = proxy->accessData();
1117 <<
"this proxy " << MSG::hex << proxy
1118 << MSG::dec <<
" has a NULL data object ptr";
1132 if (proxy->transientID(
clid) &&
1136 ptr =
static_cast<void*
>(dbb->
object());
1140 <<
"Request for an invalid object; requested CLID = "
1142 <<
", proxy primary ID is " << proxy->clID();
1163 proxy =
store->proxy(this->
clid(), key);
1166 return proxy->isValid();
1184 std::print (out,
"{}", o.
toString());
1192 bool operator==(
const VarHandleBase& l,
const VarHandleBase&
r)
1194 return (l.clid() ==
r.clid() &&
1195 l.mode() ==
r.mode() &&
1196 l.name() ==
r.name() &&
1197 l.store() ==
r.store());
bool isValid() const
Test to see if the link can be dereferenced.
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
Helper for getting a const version of a pointer.
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)
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.
std::string toString() const
Convert to a string representation.
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 * tryGetExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
const T * as_const_ptr(const T *p)
Helper for getting a const version of a pointer.
bool isConst() const
Get the const flag for this expression.
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.
virtual void reset() override
Free all allocated elements.
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.