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"
18 #include "StoreGate/exceptions.h"
19 
22 
23 // fwk includes
24 #include "GaudiKernel/MsgStream.h"
29 #include "GaudiKernel/ThreadLocalContext.h"
30 
31 #include <algorithm>
32 #include <sstream>
33 
34 
35 namespace errorcheck {
36 
37 
44  std::string context_name (const SG::VarHandleBase* context)
45  {
46  std::ostringstream ss;
47  ss << "VarHandle("
48  << context->storeHandle().name() << "+" << context->key()
49  << "[" << context->clid() << "]"
50  << ")";
51  return ss.str();
52  }
53 
54 
55 } // namespace errorcheck
56 
57 
58 namespace SG {
59 
60 
68  : public DataBucketBase
69  {
70  public:
71  SymlinkDataObject (CLID clid, void* obj) : m_clid (clid), m_obj (obj) {}
72  virtual const CLID& clID() const override { return m_clid; }
73  virtual void* object() override { return m_obj; }
74  virtual const std::type_info& tinfo() const override { return typeid(void); }
76  virtual void* cast (CLID, SG::IRegisterTransient*, bool) override { std::abort(); }
77  virtual void* cast (const std::type_info&, SG::IRegisterTransient*, bool) override { std::abort(); }
78  virtual void relinquish() override { std::abort(); }
79  virtual void lock() override { }
80 
81 
82  private:
84  void* m_obj;
85  };
86 
87 
94  IResetable(),
95  m_ptr(0),
96  m_proxy(0),
97  m_store(nullptr),
98  m_storeWasSet(false),
99  m_ownedKey (std::make_unique<VarHandleKey> (clid, "", mode)),
100  m_key (m_ownedKey.get())
101  {
102  m_ownedKey->setOwningHandle (this);
103 #ifdef DEBUG_VHB
104  std::cerr << "VarHandleBase() " << this << std::endl;
105 #endif
106  }
107 
108 
117  const std::string& sgkey,
119  const std::string& storename) :
120  IResetable(),
121  m_ptr(NULL),
122  m_proxy(NULL),
123  m_store(nullptr),
124  m_storeWasSet(false),
125  m_ownedKey (std::make_unique<VarHandleKey> (clid, sgkey, mode, storename)),
126  m_key (m_ownedKey.get())
127  {
128  m_ownedKey->setOwningHandle (this);
129  }
130 
131 
141  const EventContext* ctx)
142  : IResetable(),
143  m_ptr(nullptr),
144  m_proxy(nullptr),
145  m_store(nullptr),
146  m_storeWasSet(false),
147  m_key (&key)
148  {
149  if (key.storeHandle().get() == nullptr) {
150  throw SG::ExcUninitKey (key.clid(), key.key(),
151  key.storeHandle().name());
152  }
153 
154  if (!setStoreFromHandle(ctx)) {
155  throw SG::ExcHandleInitError (key.clid(), key.key(),
156  key.storeHandle().name());
157  }
158  }
159 
160 
170  : IResetable(),
171  m_ptr (nullptr),
172  m_proxy (nullptr),
173  m_store (proxy->store()),
174  m_storeWasSet (true),
175  m_ownedKey (std::make_unique<VarHandleKey> (proxy->clID(),
176  proxy->name(),
177  mode,
178  m_store ? m_store->name() : "")),
179  m_key (m_ownedKey.get())
180  {
181  m_ownedKey->setOwningHandle (this);
182  setProxy (proxy);
183  }
184 
185 
190  IResetable(),
191  m_ptr(rhs.m_ptr),
192  m_proxy(nullptr),
193  m_store(rhs.m_store),
194  m_storeWasSet(rhs.m_storeWasSet)
195  {
196  if (rhs.m_ownedKey) {
197  m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
198  m_ownedKey->setOwningHandle (this);
199  m_key = m_ownedKey.get();
200  }
201  else {
202  m_key = rhs.m_key;
203  }
204 #ifdef DEBUG_VHB
205  std::cerr << "::VHB::copy constr from " << &rhs
206  << " to " << this << ", "
207  << "proxy=" << this->m_proxy << ", "
208  << "key=" <<this->key()
209  << std::endl;
210 #endif
211 
212  setProxy (rhs.m_proxy);
213  }
214 
215 
220  IResetable(),
221  m_ptr(rhs.m_ptr),
222  m_proxy(nullptr),
223  m_store(rhs.m_store),
224  m_storeWasSet(rhs.m_storeWasSet),
225  m_ownedKey (std::move (rhs.m_ownedKey)),
226  m_key (rhs.m_key)
227  {
228  if (m_ownedKey) {
229  m_ownedKey->setOwningHandle (this);
230  }
231  rhs.m_ptr=0;
232 
233  if (rhs.m_proxy) {
234  if (m_ownedKey) {
235  rhs.m_proxy->unbindHandle (&rhs);
236  rhs.m_proxy->bindHandle(this);
237  }
238  m_proxy = rhs.m_proxy;
239  rhs.m_proxy=0; //no release: this has the ref now
240  }
241 #ifdef DEBUG_VHB
242  std::cerr << "::VHB:: move constr from " << &rhs
243  << "to " << this << ", "
244  << "proxy=" << this->m_proxy << ", "
245  << "key=" <<this->key()
246  << std::endl;
247 #endif
248  }
249 
250 
254  VarHandleBase&
256  {
257  if (this != &rhs) {
258  if (rhs.m_ownedKey) {
259  m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
260  m_ownedKey->setOwningHandle (this);
261  m_key = m_ownedKey.get();
262  }
263  else {
264  m_key = rhs.m_key;
265  m_ownedKey.reset();
266  }
267 
268  m_ptr = rhs.m_ptr;
269  m_store = rhs.m_store;
271  setProxy (rhs.m_proxy);
272  }
273 #ifdef DEBUG_VHB
274  std::cerr << "::VHB::assignment from " << &rhs
275  << " to " << this << ", "
276  << "proxy=" << this->m_proxy << ", "
277  << "key=" <<this->key()
278  << std::endl;
279 #endif
280  return *this;
281  }
282 
283 
287  VarHandleBase&
289  {
290  if (this != &rhs) {
291  m_ownedKey = std::move (rhs.m_ownedKey);
292  if (m_ownedKey) {
293  m_ownedKey->setOwningHandle (this);
294  }
295  m_key = rhs.m_key;
296 
297  m_ptr = rhs.m_ptr;
298  m_store = rhs.m_store;
299  m_storeWasSet = rhs.m_storeWasSet;
300 
301  rhs.m_ptr=0;
302 
303  resetProxy();
304  if (rhs.m_proxy) {
305  if (m_ownedKey) {
306  rhs.m_proxy->unbindHandle (&rhs);
307  rhs.m_proxy->bindHandle (this);
308  }
309  m_proxy = rhs.m_proxy;
310  rhs.m_proxy=0; //no release: this has the ref now
311  }
312  }
313 #ifdef DEBUG_VHB
314  std::cerr << "::VHB:: move assign from " << &rhs
315  << " to " << this << ", "
316  << "proxy=" << this->m_proxy << ", "
317  << "key=" <<this->key()
318  << std::endl;
319 #endif
320  return *this;
321  }
322 
323 
328  {
329 #ifdef DEBUG_VHB
330  std::cerr << "~VarHandleBase(" << this
331  << ",ptr=" << this->m_ptr
332  << ",proxy=" << this->m_proxy << ", ";
333  if (m_proxy) {
334  std::cerr << " -- isValid: " << m_proxy->isValid()
335  << " -- isConst: " << m_proxy->isConst();
336  }
337  std::cerr << ", key=" <<this->key() << ")...\n";
338 #endif
339 
340  if (m_ownedKey) {
341  resetProxy();
342  }
343  m_ptr = 0;
344  }
345 
346 
347 
348  //*************************************************************************
349  // Accessors
350  //
351 
352 
359  const std::string& VarHandleBase::key() const
360  {
361  return m_key->key();
362  }
363 
364 
370  const std::string& VarHandleBase::name() const
371  {
372  return this->key();
373  }
374 
375 
379  std::string VarHandleBase::store() const
380  {
381  if (m_store)
382  return m_store->name();
383  return this->storeHandle().name();
384  }
385 
386 
387  //*************************************************************************
388  // Validity checking.
389  //
390 
391 
398  {
399  return isPresent_impl (key());
400  }
401 
402 
408  bool
410  {
411 #ifdef DEBUG_VHB
412  std::cerr << "::VHB::isInitialized("
413  << this
414  << ", proxy" << m_proxy << ") const\n";
415 #endif
416  return (0 != m_proxy);
417  }
418 
419 
425  bool VarHandleBase::isSet() const
426  {
427  return isInitialized();
428  }
429 
430 
436  bool
438  {
439 #ifdef DEBUG_VHB
440  std::cerr << "::VHB::isConst("
441  << this
442  << ", proxy" << m_proxy;
443  if (m_proxy) {
444  std::cerr
445  << " -- isValid: " << m_proxy->isValid()
446  << " -- isConst: " << m_proxy->isConst();
447  }
448  std::cerr << ") const\n";
449 #endif
450  return 0 != m_proxy
451  ? m_proxy->isConst()
452  : false;
453  }
454 
455 
464  StatusCode
465  VarHandleBase::initialize (bool used /*= true*/)
466  {
467  if (!used) {
468  if (m_ownedKey) {
469  CHECK( m_ownedKey->initialize (used) );
470  }
471  return StatusCode::SUCCESS;
472  }
473 
474  if (!m_store) {
475  if (m_ownedKey) {
476  CHECK( m_ownedKey->initialize() );
477  }
478  m_store = &*(this->storeHandle());
479  m_storeWasSet = false;
480  }
481 
482  if (!m_store) {
483  return StatusCode::FAILURE;
484  }
485 
486  return StatusCode::SUCCESS;
487  }
488 
489 
499  StatusCode
501  {
502  CHECK( initialize() );
503  if (!m_storeWasSet) {
504  IProxyDict* store = storeFromHandle (nullptr);
505  if (store) m_store = store;
506  }
507 
509  if (!proxy) {
510  proxy = m_store->proxy(this->clid(), this->key());
511  }
512  StatusCode sc = this->setState(proxy);
513 
514  // Failure to find the proxy is ok in the case of a @c WriteHandle
515  // that has not yet been written to.
516  if (sc.isFailure() && mode() == Gaudi::DataHandle::Writer && m_ptr == nullptr)
517  return StatusCode::SUCCESS;
518 
519  return sc;
520  }
521 
522 
523  //*************************************************************************
524  // State setting.
525  //
526 
527 
535  {
536  reset(true);
537  m_store = store;
538  m_storeWasSet = true;
539  return StatusCode::SUCCESS;
540  }
541 
542 
552  void
553  VarHandleBase::reset (bool hard) {
554 #ifdef DEBUG_VHB
555  std::cerr << "::VHB::reset("
556  << "ptr=" << this->m_ptr << ", "
557  << "proxy=" << this->m_proxy << ", "
558  << "key=" <<this->key()
559  << ")..."
560  << std::endl;
561 #endif
562  m_ptr = 0;
563 
564  if (hard) {
565  m_store = 0;
566  m_storeWasSet = false;
567  }
568 
569  //if the proxy is not resetOnly then release it as it will become invalid
570  // Also release on a hard reset.
571  if (0 != m_proxy && (!m_proxy->isResetOnly() || hard)) {
572  resetProxy();
573  }
574  }
575 
576 
584 #ifdef DEBUG_VHB
585  std::cerr << "::VHB::finalReset("
586  << "ptr=" << this->m_ptr << ", "
587  << "proxy=" << this->m_proxy << ", "
588  << "key=" <<this->key()
589  << ")..."
590  << std::endl;
591 #endif
592  reset (true);
593  }
594 
595 
600  {
601  if (typeless_dataPointer()) {
602  m_proxy->setConst();
603  return StatusCode::SUCCESS;
604  }
605  return StatusCode::FAILURE;
606  }
607 
608 
617  {
618  if (!m_ownedKey) {
620  m_key->storeHandle().name());
621  }
622  return *m_ownedKey;
623  }
624 
625 
636  {
637  return vhKey().assign (sgkey);
638  }
639 
640 
641  //*************************************************************************
642  // Protected methods.
643  //
644 
645 
652  StatusCode
654  {
655 #ifdef DEBUG_VHB
656  std::cerr << "::VHB::setState("
657  << proxy;
658  if (0 != proxy) {
659  std::cerr << " -- isValid: " << proxy->isValid()
660  << " -- isConst: " << proxy->isConst();
661  }
662  std::cerr << ") const\n";
663 #endif
664  if (0 == proxy || !proxy->isValid()) {
665  return StatusCode::FAILURE;
666  }
667 
668  if (m_proxy != proxy) {
669  // We're changing proxies. Release the old and bind to the new.
670  setProxy (proxy);
671  // Clear cached pointer.
672  m_ptr=0;
673  }
674 
675  return StatusCode::SUCCESS;
676  }
677 
678 
684  StatusCode
686  {
687  if (0 == store) {
688  return StatusCode::FAILURE;
689  }
690 #ifdef DEBUG_VHB
691  std::cerr << "::VHB::setState("
692  << store->name() << ", "
693  << key
694  << ") const\n";
695 #endif
696  CLID cid = this->clid();
697  SG::DataProxy* proxy = store->proxy(cid, key);
698  // std::cerr << "::VHB:: -- clid=[" << cid << "] proxy=[" << proxy << "]\n";
699  return this->setState(proxy);
700  }
701 
702 
714  StatusCode
715  VarHandleBase::record_impl (std::unique_ptr<DataObject> dobj,
716  void* dataPtr,
717  bool allowMods,
718  bool returnExisting)
719  {
720  if (!m_store) {
721  if (m_ownedKey) {
722  CHECK (m_ownedKey->initialize());
723  }
724  m_store = &*(this->storeHandle());
725  m_storeWasSet = false;
726  }
727 
728  if (this->name().empty()) {
729  REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
730  return StatusCode::FAILURE;
731  }
732 
733  SG::DataObjectSharedPtr<DataObject> sptr (dobj.release());
734  unsigned int initRefCount = sptr->refCount();
735  SG::DataProxy* new_proxy =
736  m_store->recordObject (sptr, this->name(), allowMods, returnExisting);
737  if (!new_proxy) {
738  REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
739  resetProxy();
740  return StatusCode::FAILURE;
741  }
742  if (m_proxy != new_proxy) {
743  CHECK (this->setState (new_proxy));
744  }
745 
746  if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
747  // If the reference count hasn't changed, then we've returned an existing
748  // object rather than recording a new one. Retrieve the pointer, making
749  // sure that it isn't const.
750  if (m_proxy->isConst()) {
751  REPORT_ERROR (StatusCode::FAILURE)
752  << "Found an existing const object from recordOrRetrieve.";
753  return StatusCode::FAILURE;
754  }
756  if (!allowMods)
757  CHECK( setConst() );
758  }
759  else
760  m_ptr=(void*)dataPtr;
761 
762  return StatusCode::SUCCESS;
763  }
764 
765 
783  const void*
784  VarHandleBase::put_impl (const EventContext* ctx,
785  std::unique_ptr<DataObject> dobj,
786  const void* dataPtr,
787  bool allowMods,
788  bool returnExisting,
789  IProxyDict* & store) const
790  {
791  if (this->name().empty()) {
792  REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
793  return nullptr;
794  }
795 
796  store = storeFromHandle (ctx);
797  if (!store) {
798  REPORT_ERROR (StatusCode::FAILURE) << "No store.";
799  return nullptr;
800  }
801 
802  SG::DataObjectSharedPtr<DataObject> sptr (std::move (dobj));
803  unsigned int initRefCount = sptr->refCount();
804  SG::DataProxy* new_proxy =
805  store->recordObject (sptr, this->name(), allowMods, returnExisting);
806  if (!new_proxy) {
807  REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
808  return nullptr;
809  }
810 
811  if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
812  // If the reference count hasn't changed, then we've returned an existing
813  // object rather than recording a new one. Retrieve the pointer.
814  dataPtr = typeless_dataPointer_fromProxy (new_proxy, true);
815  }
816 
817  return dataPtr;
818  }
819 
820 
825  void*
827  {
828 #ifdef DEBUG_VHB
829  std::cerr << "::VHB::typeless_dataPointer_impl("
830  << this
831  << ",ptr=" << this->m_ptr
832  << ",proxy=" << this->m_proxy << ", ";
833  if (m_proxy) {
834  std::cerr << " -- isValid: " << m_proxy->isValid()
835  << " -- isConst: " << m_proxy->isConst();
836  }
837  std::cerr << ", key=" <<this->key() << ")...\n";
838 #endif
839 
840  // First check for cached pointer.
841  if (0 != m_ptr)
842  return m_ptr;
843 
844  if (0 == m_proxy) {
845  // No proxy, need to look it up.
846  if (this->setState().isFailure() || !m_proxy) {
847  if (!quiet) {
848  REPORT_MESSAGE(MSG::WARNING)
849  << "could not get proxy for key " << key();
850  if (this->mode() != Gaudi::DataHandle::Reader) {
851  REPORT_MESSAGE(MSG::WARNING)<< " try using a ReadHandle";
852  }
853  } //quiet
854  return 0;
855  } //setstate
856  } //m_proxy
857 
859  return m_ptr;
860  }
861 
862 
869  void* VarHandleBase::typeless_ptr(bool quiet/*=defaultQuiet*/)
870  {
871  void* p = typeless_dataPointer(quiet);
872  if (p != nullptr && isConst())
873  throw SG::ExcConstObject (clid(), key(), store());
874  return p;
875  }
876 
877 
878  /*
879  * @brief Retrieve an object from SG as a const pointer without caching.
880  * @param ctx The event context, or nullptr to use the current context.
881  * @param quiet If true, suppress failure messages.
882  *
883  * Like typeless_dataPointer_impl, except that we don't change
884  * any members of the handle.
885  */
886  const void* VarHandleBase::get_impl (const EventContext* ctx,
887  bool quiet/*= defaultQuiet*/) const
888  {
889  if (this->mode() != Gaudi::DataHandle::Reader) {
890  if (!quiet)
891  REPORT_ERROR (StatusCode::FAILURE)
892  << "get_impl called for a non-read handle.";
893  return nullptr;
894  }
895 
896  if (this->key().empty()) {
897  if (!quiet)
898  REPORT_ERROR (StatusCode::FAILURE)
899  << "Cannot initialize a Read/Write/Update handle with a null key.";
900  return nullptr;
901  }
902 
904  if (!store) {
905  if (!quiet)
906  REPORT_ERROR (StatusCode::FAILURE) << "No store.";
907  return nullptr;
908  }
909 
910  SG::DataProxy* proxy = store->proxy (this->clid(), this->key());
911  if (!proxy) {
912  if (!quiet)
913  REPORT_ERROR (StatusCode::FAILURE)
914  << "Cannot find proxy for "
915  << this->clid() << "/" << this->key();
916  return nullptr;
917  }
918 
919  return typeless_dataPointer_fromProxy (proxy, quiet);
920  }
921 
922 
934  const std::string& newKey)
935  {
936  if (!m_ptr || !m_store) {
937  REPORT_ERROR (StatusCode::FAILURE) << "symlink: Handle not valid.";
938  return StatusCode::FAILURE;
939  }
940 
942  SG::DataProxy* prox = m_store->recordObject (obj, newKey, false, true);
943  if (!prox)
944  return StatusCode::FAILURE;
945  return StatusCode::SUCCESS;
946  }
947 
948 
964  IProxyDict* VarHandleBase::storeFromHandle (const EventContext* ctx) const
965  {
966  if (m_key->isEventStore()) {
967  if (ctx)
968  return Atlas::getExtendedEventContext(*ctx).proxy();
969  if (m_storeWasSet && m_store) return m_store;
970 
971  if ( Atlas::hasExtendedEventContext (Gaudi::Hive::currentContext()) ) {
972  return Atlas::getExtendedEventContext (Gaudi::Hive::currentContext()).proxy();
973  } else {
974  return nullptr;
975  }
976  }
977 
978  if (m_storeWasSet && m_store) return m_store;
980  if (!store)
981  store = &*this->storeHandle();
982 
983  return store->hiveProxyDict();
984  }
985 
986 
994  bool VarHandleBase::setStoreFromHandle (const EventContext* ctx)
995  {
996  if (m_ownedKey) {
997  if (m_ownedKey->initialize().isFailure()) {
998  return false;
999  }
1000  }
1001  m_store = storeFromHandle (ctx);
1002  m_storeWasSet = (ctx && m_store ==
1003  Atlas::getExtendedEventContext(*ctx).proxy());
1004  return true;
1005  }
1006 
1007 
1012  {
1013  if (m_proxy) {
1014  if (m_ownedKey) {
1015  m_proxy->unbindHandle(this);
1016  m_proxy->release();
1017  }
1018  m_proxy = nullptr;
1019  }
1020  }
1021 
1022 
1028  {
1029  resetProxy();
1030  if (proxy) {
1031  if (m_ownedKey) {
1032  proxy->addRef();
1033  proxy->bindHandle (this);
1034  }
1035  m_proxy = proxy;
1036  }
1037  }
1038 
1039 
1047  void*
1049  bool quiet) const
1050  {
1051  if (!proxy || !proxy->isValid()) {
1052  // invalid proxy
1053  if (!quiet) {
1054  REPORT_MESSAGE(MSG::WARNING)
1055  << "Proxy "
1056  << " [" << (proxy != 0 ? proxy->clID() : 0)
1057  << "/" << (proxy != 0
1058  ? proxy->name()
1059  : std::string("<N/A>"))
1060  << "] is in an invalid state";
1061  } //quiet
1062  return nullptr;
1063  }
1064 
1065  DataObject* dobj = proxy->accessData();
1066  if (!dobj) {
1067  // invalid dobj
1068  if (!quiet) {
1069  REPORT_MESSAGE(MSG::WARNING)
1070  << "this proxy " << MSG::hex << proxy
1071  << MSG::dec << " has a NULL data object ptr";
1072  }
1073  return nullptr;
1074  }
1075 
1076  const CLID clid = this->clid();
1077  void* ptr = SG::Storable_cast(dobj, clid, proxy);
1078  if (ptr)
1079  return ptr;
1080 
1081  // If ptr is null, probably the clid we gave wasn't the clid
1082  // the object was stored with, nor it inherits from it.
1083  // before giving up, let's check its transient CLIDs
1084  DataBucketBase *dbb = 0;
1085  if (proxy->transientID(clid) &&
1086  0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
1087  // it is a symlink after all.
1088  // Let's hard cast (and keep our fingers Xed)
1089  ptr = static_cast<void*>(dbb->object());
1090  } else {
1091  if (!quiet) {
1092  REPORT_MESSAGE(MSG::WARNING)
1093  << "Request for an invalid object; requested CLID = "
1094  << clid
1095  << ", proxy primary ID is " << proxy->clID();
1096  }
1097  } // try symlink -- endif
1098  return ptr;
1099  }
1100 
1101 
1108  bool VarHandleBase::isPresent_impl (const std::string& key) const
1109  {
1110  const DataProxy* proxy = m_proxy;
1111  if (!proxy) {
1112  const IProxyDict* store = m_store;
1113  if (!store)
1114  store = this->storeHandle().get();
1115  if (store)
1116  proxy = store->proxy(this->clid(), key);
1117  }
1118  if (proxy) {
1119  return proxy->isValid();
1120  }
1121  return false;
1122  }
1123 
1124 
1125 //*************************************************************************
1126  // Free functions.
1127  //
1128 
1129 
1135  std::ostream& operator<<( std::ostream& out, const VarHandleBase& o )
1136  {
1137  out << "VarHandleBase @" << &o
1138  << " store=" <<o.store()
1139  << ", clid=" <<o.clid()
1140  << ", key=" <<o.key()
1141  << "----------- ptr@" << o.m_ptr
1142  << ", proxy@" << o.m_proxy ;
1143  if (o.m_proxy)
1144  out << ", DataObject@" << o.m_proxy->object();
1145  return out;
1146  }
1147 
1148 
1152  bool operator==(const VarHandleBase& l, const VarHandleBase& r)
1153  {
1154  return (l.clid() == r.clid() &&
1155  l.mode() == r.mode() &&
1156  l.name() == r.name() &&
1157  l.store() == r.store());
1158  }
1159 
1160 
1164  bool operator!=(const VarHandleBase& l, const VarHandleBase& r)
1165  {
1166  return !(l==r);
1167  }
1168 
1169 
1170 } /* 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
beamspotman.r
def r
Definition: beamspotman.py:676
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
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:93
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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
IHiveStore.h
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
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:964
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:583
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:74
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:170
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:635
SG::VarHandleBase::setState
StatusCode setState()
Retrieve and cache all information managed by a handle.
Definition: StoreGate/src/VarHandleBase.cxx:500
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
virtual void * typeless_dataPointer_impl(bool quiet)
Retrieve an object from StoreGate.
Definition: StoreGate/src/VarHandleBase.cxx:826
Atlas::hasExtendedEventContext
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.
Definition: ExtendedEventContext.cxx:23
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:255
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:76
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
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
DataBucketBase::cast
T * cast(SG::IRegisterTransient *irt=0, bool isConst=true)
Return the contents of the DataBucket, converted to type T.
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:51
SG::VarHandleBase::setConst
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
Definition: StoreGate/src/VarHandleBase.cxx:599
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:71
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
SG::SymlinkDataObject::clID
virtual const CLID & clID() const override
Definition: StoreGate/src/VarHandleBase.cxx:72
SG::VarHandleBase::setProxyDict
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
Definition: StoreGate/src/VarHandleBase.cxx:534
SG::SymlinkDataObject::lock
virtual void lock() override
If the held object derives from ILockable, call lock() on it.
Definition: StoreGate/src/VarHandleBase.cxx:79
SG::VarHandleBase::resetProxy
void resetProxy()
Clear the m_proxy field and release the old proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1011
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
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:379
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:77
SG::VarHandleKey::isEventStore
bool isEventStore() const
Does this key reference the primary event store?
Preparation.mode
mode
Definition: Preparation.py:96
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:409
SG::DataProxy::release
virtual unsigned long release() override final
release reference to object
Definition: DataProxy.cxx:320
SG::SymlinkDataObject
Helper for symLink_impl.
Definition: StoreGate/src/VarHandleBase.cxx:69
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
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:73
test_pythinning.out
out
Definition: test_pythinning.py:94
SG::VarHandleBase::isPresent_impl
bool isPresent_impl(const std::string &key) const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:1108
SG::VarHandleBase::reset
virtual void reset(bool hard) override
Reset this handle.
Definition: StoreGate/src/VarHandleBase.cxx:553
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:1048
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:327
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
beamspotCoolDiff.l
l
Definition: beamspotCoolDiff.py:354
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:994
SG::Storable_cast
T * Storable_cast(DataObject *pDObj, bool quiet=true, IRegisterTransient *irt=0, bool isConst=true)
Definition: StorableConversions.h:47
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:869
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:465
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:616
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:397
SG::DataProxy::isResetOnly
bool isResetOnly() const
Check reset only:
SG::VarHandleBase::isConst
bool isConst() const
True if this handle has a proxy, and the proxy is const.
Definition: StoreGate/src/VarHandleBase.cxx:437
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:46
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:784
SG::SymlinkDataObject::m_obj
void * m_obj
Definition: StoreGate/src/VarHandleBase.cxx:84
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:135
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:44
SG::SymlinkDataObject::relinquish
virtual void relinquish() override
Give up ownership of the DataBucket contents.
Definition: StoreGate/src/VarHandleBase.cxx:78
SG::VarHandleBase::isSet
virtual bool isSet() const override final
Has a proxy been retrieved from SG?
Definition: StoreGate/src/VarHandleBase.cxx:425
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:715
IProxyDict::hiveProxyDict
virtual IProxyDict * hiveProxyDict() override
Return the current event-slot-specific store.
Definition: IProxyDict.cxx:83
SG::operator<<
std::ostream & operator<<(std::ostream &os, const ArenaAllocatorBase::Stats::Stat &stat)
Format a statistic structure.
Definition: ArenaAllocatorBase.cxx:62
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:933
SG::VarHandleBase::get_impl
const void * get_impl(const EventContext *ctx, bool quiet=defaultQuiet) const
Definition: StoreGate/src/VarHandleBase.cxx:886
SG::SymlinkDataObject::m_clid
CLID m_clid
Definition: StoreGate/src/VarHandleBase.cxx:83
SG::VarHandleBase::setProxy
void setProxy(SG::DataProxy *proxy)
Set a new proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1027
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37