ATLAS Offline Software
StoreGate/src/VarHandleBase.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2021 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 
17 #include "StoreGate/StoreGateSvc.h"
19 #include "StoreGate/exceptions.h"
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
41 namespace dbg {
42 template <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 
47 template <class T> void* ptr(T* p) { return static_cast<void*>(p); }
48 
49 std::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 
54 std::string store(IProxyDict* store)
55 {
56  return !store ? std::string("null_store") : store->name();
57 }
58 }
59 #endif
60 
61 namespace 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 
78 namespace 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 
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)),
120  m_key (m_ownedKey.get())
121  {
122  m_ownedKey->setOwningHandle (this);
123 #ifdef DEBUG_VHB
124  dbg::print(stderr, "VarHandleBase() {}\n", dbg::ptr(this));
125 #endif
126  }
127 
128 
137  const std::string& sgkey,
139  const std::string& storename) :
140  IResetable(),
141  m_ptr(NULL),
142  m_proxy(NULL),
143  m_store(nullptr),
144  m_storeWasSet(false),
145  m_ownedKey (std::make_unique<VarHandleKey> (clid, sgkey, mode, storename)),
146  m_key (m_ownedKey.get())
147  {
148  m_ownedKey->setOwningHandle (this);
149  }
150 
151 
161  const EventContext* ctx)
162  : IResetable(),
163  m_ptr(nullptr),
164  m_proxy(nullptr),
165  m_store(nullptr),
166  m_storeWasSet(false),
167  m_key (&key)
168  {
169  if (key.storeHandle().get() == nullptr) {
170  throw SG::ExcUninitKey (key.clid(), key.key(),
171  key.storeHandle().name());
172  }
173 
174  if (!setStoreFromHandle(ctx)) {
175  throw SG::ExcHandleInitError (key.clid(), key.key(),
176  key.storeHandle().name());
177  }
178  }
179 
180 
190  : IResetable(),
191  m_ptr (nullptr),
192  m_proxy (nullptr),
193  m_store (proxy->store()),
194  m_storeWasSet (true),
195  m_ownedKey (std::make_unique<VarHandleKey> (proxy->clID(),
196  proxy->name(),
197  mode,
198  m_store ? m_store->name() : "")),
199  m_key (m_ownedKey.get())
200  {
201  m_ownedKey->setOwningHandle (this);
202  setProxy (proxy);
203  }
204 
205 
210  IResetable(),
211  m_ptr(rhs.m_ptr),
212  m_proxy(nullptr),
213  m_store(rhs.m_store),
214  m_storeWasSet(rhs.m_storeWasSet)
215  {
216  if (rhs.m_ownedKey) {
217  m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
218  m_ownedKey->setOwningHandle (this);
219  m_key = m_ownedKey.get();
220  }
221  else {
222  m_key = rhs.m_key;
223  }
224 #ifdef DEBUG_VHB
225  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));
226 #endif
227 
228  setProxy (rhs.m_proxy);
229  }
230 
231 
236  IResetable(),
237  m_ptr(rhs.m_ptr),
238  m_proxy(nullptr),
239  m_store(rhs.m_store),
240  m_storeWasSet(rhs.m_storeWasSet),
241  m_ownedKey (std::move (rhs.m_ownedKey)),
242  m_key (rhs.m_key)
243  {
244  if (m_ownedKey) {
245  m_ownedKey->setOwningHandle (this);
246  }
247  rhs.m_ptr=0;
248 
249  if (rhs.m_proxy) {
250  if (m_ownedKey) {
251  rhs.m_proxy->unbindHandle (&rhs);
252  rhs.m_proxy->bindHandle(this);
253  }
254  m_proxy = rhs.m_proxy;
255  rhs.m_proxy=0; //no release: this has the ref now
256  }
257 #ifdef DEBUG_VHB
258  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));
259 #endif
260  }
261 
262 
266  VarHandleBase&
268  {
269  if (this != &rhs) {
270  if (rhs.m_ownedKey) {
271  m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
272  m_ownedKey->setOwningHandle (this);
273  m_key = m_ownedKey.get();
274  }
275  else {
276  m_key = rhs.m_key;
277  m_ownedKey.reset();
278  }
279 
280  m_ptr = rhs.m_ptr;
281  m_store = rhs.m_store;
283  setProxy (rhs.m_proxy);
284  }
285 #ifdef DEBUG_VHB
286  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));
287 #endif
288  return *this;
289  }
290 
291 
295  VarHandleBase&
297  {
298  if (this != &rhs) {
299  m_ownedKey = std::move (rhs.m_ownedKey);
300  if (m_ownedKey) {
301  m_ownedKey->setOwningHandle (this);
302  }
303  m_key = rhs.m_key;
304 
305  m_ptr = rhs.m_ptr;
306  m_store = rhs.m_store;
307  m_storeWasSet = rhs.m_storeWasSet;
308 
309  rhs.m_ptr=0;
310 
311  resetProxy();
312  if (rhs.m_proxy) {
313  if (m_ownedKey) {
314  rhs.m_proxy->unbindHandle (&rhs);
315  rhs.m_proxy->bindHandle (this);
316  }
317  m_proxy = rhs.m_proxy;
318  rhs.m_proxy=0; //no release: this has the ref now
319  }
320  }
321 #ifdef DEBUG_VHB
322  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));
323 #endif
324  return *this;
325  }
326 
327 
332  {
333 #ifdef DEBUG_VHB
334  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));
335 #endif
336 
337  if (m_ownedKey) {
338  resetProxy();
339  }
340  m_ptr = 0;
341  }
342 
343 
344 
345  //*************************************************************************
346  // Accessors
347  //
348 
349 
356  const std::string& VarHandleBase::key() const
357  {
358  return m_key->key();
359  }
360 
361 
367  const std::string& VarHandleBase::name() const
368  {
369  return this->key();
370  }
371 
372 
376  std::string VarHandleBase::store() const
377  {
378  if (m_store)
379  return m_store->name();
380  return this->storeHandle().name();
381  }
382 
383 
384  //*************************************************************************
385  // Validity checking.
386  //
387 
388 
395  {
396  return isPresent_impl (key());
397  }
398 
399 
405  bool
407  {
408 #ifdef DEBUG_VHB
409  dbg::print(stderr, "::VHB::isInitialized({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
410 #endif
411  return (0 != m_proxy);
412  }
413 
414 
420  bool VarHandleBase::isSet() const
421  {
422  return isInitialized();
423  }
424 
425 
431  bool
433  {
434 #ifdef DEBUG_VHB
435  dbg::print(stderr, "::VHB::isConst({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
436 #endif
437  return 0 != m_proxy
438  ? m_proxy->isConst()
439  : false;
440  }
441 
442 
451  StatusCode
452  VarHandleBase::initialize (bool used /*= true*/)
453  {
454  if (!used) {
455  if (m_ownedKey) {
456  CHECK( m_ownedKey->initialize (used) );
457  }
458  return StatusCode::SUCCESS;
459  }
460 
461  if (!m_store) {
462  if (m_ownedKey) {
463  CHECK( m_ownedKey->initialize() );
464  }
465  m_store = &*(this->storeHandle());
466  m_storeWasSet = false;
467  }
468 
469  if (!m_store) {
470  return StatusCode::FAILURE;
471  }
472 
473  return StatusCode::SUCCESS;
474  }
475 
476 
486  StatusCode
488  {
489  CHECK( initialize() );
490  if (!m_storeWasSet) {
491  IProxyDict* store = storeFromHandle (nullptr);
492  if (store) m_store = store;
493  }
494 
495 #ifdef DEBUG_VHB
496  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());
497 #endif
498 
500  if (!proxy) {
501 #ifdef DEBUG_VHB
502  dbg::print(stderr, "::VHB:: setState() on {} ==> null proxy!\n", dbg::ptr(this));
503 #endif
504  proxy = m_store->proxy(this->clid(), this->key());
505  }
506 
507  if (!proxy) {
508 #ifdef DEBUG_VHB
509  dbg::print(stderr, "::VHB:: setState() on {} ==> STILL null proxy!\n", dbg::ptr(this));
510 #endif
511  }
512  else if (!proxy->isValid()) {
513 #ifdef DEBUG_VHB
514  dbg::print(stderr, "::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n", dbg::ptr(this));
515  if (!m_store) {
516  dbg::print(stderr, "::VHB:: setState() on {} ==> m_store is a nullptr\n", dbg::ptr(this));
517  }
518  else {
519  SGImplSvc* stor = dynamic_cast<SGImplSvc*>(m_store);
520  if (!stor) {
521  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()));
522  }
523  else {
524  dbg::print(stderr, "\n{}\n", stor->dump());
525  }
526  }
527 #endif
528  }
529  StatusCode sc = this->setState(proxy);
530 
531  // Failure to find the proxy is ok in the case of a @c WriteHandle
532  // that has not yet been written to.
533  if (sc.isFailure() && mode() == Gaudi::DataHandle::Writer && m_ptr == nullptr)
534  return StatusCode::SUCCESS;
535 
536  return sc;
537  }
538 
539 
540  //*************************************************************************
541  // State setting.
542  //
543 
544 
552  {
553  reset(true);
554  m_store = store;
555  m_storeWasSet = true;
556  return StatusCode::SUCCESS;
557  }
558 
559 
569  void
570  VarHandleBase::reset (bool hard) {
571 #ifdef DEBUG_VHB
572  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);
573 #endif
574  m_ptr = 0;
575 
576  if (hard) {
577  m_store = 0;
578  m_storeWasSet = false;
579  }
580 
581  //if the proxy is not resetOnly then release it as it will become invalid
582  // Also release on a hard reset.
583  if (0 != m_proxy && (!m_proxy->isResetOnly() || hard)) {
584  resetProxy();
585  }
586  }
587 
588 
596 #ifdef DEBUG_VHB
597  dbg::print(stderr, "::VHB::finalReset {} with proxy={}, key={}, store={}\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store));
598 #endif
599  reset (true);
600  }
601 
602 
607  {
608  if (typeless_dataPointer()) {
609  m_proxy->setConst();
610  return StatusCode::SUCCESS;
611  }
612  return StatusCode::FAILURE;
613  }
614 
615 
624  {
625  if (!m_ownedKey) {
627  m_key->storeHandle().name());
628  }
629  return *m_ownedKey;
630  }
631 
632 
643  {
644  return vhKey().assign (sgkey);
645  }
646 
647 
648  //*************************************************************************
649  // Protected methods.
650  //
651 
652 
659  StatusCode
661  {
662 #ifdef DEBUG_VHB
663  dbg::print(stderr, "::VHB::setState({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(proxy));
664 #endif
665  if (0 == proxy || !proxy->isValid()) {
666  return StatusCode::FAILURE;
667  }
668 
669  if (m_proxy != proxy) {
670  // We're changing proxies. Release the old and bind to the new.
671  setProxy (proxy);
672  // Clear cached pointer.
673  m_ptr=0;
674  }
675 
676  return StatusCode::SUCCESS;
677  }
678 
679 
685  StatusCode
687  {
688  if (0 == store) {
689  return StatusCode::FAILURE;
690  }
691 #ifdef DEBUG_VHB
692  dbg::print(stderr, "::VHB::setState({}, store={}, key={}) const\n", dbg::ptr(this), dbg::store(store), key);
693 #endif
694  CLID cid = this->clid();
695  SG::DataProxy* proxy = store->proxy(cid, key);
696  // std::cerr << "::VHB:: -- clid=[" << cid << "] proxy=[" << proxy << "]\n";
697  return this->setState(proxy);
698  }
699 
700 
712  StatusCode
713  VarHandleBase::record_impl (std::unique_ptr<DataObject> dobj,
714  void* dataPtr,
715  bool allowMods,
716  bool returnExisting)
717  {
718  if (!m_store) {
719  if (m_ownedKey) {
720  CHECK (m_ownedKey->initialize());
721  }
722  m_store = &*(this->storeHandle());
723  m_storeWasSet = false;
724  }
725 
726  if (this->name().empty()) {
727  REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
728  return StatusCode::FAILURE;
729  }
730 
731  SG::DataObjectSharedPtr<DataObject> sptr (dobj.release());
732  unsigned int initRefCount = sptr->refCount();
733  SG::DataProxy* new_proxy =
734  m_store->recordObject (sptr, this->name(), allowMods, returnExisting);
735  if (!new_proxy) {
736  REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
737  resetProxy();
738  return StatusCode::FAILURE;
739  }
740  if (m_proxy != new_proxy) {
741  CHECK (this->setState (new_proxy));
742  }
743 
744  if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
745  // If the reference count hasn't changed, then we've returned an existing
746  // object rather than recording a new one. Retrieve the pointer, making
747  // sure that it isn't const.
748  if (m_proxy->isConst()) {
749  REPORT_ERROR (StatusCode::FAILURE)
750  << "Found an existing const object from recordOrRetrieve.";
751  return StatusCode::FAILURE;
752  }
754  if (!allowMods)
755  CHECK( setConst() );
756  }
757  else
758  m_ptr=(void*)dataPtr;
759 
760  return StatusCode::SUCCESS;
761  }
762 
763 
781  const void*
782  VarHandleBase::put_impl (const EventContext* ctx,
783  std::unique_ptr<DataObject> dobj,
784  const void* dataPtr,
785  bool allowMods,
786  bool returnExisting,
787  IProxyDict* & store) const
788  {
789  if (this->name().empty()) {
790  REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
791  return nullptr;
792  }
793 
794  store = storeFromHandle (ctx);
795  if (!store) {
796  REPORT_ERROR (StatusCode::FAILURE) << "No store.";
797  return nullptr;
798  }
799 
800  SG::DataObjectSharedPtr<DataObject> sptr (std::move (dobj));
801  unsigned int initRefCount = sptr->refCount();
802  SG::DataProxy* new_proxy =
803  store->recordObject (sptr, this->name(), allowMods, returnExisting);
804  if (!new_proxy) {
805  REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
806  return nullptr;
807  }
808 
809  if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
810  // If the reference count hasn't changed, then we've returned an existing
811  // object rather than recording a new one. Retrieve the pointer.
812  dataPtr = typeless_dataPointer_fromProxy (new_proxy, true);
813  }
814 
815  return dataPtr;
816  }
817 
818 
823  void*
825  {
826 #ifdef DEBUG_VHB
827  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));
828 #endif
829 
830  // First check for cached pointer.
831  if (0 != m_ptr)
832  return m_ptr;
833 
834  if (0 == m_proxy) {
835  // No proxy, need to look it up.
836  if (this->setState().isFailure() || !m_proxy) {
837  if (!quiet) {
838  REPORT_MESSAGE(MSG::WARNING)
839  << "could not get proxy for key " << key();
840  if (this->mode() != Gaudi::DataHandle::Reader) {
841  REPORT_MESSAGE(MSG::WARNING)<< " try using a ReadHandle";
842  }
843  } //quiet
844  return 0;
845  } //setstate
846  } //m_proxy
847 
849  return m_ptr;
850  }
851 
852 
859  void* VarHandleBase::typeless_ptr(bool quiet/*=defaultQuiet*/)
860  {
861  void* p = typeless_dataPointer(quiet);
862  if (p != nullptr && isConst())
863  throw SG::ExcConstObject (clid(), key(), store());
864  return p;
865  }
866 
867 
868  /*
869  * @brief Retrieve an object from SG as a const pointer without caching.
870  * @param ctx The event context, or nullptr to use the current context.
871  * @param quiet If true, suppress failure messages.
872  *
873  * Like typeless_dataPointer_impl, except that we don't change
874  * any members of the handle.
875  */
876  const void* VarHandleBase::get_impl (const EventContext* ctx,
877  bool quiet/*= defaultQuiet*/) const
878  {
879  if (this->mode() != Gaudi::DataHandle::Reader) {
880  if (!quiet)
881  REPORT_ERROR (StatusCode::FAILURE)
882  << "get_impl called for a non-read handle.";
883  return nullptr;
884  }
885 
886  if (this->key().empty()) {
887  if (!quiet)
888  REPORT_ERROR (StatusCode::FAILURE)
889  << "Cannot initialize a Read/Write/Update handle with a null key.";
890  return nullptr;
891  }
892 
894  if (!store) {
895  if (!quiet)
896  REPORT_ERROR (StatusCode::FAILURE) << "No store.";
897  return nullptr;
898  }
899 
900  SG::DataProxy* proxy = store->proxy_exact(m_key->hashedKey());
901  if (!proxy) {
902  proxy = store->proxy(this->clid(), this->key());
903  if (!proxy) {
904  if (!quiet)
905  REPORT_ERROR (StatusCode::FAILURE)
906  << "Cannot find proxy for "
907  << this->clid() << "/" << this->key();
908  return nullptr;
909  }
910  }
911 
912  return typeless_dataPointer_fromProxy (proxy, quiet);
913  }
914 
915 
927  const std::string& newKey)
928  {
929  if (!m_ptr || !m_store) {
930  REPORT_ERROR (StatusCode::FAILURE) << "symlink: Handle not valid.";
931  return StatusCode::FAILURE;
932  }
933 
935  SG::DataProxy* prox = m_store->recordObject (obj, newKey, false, true);
936  if (!prox)
937  return StatusCode::FAILURE;
938  return StatusCode::SUCCESS;
939  }
940 
941 
957  IProxyDict* VarHandleBase::storeFromHandle (const EventContext* ctx) const
958  {
959  if (m_key->isEventStore()) {
960  if (ctx)
961  return Atlas::getExtendedEventContext(*ctx).proxy();
962  if (m_storeWasSet && m_store) return m_store;
963 
964  if ( Atlas::hasExtendedEventContext (Gaudi::Hive::currentContext()) ) {
965  return Atlas::getExtendedEventContext (Gaudi::Hive::currentContext()).proxy();
966  } else {
967  return nullptr;
968  }
969  }
970 
971  if (m_storeWasSet && m_store) return m_store;
973  if (!store)
974  store = &*this->storeHandle();
975 
976  return store->hiveProxyDict();
977  }
978 
979 
987  bool VarHandleBase::setStoreFromHandle (const EventContext* ctx)
988  {
989  if (m_ownedKey) {
990  if (m_ownedKey->initialize().isFailure()) {
991  return false;
992  }
993  }
994  m_store = storeFromHandle (ctx);
995  m_storeWasSet = (ctx && m_store ==
996  Atlas::getExtendedEventContext(*ctx).proxy());
997  return true;
998  }
999 
1000 
1005  {
1006  if (m_proxy) {
1007  if (m_ownedKey) {
1008  m_proxy->unbindHandle(this);
1009  m_proxy->release();
1010  }
1011  m_proxy = nullptr;
1012  }
1013  }
1014 
1015 
1021  {
1022  resetProxy();
1023  if (proxy) {
1024  if (m_ownedKey) {
1025  proxy->addRef();
1026  proxy->bindHandle (this);
1027  }
1028  m_proxy = proxy;
1029  }
1030  }
1031 
1032 
1040  void*
1042  bool quiet) const
1043  {
1044  if (!proxy || !proxy->isValid()) {
1045  // invalid proxy
1046  if (!quiet) {
1047  REPORT_MESSAGE(MSG::WARNING)
1048  << "Proxy "
1049  << " [" << (proxy != 0 ? proxy->clID() : 0)
1050  << "/" << (proxy != 0
1051  ? proxy->name()
1052  : std::string("<N/A>"))
1053  << "] is in an invalid state";
1054  } //quiet
1055  return nullptr;
1056  }
1057 
1058  DataObject* dobj = proxy->accessData();
1059  if (!dobj) {
1060  // invalid dobj
1061  if (!quiet) {
1062  REPORT_MESSAGE(MSG::WARNING)
1063  << "this proxy " << MSG::hex << proxy
1064  << MSG::dec << " has a NULL data object ptr";
1065  }
1066  return nullptr;
1067  }
1068 
1069  const CLID clid = this->clid();
1070  void* ptr = SG::Storable_cast(dobj, clid, proxy);
1071  if (ptr)
1072  return ptr;
1073 
1074  // If ptr is null, probably the clid we gave wasn't the clid
1075  // the object was stored with, nor it inherits from it.
1076  // before giving up, let's check its transient CLIDs
1077  DataBucketBase *dbb = 0;
1078  if (proxy->transientID(clid) &&
1079  0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
1080  // it is a symlink after all.
1081  // Let's hard cast (and keep our fingers Xed)
1082  ptr = static_cast<void*>(dbb->object());
1083  } else {
1084  if (!quiet) {
1085  REPORT_MESSAGE(MSG::WARNING)
1086  << "Request for an invalid object; requested CLID = "
1087  << clid
1088  << ", proxy primary ID is " << proxy->clID();
1089  }
1090  } // try symlink -- endif
1091  return ptr;
1092  }
1093 
1094 
1101  bool VarHandleBase::isPresent_impl (const std::string& key) const
1102  {
1103  const DataProxy* proxy = m_proxy;
1104  if (!proxy) {
1105  const IProxyDict* store = m_store;
1106  if (!store)
1107  store = this->storeHandle().get();
1108  if (store)
1109  proxy = store->proxy(this->clid(), key);
1110  }
1111  if (proxy) {
1112  return proxy->isValid();
1113  }
1114  return false;
1115  }
1116 
1117 
1118 //*************************************************************************
1119  // Free functions.
1120  //
1121 
1122 
1128  std::ostream& operator<<( std::ostream& out, const VarHandleBase& o )
1129  {
1130  out << "VarHandleBase @" << &o
1131  << " store=" <<o.store()
1132  << ", clid=" <<o.clid()
1133  << ", key=" <<o.key()
1134  << "----------- ptr@" << o.m_ptr
1135  << ", proxy@" << o.m_proxy ;
1136  if (o.m_proxy)
1137  out << ", DataObject@" << o.m_proxy->object();
1138  return out;
1139  }
1140 
1141 
1145  bool operator==(const VarHandleBase& l, const VarHandleBase& r)
1146  {
1147  return (l.clid() == r.clid() &&
1148  l.mode() == r.mode() &&
1149  l.name() == r.name() &&
1150  l.store() == r.store());
1151  }
1152 
1153 
1157  bool operator!=(const VarHandleBase& l, const VarHandleBase& r)
1158  {
1159  return !(l==r);
1160  }
1161 
1162 
1163 } /* namespace SG */
VarHandleBase.h
Base class for VarHandle classes.
SG::operator!=
bool operator!=(const VarHandleBase &l, const VarHandleBase &r)
Inequality comparison.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:129
SG::IRegisterTransient
Interface for registering a transient object in t2p map.
Definition: IRegisterTransient.h:28
used
SGTest::store
TestStore store
Definition: TestStore.cxx:23
beamspotman.r
def r
Definition: beamspotman.py:676
common.sgkey
def sgkey(tool)
Definition: common.py:1028
SG::VarHandleBase::VarHandleBase
VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode)
Constructor with default key.
Definition: StoreGate/src/VarHandleBase.cxx:113
REPORT_ERROR
#define REPORT_ERROR(SC)
Report an error.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:355
IProxyDict::proxy
virtual SG::DataProxy * proxy(const CLID &id, const std::string &key) const =0
Get proxy with given id and key.
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
IHiveStore.h
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::DataProxy::isConst
bool isConst() const
Check if it is a const object.
SG::VarHandleBase::storeFromHandle
IProxyDict * storeFromHandle(const EventContext *ctx) const
Return the store instance to use.
Definition: StoreGate/src/VarHandleBase.cxx:957
vtune_athena.format
format
Definition: vtune_athena.py:14
SG::VarHandleBase::m_ownedKey
std::unique_ptr< VarHandleKey > m_ownedKey
An owned VarHandleKey.
Definition: StoreGate/StoreGate/VarHandleBase.h:518
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
SG::VarHandleBase::finalReset
virtual void finalReset() override final
Reset this handle at the end of processing.
Definition: StoreGate/src/VarHandleBase.cxx:595
SG::VarHandleBase::typeless_dataPointer
void * typeless_dataPointer(bool quiet=defaultQuiet)
Retrieve an object from StoreGate.
SG::SymlinkDataObject::tinfo
virtual const std::type_info & tinfo() const override
Return the type_info for the stored object.
Definition: StoreGate/src/VarHandleBase.cxx:94
DataBucketBase
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
Definition: DataBucketBase.h:24
DataBucketBase.h
StorableConversions.h
convert to and from a SG storable
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
quiet
bool quiet
Definition: TrigGlobEffCorrValidation.cxx:190
SG::VarHandleKey::storeHandle
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
SG::VarHandleBase::assign
StatusCode assign(const std::string &sgkey)
Update the underlying key from a string.
Definition: StoreGate/src/VarHandleBase.cxx:642
SG::VarHandleBase::setState
StatusCode setState()
Retrieve and cache all information managed by a handle.
Definition: StoreGate/src/VarHandleBase.cxx:487
SG::VarHandleBase
Base class for VarHandle types.
Definition: StoreGate/StoreGate/VarHandleBase.h:83
ExtendedEventContext.h
DataBucketBase::object
virtual void * object()=0
SG::VarHandleBase::clid
CLID clid() const
Return the class ID for the referenced object.
SG::VarHandleBase::typeless_dataPointer_impl
void * typeless_dataPointer_impl(bool quiet)
Retrieve an object from StoreGate.
Definition: StoreGate/src/VarHandleBase.cxx:824
Atlas::hasExtendedEventContext
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
Definition: ExtendedEventContext.cxx:23
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
SG::operator==
bool operator==(const VarHandleBase &l, const VarHandleBase &r)
Equality comparison.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:119
SG::VarHandleBase::operator=
VarHandleBase & operator=(const VarHandleBase &rhs)
Assignment operator.
Definition: StoreGate/src/VarHandleBase.cxx:267
get_generator_info.stderr
stderr
Definition: get_generator_info.py:40
SG::SymlinkDataObject::cast
virtual void * cast(CLID, SG::IRegisterTransient *, bool) override
Return the contents of the DataBucket, converted to type given by clid.
Definition: StoreGate/src/VarHandleBase.cxx:96
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
SG::DataProxy::isValid
bool isValid() const
called by destructor
errorcheck::context_name
std::string context_name(const INamedInterface *context)
Return the context name from a context (this) pointer.
Definition: errorcheck.cxx:230
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:620
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
DataBucketBase::cast
T * cast(SG::IRegisterTransient *irt=0, bool isConst=true)
Return the contents of the DataBucket, converted to type T.
Args
Definition: test_lwtnn_fastgraph.cxx:12
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::VarHandleBase::setConst
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
Definition: StoreGate/src/VarHandleBase.cxx:606
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
SG::DataProxy::unbindHandle
void unbindHandle(IResetable *ir)
Definition: DataProxy.cxx:293
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
SG::SymlinkDataObject::SymlinkDataObject
SymlinkDataObject(CLID clid, void *obj)
Definition: StoreGate/src/VarHandleBase.cxx:91
Atlas::getExtendedEventContext
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
Definition: ExtendedEventContext.cxx:32
errorcheck
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:138
IProxyDict::proxy_exact
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const =0
Get proxy given a hashed key+clid.
IResetable
a resetable object (e.g. a SG DataHandle)
Definition: IResetable.h:15
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::SymlinkDataObject::clID
virtual const CLID & clID() const override
Definition: StoreGate/src/VarHandleBase.cxx:92
SG::VarHandleBase::setProxyDict
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
Definition: StoreGate/src/VarHandleBase.cxx:551
SG::SymlinkDataObject::lock
virtual void lock() override
If the held object derives from ILockable, call lock() on it.
Definition: StoreGate/src/VarHandleBase.cxx:99
SG::VarHandleBase::resetProxy
void resetProxy()
Clear the m_proxy field and release the old proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1004
exceptions.h
Exceptions that can be thrown from StoreGate.
SG::VarHandleKey::assign
virtual StatusCode assign(const std::string &sgkey)
Change the key of the object to which we're referring.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:88
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::VarHandleBase::m_key
const VarHandleKey * m_key
The associated key object.
Definition: StoreGate/StoreGate/VarHandleBase.h:523
SGImplSvc.h
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:376
LHEF::Reader
Pythia8::Reader Reader
Definition: Prophecy4fMerger.cxx:11
SG::SymlinkDataObject::cast
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.
Definition: StoreGate/src/VarHandleBase.cxx:97
SG::VarHandleKey::isEventStore
bool isEventStore() const
Does this key reference the primary event store?
Preparation.mode
mode
Definition: Preparation.py:94
SGImplSvc
The Athena Transient Store API.
Definition: SGImplSvc.h:112
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleBase::m_proxy
SG::DataProxy * m_proxy
Proxy holding the object to which we are bound.
Definition: StoreGate/StoreGate/VarHandleBase.h:505
SG::ExcConstObject
Exception — Tried to retrieve non-const pointer to const object.
Definition: Control/StoreGate/StoreGate/exceptions.h:134
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::VarHandleBase::isInitialized
bool isInitialized() const
Has a proxy been retrieved from SG?
Definition: StoreGate/src/VarHandleBase.cxx:406
SG::DataProxy::release
virtual unsigned long release() override final
release reference to object
Definition: DataProxy.cxx:320
SGImplSvc::dump
std::string dump() const
dump objects in store.
Definition: SGImplSvc.cxx:557
dbg
Definition: SGImplSvc.cxx:69
SG::SymlinkDataObject
Helper for symLink_impl.
Definition: StoreGate/src/VarHandleBase.cxx:89
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::VarHandleBase::mode
Gaudi::DataHandle::Mode mode() const
Return the mode (read/write/update) for this handle.
errorcheck.h
Helpers for checking error return status codes and reporting errors.
EventContainers::Mode
Mode
Definition: IdentifiableContainerBase.h:13
SG::SymlinkDataObject::object
virtual void * object() override
Definition: StoreGate/src/VarHandleBase.cxx:93
SG::VarHandleBase::isPresent_impl
bool isPresent_impl(const std::string &key) const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:1101
SG::VarHandleBase::reset
virtual void reset(bool hard) override
Reset this handle.
Definition: StoreGate/src/VarHandleBase.cxx:570
SG::VarHandleBase::typeless_dataPointer_fromProxy
void * typeless_dataPointer_fromProxy(SG::DataProxy *proxy, bool quiet) const
Retrieve a pointer from a proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1041
SG::VarHandleKey::clid
CLID clid() const
Return the class ID for the referenced object.
Definition: StoreGate/src/VarHandleKey.cxx:177
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
SG::VarHandleBase::~VarHandleBase
virtual ~VarHandleBase() override
Destructor.
Definition: StoreGate/src/VarHandleBase.cxx:331
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
SG::throwExcNonConstHandleKey
void throwExcNonConstHandleKey(CLID clid, const std::string &sgkey, const std::string &storename)
Throw a SG::ExcNonConstHandleKey exception.
Definition: Control/StoreGate/src/exceptions.cxx:337
SG::VarHandleBase::storeHandle
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
SG::VarHandleBase::setStoreFromHandle
bool setStoreFromHandle(const EventContext *ctx)
Initialize the store pointer from the store handle.
Definition: StoreGate/src/VarHandleBase.cxx:987
fmt
SG::Storable_cast
T * Storable_cast(DataObject *pDObj, bool quiet=true, IRegisterTransient *irt=0, bool isConst=true)
Definition: StorableConversions.h:42
SG::ExcUninitKey
Exception — Tried to create a handle from an uninitialized key.
Definition: Control/StoreGate/StoreGate/exceptions.h:111
SG::VarHandleBase::typeless_ptr
void * typeless_ptr(bool quiet=defaultQuiet)
Retrieve an object from StoreGate as non-const pointer.
Definition: StoreGate/src/VarHandleBase.cxx:859
SG::DataProxy::setConst
void setConst()
Mark this object as const.
Definition: DataProxy.cxx:204
SG::VarHandleKey::hashedKey
SG::sgkey_t hashedKey() const
Return the hashed StoreGate key.
SG::VarHandleBase::initialize
StatusCode initialize(bool used=true)
Verify that the handle has been configured properly.
Definition: StoreGate/src/VarHandleBase.cxx:452
SG::ExcHandleInitError
Exception — Error initializing VarHandle from VarHandleKey.
Definition: Control/StoreGate/StoreGate/exceptions.h:92
SG::VarHandleBase::vhKey
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
Definition: StoreGate/src/VarHandleBase.cxx:623
SG::VarHandleBase::m_storeWasSet
bool m_storeWasSet
True if the store was set explicitly via setProxyDict.
Definition: StoreGate/StoreGate/VarHandleBase.h:511
SG::VarHandleBase::m_ptr
void * m_ptr
The object to which we are bound.
Definition: StoreGate/StoreGate/VarHandleBase.h:502
IProxyDict::recordObject
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting)=0
Record an object in the store.
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:394
SG::DataProxy::isResetOnly
bool isResetOnly() const
Check reset only:
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70
SG::VarHandleBase::isConst
bool isConst() const
True if this handle has a proxy, and the proxy is const.
Definition: StoreGate/src/VarHandleBase.cxx:432
LHEF::Writer
Pythia8::Writer Writer
Definition: Prophecy4fMerger.cxx:12
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:45
SG::VarHandleBase::put_impl
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.
Definition: StoreGate/src/VarHandleBase.cxx:782
SG::SymlinkDataObject::m_obj
void * m_obj
Definition: StoreGate/src/VarHandleBase.cxx:104
SG::get
const T * get(const ReadHandleKey< T > &key)
Convenience function to retrieve an object given a ReadHandleKey.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::VarHandleBase::m_store
IProxyDict * m_store
Pointer to the store that owns the object.
Definition: StoreGate/StoreGate/VarHandleBase.h:508
SG::DataProxy
Definition: DataProxy.h:45
SG::SymlinkDataObject::relinquish
virtual void relinquish() override
Give up ownership of the DataBucket contents.
Definition: StoreGate/src/VarHandleBase.cxx:98
SG::VarHandleBase::isSet
virtual bool isSet() const override final
Has a proxy been retrieved from SG?
Definition: StoreGate/src/VarHandleBase.cxx:420
StoreGateSvc.h
SG::VarHandleBase::record_impl
StatusCode record_impl(std::unique_ptr< DataObject > dobj, void *dataPtr, bool allowMods, bool returnExisting)
Helper to record an object in the event store.
Definition: StoreGate/src/VarHandleBase.cxx:713
IProxyDict::hiveProxyDict
virtual IProxyDict * hiveProxyDict() override
Return the current event-slot-specific store.
Definition: IProxyDict.cxx:83
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
SG::operator<<
std::ostream & operator<<(std::ostream &os, const ArenaAllocatorBase::Stats::Stat &stat)
Format a statistic structure.
Definition: ArenaAllocatorBase.cxx:61
SG::VarHandleBase::symLink_impl
StatusCode symLink_impl(CLID newClid, const std::string &newKey)
Make a symlink or alias to the object currently referenced by this handle.
Definition: StoreGate/src/VarHandleBase.cxx:926
SG::VarHandleBase::get_impl
const void * get_impl(const EventContext *ctx, bool quiet=defaultQuiet) const
Definition: StoreGate/src/VarHandleBase.cxx:876
SG::SymlinkDataObject::m_clid
CLID m_clid
Definition: StoreGate/src/VarHandleBase.cxx:103
SG::VarHandleBase::setProxy
void setProxy(SG::DataProxy *proxy)
Set a new proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1020
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37