From 050f95a42ae0df41bc5edadb89206c06bdf39eb6 Mon Sep 17 00:00:00 2001
From: zoujh <zoujh@ihep.ac.cn>
Date: Tue, 15 Sep 2020 19:28:36 +0800
Subject: [PATCH] make edm4hep read & write examples be consistency

---
 Examples/options/edm4hep_read.py             | 14 ++++++++------
 Examples/options/edm4hep_write.py            |  4 ++--
 Examples/src/Edm4hepTest/Edm4hepReadAlg.cpp  |  3 ++-
 Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp | 17 +++++++++++++++--
 Examples/src/Edm4hepTest/Edm4hepWriteAlg.h   |  5 ++++-
 5 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/Examples/options/edm4hep_read.py b/Examples/options/edm4hep_read.py
index 998b300e..fa8edc53 100644
--- a/Examples/options/edm4hep_read.py
+++ b/Examples/options/edm4hep_read.py
@@ -5,17 +5,19 @@ from Gaudi.Configuration import *
 from Configurables import K4DataSvc
 dsvc = K4DataSvc("EventDataSvc", input="test.root")
 
-from Configurables import Edm4hepReadAlg
-alg = Edm4hepReadAlg("Edm4hepReadAlg")
-alg.HeaderCol.Path = "EventHeader"
-alg.InputCol.Path = "MCParticle"
-
 from Configurables import PodioInput
 podioinput = PodioInput("PodioReader", collections=[
     "EventHeader",
-    "MCParticle"
+    "MCParticle",
+    "SimCalorimeterHit"
     ])
 
+from Configurables import Edm4hepReadAlg
+alg = Edm4hepReadAlg("Edm4hepReadAlg")
+#alg.HeaderCol.Path = "EventHeader"
+#alg.MCParticleCol.Path = "MCParticle"
+alg.SimCalorimeterHitCol.Path = "SimCalorimeterHit"
+
 # ApplicationMgr
 from Configurables import ApplicationMgr
 ApplicationMgr( TopAlg = [podioinput, alg],
diff --git a/Examples/options/edm4hep_write.py b/Examples/options/edm4hep_write.py
index f5ad0bef..935440fc 100644
--- a/Examples/options/edm4hep_write.py
+++ b/Examples/options/edm4hep_write.py
@@ -7,8 +7,8 @@ dsvc = K4DataSvc("EventDataSvc")
 
 from Configurables import Edm4hepWriteAlg
 alg = Edm4hepWriteAlg("Edm4hepWriteAlg")
-alg.HeaderCol.Path = "EventHeader"
-alg.OutputCol.Path = "MCParticle"
+alg.HeaderOut.Path = "EventHeader"
+alg.MCParticleOut.Path = "MCParticle"
 
 from Configurables import PodioOutput
 out = PodioOutput("out")
diff --git a/Examples/src/Edm4hepTest/Edm4hepReadAlg.cpp b/Examples/src/Edm4hepTest/Edm4hepReadAlg.cpp
index f41d333b..c2c70be1 100644
--- a/Examples/src/Edm4hepTest/Edm4hepReadAlg.cpp
+++ b/Examples/src/Edm4hepTest/Edm4hepReadAlg.cpp
@@ -10,7 +10,8 @@ Edm4hepReadAlg::Edm4hepReadAlg(const std::string& name, ISvcLocator* svcLoc)
     : GaudiAlgorithm(name, svcLoc)
 {
     declareProperty("HeaderCol", m_headerCol);
-    declareProperty("InputCol", m_mcParCol, "MCParticle collection (input)");
+    declareProperty("MCParticleCol", m_mcParCol, "MCParticle collection (input)");
+    declareProperty("SimCalorimeterHitCol", m_calorimeterCol, "MCParticle collection (input)");
 }
 
 StatusCode Edm4hepReadAlg::initialize()
diff --git a/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp b/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp
index b33d5e80..39273600 100644
--- a/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp
+++ b/Examples/src/Edm4hepTest/Edm4hepWriteAlg.cpp
@@ -1,14 +1,18 @@
 #include "Edm4hepWriteAlg.h"
 #include "edm4hep/EventHeaderCollection.h"
 #include "edm4hep/MCParticleCollection.h"
+#include "edm4hep/SimCalorimeterHitCollection.h"
+#include "edm4hep/CaloHitContributionCollection.h"
 
 DECLARE_COMPONENT(Edm4hepWriteAlg)
 
 Edm4hepWriteAlg::Edm4hepWriteAlg(const std::string& name, ISvcLocator* svcLoc)
     : GaudiAlgorithm(name, svcLoc)
 {
-    declareProperty("HeaderCol", m_headerCol);
-    declareProperty("OutputCol", m_mcParCol, "MCParticle collection (output)");
+    declareProperty("HeaderOut", m_headerCol);
+    declareProperty("MCParticleOut", m_mcParCol, "MCParticle collection (output)");
+    declareProperty("SimCalorimeterHitOut", m_simCaloHitCol, "SimCalorimeterHit collection (output)");
+    declareProperty("CaloHitContributionOut", m_caloHitContCol, "CaloHitContribution collection (output)");
 }
 
 StatusCode Edm4hepWriteAlg::initialize()
@@ -32,6 +36,8 @@ StatusCode Edm4hepWriteAlg::execute()
     //auto mcCol = new edm4hep::MCParticleCollection;
     //m_mcParCol.put(mcCol);
     auto mcCol = m_mcParCol.createAndPut();
+    auto simCaloCol = m_simCaloHitCol.createAndPut();
+    auto caloHitContCol = m_caloHitContCol.createAndPut();
 
     auto p1 = mcCol->create();
     auto p2 = mcCol->create();
@@ -42,6 +48,13 @@ StatusCode Edm4hepWriteAlg::execute()
         d.addToParents(p2);
         p1.addToDaughters(d);
         p2.addToDaughters(d);
+
+        auto hit = simCaloCol->create();
+        for ( int j = 0; j < i; ++j ) {
+            auto cont = caloHitContCol->create();
+            cont.setParticle(mcCol->at(j));
+            hit.addToContributions(cont);
+        }
     }
 
     return StatusCode::SUCCESS;
diff --git a/Examples/src/Edm4hepTest/Edm4hepWriteAlg.h b/Examples/src/Edm4hepTest/Edm4hepWriteAlg.h
index 80587474..2d980885 100644
--- a/Examples/src/Edm4hepTest/Edm4hepWriteAlg.h
+++ b/Examples/src/Edm4hepTest/Edm4hepWriteAlg.h
@@ -7,6 +7,8 @@
 namespace edm4hep {
     class EventHeaderCollection;
     class MCParticleCollection;
+    class SimCalorimeterHitCollection;
+    class CaloHitContributionCollection;
 }
 
 class Edm4hepWriteAlg : public GaudiAlgorithm
@@ -24,7 +26,8 @@ class Edm4hepWriteAlg : public GaudiAlgorithm
 
         DataHandle<edm4hep::EventHeaderCollection> m_headerCol{"EventHeader", Gaudi::DataHandle::Writer, this};
         DataHandle<edm4hep::MCParticleCollection> m_mcParCol{"MCParticle", Gaudi::DataHandle::Writer, this};
-
+        DataHandle<edm4hep::SimCalorimeterHitCollection> m_simCaloHitCol{"SimCalorimeterHit", Gaudi::DataHandle::Writer, this};
+        DataHandle<edm4hep::CaloHitContributionCollection> m_caloHitContCol{"CaloHitContribution", Gaudi::DataHandle::Writer, this};
 };
 
 #endif  // TEST_EDM4HEP_WRITE_ALG_H
-- 
GitLab