From 06818baea5272c055a3cf0111681bd07a2dc33f8 Mon Sep 17 00:00:00 2001
From: lintao <lintao51@gmail.com>
Date: Sun, 10 Nov 2019 21:21:20 +0800
Subject: [PATCH] WIP: migrate HepMCRdr.

---
 Generator/CMakeLists.txt   |  2 +-
 Generator/src/HepMCRdr.cpp | 38 ++++++++++++++++++++++++++++----------
 Generator/src/HepMCRdr.h   | 22 ++++++++++++++++------
 3 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/Generator/CMakeLists.txt b/Generator/CMakeLists.txt
index 43149bd0..5d0c6d94 100644
--- a/Generator/CMakeLists.txt
+++ b/Generator/CMakeLists.txt
@@ -10,7 +10,7 @@ set(GenAlgo_srcs
     # src/LCAscHepRdr.cc
     # src/HepevtRdr.cpp
     src/SLCIORdr.cpp
-    # src/HepMCRdr.cpp
+    src/HepMCRdr.cpp
     src/GtGunTool.cpp
 )
 set(GenAlgo_incs src)
diff --git a/Generator/src/HepMCRdr.cpp b/Generator/src/HepMCRdr.cpp
index 22acd3ff..b8c81809 100644
--- a/Generator/src/HepMCRdr.cpp
+++ b/Generator/src/HepMCRdr.cpp
@@ -24,13 +24,7 @@
 using namespace plcio;
 using namespace std;
 
-
-HepMCRdr::HepMCRdr(string name){
-
-ascii_in = new HepMC::IO_GenEvent(name.c_str(),std::ios::in);
-
-m_processed_event=0;
-}
+DECLARE_COMPONENT(HepMCRdr)
 
 HepMCRdr::~HepMCRdr(){
 delete ascii_in;
@@ -104,10 +98,34 @@ bool HepMCRdr::isEnd(){
 return false;
 }
 
-bool HepMCRdr::configure(){
-return true;
+bool HepMCRdr::configure_gentool(){
+    ascii_in = new HepMC::IO_GenEvent(m_filename.value().c_str(),std::ios::in);
+
+    m_processed_event=0;
+    return true;
 }
 
 bool HepMCRdr::finish(){
-return true;
+    return true;
+}
+
+StatusCode
+HepMCRdr::initialize() {
+    StatusCode sc;
+    if (not configure_gentool()) {
+        error() << "failed to initialize." << endmsg;
+        return StatusCode::FAILURE;
+    }
+
+    return sc;
+}
+
+StatusCode
+HepMCRdr::finalize() {
+    StatusCode sc;
+    if (not finish()) {
+        error() << "Failed to finalize." << endmsg;
+        return StatusCode::FAILURE;
+    }
+    return sc;
 }
diff --git a/Generator/src/HepMCRdr.h b/Generator/src/HepMCRdr.h
index 61c777bb..e6ff3969 100644
--- a/Generator/src/HepMCRdr.h
+++ b/Generator/src/HepMCRdr.h
@@ -1,6 +1,8 @@
 #ifndef HepMCRdr_h
 #define HepMCRdr_h 1
 
+#include "GaudiKernel/AlgTool.h"
+
 #include "GenReader.h"
 #include "GenEvent.h"
 
@@ -8,19 +10,27 @@
 #include "HepMC/GenEvent.h"
 
 
-class HepMCRdr: public GenReader{
+class HepMCRdr: public extends<AlgTool, GenReader> {
 
     public:
-        HepMCRdr(string name);
+        using extends::extends;
         ~HepMCRdr();
-        bool configure();               
+
+        StatusCode initialize() override;
+        StatusCode finalize() override;    
+
+        bool configure_gentool();               
         bool mutate(MyHepMC::GenEvent& event);    
         bool finish();
         bool isEnd();
     private:
-        HepMC::IO_GenEvent *ascii_in;
-        long m_total_event;
-        long m_processed_event;
+        HepMC::IO_GenEvent *ascii_in{nullptr};
+        long m_total_event{-1};
+        long m_processed_event{-1};
+
+        // input file name
+        Gaudi::Property<std::string> m_filename{this, "Input"};
+
 };
 
 #endif
-- 
GitLab