From 77ab2b626f7b6208c5491e772c84cfba48d43f40 Mon Sep 17 00:00:00 2001
From: scott snyder <scott.snyder@cern.ch>
Date: Thu, 7 Sep 2017 15:32:13 +0200
Subject: [PATCH] StoreGate: Removing references to transientAddress().

In order to make DataProxy properly thread-safe, it is helpful to remove
calls to DataProxy::transientAddress.  That way, it suffices to have
a lock in the DataProxy object.  Trying to add the needed accessor
methods to DataProxy and get rid of calls to transientAddress().
---
 Control/StoreGate/src/SGImplSvc.cxx           | 16 +++++++---------
 Control/StoreGate/src/VarHandleBase.cxx       |  2 +-
 Control/StoreGate/test/ReadHandle_test.cxx    |  4 ++--
 Control/StoreGate/test/VarHandleBase_test.cxx |  4 ++--
 Control/StoreGate/test/WriteHandle_test.cxx   |  4 ++--
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/Control/StoreGate/src/SGImplSvc.cxx b/Control/StoreGate/src/SGImplSvc.cxx
index 44997ad5e94..043adfd9d9b 100644
--- a/Control/StoreGate/src/SGImplSvc.cxx
+++ b/Control/StoreGate/src/SGImplSvc.cxx
@@ -416,7 +416,7 @@ StatusCode SGImplSvc::recordAddress(const std::string& skey,
   //do not overwrite a persistent object
   if (m_pPPS) {
     DataProxy *dp(m_pPPS->retrieveProxy(dataID, skey, *m_pStore));
-    if (dp && dp->transientAddress() && dp->transientAddress()->provider()) {
+    if (dp && dp->provider()) {
       std::string clidTypeName; 
       m_pCLIDSvc->getTypeNameOfID(dataID, clidTypeName).ignore();
       msg() << MSG::WARNING
@@ -551,7 +551,7 @@ SGImplSvc::keys(const CLID& id, std::vector<std::string>& vkeys,
 
 bool SGImplSvc::isSymLinked(const CLID& linkID, DataProxy* dp)   
 {        
-  return (0 != dp) ? dp->transientAddress()->transientID(linkID) : false;        
+  return (0 != dp) ? dp->transientID(linkID) : false;        
 }
 
 //////////////////////////////////////////////////////////////////
@@ -760,7 +760,7 @@ SG::DataProxy* SGImplSvc::recordObject (SG::DataObjectSharedPtr<DataObject> obj,
     // Look for the same object recorded under a different key/clid.
     proxy = this->proxy (raw_ptr);
     if (proxy && proxy->isValid()) {
-      if (proxy->transientAddress()->transientID (obj->clID())) {
+      if (proxy->transientID (obj->clID())) {
         // CLID matches.  Make an alias.
         if (addAlias (key, proxy).isFailure()) {
           CLID clid = proxy->clID();
@@ -1056,9 +1056,7 @@ SGImplSvc::record_impl( DataObject* pDObj, const std::string& key,
     DataProxy *dp(proxy(clid, vk.key()));
     if (dp) {
       //proxies primary key
-      TransientAddress *pTA(dp->transientAddress());
-      assert(pTA);
-      const std::string& pTAName(pTA->name());
+      const std::string& pTAName(dp->name());
       //original key as versioned
       SG::VersionedKey primaryVK(pTAName);
       
@@ -1088,7 +1086,7 @@ SGImplSvc::record_impl( DataObject* pDObj, const std::string& key,
   if (!allowOverwrite && m_pPPS) {
     //do not overwrite a persistent object
     DataProxy *dp(m_pPPS->retrieveProxy(clid, rawKey, *m_pStore));
-    if (dp && dp->transientAddress() && dp->transientAddress()->provider()) {
+    if (dp && dp->provider()) {
       std::string clidTypeName; 
       m_pCLIDSvc->getTypeNameOfID(clid, clidTypeName).ignore();
       msg() << MSG::WARNING
@@ -1626,7 +1624,7 @@ void SGImplSvc::addedNewPersObject(CLID clid, DataProxy* dp) {
   lock_t lock (m_mutex);
   //if proxy is loading from persistency
   //add key of object to list of "newly recorded" objects
-  if (0 != dp->transientAddress()->provider()) {
+  if (0 != dp->provider()) {
     // The object itself.
     s_newObjs.insert(DataObjID(clid,dp->name()));
 
@@ -1636,7 +1634,7 @@ void SGImplSvc::addedNewPersObject(CLID clid, DataProxy* dp) {
     }
 
     // Symlinks.
-    for (CLID clid2 : dp->transientAddress()->transientID()) {
+    for (CLID clid2 : dp->transientID()) {
       if (clid2 != clid)
         s_newObjs.insert(DataObjID(clid2,dp->name()));
     }
diff --git a/Control/StoreGate/src/VarHandleBase.cxx b/Control/StoreGate/src/VarHandleBase.cxx
index 9f26b751e8e..9a4264ac8c4 100644
--- a/Control/StoreGate/src/VarHandleBase.cxx
+++ b/Control/StoreGate/src/VarHandleBase.cxx
@@ -981,7 +981,7 @@ namespace SG {
     // the object was stored with, nor it inherits from it.
     // before giving up, let's check its transient CLIDs
     DataBucketBase *dbb = 0;
-    if (proxy->transientAddress()->transientID(clid) &&
+    if (proxy->transientID(clid) &&
         0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
       // it is a symlink after all.
       // Let's hard cast (and keep our fingers Xed)
diff --git a/Control/StoreGate/test/ReadHandle_test.cxx b/Control/StoreGate/test/ReadHandle_test.cxx
index e712d18edfb..f3240b151d6 100644
--- a/Control/StoreGate/test/ReadHandle_test.cxx
+++ b/Control/StoreGate/test/ReadHandle_test.cxx
@@ -288,14 +288,14 @@ void test5()
   SG::WriteHandleKey<MyObj> h2 ("foo3", "FooSvc");
   assert (h1.alias (h2).isSuccess());
   assert (testStore.proxy (MyCLID, "foo3") == prox1);
-  assert (prox1->transientAddress()->alias().count ("foo3") == 1);
+  assert (prox1->alias().count ("foo3") == 1);
   #if 0
 
   // Making symlink.
   SG::WriteHandleKey<MyObj2> h3 ("foo1", "FooSvc");
   assert (h1.symLink (h3).isSuccess());
   assert (testStore.proxy (ClassID_traits<MyObj2>::ID(), "foo1") == prox1);
-  assert (prox1->transientAddress()->transientID (ClassID_traits<MyObj2>::ID()));
+  assert (prox1->transientID (ClassID_traits<MyObj2>::ID()));
 
   // Should give an error.
   SG::WriteHandleKey<MyObj2> h4 ("foo3", "FooSvc");
diff --git a/Control/StoreGate/test/VarHandleBase_test.cxx b/Control/StoreGate/test/VarHandleBase_test.cxx
index bdaa065435d..ac40efc6860 100644
--- a/Control/StoreGate/test/VarHandleBase_test.cxx
+++ b/Control/StoreGate/test/VarHandleBase_test.cxx
@@ -421,7 +421,7 @@ void test6()
   testStore.record (new MyObj, "bar");
   assert (h1.setState (&testStore, "bar").isSuccess());
   assert (h1.isInitialized());
-  assert (h1.m_proxy->transientAddress()->name() == "bar");
+  assert (h1.m_proxy->name() == "bar");
 }
 
 
@@ -535,7 +535,7 @@ void test8()
   assert (h3.typeless_dataPointer_impl(false) == nullptr);
   assert (h3.typeless_dataPointer_impl(true) == nullptr);
 
-  testStore.proxy (293847296, "fee")->transientAddress()->setTransientID(293847295);
+  testStore.proxy (293847296, "fee")->setTransientID(293847295);
   assert (h3.typeless_dataPointer_impl(false) == obj2ptr);
   assert (h3.typeless_dataPointer(false) == obj2ptr);
   assert (h3.typeless_cptr() == obj2ptr);
diff --git a/Control/StoreGate/test/WriteHandle_test.cxx b/Control/StoreGate/test/WriteHandle_test.cxx
index ae1371d27e8..5b9501190ef 100644
--- a/Control/StoreGate/test/WriteHandle_test.cxx
+++ b/Control/StoreGate/test/WriteHandle_test.cxx
@@ -691,13 +691,13 @@ void test12()
   SG::WriteHandleKey<MyObj> h2 ("foo3", "FooSvc");
   assert (h1.alias (h2).isSuccess());
   assert (testStore.proxy (ClassID_traits<MyObj>::ID(), "foo3") == prox1);
-  assert (prox1->transientAddress()->alias().count ("foo3") == 1);
+  assert (prox1->alias().count ("foo3") == 1);
 
   // Making symlink.
   SG::WriteHandleKey<MyObj2> h3 ("foo1", "FooSvc");
   assert (h1.symLink (h3).isSuccess());
   assert (testStore.proxy (ClassID_traits<MyObj2>::ID(), "foo1") == prox1);
-  assert (prox1->transientAddress()->transientID (ClassID_traits<MyObj2>::ID()));
+  assert (prox1->transientID (ClassID_traits<MyObj2>::ID()));
 
   // Should give an error.
   SG::WriteHandleKey<MyObj2> h4 ("foo3", "FooSvc");
-- 
GitLab