From 1a375c420306273c3ba7cbe34d250a8c87696d5b Mon Sep 17 00:00:00 2001
From: lintao <lintao51@gmail.com>
Date: Sun, 10 Nov 2019 20:59:05 +0800
Subject: [PATCH] WIP: migrate GenPrinter.

---
 Generator/CMakeLists.txt     |  2 +-
 Generator/src/GenPrinter.cpp | 46 +++++++++++++++++++++++++-----------
 Generator/src/GenPrinter.h   | 19 +++++++++------
 3 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/Generator/CMakeLists.txt b/Generator/CMakeLists.txt
index 0f850fcf..79fbb6a6 100644
--- a/Generator/CMakeLists.txt
+++ b/Generator/CMakeLists.txt
@@ -6,7 +6,7 @@ set(GenAlgo_srcs
     src/GenEvent.cpp 
     src/GenReader.cpp 
     src/StdHepRdr.cpp 
-    # src/GenPrinter.cpp
+    src/GenPrinter.cpp
     # src/LCAscHepRdr.cc
     # src/HepevtRdr.cpp
     # src/SLCIORdr.cpp
diff --git a/Generator/src/GenPrinter.cpp b/Generator/src/GenPrinter.cpp
index 827f5b40..48c6d499 100644
--- a/Generator/src/GenPrinter.cpp
+++ b/Generator/src/GenPrinter.cpp
@@ -1,11 +1,7 @@
 #include "GenPrinter.h"
 #include "GenEvent.h"
 
-GenPrinter::GenPrinter(string name){}
-
-
-GenPrinter::~GenPrinter(){
-}
+DECLARE_COMPONENT(GenPrinter)
 
 bool GenPrinter::mutate(MyHepMC::GenEvent& event){
     std::cout << "print mc info for event "<< event.getID() << ", mc size ="<< event.m_mc_vec.size() <<  std::endl;
@@ -19,12 +15,12 @@ bool GenPrinter::mutate(MyHepMC::GenEvent& event){
     << "Charge            :"<< p.getCharge            ()<<std::endl 
     << "Time              :"<< p.getTime              ()<<std::endl 
     << "Mass              :"<< p.getMass              ()<<std::endl 
-    << "Vertex            :"<< p.getVertex            ()[0]<<std::endl 
-    << "Endpoint          :"<< p.getEndpoint          ()[1]<<std::endl 
-    << "Momentum          :"<< p.getMomentum          ()[2]<<std::endl 
-    << "MomentumAtEndpoint:"<< p.getMomentumAtEndpoint()[0]<<std::endl 
-    << "Spin              :"<< p.getSpin              ()[1]<<std::endl 
-    << "ColorFlow         :"<< p.getColorFlow         ()[1]<<std::endl 
+    << "Vertex            :"<< p.getVertex            ()<<std::endl 
+    << "Endpoint          :"<< p.getEndpoint          ()<<std::endl 
+    << "Momentum          :"<< p.getMomentum          ()<<std::endl 
+    << "MomentumAtEndpoint:"<< p.getMomentumAtEndpoint()<<std::endl 
+    << "Spin              :"<< p.getSpin              ()<<std::endl 
+    << "ColorFlow         :"<< p.getColorFlow         ()<<std::endl 
     << "Parent size       :"<< p.parents_size         ()<<std::endl 
     << "Daughter size     :"<< p.daughters_size       ()<<std::endl; 
     //for(unsigned int j=0; j<p.parents_size(); j++) std::cout << " for parent: "<< j << ",PDG="<< p.getParents(j).getPDG() << ",id=:"<< p.getParents(j).id()<<std::endl;
@@ -33,10 +29,32 @@ bool GenPrinter::mutate(MyHepMC::GenEvent& event){
     return true;
 }
 
-bool GenPrinter::configure(){
-return true;
+bool GenPrinter::configure_gentool(){
+    return true;
 }
 
 bool GenPrinter::finish(){
-return true;
+    return true;
 }
+
+StatusCode
+GenPrinter::initialize() {
+    StatusCode sc;
+    if (not configure_gentool()) {
+        error() << "failed to initialize." << endmsg;
+        return StatusCode::FAILURE;
+    }
+
+    return sc;
+}
+
+StatusCode
+GenPrinter::finalize() {
+    StatusCode sc;
+    if (not finish()) {
+        error() << "Failed to finalize." << endmsg;
+        return StatusCode::FAILURE;
+    }
+    return sc;
+}
+
diff --git a/Generator/src/GenPrinter.h b/Generator/src/GenPrinter.h
index 9fe8a1c9..bf532003 100644
--- a/Generator/src/GenPrinter.h
+++ b/Generator/src/GenPrinter.h
@@ -1,19 +1,24 @@
 #ifndef GenPrinter_h
 #define GenPrinter_h 1
 
+#include <GaudiKernel/AlgTool.h>
 #include "GenEvent.h"
 #include "IGenTool.h"
 
 using namespace std;
 
-class GenPrinter: public IGenTool{
+class GenPrinter: public extends<AlgTool, IGenTool> {
+public:
+    using extends::extends;
 
-    public:
-        GenPrinter(string name);
-        ~GenPrinter();
-        bool configure() override;               
-        bool mutate(MyHepMC::GenEvent& event) override;    
-        bool finish() override;
+    // Overriding initialize and finalize
+    StatusCode initialize() override;
+    StatusCode finalize() override;
+
+public:
+    bool configure_gentool() override;               
+    bool mutate(MyHepMC::GenEvent& event) override;    
+    bool finish() override;
 };
 
 #endif
-- 
GitLab