From 15b0f1f29991790376f589280d1676bc3fbd35a3 Mon Sep 17 00:00:00 2001
From: "lintao@ihep.ac.cn" <lintao@ihep.ac.cn>
Date: Fri, 14 Jun 2024 06:34:44 +0000
Subject: [PATCH] add edm4cepc

---
 Examples/CMakeLists.txt                       |  2 +
 Examples/options/edm4cepc_write.py            | 23 ++++++++
 Examples/src/Edm4hepTest/Edm4cepcWriteAlg.cpp | 57 +++++++++++++++++++
 cmake/CEPCSWDependencies.cmake                |  9 +++
 cmake/CEPCSWOptions.cmake                     |  3 +
 cmake/internal_edm4cepc.cmake                 | 10 ++++
 6 files changed, 104 insertions(+)
 create mode 100644 Examples/options/edm4cepc_write.py
 create mode 100644 Examples/src/Edm4hepTest/Edm4cepcWriteAlg.cpp
 create mode 100644 cmake/internal_edm4cepc.cmake

diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt
index 6d37ea63..2a4bf50b 100644
--- a/Examples/CMakeLists.txt
+++ b/Examples/CMakeLists.txt
@@ -8,12 +8,14 @@ gaudi_add_module(Examples
                          src/Edm4hepTest/Edm4hepReadAlg.cpp
                          src/Edm4hepTest/Edm4hepReadDCAlg.cpp
                          src/Edm4hepTest/Edm4hepWriteAlg.cpp
+                         src/Edm4hepTest/Edm4cepcWriteAlg.cpp
                          src/DumpIDAlg/DumpIDAlg.cpp
                  LINK DetInterface
                       k4FWCore::k4FWCore
                       Gaudi::GaudiAlgLib Gaudi::GaudiKernel
                       ${LCIO_LIBRARIES} 
                       ${DD4hep_COMPONENT_LIBRARIES}
+                      EDM4CEPC::edm4cepc EDM4CEPC::edm4cepcDict
                       EDM4HEP::edm4hep EDM4HEP::edm4hepDict
                       ${podio_LIBRARIES} podio::podioRootIO
 )
diff --git a/Examples/options/edm4cepc_write.py b/Examples/options/edm4cepc_write.py
new file mode 100644
index 00000000..133b2470
--- /dev/null
+++ b/Examples/options/edm4cepc_write.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+from Gaudi.Configuration import *
+
+from Configurables import k4DataSvc
+dsvc = k4DataSvc("EventDataSvc")
+
+from Configurables import Edm4cepcWriteAlg
+alg = Edm4cepcWriteAlg("Edm4cepcWriteAlg")
+
+from Configurables import PodioOutput
+out = PodioOutput("out")
+out.filename = "test.root"
+out.outputCommands = ["keep *"]
+
+# ApplicationMgr
+from Configurables import ApplicationMgr
+ApplicationMgr( TopAlg = [alg, out],
+                EvtSel = 'NONE',
+                EvtMax = 10,
+                ExtSvc=[dsvc],
+                OutputLevel=DEBUG
+)
diff --git a/Examples/src/Edm4hepTest/Edm4cepcWriteAlg.cpp b/Examples/src/Edm4hepTest/Edm4cepcWriteAlg.cpp
new file mode 100644
index 00000000..87b2e219
--- /dev/null
+++ b/Examples/src/Edm4hepTest/Edm4cepcWriteAlg.cpp
@@ -0,0 +1,57 @@
+/*
+ * Description:
+ *   This algorithm is used to test the EDM4hep extension for cepc.
+ *
+ *   In the extension, we keep the same namespace as edm4hep. 
+ *   The header file path is different.
+ *
+ * Author: 
+ *   Tao Lin <lintao AT ihep.ac.cn>
+ */
+
+#include "k4FWCore/DataHandle.h"
+#include "GaudiAlg/GaudiAlgorithm.h"
+
+#include "edm4cepc/RecTofCollection.h"
+
+class Edm4cepcWriteAlg: public GaudiAlgorithm {
+public:
+
+    Edm4cepcWriteAlg(const std::string& name, ISvcLocator* svcLoc)
+        : GaudiAlgorithm(name, svcLoc) {
+
+    }
+
+    StatusCode initialized() {
+
+        return GaudiAlgorithm::initialize();
+    }
+
+    StatusCode execute() {
+
+        auto rectofCol = m_rectofCol.createAndPut();
+
+        for (size_t i = 0; i < 3; ++i) {
+            auto rectof = rectofCol->create();
+
+            rectof.setTime(100.);
+            rectof.setTimeExp({99.,99.5,100,100.5,101});
+            rectof.setSigma(1.);
+            rectof.setPathLength({50,50.5,51,51.5,52});
+            rectof.setPosition({100,100,10});
+        }
+
+        return StatusCode::SUCCESS;
+    }
+
+    StatusCode finalize() {
+
+        return GaudiAlgorithm::finalize();
+    }
+
+private:
+    DataHandle<edm4hep::RecTofCollection> m_rectofCol{"RecTofCollection", Gaudi::DataHandle::Writer, this};
+
+};
+
+DECLARE_COMPONENT(Edm4cepcWriteAlg)
diff --git a/cmake/CEPCSWDependencies.cmake b/cmake/CEPCSWDependencies.cmake
index 90d8914e..f14a91c5 100644
--- a/cmake/CEPCSWDependencies.cmake
+++ b/cmake/CEPCSWDependencies.cmake
@@ -44,3 +44,12 @@ else()
   message("Try to use an internal installation of CKF BELLE")
   include("${CMAKE_CURRENT_LIST_DIR}/internal_ckf.cmake")
 endif()
+
+
+if (CEPCSW_USE_SYSTEM_EDM4CEPC)
+  message("Try to use an existing installation of EDM4CEPC")
+  find_package(EDM4CEPC)
+else()
+  message("Try to use an internal installation of EDM4CEPC")
+  include("${CMAKE_CURRENT_LIST_DIR}/internal_edm4cepc.cmake")
+endif()
diff --git a/cmake/CEPCSWOptions.cmake b/cmake/CEPCSWOptions.cmake
index 32e00142..a853022f 100644
--- a/cmake/CEPCSWOptions.cmake
+++ b/cmake/CEPCSWOptions.cmake
@@ -8,3 +8,6 @@ option(CEPCSW_USE_SYSTEM_CKF_BELLE
        "Use the existing installation of CKF BELLE. Otherwise the internal version will be used."
        FALSE)
 
+option(CEPCSW_USER_SYSTEM_EDM4CEPC
+       "Use the existing installation of EDM4CEPC. Otherwise the internal version will be used."
+       FALSE)
diff --git a/cmake/internal_edm4cepc.cmake b/cmake/internal_edm4cepc.cmake
new file mode 100644
index 00000000..65c5f1f6
--- /dev/null
+++ b/cmake/internal_edm4cepc.cmake
@@ -0,0 +1,10 @@
+
+include(FetchContent)
+
+FetchContent_Declare(
+  EDM4CEPC
+  GIT_REPOSITORY https://code.ihep.ac.cn/cepc/externals/EDM4cepc.git
+  GIT_TAG 8eb38894b7b055bf6fe99d4b156e97f7e9466a26
+  )
+
+FetchContent_MakeAvailable(EDM4CEPC)
-- 
GitLab