From ac9e274b5435ae082c50d1afabff613c5f9fe196 Mon Sep 17 00:00:00 2001
From: lintao <lintao51@gmail.com>
Date: Sat, 13 Jun 2020 14:56:37 +0800
Subject: [PATCH] WIP: migrate the code to use the latest EDM4hep.

---
 Examples/CMakeLists.txt                          |  8 ++++----
 Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp     |  8 ++++----
 Generator/src/HepMCRdr.cpp                       |  4 ++--
 Generator/src/SLCIORdr.cpp                       |  6 +++---
 Generator/src/StdHepRdr.cpp                      |  4 ++--
 Reconstruction/Digitisers/CMakeLists.txt         | 16 ++++++++--------
 .../PFA/Pandora/GaudiPandora/CMakeLists.txt      |  6 +++++-
 .../Pandora/GaudiPandora/src/PandoraPFAlg.cpp    |  2 +-
 .../PFA/Pandora/GaudiPandora/src/PfoCreator.cpp  |  6 +++---
 .../PFA/Pandora/MatrixPandora/CMakeLists.txt     |  5 ++++-
 .../MatrixPandora/src/PandoraMatrixAlg.cpp       |  2 +-
 .../PFA/Pandora/MatrixPandora/src/PfoCreator.cpp |  6 +++---
 .../DetSimAna/src/Edm4hepWriterAnaElemTool.cpp   |  2 +-
 13 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt
index d9e58295..a53bc0fa 100644
--- a/Examples/CMakeLists.txt
+++ b/Examples/CMakeLists.txt
@@ -2,7 +2,7 @@
 gaudi_subdir(Examples v0r0)
 
 find_package(podio REQUIRED)
-find_package(plcio REQUIRED)
+#find_package(plcio REQUIRED)
 find_package(LCIO REQUIRED)
 find_package(EDM4HEP REQUIRED)
 find_package(K4FWCore REQUIRED)
@@ -11,7 +11,7 @@ set(Examples_srcs
     src/HelloWorld/*.cpp
     src/FirstSvc/*.cpp
     src/SecondAlg/*.cpp
-    src/PlcioTest/*.cpp
+ #   src/PlcioTest/*.cpp
     src/Edm4hepTest/*.cpp
 )
 
@@ -21,8 +21,8 @@ gaudi_install_headers(Examples)
 
 # Modules
 gaudi_add_module(Examples ${Examples_srcs}
-    INCLUDE_DIRS K4FWCore GaudiAlgLib GaudiKernel  ${plcio_INCLUDE_DIRS} ${podio_INCLUDE_DIRS} ${LCIO_INCLUDE_DIRS}
-    LINK_LIBRARIES K4FWCore GaudiAlgLib GaudiKernel ${LCIO_LIBRARIES} $ENV{PLCIO}/lib/libplcio.so
+    INCLUDE_DIRS K4FWCore GaudiAlgLib GaudiKernel ${podio_INCLUDE_DIRS} ${LCIO_INCLUDE_DIRS}
+    LINK_LIBRARIES K4FWCore GaudiAlgLib GaudiKernel ${LCIO_LIBRARIES} 
       # Force loading the libraries.
       -Wl,--no-as-needed EDM4HEP::edm4hep EDM4HEP::edm4hepDict ${podio_LIBRARIES} podio::podioRootIO -Wl,--as-needed
 )
diff --git a/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp b/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp
index 2e545734..b33d5e80 100644
--- a/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp
+++ b/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp
@@ -38,10 +38,10 @@ StatusCode Edm4hepWriteAlg::execute()
 
     for ( int i = 0; i < 4; ++i ) {
         auto d = mcCol->create();
-        d.addParent(p1);
-        d.addParent(p2);
-        p1.addDaughter(d);
-        p2.addDaughter(d);
+        d.addToParents(p1);
+        d.addToParents(p2);
+        p1.addToDaughters(d);
+        p2.addToDaughters(d);
     }
 
     return StatusCode::SUCCESS;
diff --git a/Generator/src/HepMCRdr.cpp b/Generator/src/HepMCRdr.cpp
index 491e0b47..c4bfb60d 100644
--- a/Generator/src/HepMCRdr.cpp
+++ b/Generator/src/HepMCRdr.cpp
@@ -76,12 +76,12 @@ bool HepMCRdr::mutate(MyHepMC::GenEvent& event){
         index++;
         if ( (*p)->production_vertex() ) {
             for ( HepMC::GenVertex::particle_iterator mother = (*p)->production_vertex()-> particles_begin(HepMC::parents); mother != (*p)->production_vertex()-> particles_end(HepMC::parents); ++mother ) {
-                pmc.addParent( event.m_mc_vec.at( pmcid_lmcid.at((*mother)->barcode()) ) );
+                pmc.addToParents( event.m_mc_vec.at( pmcid_lmcid.at((*mother)->barcode()) ) );
             }
         }
         if ( (*p)->end_vertex() ) {
             for ( HepMC::GenVertex::particle_iterator des =(*p)->end_vertex()-> particles_begin(HepMC::descendants); des != (*p)->end_vertex()-> particles_end(HepMC::descendants); ++des ) {
-                pmc.addDaughter( event.m_mc_vec.at( pmcid_lmcid.at((*des)->barcode()) ) );
+                pmc.addToDaughters( event.m_mc_vec.at( pmcid_lmcid.at((*des)->barcode()) ) );
                 }
         }   
     }
diff --git a/Generator/src/SLCIORdr.cpp b/Generator/src/SLCIORdr.cpp
index 13bd39ed..2f0b940a 100644
--- a/Generator/src/SLCIORdr.cpp
+++ b/Generator/src/SLCIORdr.cpp
@@ -87,7 +87,7 @@ bool SLCIORdr::mutate(MyHepMC::GenEvent& event){
               if(d==lcCol->getElementAt(i)) break;
             }
             if(i==NHEP) cout << "Heedm4hepInterfaceNew: error" << endl;
-            mcp->addDaughter(dynamic_cast<MCParticleImpl*>(lcMCVec->getElementAt(i)));
+            mcp->addToDaughters(dynamic_cast<MCParticleImpl*>(lcMCVec->getElementAt(i)));
           }
           */
           
@@ -133,12 +133,12 @@ bool SLCIORdr::mutate(MyHepMC::GenEvent& event){
         //std::cout<<"mc at "<< i<<", parent size "<<mc_parents.size() <<std::endl;
         for(unsigned int j=0; j< mc_parents.size(); j++){int p_id = mc_parents.at(j)->id();
                                                  //std::cout<<"parent id "<<p_id<<std::endl;
-                                                 pmc.addParent( event.m_mc_vec.at( pmcid_lmcid.at(p_id) ) );
+                                                 pmc.addToParents( event.m_mc_vec.at( pmcid_lmcid.at(p_id) ) );
                                                 }
         //std::cout<<"mc at "<< i<<", daughter size "<<mc_daughters.size() <<std::endl;
         for(unsigned int j=0; j< mc_daughters.size(); j++){int d_id = mc_daughters.at(j)->id();
                                                  //std::cout<<"daughter id "<<d_id<<std::endl;
-                                                 pmc.addDaughter( event.m_mc_vec.at( pmcid_lmcid.at(d_id) ) );
+                                                 pmc.addToDaughters( event.m_mc_vec.at( pmcid_lmcid.at(d_id) ) );
                                                 }
     }
     event.SetEventHeader( m_processed_event, -99, 9999, "Generator");
diff --git a/Generator/src/StdHepRdr.cpp b/Generator/src/StdHepRdr.cpp
index 3bc1412f..09fa9ddc 100644
--- a/Generator/src/StdHepRdr.cpp
+++ b/Generator/src/StdHepRdr.cpp
@@ -67,12 +67,12 @@ bool StdHepRdr::mutate(MyHepMC::GenEvent& event){
         //std::cout<<"mc at "<< i<<", parent size "<<mc_parents.size() <<std::endl;
         for(unsigned int j=0; j< mc_parents.size(); j++){int p_id = mc_parents.at(j)->id();
                                                  //std::cout<<"parent id "<<p_id<<std::endl;
-                                                 pmc.addParent( event.m_mc_vec.at( pmcid_lmcid.at(p_id) ) );
+                                                 pmc.addToParents( event.m_mc_vec.at( pmcid_lmcid.at(p_id) ) );
                                                 }
         //std::cout<<"mc at "<< i<<", daughter size "<<mc_daughters.size() <<std::endl;
         for(unsigned int j=0; j< mc_daughters.size(); j++){int d_id = mc_daughters.at(j)->id();
                                                  //std::cout<<"daughter id "<<d_id<<std::endl;
-                                                 pmc.addDaughter( event.m_mc_vec.at( pmcid_lmcid.at(d_id) ) );
+                                                 pmc.addToDaughters( event.m_mc_vec.at( pmcid_lmcid.at(d_id) ) );
                                                 }
     }
      
diff --git a/Reconstruction/Digitisers/CMakeLists.txt b/Reconstruction/Digitisers/CMakeLists.txt
index 7c0c14ea..56952b16 100644
--- a/Reconstruction/Digitisers/CMakeLists.txt
+++ b/Reconstruction/Digitisers/CMakeLists.txt
@@ -12,12 +12,12 @@ gaudi_depends_on_subdirs(
     Service/EventSeeder
 )
 
-set(Digitisers_srcs
-    src/*.cpp
-)
+# set(Digitisers_srcs
+#     src/*.cpp
+# )
 
-# Modules
-gaudi_add_module(Digitisers ${Digitisers_srcs}
-    INCLUDE_DIRS K4FWCore GaudiKernel GaudiAlgLib CLHEP gear ${plcio_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} ${LCIO_INCLUDE_DIRS}
-    LINK_LIBRARIES K4FWCore GaudiKernel GaudiAlgLib CLHEP $ENV{GEAR}/lib/libgearsurf.so ${GSL_LIBRARIES} $ENV{PLCIO}/lib/libplcio.so ${LCIO_LIBRARIES}
-)
+# # Modules
+# gaudi_add_module(Digitisers ${Digitisers_srcs}
+#     INCLUDE_DIRS K4FWCore GaudiKernel GaudiAlgLib CLHEP gear ${plcio_INCLUDE_DIRS} ${GSL_INCLUDE_DIRS} ${LCIO_INCLUDE_DIRS}
+#     LINK_LIBRARIES K4FWCore GaudiKernel GaudiAlgLib CLHEP $ENV{GEAR}/lib/libgearsurf.so ${GSL_LIBRARIES} $ENV{PLCIO}/lib/libplcio.so ${LCIO_LIBRARIES}
+# )
diff --git a/Reconstruction/PFA/Pandora/GaudiPandora/CMakeLists.txt b/Reconstruction/PFA/Pandora/GaudiPandora/CMakeLists.txt
index c60217b9..94651123 100644
--- a/Reconstruction/PFA/Pandora/GaudiPandora/CMakeLists.txt
+++ b/Reconstruction/PFA/Pandora/GaudiPandora/CMakeLists.txt
@@ -13,7 +13,7 @@ message("ENV GEAR: $ENV{GEAR}")
 
 find_package(EDM4HEP REQUIRED )
 include_directories(${EDM4HEP_INCLUDE_DIR})
-link_libraries("/cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/EDM4hep/lib64/libedm4hep.so")
+
 find_package(PandoraSDK REQUIRED ) 
 include_directories(${PandoraSDK_INCLUDE_DIRS})
 link_libraries(${PandoraSDK_LIBRARIES})
@@ -48,4 +48,8 @@ set(dir_include include)
 gaudi_add_module(GaudiPandora ${dir_srcs}
     INCLUDE_DIRS ${gsl_include} ${dir_include} GaudiKernel FWCore CLHEP  ${LCIO_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} gear  
     LINK_LIBRARIES ${gsl_lib1} ${gsl_lib2} GaudiKernel FWCore CLHEP ROOT ${LCIO_LIBRARIES} $ENV{GEAR}/lib/libgear.so $ENV{GEAR}/lib/libgearxml.so 
+      -Wl,--no-as-needed 
+      EDM4HEP::edm4hep EDM4HEP::edm4hepDict
+      -Wl,--as-needed 
+
 )
diff --git a/Reconstruction/PFA/Pandora/GaudiPandora/src/PandoraPFAlg.cpp b/Reconstruction/PFA/Pandora/GaudiPandora/src/PandoraPFAlg.cpp
index 401a6e7a..9489897f 100644
--- a/Reconstruction/PFA/Pandora/GaudiPandora/src/PandoraPFAlg.cpp
+++ b/Reconstruction/PFA/Pandora/GaudiPandora/src/PandoraPFAlg.cpp
@@ -618,7 +618,7 @@ StatusCode PandoraPFAlg::updateMap()
                                 edm4hep::SimCalorimeterHit sim_hit( it->getCellID(), it->getEnergy(), it->getPosition() );
                                 edm4hep::CaloHitContribution conb ( MCParticle->at(i).getPDG(), it->getEnergy(), 0, it->getPosition() ); 
                                 conb.setParticle( MCParticle->at(i) );
-                                sim_hit.addContribution(conb);
+                                sim_hit.addToContributions(conb);
                                 edm4hep::MCRecoCaloAssociation calo_association;
                                 calo_association.setRec(*it);
                                 calo_association.setSim(sim_hit);
diff --git a/Reconstruction/PFA/Pandora/GaudiPandora/src/PfoCreator.cpp b/Reconstruction/PFA/Pandora/GaudiPandora/src/PfoCreator.cpp
index a3d35da1..a8c9f0c4 100644
--- a/Reconstruction/PFA/Pandora/GaudiPandora/src/PfoCreator.cpp
+++ b/Reconstruction/PFA/Pandora/GaudiPandora/src/PfoCreator.cpp
@@ -97,7 +97,7 @@ pandora::StatusCode PfoCreator::CreateParticleFlowObjects(CollectionMaps& collec
 
             //pClusterCollection->addElement(p_Cluster);
             edm4hep::ConstCluster p_ClusterCon = *p_Cluster;
-            pReconstructedParticle->addCluster(p_ClusterCon);
+            pReconstructedParticle->addToClusters(p_ClusterCon);
         }
 
         if (!hasTrack)
@@ -157,7 +157,7 @@ void PfoCreator::SetClusterSubDetectorEnergies(const pandora::StringVector &subD
         edm4hep::CalorimeterHit *const pCalorimeterHit0 = (edm4hep::CalorimeterHit*)(pPandoraCaloHit->GetParentAddress());
         const edm4hep::CalorimeterHit pCalorimeterHit = *pCalorimeterHit0;
         
-        p_Cluster->addHit(pCalorimeterHit);
+        p_Cluster->addToHits(pCalorimeterHit);
 
         const float caloHitEnergy(pCalorimeterHit.getEnergy());
         hitE.push_back(caloHitEnergy);
@@ -401,7 +401,7 @@ void PfoCreator::AddTracksToRecoParticle(const pandora::ParticleFlowObject *cons
         const pandora::Track *const pTrack(*tIter);
         const edm4hep::Track *const pLcioTrack0 = (edm4hep::Track*)(pTrack->GetParentAddress());
         const edm4hep::Track pLcioTrack = *pLcioTrack0;
-        pReconstructedParticle->addTrack(pLcioTrack);
+        pReconstructedParticle->addToTracks(pLcioTrack);
 
     }
 }
diff --git a/Reconstruction/PFA/Pandora/MatrixPandora/CMakeLists.txt b/Reconstruction/PFA/Pandora/MatrixPandora/CMakeLists.txt
index 99429ca5..73dc84e3 100644
--- a/Reconstruction/PFA/Pandora/MatrixPandora/CMakeLists.txt
+++ b/Reconstruction/PFA/Pandora/MatrixPandora/CMakeLists.txt
@@ -14,7 +14,7 @@ find_package(EDM4HEP REQUIRED )
 #message("EDM4HEP_INCLUDE_DIRS: ${EDM4HEP_INCLUDE_DIR}")
 #message("EDM4HEP_LIB: ${EDM4HEP_LIBRARIES}")
 include_directories(${EDM4HEP_INCLUDE_DIR})
-link_libraries("/cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/EDM4hep/lib64/libedm4hep.so")
+
 find_package(PandoraSDK REQUIRED ) 
 #message("PandoraSDK_INCLUDE_DIRS: ${PandoraSDK_INCLUDE_DIRS}")
 #message("PandoraSDK_LIB:          ${PandoraSDK_LIBRARIES}")
@@ -54,4 +54,7 @@ set(dir_include include)
 gaudi_add_module(MatrixPandora ${dir_srcs}
     INCLUDE_DIRS ${gsl_include} ${dir_include} GaudiKernel FWCore CLHEP  ${LCIO_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS} gear DD4hep  
     LINK_LIBRARIES ${gsl_lib1} ${gsl_lib2} GaudiKernel FWCore CLHEP ROOT ${LCIO_LIBRARIES} $ENV{GEAR}/lib/libgear.so $ENV{GEAR}/lib/libgearxml.so DD4hep ${DD4hep_COMPONENT_LIBRARIES} DDRec
+      -Wl,--no-as-needed 
+      EDM4HEP::edm4hep EDM4HEP::edm4hepDict
+      -Wl,--as-needed 
 )
diff --git a/Reconstruction/PFA/Pandora/MatrixPandora/src/PandoraMatrixAlg.cpp b/Reconstruction/PFA/Pandora/MatrixPandora/src/PandoraMatrixAlg.cpp
index 07527dbb..e1d2e199 100644
--- a/Reconstruction/PFA/Pandora/MatrixPandora/src/PandoraMatrixAlg.cpp
+++ b/Reconstruction/PFA/Pandora/MatrixPandora/src/PandoraMatrixAlg.cpp
@@ -625,7 +625,7 @@ StatusCode PandoraMatrixAlg::updateMap()
                                 edm4hep::SimCalorimeterHit sim_hit( it->getCellID(), it->getEnergy(), it->getPosition() );
                                 edm4hep::CaloHitContribution conb ( MCParticle->at(i).getPDG(), it->getEnergy(), 0, it->getPosition() ); 
                                 conb.setParticle( MCParticle->at(i) );
-                                sim_hit.addContribution(conb);
+                                sim_hit.addToContributions(conb);
                                 edm4hep::MCRecoCaloAssociation calo_association;
                                 calo_association.setRec(*it);
                                 calo_association.setSim(sim_hit);
diff --git a/Reconstruction/PFA/Pandora/MatrixPandora/src/PfoCreator.cpp b/Reconstruction/PFA/Pandora/MatrixPandora/src/PfoCreator.cpp
index 1c6069c5..b197f2db 100644
--- a/Reconstruction/PFA/Pandora/MatrixPandora/src/PfoCreator.cpp
+++ b/Reconstruction/PFA/Pandora/MatrixPandora/src/PfoCreator.cpp
@@ -97,7 +97,7 @@ pandora::StatusCode PfoCreator::CreateParticleFlowObjects(CollectionMaps& collec
 
             //pClusterCollection->addElement(p_Cluster);
             edm4hep::ConstCluster p_ClusterCon = *p_Cluster;
-            pReconstructedParticle->addCluster(p_ClusterCon);
+            pReconstructedParticle->addToClusters(p_ClusterCon);
         }
 
         if (!hasTrack)
@@ -157,7 +157,7 @@ void PfoCreator::SetClusterSubDetectorEnergies(const pandora::StringVector &subD
         edm4hep::CalorimeterHit *const pCalorimeterHit0 = (edm4hep::CalorimeterHit*)(pPandoraCaloHit->GetParentAddress());
         const edm4hep::CalorimeterHit pCalorimeterHit = *pCalorimeterHit0;
         
-        p_Cluster->addHit(pCalorimeterHit);
+        p_Cluster->addToHits(pCalorimeterHit);
 
         const float caloHitEnergy(pCalorimeterHit.getEnergy());
         hitE.push_back(caloHitEnergy);
@@ -401,7 +401,7 @@ void PfoCreator::AddTracksToRecoParticle(const pandora::ParticleFlowObject *cons
         const pandora::Track *const pTrack(*tIter);
         const edm4hep::Track *const pLcioTrack0 = (edm4hep::Track*)(pTrack->GetParentAddress());
         const edm4hep::Track pLcioTrack = *pLcioTrack0;
-        pReconstructedParticle->addTrack(pLcioTrack);
+        pReconstructedParticle->addToTracks(pLcioTrack);
 
     }
 }
diff --git a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
index 595ca3d7..ea62694d 100644
--- a/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
+++ b/Simulation/DetSimAna/src/Edm4hepWriterAnaElemTool.cpp
@@ -193,7 +193,7 @@ Edm4hepWriterAnaElemTool::EndOfEventAction(const G4Event* anEvent) {
                         edm_calo_contrib.setTime(c.time/CLHEP::ns);
                         edm_calo_contrib.setStepPosition(edm4hep::Vector3f(pos));
                         edm_calo_contrib.setParticle(mcCol->at(0)); // todo
-                        edm_calo_hit.addContribution(edm_calo_contrib);
+                        edm_calo_hit.addToContributions(edm_calo_contrib);
                     }
                 }
 
-- 
GitLab