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-2025 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"
30#include "GaudiKernel/ThreadLocalContext.h"
31
32#include <algorithm>
33#include <cstdio>
34#include <format>
35
36#ifdef DEBUG_VHB
37#include <boost/core/demangle.hpp>
38
39// Helpers for debug formatting
40// std::print implementation to be replaced when C++ 23 is available
41namespace dbg {
42template <class... Args> void print(std::FILE* stream, std::format_string<Args...> fmt, Args&&... args)
43{
44 std::fputs(std::format(fmt, std::forward<Args>(args)...), stream);
45}
46
47template <class T> void* ptr(T* p) { return static_cast<void*>(p); }
48
49std::string proxy(SG::DataProxy* proxy)
50{
51 return !proxy ? std::string("PROXY(null)") : std::format("PROXY({}, isValid={}, isConst={})", dbg::ptr(proxy), proxy->isValid(), proxy->isConst());
52}
53
54std::string store(IProxyDict* store)
55{
56 return !store ? std::string("null_store") : store->name();
57}
58}
59#endif
60
61namespace errorcheck {
62
63
70 std::string context_name (const SG::VarHandleBase* context)
71 {
72 return std::format("VarHandle({}+{}[{}])", context->storeHandle().name(), context->key(), context->clid());
73 }
74
75} // namespace errorcheck
76
77
78namespace SG {
79
80
88 : public DataBucketBase
89 {
90 public:
91 SymlinkDataObject (CLID clid, void* obj) : m_clid (clid), m_obj (obj) {}
92 virtual const CLID& clID() const override { return m_clid; }
93 virtual void* object() override { return m_obj; }
94 virtual const std::type_info& tinfo() const override { return typeid(void); }
96 virtual void* cast (CLID, SG::IRegisterTransient*, bool) override { std::abort(); }
97 virtual void* cast (const std::type_info&, SG::IRegisterTransient*, bool) override { std::abort(); }
98 virtual void relinquish() override { std::abort(); }
99 virtual void lock() override { }
100
101
102 private:
104 void* m_obj;
105 };
106
107
113 VarHandleBase::VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode) :
114 IResetable(),
115 m_ptr(0),
116 m_proxy(0),
117 m_store(nullptr),
118 m_storeWasSet(false),
119 m_ownedKey (std::make_unique<VarHandleKey> (clid, "", mode)),
121 {
122 m_ownedKey->setOwningHandle (this);
123#ifdef DEBUG_VHB
124 dbg::print(stderr, "VarHandleBase() {}\n", dbg::ptr(this));
125#endif
126 }
127
128
138 const std::string& sgkey,
139 Gaudi::DataHandle::Mode mode,
140 const std::string& storename,
141 const EventContext* ctx) :
142 IResetable(),
143 m_ptr(NULL),
144 m_proxy(NULL),
145 m_store(nullptr),
146 m_storeWasSet(false),
147 m_ownedKey (std::make_unique<VarHandleKey> (clid, sgkey, mode, storename)),
149 {
150 m_ownedKey->setOwningHandle (this);
151
152 if (ctx && !setStoreFromHandle(ctx)) {
153 throw SG::ExcHandleInitError (clid, sgkey, storename);
154 }
155 }
156
157
167 const EventContext* ctx)
168 : IResetable(),
169 m_ptr(nullptr),
170 m_proxy(nullptr),
171 m_store(nullptr),
172 m_storeWasSet(false),
173 m_key (&key)
174 {
175 if (key.storeHandle().get() == nullptr) {
176 throw SG::ExcUninitKey (key.clid(), key.key(),
177 key.storeHandle().name());
178 }
179
180 if (!setStoreFromHandle(ctx)) {
181 throw SG::ExcHandleInitError (key.clid(), key.key(),
182 key.storeHandle().name());
183 }
184 }
185
186
192 * This handle will be bound to the given proxy.
193 */
195 Gaudi::DataHandle::Mode mode)
196 : IResetable(),
197 m_ptr (nullptr),
198 m_proxy (nullptr),
199 m_store (proxy->store()),
200 m_storeWasSet (true),
201 m_ownedKey (std::make_unique<VarHandleKey> (proxy->clID(),
202 proxy->name(),
203 mode,
204 m_store ? m_store->name() : "")),
206 {
207 m_ownedKey->setOwningHandle (this);
208 setProxy (proxy);
209 }
210
211
213 * @brief Copy constructor.
214 */
216 IResetable(),
217 m_ptr(rhs.m_ptr),
218 m_proxy(nullptr),
219 m_store(rhs.m_store),
222 if (rhs.m_ownedKey) {
223 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
224 m_ownedKey->setOwningHandle (this);
225 m_key = m_ownedKey.get();
226 }
227 else {
228 m_key = rhs.m_key;
230#ifdef DEBUG_VHB
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));
232#endif
233
234 setProxy (rhs.m_proxy);
235 }
236
242 IResetable(),
243 m_ptr(rhs.m_ptr),
244 m_proxy(nullptr),
245 m_store(rhs.m_store),
247 m_ownedKey (std::move (rhs.m_ownedKey)),
249 {
250 if (m_ownedKey) {
251 m_ownedKey->setOwningHandle (this);
252 }
253 rhs.m_ptr=0;
254
255 if (rhs.m_proxy) {
256 if (m_ownedKey) {
257 rhs.m_proxy->unbindHandle (&rhs);
258 rhs.m_proxy->bindHandle(this);
259 }
261 rhs.m_proxy=0; //no release: this has the ref now
262 }
263#ifdef DEBUG_VHB
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));
265#endif
266 }
267
268
272 VarHandleBase&
275 if (this != &rhs) {
276 if (rhs.m_ownedKey) {
277 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
278 m_ownedKey->setOwningHandle (this);
279 m_key = m_ownedKey.get();
280 }
281 else {
282 m_key = rhs.m_key;
283 m_ownedKey.reset();
284 }
285
287 m_store = rhs.m_store;
289 setProxy (rhs.m_proxy);
290 }
291#ifdef DEBUG_VHB
292 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));
293#endif
294 return *this;
296
297
303 {
304 if (this != &rhs) {
305 m_ownedKey = std::move (rhs.m_ownedKey);
306 if (m_ownedKey) {
307 m_ownedKey->setOwningHandle (this);
308 }
309 m_key = rhs.m_key;
310
311 m_ptr = rhs.m_ptr;
312 m_store = rhs.m_store;
314
315 rhs.m_ptr=0;
316
317 resetProxy();
318 if (rhs.m_proxy) {
319 if (m_ownedKey) {
320 rhs.m_proxy->unbindHandle (&rhs);
321 rhs.m_proxy->bindHandle (this);
322 }
323 m_proxy = rhs.m_proxy;
324 rhs.m_proxy=0; //no release: this has the ref now
325 }
326 }
327#ifdef DEBUG_VHB
328 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));
329#endif
330 return *this;
331 }
332
333
338 {
339#ifdef DEBUG_VHB
340 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));
341#endif
342
343 if (m_ownedKey) {
344 resetProxy();
345 }
346 m_ptr = 0;
347 }
349
350
351 //*************************************************************************
352 // Accessors
353 //
354
355
360 * it's also in @c IResetable. (Otherwise there would be an ambiguity.)
361 */
362 const std::string& VarHandleBase::key() const
363 {
364 return m_key->key();
365 }
366
367
373 const std::string& VarHandleBase::name() const
374 {
375 return this->key();
376 }
377
378
382 std::string VarHandleBase::store() const
383 {
384 if (m_store)
385 return m_store->name();
386 return this->storeHandle().name();
387 }
388
389
390 //*************************************************************************
391 // Validity checking.
392 //
393
394
399 */
401 {
402 return isPresent_impl (key());
403 }
404
405
411 bool
413 {
414#ifdef DEBUG_VHB
415 dbg::print(stderr, "::VHB::isInitialized({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
416#endif
417 return (0 != m_proxy);
418 }
419
420
422 * @brief Has a proxy been retrieved from SG?
423 *
424 * Same as @c isInitialized; this is an interface required by @c IResetable.
425 */
427 {
428 return isInitialized();
429 }
430
431
435 * Refers to the state of the proxy, not of the handle.
436 */
437 bool
439 {
440#ifdef DEBUG_VHB
441 dbg::print(stderr, "::VHB::isConst({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
442#endif
443 return 0 != m_proxy
444 ? m_proxy->isConst()
445 : false;
446 }
447
448
457 StatusCode
459 {
460 if (!used) {
461 if (m_ownedKey) {
462 CHECK( m_ownedKey->initialize (used) );
463 }
464 return StatusCode::SUCCESS;
465 }
466
467 if (!m_store) {
468 if (m_ownedKey) {
469 CHECK( m_ownedKey->initialize() );
470 }
471 m_store = &*(this->storeHandle());
472 m_storeWasSet = false;
473 }
474
475 if (!m_store) {
476 return StatusCode::FAILURE;
477 }
478
479 return StatusCode::SUCCESS;
480 }
481
482
486 * This will retrieve and cache the associated @c DataProxy.
487 *
488 * Note for the case of a WriteHandle that has not yet been written to,
489 * the proxy may not exist. We return Success in that case; however,
490 * @c isInitialized will still return false.
491 */
492 StatusCode
495 CHECK( initialize() );
496 if (!m_storeWasSet) {
497 IProxyDict* store = storeFromHandle (nullptr);
498 if (store) m_store = store;
499 }
500
501#ifdef DEBUG_VHB
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());
503#endif
504
505 SG::DataProxy* proxy = m_store->proxy_exact (m_key->hashedKey());
506 if (!proxy) {
507#ifdef DEBUG_VHB
508 dbg::print(stderr, "::VHB:: setState() on {} ==> null proxy!\n", dbg::ptr(this));
509#endif
510 proxy = m_store->proxy(this->clid(), this->key());
511 }
512
513 if (!proxy) {
514#ifdef DEBUG_VHB
515 dbg::print(stderr, "::VHB:: setState() on {} ==> STILL null proxy!\n", dbg::ptr(this));
516#endif
517 }
518 else if (!proxy->isValid()) {
519#ifdef DEBUG_VHB
520 dbg::print(stderr, "::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n", dbg::ptr(this));
521 if (!m_store) {
522 dbg::print(stderr, "::VHB:: setState() on {} ==> m_store is a nullptr\n", dbg::ptr(this));
523 }
524 else {
525 SGImplSvc* stor = dynamic_cast<SGImplSvc*>(m_store);
526 if (!stor) {
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()));
528 }
529 else {
530 dbg::print(stderr, "\n{}\n", stor->dump());
532 }
533#endif
534 }
535 StatusCode sc = this->setState(proxy);
536
537 // Failure to find the proxy is ok in the case of a @c WriteHandle
538 // that has not yet been written to.
539 if (sc.isFailure() && mode() == Gaudi::DataHandle::Writer && m_ptr == nullptr)
540 return StatusCode::SUCCESS;
542 return sc;
543 }
544
545
546 //*************************************************************************
547 // State setting.
548 //
549
550
555 * This implicitly does a reset().
556 */
558 {
559 reset(true);
560 m_store = store;
561 m_storeWasSet = true;
562 return StatusCode::SUCCESS;
563 }
564
575 void
577#ifdef DEBUG_VHB
578 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);
579#endif
580 m_ptr = 0;
581
582 if (hard) {
583 m_store = 0;
584 m_storeWasSet = false;
585 }
586
587 //if the proxy is not resetOnly then release it as it will become invalid
588 // Also release on a hard reset.
589 if (0 != m_proxy && (!m_proxy->isResetOnly() || hard)) {
590 resetProxy();
591 }
592 }
593
594
602#ifdef DEBUG_VHB
603 dbg::print(stderr, "::VHB::finalReset {} with proxy={}, key={}, store={}\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store));
604#endif
605 reset (true);
606 }
607
608
613 {
614 if (typeless_dataPointer()) {
615 m_proxy->setConst();
616 return StatusCode::SUCCESS;
617 }
618 return StatusCode::FAILURE;
619 }
620
621
630 {
631 if (!m_ownedKey) {
632 throwExcNonConstHandleKey (m_key->clid(), m_key->key(),
633 m_key->storeHandle().name());
634 }
635 return *m_ownedKey;
636 }
637
638
648 StatusCode VarHandleBase::assign (const std::string& sgkey)
649 {
650 return vhKey().assign (sgkey);
651 }
652
653
654 //*************************************************************************
655 // Protected methods.
656 //
657
658
665 StatusCode
667 {
668#ifdef DEBUG_VHB
669 dbg::print(stderr, "::VHB::setState({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(proxy));
670#endif
671 if (0 == proxy || !proxy->isValid()) {
672 return StatusCode::FAILURE;
673 }
674
675 if (m_proxy != proxy) {
676 // We're changing proxies. Release the old and bind to the new.
677 setProxy (proxy);
678 // Clear cached pointer.
679 m_ptr=0;
680 }
681
682 return StatusCode::SUCCESS;
683 }
684
685
691 StatusCode
693 {
694 if (0 == store) {
695 return StatusCode::FAILURE;
696 }
697#ifdef DEBUG_VHB
698 dbg::print(stderr, "::VHB::setState({}, store={}, key={}) const\n", dbg::ptr(this), dbg::store(store), key);
699#endif
700 CLID cid = this->clid();
701 SG::DataProxy* proxy = store->proxy(cid, key);
702 // std::cerr << "::VHB:: -- clid=[" << cid << "] proxy=[" << proxy << "]\n";
703 return this->setState(proxy);
704 }
705
706
718 StatusCode
719 VarHandleBase::record_impl (std::unique_ptr<DataObject> dobj,
720 void* dataPtr,
721 bool allowMods,
722 bool returnExisting)
723 {
724 if (!m_store) {
725 if (m_ownedKey) {
726 CHECK (m_ownedKey->initialize());
727 }
728 m_store = &*(this->storeHandle());
729 m_storeWasSet = false;
730 }
731
732 if (this->name().empty()) {
733 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
734 return StatusCode::FAILURE;
735 }
736 if (!dobj) {
737 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer";
738 return StatusCode::FAILURE;
739 }
740
741 SG::DataObjectSharedPtr<DataObject> sptr (dobj.release());
742 unsigned int initRefCount = sptr->refCount();
743 SG::DataProxy* new_proxy =
744 m_store->recordObject (sptr, this->name(), allowMods, returnExisting);
745 if (!new_proxy) {
746 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
747 resetProxy();
748 return StatusCode::FAILURE;
749 }
750 if (m_proxy != new_proxy) {
751 CHECK (this->setState (new_proxy));
752 }
753
754 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
755 // If the reference count hasn't changed, then we've returned an existing
756 // object rather than recording a new one. Retrieve the pointer, making
757 // sure that it isn't const.
758 if (m_proxy->isConst()) {
759 REPORT_ERROR (StatusCode::FAILURE)
760 << "Found an existing const object from recordOrRetrieve.";
761 return StatusCode::FAILURE;
762 }
764 if (!allowMods)
765 CHECK( setConst() );
766 }
767 else
768 m_ptr=(void*)dataPtr;
769
770 return StatusCode::SUCCESS;
771 }
772
773
791 const void*
792 VarHandleBase::put_impl (const EventContext* ctx,
793 std::unique_ptr<DataObject> dobj,
794 const void* dataPtr,
795 bool allowMods,
796 bool returnExisting,
797 IProxyDict* & store) const
798 {
799 if (this->name().empty()) {
800 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
801 return nullptr;
802 }
803
804 store = storeFromHandle (ctx);
805 if (!store) {
806 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
807 return nullptr;
808 }
809 if (!dobj) {
810 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer.";
811 return nullptr;
812 }
813
814 SG::DataObjectSharedPtr<DataObject> sptr (std::move (dobj));
815 unsigned int initRefCount = sptr->refCount();
816 SG::DataProxy* new_proxy =
817 store->recordObject (sptr, this->name(), allowMods, returnExisting);
818 if (!new_proxy) {
819 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
820 return nullptr;
821 }
822
823 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
824 // If the reference count hasn't changed, then we've returned an existing
825 // object rather than recording a new one. Retrieve the pointer.
826 dataPtr = typeless_dataPointer_fromProxy (new_proxy, true);
827 }
828
829 return dataPtr;
830 }
831
832
837 void*
839 {
840#ifdef DEBUG_VHB
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));
842#endif
843
844 // First check for cached pointer.
845 if (0 != m_ptr)
846 return m_ptr;
847
848 if (0 == m_proxy) {
849 // No proxy, need to look it up.
850 if (this->setState().isFailure() || !m_proxy) {
851 if (!quiet) {
852 REPORT_MESSAGE(MSG::WARNING)
853 << "could not get proxy for key " << key();
854 if (this->mode() != Gaudi::DataHandle::Reader) {
855 REPORT_MESSAGE(MSG::WARNING)<< " try using a ReadHandle";
856 }
857 } //quiet
858 return 0;
859 } //setstate
860 } //m_proxy
861
863 return m_ptr;
864 }
865
866
873 void* VarHandleBase::typeless_ptr(bool quiet/*=defaultQuiet*/)
874 {
875 void* p = typeless_dataPointer(quiet);
876 if (p != nullptr && isConst())
877 throw SG::ExcConstObject (clid(), key(), store());
878 return p;
879 }
880
881
882 /*
883 * @brief Retrieve an object from SG as a const pointer without caching.
884 * @param ctx The event context, or nullptr to use the current context.
885 * @param quiet If true, suppress failure messages.
886 *
887 * Like typeless_dataPointer_impl, except that we don't change
888 * any members of the handle.
889 */
890 const void* VarHandleBase::get_impl (const EventContext* ctx,
891 bool quiet/*= defaultQuiet*/) const
892 {
893 if (this->mode() != Gaudi::DataHandle::Reader) {
894 if (!quiet)
895 REPORT_ERROR (StatusCode::FAILURE)
896 << "get_impl called for a non-read handle.";
897 return nullptr;
898 }
899
900 if (this->key().empty()) {
901 if (!quiet)
902 REPORT_ERROR (StatusCode::FAILURE)
903 << "Cannot initialize a Read/Write/Update handle with a null key.";
904 return nullptr;
905 }
906
908 if (!store) {
909 if (!quiet)
910 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
911 return nullptr;
912 }
913
914 SG::DataProxy* proxy = store->proxy_exact(m_key->hashedKey());
915 if (!proxy) {
916 proxy = store->proxy(this->clid(), this->key());
917 if (!proxy) {
918 if (!quiet)
919 REPORT_ERROR (StatusCode::FAILURE)
920 << "Cannot find proxy for "
921 << this->clid() << "/" << this->key();
922 return nullptr;
923 }
924 }
925
927 }
928
929
941 const std::string& newKey)
942 {
943 if (!m_ptr || !m_store) {
944 REPORT_ERROR (StatusCode::FAILURE) << "symlink: Handle not valid.";
945 return StatusCode::FAILURE;
946 }
947
949 SG::DataProxy* prox = m_store->recordObject (obj, newKey, false, true);
950 if (!prox)
951 return StatusCode::FAILURE;
952 return StatusCode::SUCCESS;
953 }
954
955
971 IProxyDict* VarHandleBase::storeFromHandle (const EventContext* ctx) const
972 {
973 if (m_key->isEventStore()) {
974 if (ctx)
975 return Atlas::getExtendedEventContext(*ctx).proxy();
976 if (m_storeWasSet && m_store) return m_store;
977
978 if ( Atlas::hasExtendedEventContext (Gaudi::Hive::currentContext()) ) {
979 return Atlas::getExtendedEventContext (Gaudi::Hive::currentContext()).proxy();
980 } else {
981 return nullptr;
982 }
983 }
984
985 if (m_storeWasSet && m_store) return m_store;
987 if (!store)
988 store = &*this->storeHandle();
989
990 return store->hiveProxyDict();
991 }
992
993
1001 bool VarHandleBase::setStoreFromHandle (const EventContext* ctx)
1002 {
1003 if (m_ownedKey) {
1004 if (m_ownedKey->initialize().isFailure()) {
1005 return false;
1006 }
1007 }
1008 m_store = storeFromHandle (ctx);
1009 m_storeWasSet = (ctx && m_store ==
1010 Atlas::getExtendedEventContext(*ctx).proxy());
1011 return true;
1012 }
1013
1014
1019 {
1020 if (m_proxy) {
1021 if (m_ownedKey) {
1022 m_proxy->unbindHandle(this);
1023 m_proxy->release();
1024 }
1025 m_proxy = nullptr;
1026 }
1027 }
1028
1029
1035 {
1036 resetProxy();
1037 if (proxy) {
1038 if (m_ownedKey) {
1039 proxy->addRef();
1040 proxy->bindHandle (this);
1041 }
1042 m_proxy = proxy;
1043 }
1044 }
1045
1046
1054 void*
1056 bool quiet) const
1057 {
1058 if (!proxy || !proxy->isValid()) {
1059 // invalid proxy
1060 if (!quiet) {
1061 REPORT_MESSAGE(MSG::WARNING)
1062 << "Proxy "
1063 << " [" << (proxy != 0 ? proxy->clID() : 0)
1064 << "/" << (proxy != 0
1065 ? proxy->name()
1066 : std::string("<N/A>"))
1067 << "] is in an invalid state";
1068 } //quiet
1069 return nullptr;
1070 }
1071
1072 DataObject* dobj = proxy->accessData();
1073 if (!dobj) {
1074 // invalid dobj
1075 if (!quiet) {
1076 REPORT_MESSAGE(MSG::WARNING)
1077 << "this proxy " << MSG::hex << proxy
1078 << MSG::dec << " has a NULL data object ptr";
1079 }
1080 return nullptr;
1081 }
1082
1083 const CLID clid = this->clid();
1084 void* ptr = SG::Storable_cast(dobj, clid, nullptr, true, proxy);
1085 if (ptr)
1086 return ptr;
1087
1088 // If ptr is null, probably the clid we gave wasn't the clid
1089 // the object was stored with, nor it inherits from it.
1090 // before giving up, let's check its transient CLIDs
1091 DataBucketBase *dbb = 0;
1092 if (proxy->transientID(clid) &&
1093 0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
1094 // it is a symlink after all.
1095 // Let's hard cast (and keep our fingers Xed)
1096 ptr = static_cast<void*>(dbb->object());
1097 } else {
1098 if (!quiet) {
1099 REPORT_MESSAGE(MSG::WARNING)
1100 << "Request for an invalid object; requested CLID = "
1101 << clid
1102 << ", proxy primary ID is " << proxy->clID();
1103 }
1104 } // try symlink -- endif
1105 return ptr;
1106 }
1107
1108
1115 bool VarHandleBase::isPresent_impl (const std::string& key) const
1116 {
1117 const DataProxy* proxy = m_proxy;
1118 if (!proxy) {
1119 const IProxyDict* store = m_store;
1120 if (!store)
1121 store = this->storeHandle().get();
1122 if (store)
1123 proxy = store->proxy(this->clid(), key);
1124 }
1125 if (proxy) {
1126 return proxy->isValid();
1127 }
1128 return false;
1129 }
1130
1131
1132//*************************************************************************
1133 // Free functions.
1134 //
1135
1136
1142 std::ostream& operator<<( std::ostream& out, const VarHandleBase& o )
1143 {
1144 out << "VarHandleBase @" << &o
1145 << " store=" <<o.store()
1146 << ", clid=" <<o.clid()
1147 << ", key=" <<o.key()
1148 << "----------- ptr@" << o.m_ptr
1149 << ", proxy@" << o.m_proxy ;
1150 if (o.m_proxy)
1151 out << ", DataObject@" << o.m_proxy->object();
1152 return out;
1153 }
1154
1155
1159 bool operator==(const VarHandleBase& l, const VarHandleBase& r)
1160 {
1161 return (l.clid() == r.clid() &&
1162 l.mode() == r.mode() &&
1163 l.name() == r.name() &&
1164 l.store() == r.store());
1165 }
1166
1167
1171 bool operator!=(const VarHandleBase& l, const VarHandleBase& r)
1172 {
1173 return !(l==r);
1174 }
1175
1176
1177} /* namespace SG */
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
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(febId1==febId2)
convert to and from a SG storable
Base class for VarHandle classes.
const char *const fmt
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.
a resetable object (e.g.
Definition IResetable.h:15
The Athena Transient Store API.
Definition SGImplSvc.h:110
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
int r
Definition globals.cxx:22
#define DEBUG_VHB
bool dbg
Definition listroot.cxx:36
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.
TestStore store
Definition TestStore.cxx:23
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.
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:74
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition SGImplSvc.cxx:70
std::string context_name(const INamedInterface *context)
Return the context name from a context (this) pointer.
STL namespace.
void initialize()