From ee9fe93830b7842670f6e90577e4d7634448ac47 Mon Sep 17 00:00:00 2001
From: John Chapman <John.Chapman@cern.ch>
Date: Thu, 10 Oct 2024 12:49:15 +0200
Subject: [PATCH] InDetV0Finder and InDetAlignGenTools clean-up obsolete syntax
 related to PartPropSvc

---
 .../InDetAlignGenTools/src/InDetAlignFillTrack.cxx        | 8 +-------
 InnerDetector/InDetConfig/python/InDetV0FinderConfig.py   | 7 ++++++-
 .../InDetV0Finder/InDetV0Finder/InDetV0FinderTool.h       | 2 ++
 .../InDetV0Finder/InDetV0Finder/V0MainDecorator.h         | 5 +++--
 .../InDetRecAlgs/InDetV0Finder/src/InDetV0FinderTool.cxx  | 7 ++-----
 .../InDetRecAlgs/InDetV0Finder/src/V0MainDecorator.cxx    | 8 +++-----
 6 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/InnerDetector/InDetAlignTools/InDetAlignGenTools/src/InDetAlignFillTrack.cxx b/InnerDetector/InDetAlignTools/InDetAlignGenTools/src/InDetAlignFillTrack.cxx
index 3bf486d087a..394919a31de 100644
--- a/InnerDetector/InDetAlignTools/InDetAlignGenTools/src/InDetAlignFillTrack.cxx
+++ b/InnerDetector/InDetAlignTools/InDetAlignGenTools/src/InDetAlignFillTrack.cxx
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
+   Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
  */
 
 //////////////////////////////////////////////////////////////////////////
@@ -19,8 +19,6 @@
 #include "GaudiKernel/INTupleSvc.h"
 #include "GaudiKernel/SmartDataPtr.h"
 
-#include "GaudiKernel/IPartPropSvc.h"
-
 #include "AthContainers/DataVector.h"
 
 #include "TrkTrack/Track.h"
@@ -125,10 +123,6 @@ StatusCode InDetAlignFillTrack::initialize() {
     ATH_CHECK(m_truthToTrack.retrieve());
     // Get Extrapolator Tool
     ATH_CHECK(m_extrapolator.retrieve());
-    // retrieve the PartPropSvc service (need for Cosmics)
-    IPartPropSvc* p_PartPropSvc;
-    static const bool CREATEIFNOTTHERE(true);
-    ATH_CHECK(svcLoc()->service("PartPropSvc", p_PartPropSvc, CREATEIFNOTTHERE));
   }
   // Book Ntuple
   bookNtuple();
diff --git a/InnerDetector/InDetConfig/python/InDetV0FinderConfig.py b/InnerDetector/InDetConfig/python/InDetV0FinderConfig.py
index d64fa643760..9fe3824aef3 100644
--- a/InnerDetector/InDetConfig/python/InDetV0FinderConfig.py
+++ b/InnerDetector/InDetConfig/python/InDetV0FinderConfig.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 
 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
 from AthenaConfiguration.ComponentFactory import CompFactory
@@ -77,6 +77,8 @@ def InDetV0FinderToolCfg(flags, name="InDetV0FinderTool", **kwargs):
                                useThetaCnst        = True,
                                InputParticleMasses = [0.511,0.511])))
 
+    from AthenaServices.PartPropSvcConfig import PartPropSvcCfg
+    kwargs.setdefault("PartPropSvc", acc.getPrimaryAndMerge(PartPropSvcCfg(flags)).name)
     acc.setPrivateTools(CompFactory.InDet.InDetV0FinderTool(name, **kwargs))
     return acc
 
@@ -104,6 +106,9 @@ def V0MainDecoratorCfg(flags, name="V0Decorator", **kwargs):
         kwargs.setdefault("V0Tools",  acc.popToolsAndMerge(
             V0ToolsCfg(flags, name+"_V0Tools")))
 
+    if "masses" not in kwargs or kwargs("masses") == 1:
+        from AthenaServices.PartPropSvcConfig import PartPropSvcCfg
+        kwargs.setdefault("PartPropSvc", acc.getPrimaryAndMerge(PartPropSvcCfg(flags)).name)
     acc.setPrivateTools(CompFactory.InDet.V0MainDecorator(name, **kwargs))
     return acc
 
diff --git a/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/InDetV0FinderTool.h b/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/InDetV0FinderTool.h
index 3784ce51014..c776689f56e 100755
--- a/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/InDetV0FinderTool.h
+++ b/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/InDetV0FinderTool.h
@@ -26,6 +26,7 @@
 #include "BeamSpotConditionsData/BeamSpotData.h"
 #include "TrkParameters/TrackParameters.h"
 #include "GeoPrimitives/GeoPrimitives.h" //Needed for Amg::Vector3D
+#include "GaudiKernel/IPartPropSvc.h"
 #include <atomic>
 
 #include "InDetConversionFinderTools/VertexPointEstimator.h"
@@ -232,6 +233,7 @@ namespace InDet
     SG::ReadHandleKeyArray<xAOD::TrackParticleContainer> m_RelinkContainers{this, "RelinkTracks", {}, "Track Containers if they need to be relinked through indirect use" };
     ElementLink<xAOD::TrackParticleContainer> makeLink(const xAOD::TrackParticle*, const std::vector<const xAOD::TrackParticleContainer*>&) const;
 
+    ServiceHandle<IPartPropSvc> m_partPropSvc{this, "PartPropSvc", "PartPropSvc"};
   };
 
 }//end of namespace InDet
diff --git a/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/V0MainDecorator.h b/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/V0MainDecorator.h
index cbfe6452f45..ccff90bd148 100644
--- a/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/V0MainDecorator.h
+++ b/InnerDetector/InDetRecAlgs/InDetV0Finder/InDetV0Finder/V0MainDecorator.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 */
 
 #ifndef INDETV0FINDER_V0MAINDECORATOR_H
@@ -9,7 +9,7 @@
 #include "GaudiKernel/ToolHandle.h"
 #include "xAODTracking/VertexContainerFwd.h"
 #include "TrkVertexAnalysisUtils/V0Tools.h"
-
+#include "GaudiKernel/IPartPropSvc.h"
 
 namespace InDet
 {
@@ -131,6 +131,7 @@ namespace InDet
     SG::WriteDecorHandleKey<xAOD::VertexContainer>  m_decorPz_lb 
                     { this, "Pz_lb", ".pz", "Pz for Lambdabar" };
 
+    ServiceHandle<IPartPropSvc> m_partPropSvc{this, "PartPropSvc", "PartPropSvc"};
   };
 
 }
diff --git a/InnerDetector/InDetRecAlgs/InDetV0Finder/src/InDetV0FinderTool.cxx b/InnerDetector/InDetRecAlgs/InDetV0Finder/src/InDetV0FinderTool.cxx
index fe9d07e8b85..727b70e6252 100755
--- a/InnerDetector/InDetRecAlgs/InDetV0Finder/src/InDetV0FinderTool.cxx
+++ b/InnerDetector/InDetRecAlgs/InDetV0Finder/src/InDetV0FinderTool.cxx
@@ -20,8 +20,6 @@
 #include "TrkVertexAnalysisUtils/V0Tools.h"
 #include "TrkVKalVrtFitter/TrkVKalVrtFitter.h"
 
-#include "GaudiKernel/IPartPropSvc.h"
-
 #include "xAODTracking/TrackingPrimitives.h"
 #include "HepPDT/ParticleDataTable.hh"
 #include "TruthUtils/HepMCHelpers.h"
@@ -71,9 +69,8 @@ StatusCode InDetV0FinderTool::initialize()
   ATH_MSG_DEBUG("Retrieved tool " << m_iGammaFitter);
 
   // get the Particle Properties Service
-  IPartPropSvc* partPropSvc = nullptr;
-  ATH_CHECK( service("PartPropSvc", partPropSvc, true) );
-  m_particleDataTable = partPropSvc->PDT();
+  ATH_CHECK(m_partPropSvc.retrieve());
+  m_particleDataTable = m_partPropSvc->PDT();
 
   // uploading the V0 tools
   ATH_CHECK( m_V0Tools.retrieve() );
diff --git a/InnerDetector/InDetRecAlgs/InDetV0Finder/src/V0MainDecorator.cxx b/InnerDetector/InDetRecAlgs/InDetV0Finder/src/V0MainDecorator.cxx
index cf2bef2935a..ece93b05c85 100644
--- a/InnerDetector/InDetRecAlgs/InDetV0Finder/src/V0MainDecorator.cxx
+++ b/InnerDetector/InDetRecAlgs/InDetV0Finder/src/V0MainDecorator.cxx
@@ -1,10 +1,9 @@
 /*
-  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 */
 #include "InDetV0Finder/V0MainDecorator.h"
 #include "StoreGate/WriteDecorHandle.h"
 #include "HepPDT/ParticleDataTable.hh"
-#include "GaudiKernel/IPartPropSvc.h"
 #include "xAODTracking/Vertex.h"
 #include "xAODTracking/VertexContainer.h"
 #include "TruthUtils/HepMCHelpers.h"
@@ -74,9 +73,8 @@ StatusCode V0MainDecorator::initialize(){
 
   if (m_masses == 1) {
     // get the Particle Properties Service
-    IPartPropSvc* partPropSvc = nullptr;
-    ATH_CHECK( service("PartPropSvc", partPropSvc, true) );
-    auto *particleDataTable = partPropSvc->PDT();
+    ATH_CHECK(m_partPropSvc.retrieve());
+    auto *particleDataTable = m_partPropSvc->PDT();
   
     const HepPDT::ParticleData* pd_pi = particleDataTable->particle(MC::PIPLUS);
     const HepPDT::ParticleData* pd_p  = particleDataTable->particle(MC::PROTON);
-- 
GitLab