From a0529eefb801dcd687b640285adcebc79cf19633 Mon Sep 17 00:00:00 2001
From: John Chapman <jchapman@cern.ch>
Date: Fri, 28 Jul 2017 09:46:14 +0200
Subject: [PATCH] Migrate InDetSimData TP Converters to use the new
 HepMcParticleLink

This commit adds code to write rather than just read the persistent formats which
use `HepMcParticleLink_p2` to the relevant TP converters. These are the remaining
changes from `InDetEventAthenaPool-00-10-18`. These changes are part of the
`HepMcParticleLink` migration. See ATLASSIM-2430.

NB There are no unit tests for any of the `InDetSimData` TP Converters.
---
 .../InDetEventAthenaPoolCnvDict.h             |  8 +++----
 .../src/InDetSimDataCnv_p1.cxx                |  5 +++--
 .../src/InDetSimDataCnv_p2.cxx                | 16 ++++++++++++--
 .../src/InDetSimDataCollectionCnv.h           |  4 ++--
 .../src/InDetSimDataCollectionCnv_p3.cxx      | 21 +++++++++++++++++--
 5 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/InDetEventAthenaPool/InDetEventAthenaPoolCnvDict.h b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/InDetEventAthenaPool/InDetEventAthenaPoolCnvDict.h
index 1d4249e409c..c4521126f44 100644
--- a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/InDetEventAthenaPool/InDetEventAthenaPoolCnvDict.h
+++ b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/InDetEventAthenaPool/InDetEventAthenaPoolCnvDict.h
@@ -24,10 +24,10 @@
 
 namespace InDetEventAthenaPoolCnvDict
 {
-    std::pair<unsigned int, InDetSimData_p1> t1;
-    std::pair<unsigned long long, InDetSimData_p1> t2;
-    std::vector<std::pair<unsigned int, InDetSimData_p1> > t3;
-    std::vector<std::pair<unsigned long long, InDetSimData_p1> > t4;
+    std::pair<unsigned int, InDetSimData_p2> t1;
+    std::pair<unsigned long long, InDetSimData_p2> t2;
+    std::vector<std::pair<unsigned int, InDetSimData_p2> > t3;
+    std::vector<std::pair<unsigned long long, InDetSimData_p2> > t4;
 }
 
 #endif
diff --git a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p1.cxx b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p1.cxx
index df32aa4e292..56c9df08ce5 100644
--- a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p1.cxx
+++ b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p1.cxx
@@ -23,10 +23,11 @@ void
 InDetSimDataCnv_p1::persToTrans(const InDetSimData_p1* persObj, InDetSimData* transObj, MsgStream &log)
 {
    MSG_VERBOSE(log,"InDetSimDataCnv_p1::persToTrans called ");
-   HepMcParticleLink mcLink (m_sg);
+   HepMcParticleLinkCnv_p1 HepMcPLCnv;
    std::vector<InDetSimData::Deposit> deposits;
    deposits.reserve( persObj->m_enDeposits.size() );
    for (unsigned int icount=0; icount < persObj->m_enDeposits.size(); icount++) {
+     HepMcParticleLink mcLink(m_sg); //FIXME This is left as a note to make the new implementation thread-safe
      HepMcPLCnv.persToTrans(&(persObj->m_links[icount]),&mcLink, log);
      deposits.emplace_back (mcLink, persObj->m_enDeposits[icount]);
    }
@@ -36,7 +37,7 @@ InDetSimDataCnv_p1::persToTrans(const InDetSimData_p1* persObj, InDetSimData* tr
 }
 
 void
-InDetSimDataCnv_p1::transToPers(const InDetSimData* transObj, InDetSimData_p1* persObj, MsgStream &log) 
+InDetSimDataCnv_p1::transToPers(const InDetSimData* transObj, InDetSimData_p1* persObj, MsgStream &log)
 {
    MSG_VERBOSE(log,"InDetSimDataCnv_p1::transToPers called ");
 
diff --git a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p2.cxx b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p2.cxx
index 4d0d44214a4..3cbfe0c090e 100644
--- a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p2.cxx
+++ b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCnv_p2.cxx
@@ -36,9 +36,21 @@ InDetSimDataCnv_p2::persToTrans(const InDetSimData_p2* persObj, InDetSimData* tr
 }
 
 void
-InDetSimDataCnv_p2::transToPers(const InDetSimData*, InDetSimData_p2*, MsgStream &/*log*/)
+InDetSimDataCnv_p2::transToPers(const InDetSimData* transObj, InDetSimData_p2* persObj, MsgStream &log)
 {
-  throw std::runtime_error("InDetSimDataCnv_p2::transToPers is not supported in this release!");}
+   MSG_VERBOSE(log,"InDetSimDataCnv_p2::transToPers called ");
+   HepMcParticleLinkCnv_p2 HepMcPLCnv;
+
+   persObj->m_word = transObj->word();
+   const std::vector<InDetSimData::Deposit> &dep(transObj->getdeposits());
+   persObj->m_links.resize(dep.size() );
+   persObj->m_enDeposits.resize(dep.size() );
+   depositIterator it=dep.begin();
+   for (int icount=0; it != dep.end(); it++, icount++) {
+     HepMcPLCnv.transToPers(&(dep[icount].first), &(persObj->m_links[icount]), log);
+     persObj->m_enDeposits[icount] = dep[icount].second;
+   }
+}
 
 void InDetSimDataCnv_p2::setCurrentStore (IProxyDict* store)
 {
diff --git a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv.h b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv.h
index 653b709f796..478a44d21f8 100644
--- a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv.h
+++ b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv.h
@@ -15,8 +15,8 @@
 // Gaudi
 #include "GaudiKernel/MsgStream.h"
 // typedef to the latest persistent version
-typedef  InDetSimDataCollection_p2     InDetSimDataCollection_PERS;
-typedef  InDetSimDataCollectionCnv_p2  InDetSimDataCollectionCnv_PERS;
+typedef  InDetSimDataCollection_p3     InDetSimDataCollection_PERS;
+typedef  InDetSimDataCollectionCnv_p3  InDetSimDataCollectionCnv_PERS;
 
 // base class 
 typedef  T_AthenaPoolCustomCnv<InDetSimDataCollection, InDetSimDataCollection_PERS >   InDetSimDataCollectionCnvBase;
diff --git a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv_p3.cxx b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv_p3.cxx
index 18268fe191b..111926bfeaa 100644
--- a/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv_p3.cxx
+++ b/InnerDetector/InDetEventCnv/InDetEventAthenaPool/src/InDetSimDataCollectionCnv_p3.cxx
@@ -11,9 +11,26 @@
 #include "SGTools/CurrentEventStore.h"
 #include "MsgUtil.h"
 
-void InDetSimDataCollectionCnv_p3::transToPers(const InDetSimDataCollection*, InDetSimDataCollection_p3*, MsgStream &/*log*/)
+void InDetSimDataCollectionCnv_p3::transToPers(const InDetSimDataCollection* transCont, InDetSimDataCollection_p3* persCont, MsgStream &log)
 {
-  throw std::runtime_error("InDetSimDataCollectionCnv_p3::transToPers is not supported in this release!");
+
+
+    typedef InDetSimDataCollection TRANS;
+
+    InDetSimDataCnv_p2  simDataCnv;
+
+    TRANS::const_iterator it_Coll     = transCont->begin();
+    TRANS::const_iterator it_CollEnd  = transCont->end();
+    persCont->m_simdata.resize(transCont->size());
+    MSG_DEBUG(log," Preparing " << persCont->m_simdata.size() << "Collections");
+    for (int collIndex=0 ; it_Coll != it_CollEnd; it_Coll++, collIndex++)  {
+        // Add in new collection
+        (persCont->m_simdata[collIndex]).first = (*it_Coll).first.get_compact();
+        const InDetSimData& simData = (*it_Coll).second;
+        InDetSimData_p2& psimData = persCont->m_simdata[collIndex].second;
+        simDataCnv.transToPers(&simData,&psimData,log);
+    }
+    MSG_DEBUG(log," ***  Writing InDetSimdataCollection");
 }
 
 void  InDetSimDataCollectionCnv_p3::persToTrans(const InDetSimDataCollection_p3* persCont, InDetSimDataCollection* transCont, MsgStream &log)
-- 
GitLab