ATLAS Offline Software
Loading...
Searching...
No Matches
StoreGate/src/VarHandleBase.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// VarHandleBase.cxx
8// Implementation file for class VarHandleBase
9// Author: Paolo Calafiura
10// Author: S.Binet<binet@cern.ch>
12
13#undef DEBUG_VHB /* define to get verbose debug printouts */
14
16
20
23
24// fwk includes
25#include "GaudiKernel/MsgStream.h"
31#include "GaudiKernel/ThreadLocalContext.h"
32
33#include <algorithm>
34#include <cstdio>
35#include <format>
36
37#ifdef DEBUG_VHB
38#include <boost/core/demangle.hpp>
39
40// Helpers for debug formatting
41// std::print implementation to be replaced when C++ 23 is available
42namespace dbg {
43template <class... Args> void print(std::FILE* stream, std::format_string<Args...> fmt, Args&&... args)
44{
45 std::fputs(std::format(fmt, std::forward<Args>(args)...), stream);
46}
47
48template <class T> void* ptr(T* p) { return static_cast<void*>(p); }
49
50std::string proxy(SG::DataProxy* proxy)
51{
52 return !proxy ? std::string("PROXY(null)") : std::format("PROXY({}, isValid={}, isConst={})", dbg::ptr(proxy), proxy->isValid(), proxy->isConst());
53}
54
55std::string store(IProxyDict* store)
56{
57 return !store ? std::string("null_store") : store->name();
58}
59}
60#endif
61
62namespace errorcheck {
63
64
71 std::string context_name (const SG::VarHandleBase* context)
72 {
73 return std::format("VarHandle({}+{}[{}])", context->storeHandle().name(), context->key(), context->clid());
74 }
75
76} // namespace errorcheck
77
78
79namespace SG {
80
81
89 : public DataBucketBase
90 {
91 public:
92 SymlinkDataObject (CLID clid, void* obj) : m_clid (clid), m_obj (obj) {}
93 virtual const CLID& clID() const override { return m_clid; }
94 virtual void* object() override { return m_obj; }
95 virtual const std::type_info& tinfo() const override { return typeid(void); }
97 virtual void* cast (CLID, SG::IRegisterTransient*, bool) override { std::abort(); }
98 virtual void* cast (const std::type_info&, SG::IRegisterTransient*, bool) override { std::abort(); }
99 virtual void relinquish() override { std::abort(); }
100 virtual void lock() override { }
101
102
103 private:
105 void* m_obj;
106 };
107
108
114 VarHandleBase::VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode) :
115 IResetable(),
116 m_ptr(0),
117 m_proxy(0),
118 m_store(nullptr),
119 m_storeWasSet(false),
120 m_ownedKey (std::make_unique<VarHandleKey> (clid, "", mode)),
122 {
123 m_ownedKey->setOwningHandle (this);
124#ifdef DEBUG_VHB
125 dbg::print(stderr, "VarHandleBase() {}\n", dbg::ptr(this));
126#endif
127 }
128
129
139 const std::string& sgkey,
140 Gaudi::DataHandle::Mode mode,
141 const std::string& storename,
142 const EventContext* ctx) :
143 IResetable(),
144 m_ptr(NULL),
145 m_proxy(NULL),
146 m_store(nullptr),
147 m_storeWasSet(false),
148 m_ownedKey (std::make_unique<VarHandleKey> (clid, sgkey, mode, storename)),
150 {
151 m_ownedKey->setOwningHandle (this);
152
153 if (ctx && !setStoreFromHandle(ctx)) {
154 throw SG::ExcHandleInitError (clid, sgkey, storename);
155 }
156 }
157
158
167 const std::string& sgkey,
168 Gaudi::DataHandle::Mode mode,
169 IProxyDict* sg) :
170 IResetable(),
171 m_ptr(nullptr),
172 m_proxy(nullptr),
173 m_store(sg),
174 m_storeWasSet(true),
175 m_ownedKey (std::make_unique<VarHandleKey> (clid, sgkey, mode, sg->name())),
177 {
178 m_ownedKey->setOwningHandle (this);
179 }
180
181
191 const EventContext* ctx)
192 : IResetable(),
193 m_ptr(nullptr),
194 m_proxy(nullptr),
195 m_store(nullptr),
196 m_storeWasSet(false),
197 m_key (&key)
198 {
199 if (key.storeHandle().get() == nullptr) {
200 throw SG::ExcUninitKey (key.clid(), key.key(),
201 key.storeHandle().name());
202 }
203
205 throw SG::ExcHandleInitError (key.clid(), key.key(),
206 key.storeHandle().name());
207 }
208 }
209
210
219 Gaudi::DataHandle::Mode mode)
220 : IResetable(),
221 m_ptr (nullptr),
222 m_proxy (nullptr),
223 m_store (proxy->store()),
224 m_storeWasSet (true),
225 m_ownedKey (std::make_unique<VarHandleKey> (proxy->clID(),
226 proxy->name(),
227 mode,
228 m_store ? m_store->name() : "")),
230 {
231 m_ownedKey->setOwningHandle (this);
232 setProxy (proxy);
234
235
240 IResetable(),
242 m_proxy(nullptr),
243 m_store(rhs.m_store),
245 {
246 if (rhs.m_ownedKey) {
247 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
248 m_ownedKey->setOwningHandle (this);
249 m_key = m_ownedKey.get();
250 }
251 else {
252 m_key = rhs.m_key;
253 }
254#ifdef DEBUG_VHB
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));
256#endif
257
258 setProxy (rhs.m_proxy);
259 }
261
266 IResetable(),
267 m_ptr(rhs.m_ptr),
268 m_proxy(nullptr),
269 m_store(rhs.m_store),
271 m_ownedKey (std::move (rhs.m_ownedKey)),
273 {
274 if (m_ownedKey) {
275 m_ownedKey->setOwningHandle (this);
276 }
277 rhs.m_ptr=0;
278
279 if (rhs.m_proxy) {
280 if (m_ownedKey) {
281 rhs.m_proxy->unbindHandle (&rhs);
282 rhs.m_proxy->bindHandle(this);
283 }
284 m_proxy = rhs.m_proxy;
285 rhs.m_proxy=0; //no release: this has the ref now
287#ifdef DEBUG_VHB
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));
289#endif
290 }
291
292
296 VarHandleBase&
299 if (this != &rhs) {
300 if (rhs.m_ownedKey) {
301 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
302 m_ownedKey->setOwningHandle (this);
303 m_key = m_ownedKey.get();
304 }
305 else {
306 m_key = rhs.m_key;
307 m_ownedKey.reset();
308 }
309
310 m_ptr = rhs.m_ptr;
311 m_store = rhs.m_store;
314 }
315#ifdef DEBUG_VHB
316 dbg::print(stderr, "::VHB::assignment 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));
317#endif
318 return *this;
319 }
320
321
325 VarHandleBase&
327 {
328 if (this != &rhs) {
329 m_ownedKey = std::move (rhs.m_ownedKey);
330 if (m_ownedKey) {
331 m_ownedKey->setOwningHandle (this);
332 }
333 m_key = rhs.m_key;
334
335 m_ptr = rhs.m_ptr;
336 m_store = rhs.m_store;
338
339 rhs.m_ptr=0;
340
341 resetProxy();
342 if (rhs.m_proxy) {
343 if (m_ownedKey) {
344 rhs.m_proxy->unbindHandle (&rhs);
345 rhs.m_proxy->bindHandle (this);
346 }
347 m_proxy = rhs.m_proxy;
348 rhs.m_proxy=0; //no release: this has the ref now
349 }
350 }
351#ifdef DEBUG_VHB
352 dbg::print(stderr, "::VHB:: move assign 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));
353#endif
354 return *this;
355 }
356
357
360 */
362 {
363#ifdef DEBUG_VHB
364 dbg::print(stderr, "::VHB:: DESTROY {} with 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));
365#endif
366
367 if (m_ownedKey) {
368 resetProxy();
369 }
370 m_ptr = 0;
371 }
373
374
375 //*************************************************************************
376 // Accessors
377 //
379
386 const std::string& VarHandleBase::key() const
387 {
388 return m_key->key();
389 }
390
391
393 * @brief Return the StoreGate ID for the referenced object.
394 *
395 * A synonym for key().
396 */
397 const std::string& VarHandleBase::name() const
398 {
399 return this->key();
400 }
401
402
403 /**
404 * @brief Return the name of the store holding the object we are proxying.
405 */
406 std::string VarHandleBase::store() const
407 {
408 if (m_store)
409 return m_store->name();
410 return this->storeHandle().name();
411 }
412
413
414 //*************************************************************************
415 // Validity checking.
416 //
418
425 {
426 return isPresent_impl (key());
427 }
428
429
435 bool
437 {
438#ifdef DEBUG_VHB
439 dbg::print(stderr, "::VHB::isInitialized({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
440#endif
441 return (0 != m_proxy);
442 }
443
444
451 {
453 }
454
455
461 bool
463 {
464#ifdef DEBUG_VHB
465 dbg::print(stderr, "::VHB::isConst({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
466#endif
467 return 0 != m_proxy
468 ? m_proxy->isConst()
469 : false;
470 }
471
472
478 * This will return failure if the key is blank or if the event store
479 * cannot be found.
480 */
481 StatusCode
483 {
484 if (!used) {
485 if (m_ownedKey) {
486 CHECK( m_ownedKey->initialize (used) );
487 }
488 return StatusCode::SUCCESS;
490
491 if (!m_store) {
492 if (m_ownedKey) {
493 CHECK( m_ownedKey->initialize() );
494 }
495 m_store = &*(this->storeHandle());
496 m_storeWasSet = false;
497 }
498
499 if (!m_store) {
500 return StatusCode::FAILURE;
501 }
502
503 return StatusCode::SUCCESS;
504 }
505
506
512 * Note for the case of a WriteHandle that has not yet been written to,
513 * the proxy may not exist. We return Success in that case; however,
514 * @c isInitialized will still return false.
515 */
516 StatusCode
518 {
519 CHECK( initialize() );
520 if (!m_storeWasSet) {
521 IProxyDict* store = storeFromHandle (nullptr);
522 if (store) m_store = store;
523 }
524
525#ifdef DEBUG_VHB
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());
527#endif
528
529 SG::DataProxy* proxy = m_store->proxy_exact (m_key->hashedKey());
530 if (!proxy) {
531#ifdef DEBUG_VHB
532 dbg::print(stderr, "::VHB:: setState() on {} ==> null proxy!\n", dbg::ptr(this));
533#endif
534 proxy = m_store->proxy(this->clid(), this->key());
535 }
536
537 if (!proxy) {
538#ifdef DEBUG_VHB
539 dbg::print(stderr, "::VHB:: setState() on {} ==> STILL null proxy!\n", dbg::ptr(this));
540#endif
541 }
542 else if (!proxy->isValid()) {
543#ifdef DEBUG_VHB
544 dbg::print(stderr, "::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n", dbg::ptr(this));
545 if (!m_store) {
546 dbg::print(stderr, "::VHB:: setState() on {} ==> m_store is a nullptr\n", dbg::ptr(this));
547 }
548 else {
549 SGImplSvc* stor = dynamic_cast<SGImplSvc*>(m_store);
550 if (!stor) {
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()));
552 }
553 else {
554 dbg::print(stderr, "\n{}\n", stor->dump());
555 }
556 }
557#endif
558 }
559 StatusCode sc = this->setState(proxy);
560
561 // Failure to find the proxy is ok in the case of a @c WriteHandle
562 // that has not yet been written to.
563 if (sc.isFailure() && mode() == Gaudi::DataHandle::Writer && m_ptr == nullptr)
564 return StatusCode::SUCCESS;
566 return sc;
567 }
568
569
570 //*************************************************************************
571 // State setting.
572 //
573
574
582 {
583 reset(true);
584 m_store = store;
585 m_storeWasSet = true;
586 return StatusCode::SUCCESS;
587 }
588
589
599 void
601#ifdef DEBUG_VHB
602 dbg::print(stderr, "::VHB::reset {} with proxy={}, key={}, store={} (hard={})\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store), hard);
603#endif
604 m_ptr = 0;
605
606 if (hard) {
607 m_store = 0;
608 m_storeWasSet = false;
609 }
610
611 //if the proxy is not resetOnly then release it as it will become invalid
612 // Also release on a hard reset.
613 if (0 != m_proxy && (!m_proxy->isResetOnly() || hard)) {
614 resetProxy();
615 }
616 }
617
618
626#ifdef DEBUG_VHB
627 dbg::print(stderr, "::VHB::finalReset {} with proxy={}, key={}, store={}\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store));
628#endif
629 reset (true);
630 }
631
632
637 {
638 if (typeless_dataPointer()) {
639 m_proxy->setConst();
640 return StatusCode::SUCCESS;
641 }
642 return StatusCode::FAILURE;
643 }
644
645
654 {
655 if (!m_ownedKey) {
656 throwExcNonConstHandleKey (m_key->clid(), m_key->key(),
657 m_key->storeHandle().name());
658 }
659 return *m_ownedKey;
660 }
661
662
672 StatusCode VarHandleBase::assign (const std::string& sgkey)
673 {
674 return vhKey().assign (sgkey);
675 }
676
677
681 std::string VarHandleBase::toString() const
682 {
683 std::string s =
684 std::format ("VarHandleBase @{} store={}, clid={}, key{}----------- ptr@{}, proxy@{}",
685 static_cast<const void*>(this),
686 store(), clid(), key(),
688 static_cast<const void*>(m_proxy));
689 if (m_proxy)
690 s += std::format (", DataObject@{}",
691 static_cast<const void*>(m_proxy->object()));
692 return s;
693 }
694
695
696 //*************************************************************************
697 // Protected methods.
698 //
699
700
707 StatusCode
709 {
710#ifdef DEBUG_VHB
711 dbg::print(stderr, "::VHB::setState({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(proxy));
712#endif
713 if (0 == proxy || !proxy->isValid()) {
714 return StatusCode::FAILURE;
715 }
716
717 if (m_proxy != proxy) {
718 // We're changing proxies. Release the old and bind to the new.
719 setProxy (proxy);
720 // Clear cached pointer.
721 m_ptr=0;
722 }
723
724 return StatusCode::SUCCESS;
725 }
726
727
733 StatusCode
735 {
736 if (0 == store) {
737 return StatusCode::FAILURE;
738 }
739#ifdef DEBUG_VHB
740 dbg::print(stderr, "::VHB::setState({}, store={}, key={}) const\n", dbg::ptr(this), dbg::store(store), key);
741#endif
742 CLID cid = this->clid();
743 SG::DataProxy* proxy = store->proxy(cid, key);
744 return this->setState(proxy);
745 }
746
747
759 StatusCode
760 VarHandleBase::record_impl (std::unique_ptr<DataObject> dobj,
761 void* dataPtr,
762 bool allowMods,
763 bool returnExisting)
764 {
765 if (!m_store) {
766 if (m_ownedKey) {
767 CHECK (m_ownedKey->initialize());
768 }
769 m_store = &*(this->storeHandle());
770 m_storeWasSet = false;
771 }
772
773 if (this->name().empty()) {
774 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
775 return StatusCode::FAILURE;
776 }
777 if (!dobj) {
778 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer";
779 return StatusCode::FAILURE;
780 }
781
782 SG::DataObjectSharedPtr<DataObject> sptr (dobj.release());
783 unsigned int initRefCount = sptr->refCount();
784 SG::DataProxy* new_proxy =
785 m_store->recordObject (sptr, this->name(), allowMods, returnExisting);
786 if (!new_proxy) {
787 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
788 resetProxy();
789 return StatusCode::FAILURE;
790 }
791 if (m_proxy != new_proxy) {
792 CHECK (this->setState (new_proxy));
793 }
794
795 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
796 // If the reference count hasn't changed, then we've returned an existing
797 // object rather than recording a new one. Retrieve the pointer, making
798 // sure that it isn't const.
799 if (m_proxy->isConst()) {
800 REPORT_ERROR (StatusCode::FAILURE)
801 << "Found an existing const object from recordOrRetrieve.";
802 return StatusCode::FAILURE;
803 }
805 if (!allowMods)
806 CHECK( setConst() );
807 }
808 else
809 m_ptr=(void*)dataPtr;
810
811 return StatusCode::SUCCESS;
812 }
813
814
832 const void*
833 VarHandleBase::put_impl (const EventContext* ctx,
834 std::unique_ptr<DataObject> dobj,
835 const void* dataPtr,
836 bool allowMods,
837 bool returnExisting,
838 IProxyDict* & store) const
839 {
840 if (this->name().empty()) {
841 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
842 return nullptr;
843 }
844
845 store = storeFromHandle (ctx);
846 if (!store) {
847 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
848 return nullptr;
849 }
850 if (!dobj) {
851 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer.";
852 return nullptr;
853 }
854
855 SG::DataObjectSharedPtr<DataObject> sptr (std::move (dobj));
856 unsigned int initRefCount = sptr->refCount();
857 SG::DataProxy* new_proxy =
858 store->recordObject (sptr, this->name(), allowMods, returnExisting);
859 if (!new_proxy) {
860 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
861 return nullptr;
862 }
863
864 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
865 // If the reference count hasn't changed, then we've returned an existing
866 // object rather than recording a new one. Retrieve the pointer.
867 dataPtr = typeless_dataPointer_fromProxy (new_proxy, true);
868 }
869
870 return dataPtr;
871 }
872
873
878 void*
880 {
881#ifdef DEBUG_VHB
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));
883#endif
884
885 // First check for cached pointer.
886 if (0 != m_ptr)
887 return m_ptr;
888
889 if (0 == m_proxy) {
890 // No proxy, need to look it up.
891 if (this->setState().isFailure() || !m_proxy) {
892 if (!quiet) {
893 REPORT_MESSAGE(MSG::WARNING)
894 << "could not get proxy for key " << key();
895 if (this->mode() != Gaudi::DataHandle::Reader) {
896 REPORT_MESSAGE(MSG::WARNING)<< " try using a ReadHandle";
897 }
898 } //quiet
899 return 0;
900 } //setstate
901 } //m_proxy
902
904 return m_ptr;
905 }
906
907
914 void* VarHandleBase::typeless_ptr(bool quiet/*=defaultQuiet*/)
915 {
916 void* p = typeless_dataPointer(quiet);
917 if (p != nullptr && isConst())
918 throw SG::ExcConstObject (clid(), key(), store());
919 return p;
920 }
921
922
923 /*
924 * @brief Retrieve an object from SG as a const pointer without caching.
925 * @param ctx The event context, or nullptr to use the current context.
926 * @param quiet If true, suppress failure messages.
927 *
928 * Like typeless_dataPointer_impl, except that we don't change
929 * any members of the handle.
930 */
931 const void* VarHandleBase::get_impl (const EventContext* ctx,
932 bool quiet/*= defaultQuiet*/) const
933 {
934 if (this->mode() != Gaudi::DataHandle::Reader) {
935 if (!quiet)
936 REPORT_ERROR (StatusCode::FAILURE)
937 << "get_impl called for a non-read handle.";
938 return nullptr;
939 }
940
941 if (this->key().empty()) {
942 if (!quiet)
943 REPORT_ERROR (StatusCode::FAILURE)
944 << "Cannot initialize a Read/Write/Update handle with a null key.";
945 return nullptr;
946 }
947
949 if (!store) {
950 if (!quiet)
951 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
952 return nullptr;
953 }
954
955 SG::DataProxy* proxy = store->proxy_exact(m_key->hashedKey());
956 if (!proxy) {
957 proxy = store->proxy(this->clid(), this->key());
958 if (!proxy) {
959 if (!quiet)
960 REPORT_ERROR (StatusCode::FAILURE)
961 << "Cannot find proxy for "
962 << this->clid() << "/" << this->key();
963 return nullptr;
964 }
965 }
966
968 }
969
970
982 const std::string& newKey)
983 {
984 if (!m_ptr || !m_store) {
985 REPORT_ERROR (StatusCode::FAILURE) << "symlink: Handle not valid.";
986 return StatusCode::FAILURE;
987 }
988
990 SG::DataProxy* prox = m_store->recordObject (obj, newKey, false, true);
991 if (!prox)
992 return StatusCode::FAILURE;
993 return StatusCode::SUCCESS;
994 }
995
996
1012 IProxyDict* VarHandleBase::storeFromHandle (const EventContext* ctx) const
1013 {
1014 if (m_key->isEventStore()) {
1015 if (ctx)
1016 return Atlas::getExtendedEventContext(*ctx).proxy();
1017 if (m_storeWasSet && m_store) return m_store;
1018
1019 const Atlas::ExtendedEventContext* ectx =
1020 Atlas::tryGetExtendedEventContext (Gaudi::Hive::currentContext());
1021
1022 return (ectx ? ectx->proxy() : nullptr);
1023 }
1024
1025 if (m_storeWasSet && m_store) return m_store;
1027 if (!store)
1028 store = &*this->storeHandle();
1029
1030 return store->hiveProxyDict();
1031 }
1032
1033
1041 bool VarHandleBase::setStoreFromHandle (const EventContext* ctx)
1042 {
1043 if (m_ownedKey) {
1044 if (m_ownedKey->initialize().isFailure()) {
1045 return false;
1046 }
1047 }
1048 m_store = storeFromHandle (ctx);
1049 m_storeWasSet = (ctx && m_store ==
1050 Atlas::getExtendedEventContext(*ctx).proxy());
1051 return true;
1052 }
1053
1054
1059 {
1060 if (m_proxy) {
1061 if (m_ownedKey) {
1062 m_proxy->unbindHandle(this);
1063 m_proxy->release();
1064 }
1065 m_proxy = nullptr;
1066 }
1067 }
1068
1069
1075 {
1076 resetProxy();
1077 if (proxy) {
1078 if (m_ownedKey) {
1079 proxy->addRef();
1080 proxy->bindHandle (this);
1081 }
1082 m_proxy = proxy;
1083 }
1084 }
1085
1086
1094 void*
1096 bool quiet) const
1097 {
1098 if (!proxy || !proxy->isValid()) {
1099 // invalid proxy
1100 if (!quiet) {
1101 REPORT_MESSAGE(MSG::WARNING)
1102 << "Proxy "
1103 << " [" << (proxy != 0 ? proxy->clID() : 0)
1104 << "/" << (proxy != 0
1105 ? proxy->name()
1106 : std::string("<N/A>"))
1107 << "] is in an invalid state";
1108 } //quiet
1109 return nullptr;
1110 }
1111
1112 DataObject* dobj = proxy->accessData();
1113 if (!dobj) {
1114 // invalid dobj
1115 if (!quiet) {
1116 REPORT_MESSAGE(MSG::WARNING)
1117 << "this proxy " << MSG::hex << proxy
1118 << MSG::dec << " has a NULL data object ptr";
1119 }
1120 return nullptr;
1121 }
1122
1123 const CLID clid = this->clid();
1124 void* ptr = SG::Storable_cast(dobj, clid, nullptr, true, proxy);
1125 if (ptr)
1126 return ptr;
1127
1128 // If ptr is null, probably the clid we gave wasn't the clid
1129 // the object was stored with, nor it inherits from it.
1130 // before giving up, let's check its transient CLIDs
1131 DataBucketBase *dbb = 0;
1132 if (proxy->transientID(clid) &&
1133 0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
1134 // it is a symlink after all.
1135 // Let's hard cast (and keep our fingers Xed)
1136 ptr = static_cast<void*>(dbb->object());
1137 } else {
1138 if (!quiet) {
1139 REPORT_MESSAGE(MSG::WARNING)
1140 << "Request for an invalid object; requested CLID = "
1141 << clid
1142 << ", proxy primary ID is " << proxy->clID();
1143 }
1144 } // try symlink -- endif
1145 return ptr;
1146 }
1147
1148
1155 bool VarHandleBase::isPresent_impl (const std::string& key) const
1156 {
1157 const DataProxy* proxy = m_proxy;
1158 if (!proxy) {
1159 const IProxyDict* store = m_store;
1160 if (!store)
1161 store = this->storeHandle().get();
1162 if (store)
1163 proxy = store->proxy(this->clid(), key);
1164 }
1165 if (proxy) {
1166 return proxy->isValid();
1167 }
1168 return false;
1169 }
1170
1171
1172//*************************************************************************
1173 // Free functions.
1174 //
1175
1176
1182 std::ostream& operator<<( std::ostream& out, const VarHandleBase& o )
1183 {
1184 std::print (out, "{}", o.toString());
1185 return out;
1186 }
1187
1188
1192 bool operator==(const VarHandleBase& l, const VarHandleBase& r)
1193 {
1194 return (l.clid() == r.clid() &&
1195 l.mode() == r.mode() &&
1196 l.name() == r.name() &&
1197 l.store() == r.store());
1198 }
1199
1200
1204 bool operator!=(const VarHandleBase& l, const VarHandleBase& r)
1205 {
1206 return !(l==r);
1207 }
1208
1209
1210} /* namespace SG */
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.
static Double_t sc
if(pathvar)
convert to and from a SG storable
Base class for VarHandle classes.
const char *const fmt
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.
a resetable object (e.g.
Definition IResetable.h:15
The Athena Transient Store API.
Definition SGImplSvc.h:109
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?
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
int r
Definition globals.cxx:22
bool dbg
Definition listroot.cxx:36
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.
TestStore store
Definition TestStore.cxx:22
Forward declaration.
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 * ptr(T *p)
Definition SGImplSvc.cxx:75
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition SGImplSvc.cxx:71
std::string context_name(const INamedInterface *context)
Return the context name from a context (this) pointer.
STL namespace.
void initialize()