From 8647c2bc9757d5a4018a3520ec063d649de9514a Mon Sep 17 00:00:00 2001
From: Mark Hodgkinson <m.hodgkinson@sheffield.ac.uk>
Date: Thu, 23 Nov 2017 16:02:24 +0000
Subject: [PATCH] Update PhysValPFO to retrieve all objects from StoreGate via
 ReadHandleKeys.

Former-commit-id: 64d71506366b3b7bbbfe8489a18952c1ce7d2d84
---
 .../PFlowValidation/PFODQA/CMakeLists.txt     |  2 +-
 .../PFlowValidation/PFODQA/src/PhysValPFO.cxx | 57 ++++++++++---------
 .../PFlowValidation/PFODQA/src/PhysValPFO.h   | 13 +++--
 3 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/Reconstruction/PFlow/PFlowValidation/PFODQA/CMakeLists.txt b/Reconstruction/PFlow/PFlowValidation/PFODQA/CMakeLists.txt
index 4212942edcb5..1ba0b67b81c6 100644
--- a/Reconstruction/PFlow/PFlowValidation/PFODQA/CMakeLists.txt
+++ b/Reconstruction/PFlow/PFlowValidation/PFODQA/CMakeLists.txt
@@ -10,10 +10,10 @@ atlas_depends_on_subdirs( PUBLIC
                           GaudiKernel
                           PRIVATE
                           Control/AthenaMonitoring
+			  Control/StoreGate
                           Event/xAOD/xAODCaloEvent
                           Event/xAOD/xAODPFlow
 			  Event/xAOD/xAODTracking
-                          Reconstruction/PFlow/PFlowUtils
                           Reconstruction/PFlow/PFlowValidation/PFOHistUtils
                           Tracking/TrkValidation/TrkValHistUtils )
 
diff --git a/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.cxx b/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.cxx
index 0efae73a673b..a2ed45c58e2c 100644
--- a/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.cxx
+++ b/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.cxx
@@ -5,8 +5,7 @@
 #include "PhysValPFO.h"
 #include "xAODPFlow/PFOContainer.h"
 
-PhysValPFO::PhysValPFO (const std::string& type, const std::string& name, const IInterface* parent ) : ManagedMonitorToolBase( type, name, parent ), m_vertexContainerReadHandle("PrimaryVertices"),m_retrievePFOTool("RetrievePFOTool",this), m_useLCScale(false), m_useNeutralPFO(false) {
-  declareProperty("RetrievePFOTool",m_retrievePFOTool,"Name of PFO getter");
+PhysValPFO::PhysValPFO (const std::string& type, const std::string& name, const IInterface* parent ) : ManagedMonitorToolBase( type, name, parent ), m_useLCScale(false), m_useNeutralPFO(false) {
   declareProperty("useLCScale",m_useLCScale, " Select which PFO setup to use - LC or EM ");
   declareProperty("useNeutralPFO", m_useNeutralPFO, "Select whether to use neutral or charged PFO");
 }
@@ -15,7 +14,10 @@ PhysValPFO::~PhysValPFO() {}
 
 StatusCode PhysValPFO::initialize(){
   ATH_CHECK(ManagedMonitorToolBase::initialize());
-  ATH_CHECK(m_retrievePFOTool.retrieve());
+
+  ATH_CHECK(m_vertexContainerReadHandleKey.initialize());
+  ATH_CHECK(m_PFOContainerHandleKey.initialize());
+
   return StatusCode::SUCCESS;
 }
 
@@ -57,15 +59,16 @@ StatusCode PhysValPFO::bookHistograms(){
 StatusCode PhysValPFO::fillHistograms(){
 
   const xAOD::Vertex* theVertex = nullptr;
-
+  
   if (!m_useNeutralPFO){
-    if(!m_vertexContainerReadHandle.isValid()){
-      ATH_MSG_WARNING("Invalid ReadHandle for xAOD::VertexContainer with key: " << m_vertexContainerReadHandle.key());
+    SG::ReadHandle<xAOD::VertexContainer> vertexContainerReadHandle(m_vertexContainerReadHandleKey);
+    if(!vertexContainerReadHandle.isValid()){
+      ATH_MSG_WARNING("Invalid ReadHandle for xAOD::VertexContainer with key: " << vertexContainerReadHandle.key());
     }
     else {
       //Vertex finding logic based on logic in JetRecTools/PFlowPseudoJetGetter tool
       //Usually the 0th vertex is the primary one, but this is not always the case. So we will choose the first vertex of type PriVtx
-      for (auto vertex : (*m_vertexContainerReadHandle.ptr())) {
+      for (auto vertex : *vertexContainerReadHandle) {
 	if (xAOD::VxType::PriVtx == vertex->vertexType() ) {
 	theVertex = vertex;
 	break;
@@ -77,29 +80,31 @@ StatusCode PhysValPFO::fillHistograms(){
     }//if valid read handle
   }
 
-  
-  const xAOD::PFOContainer* thePFOContainer = nullptr;
-
-  if (!m_useNeutralPFO) thePFOContainer = m_retrievePFOTool->retrievePFO(CP::EM,CP::charged);
-  else{
-    if (!m_useLCScale) thePFOContainer = m_retrievePFOTool->retrievePFO(CP::EM,CP::neutral);
-    else thePFOContainer = m_retrievePFOTool->retrievePFO(CP::LC,CP::neutral);
+  StatusCode sc = StatusCode::SUCCESS;
+  if (m_useNeutralPFO) {    
+    if (m_useLCScale) sc = m_PFOContainerHandleKey.assign("JetETMiss_LCNeutralParticleFlowObjects");
+    else sc = m_PFOContainerHandleKey.assign("JetETMissNeutralParticleFlowObjects");
   }
-
-  if (!thePFOContainer){
-    ATH_MSG_WARNING(" Have NULL pointer to xAOD::PFOContainer");
-    return StatusCode::SUCCESS;
+    
+  if (StatusCode::SUCCESS != sc) {
+    ATH_MSG_ERROR("Could not assign PFO Container key name");
+    return sc;
+  }
+    
+  SG::ReadHandle<xAOD::PFOContainer> PFOContainerReadHandle(m_PFOContainerHandleKey);
+  if(!PFOContainerReadHandle.isValid()){
+     ATH_MSG_WARNING("Invalid ReadHandle for xAOD::PFOContainer with key: " << PFOContainerReadHandle.key());
+     return StatusCode::SUCCESS;
   }
   
-  xAOD::PFOContainer::const_iterator firstPFO = thePFOContainer->begin();
-  xAOD::PFOContainer::const_iterator lastPFO = thePFOContainer->end();
-
-  for (; firstPFO != lastPFO; ++firstPFO) {
-    const xAOD::PFO* thePFO = *firstPFO;
-    if (!m_useNeutralPFO) m_PFOChargedValidationPlots->fill(*thePFO,theVertex);
-    else if (m_useNeutralPFO) m_PFONeutralValidationPlots->fill(*thePFO);
+  for (auto thePFO : *PFOContainerReadHandle){
+    if(thePFO){
+       if (!m_useNeutralPFO) m_PFOChargedValidationPlots->fill(*thePFO,theVertex);
+       else if (m_useNeutralPFO) m_PFONeutralValidationPlots->fill(*thePFO);
+    }
+    else ATH_MSG_WARNING("Invalid pointer to xAOD::PFO");
   }
-
+  
   return StatusCode::SUCCESS;
 
 }
diff --git a/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.h b/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.h
index 638dc763098f..c5d35c070d22 100644
--- a/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.h
+++ b/Reconstruction/PFlow/PFlowValidation/PFODQA/src/PhysValPFO.h
@@ -9,8 +9,9 @@
 #include "PFONeutralValidationPlots.h"
 #include "AthenaMonitoring/ManagedMonitorToolBase.h"
 #include <string>
-#include "PFlowUtils/IRetrievePFOTool.h"
 #include "xAODTracking/VertexContainer.h"
+#include "xAODPFlow/PFOContainer.h"
+#include "StoreGate/ReadHandleKey.h"
 
 class PhysValPFO : public ManagedMonitorToolBase {
 
@@ -31,17 +32,17 @@ public:
  private:
 
   /** ReadHandle to retrieve xAOD::VertexContainer */
-  SG::ReadHandle<xAOD::VertexContainer> m_vertexContainerReadHandle;
-  
+  SG::ReadHandleKey<xAOD::VertexContainer> m_vertexContainerReadHandleKey{this,"primaryVerticesName","PrimaryVertices","ReadHandleKey for the PrimaryVertices container"};
+
+  /** ReadHandle to retrieve xAOD::PFOContainer */
+  SG::ReadHandleKey<xAOD::PFOContainer> m_PFOContainerHandleKey{this,"PFOContainerName","JetETMissChargedParticleFlowObjects","ReadHandleKey for the PFO container"};
+    
   /** Pointer to class that deals with histograms for charged PFO */
   std::unique_ptr<PFOChargedValidationPlots> m_PFOChargedValidationPlots;
 
   /** Pointer to class that deals with histograms for neutral PFO */
   std::unique_ptr<PFONeutralValidationPlots> m_PFONeutralValidationPlots;
   
-  /** Tool to retrieve PFO */
-  ToolHandle<CP::IRetrievePFOTool> m_retrievePFOTool;
-
   /** Select which PFO setup to use - LC or EM */
   bool m_useLCScale;
   
-- 
GitLab