From 460b22755e23d2c87a9df614a7a6f6b94fdf63f9 Mon Sep 17 00:00:00 2001
From: Tadej Novak <tadej.novak@cern.ch>
Date: Thu, 6 Aug 2020 16:14:49 +0200
Subject: [PATCH] Cleanup EventInfoTagBuilder

---
 .../python/CreateOutputStreams.py             |   5 +-
 .../python/OutputStreamConfig.py              |   4 +-
 .../src/EventInfoTagBuilder.cxx               | 107 ++++++++----------
 .../src/EventInfoTagBuilder.h                 |  48 ++++----
 4 files changed, 80 insertions(+), 84 deletions(-)

diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/python/CreateOutputStreams.py b/Database/AthenaPOOL/OutputStreamAthenaPool/python/CreateOutputStreams.py
index cee6ab3ebd0..ffa782fb93c 100644
--- a/Database/AthenaPOOL/OutputStreamAthenaPool/python/CreateOutputStreams.py
+++ b/Database/AthenaPOOL/OutputStreamAthenaPool/python/CreateOutputStreams.py
@@ -47,8 +47,9 @@ def createOutputStream( streamName, fileName = "", asAlg = False, noTag = False,
          # Tell tool to pick it up
          outputStream.WritingTool.AttributeListKey=key
          # build eventinfo attribute list
-         from .OutputStreamAthenaPoolConf import EventInfoTagBuilder
-         EventInfoTagBuilder   = EventInfoTagBuilder(AttributeList=key, EventInfoKey=eventInfoKey, FilterString=decisionFilter)
+         from .OutputStreamAthenaPoolConf import EventInfoAttListTool, EventInfoTagBuilder
+         EventInfoTagBuilder = EventInfoTagBuilder(AttributeList=key, EventInfoKey=eventInfoKey, FilterString=decisionFilter,
+                                                   Tool=EventInfoAttListTool())
          from AthenaCommon.GlobalFlags  import globalflags
          if globalflags.InputFormat() == 'bytestream':
             #No event-tag input in bytestream
diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/python/OutputStreamConfig.py b/Database/AthenaPOOL/OutputStreamAthenaPool/python/OutputStreamConfig.py
index fb55e77dafb..336db1fff8c 100644
--- a/Database/AthenaPOOL/OutputStreamAthenaPool/python/OutputStreamConfig.py
+++ b/Database/AthenaPOOL/OutputStreamAthenaPool/python/OutputStreamConfig.py
@@ -56,8 +56,8 @@ def OutputStreamCfg(configFlags, streamName, ItemList=[], disableEventTag=False
       outputStream.WritingTool.AttributeListKey=key
       # build eventinfo attribute list
       EventInfoAttListTool, EventInfoTagBuilder=CompFactory.getComps("EventInfoAttListTool","EventInfoTagBuilder",)
-      result.addPublicTool(EventInfoAttListTool())
-      tagBuilder = EventInfoTagBuilder(AttributeList=key)
+      tagBuilder = EventInfoTagBuilder(AttributeList=key,
+                                       Tool=EventInfoAttListTool())
       result.addEventAlgo(tagBuilder)
 
    # For xAOD output
diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.cxx b/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.cxx
index 0df956aac45..84002f72424 100755
--- a/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.cxx
+++ b/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.cxx
@@ -4,84 +4,77 @@
 
 #include "EventInfoTagBuilder.h"
 
-#include "StoreGate/ReadHandle.h"
-#include "StoreGate/WriteHandle.h"
-
-EventInfoTagBuilder::EventInfoTagBuilder( const std::string& name, ISvcLocator* pSvcLocator ) 
-  : AthAlgorithm(name, pSvcLocator),
-    m_tool("EventInfoAttListTool/EventInfoAttListTool",this) {
-  declareProperty("EventInfoKey", m_evtKey = "EventInfo");
-  declareProperty("InputList", m_inputAttList = "Input");
-  declareProperty("AttributeList", m_attributeListName);
-  declareProperty("PropagateInput", m_propInput = true);
-  declareProperty("FilterString", m_filter = "");
+#include <StoreGate/ReadHandle.h>
+#include <StoreGate/WriteHandle.h>
+
+EventInfoTagBuilder::EventInfoTagBuilder( const std::string& name, ISvcLocator* pSvcLocator )
+  : AthAlgorithm(name, pSvcLocator)
+{
 }
 
-EventInfoTagBuilder::~EventInfoTagBuilder() 
-{}
 
-StatusCode EventInfoTagBuilder::initialize() {
+StatusCode EventInfoTagBuilder::initialize()
+{
   ATH_MSG_DEBUG( "Initializing " << name() );
 
+  if (m_attributeListName.empty()) {
+    ATH_MSG_ERROR("Output attribute list name should not be empty.");
+    return StatusCode::FAILURE;
+  }
+
   ATH_CHECK( m_tool.retrieve() );
 
   ATH_CHECK( m_evtKey.initialize() );
-  ATH_CHECK( m_attributeListName.initialize() );
   ATH_CHECK( m_inputAttList.initialize() );
+  ATH_CHECK( m_attributeListName.initialize() );
 
   return StatusCode::SUCCESS;
 }
 
 
-StatusCode EventInfoTagBuilder::execute() {
+StatusCode EventInfoTagBuilder::execute()
+{
   ATH_MSG_DEBUG( "Executing " << name() );
 
-
   SG::ReadHandle<xAOD::EventInfo> h_evt(m_evtKey);
+  if (!h_evt.isValid()) {
+    ATH_MSG_ERROR("Did not find xAOD::EventInfo");
+    return StatusCode::FAILURE;
+  }
 
-  /** create a EventInfo Tag and ask the tool to fill it */ 
-  if (h_evt.isValid()) {
-    std::unique_ptr<AthenaAttributeList> attribList =
-      m_tool->getAttributeListPtr( *h_evt );
-
-    // Check whether to propagate
-    if (m_propInput) {
-      SG::ReadHandle<AthenaAttributeList> h_att(m_inputAttList);
-      // Check if there is an input to propagate
-      if (h_att.isValid()) {
-        for (auto it = h_att->specification().begin();
-                  it!= h_att->specification().end(); ++it) {
-          // Only propagate bool properties
-          if (it->typeName()=="bool"&&!attribList->exists(it->name())) {
-            // Check if there is filtering on the name
-            if (m_filter != "") {
-              if (it->name().find(m_filter)!=std::string::npos) {
-                // Add those bools to the output attribute list
-                (*attribList).extend(it->name(),it->type());
-                (*attribList)[it->name()].data<bool>() = (*h_att)[it->name()].data<bool>();
-              }
+  /** create a EventInfo Tag and ask the tool to fill it */
+  std::unique_ptr<AthenaAttributeList> attribList =
+    m_tool->getAttributeListPtr( *h_evt );
+
+  // Check whether to propagate
+  if (m_propInput) {
+    SG::ReadHandle<AthenaAttributeList> h_att(m_inputAttList);
+    // Check if there is an input to propagate
+    if (h_att.isValid()) {
+      for (auto it = h_att->specification().begin();
+                it!= h_att->specification().end(); ++it) {
+        // Only propagate bool properties
+        if (it->typeName()=="bool"&&!attribList->exists(it->name())) {
+          // Check if there is filtering on the name
+          if (m_filter != "") {
+            if (it->name().find(m_filter)!=std::string::npos) {
+              // Add those bools to the output attribute list
+              (*attribList).extend(it->name(),it->type());
+              (*attribList)[it->name()].data<bool>() = (*h_att)[it->name()].data<bool>();
             }
-          } // take only bools
-        }   // loop
-      } else {     // valid input
-        ATH_MSG_INFO("No input attribute list");
-      }
-    }       // propagate
-
-    /** record attribute list to SG */
-    SG::WriteHandle<AthenaAttributeList> wh(m_attributeListName);
-    ATH_CHECK( wh.record(std::move(attribList)) );
-  } else {
-    ATH_MSG_WARNING("Did not find xAOD::EventInfo");
-  }
+          }
+        } // take only bools
+      }   // loop
+    } else { // valid input
+      ATH_MSG_INFO("No input attribute list");
+    }
+  } // propagate
+
+  /** record attribute list to SG */
+  SG::WriteHandle<AthenaAttributeList> wh(m_attributeListName);
+  ATH_CHECK( wh.record(std::move(attribList)) );
 
   ATH_MSG_DEBUG( "Finished " << name() );
 
   return StatusCode::SUCCESS;
 }
-
-
-StatusCode EventInfoTagBuilder::finalize() 
-{
-  return StatusCode::SUCCESS;
-}
diff --git a/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.h b/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.h
index 5e34bf6bf95..b0b3fb85fc1 100755
--- a/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.h
+++ b/Database/AthenaPOOL/OutputStreamAthenaPool/src/EventInfoTagBuilder.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef EVENTTAGALGS_EVENTINFOTAGBUILDER_H
@@ -14,8 +14,8 @@ Updated : February 2006
 
 DESCRIPTION:
 
-Retrieves event tag data from an AOD file, stores this data in an attribute 
-list object and records the attribute list object in the TDS for subsequent 
+Retrieves event tag data from an AOD file, stores this data in an attribute
+list object and records the attribute list object in the TDS for subsequent
 inclusion in an event tag database.
 
 *****************************************************************************/
@@ -27,37 +27,39 @@ inclusion in an event tag database.
 
 */
 
-#include "AthenaBaseComps/AthAlgorithm.h"
+#include <AthenaBaseComps/AthAlgorithm.h>
+#include <GaudiKernel/ToolHandle.h>
+#include <PersistentDataModel/AthenaAttributeList.h>
+#include <StoreGate/ReadHandleKey.h>
+#include <StoreGate/WriteHandleKey.h>
+#include <xAODEventInfo/EventInfo.h>
+
 #include "EventInfoAttListTool.h"
-#include "StoreGate/ReadHandleKey.h"
-#include "StoreGate/WriteHandleKey.h"
-#include "xAODEventInfo/EventInfo.h"
-#include "PersistentDataModel/AthenaAttributeList.h"
-#include "GaudiKernel/ToolHandle.h"
 
-class EventInfoTagBuilder : public AthAlgorithm {
+class EventInfoTagBuilder : public AthAlgorithm
+{
 public:
 
   /// Standard constructor.
   EventInfoTagBuilder(const std::string& name, ISvcLocator* pSvcLocator);
-  
+
   /// Destructor.
-  ~EventInfoTagBuilder();
-  
-  StatusCode initialize();
-  StatusCode execute();
-  StatusCode finalize();
+  ~EventInfoTagBuilder() = default;
+
+  virtual StatusCode initialize() override;
+  virtual StatusCode execute() override;
 
 private:
-  
+
   /// Global Event Tag Tool
-  ToolHandle<EventInfoAttListTool> m_tool;
+  ToolHandle<EventInfoAttListTool> m_tool{this, "Tool", "EventInfoAttListTool/EventInfoAttListTool", "EventInfoAttListTool used"};
+
+  SG::ReadHandleKey<xAOD::EventInfo> m_evtKey{this, "EventInfoKey", "EventInfo", "xAOD::EventInfo ReadHandleKey"};
+  SG::ReadHandleKey<AthenaAttributeList> m_inputAttList{this, "InputList", "Input", "Input Athena attribute list ReadHandleKey"};
+  SG::WriteHandleKey<AthenaAttributeList> m_attributeListName{this, "AttributeList", "SimpleTag", "Output Athena attribute list WriteHandleKey"};
 
-  SG::ReadHandleKey<xAOD::EventInfo> m_evtKey;
-  SG::ReadHandleKey<AthenaAttributeList> m_inputAttList;
-  SG::WriteHandleKey<AthenaAttributeList> m_attributeListName;
-  bool m_propInput;
-  std::string m_filter;
+  Gaudi::Property<bool> m_propInput{this, "PropagateInput", true, "Propagate input attribute list to the output"};
+  Gaudi::Property<std::string> m_filter{this, "FilterString", "", "Filter input attribute list when propagating to the output"};
 
 };
 
-- 
GitLab