From 5f7cbb33bc99061414f4815ba152b82e81c0f624 Mon Sep 17 00:00:00 2001
From: scott snyder <sss@karma>
Date: Thu, 11 Apr 2024 11:00:00 -0400
Subject: [PATCH] InDetTrackSystematicsTools: Use Accessor, etc instead of
 auxdata().

Replace auxdata, etc. with Accessor classes.
Moving to deprecate these usages in the Athena build.
---
 .../Root/InDetTrackTruthFilterTool.cxx              | 13 ++++++++++---
 .../Root/InDetTrackTruthOriginTool.cxx              |  9 ++++++---
 .../Root/InclusiveTrackFilterTool.cxx               |  6 ++++--
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthFilterTool.cxx b/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthFilterTool.cxx
index 30e8f52482f3..a8d98335b7cb 100644
--- a/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthFilterTool.cxx
+++ b/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthFilterTool.cxx
@@ -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
 */
 
 #include "InDetTrackSystematicsTools/InDetTrackTruthFilterTool.h"
@@ -11,6 +11,7 @@
 #include "xAODTruth/TruthParticleContainer.h"
 #include "xAODTruth/TruthVertex.h"
 #include "xAODTruth/TruthVertexContainer.h"
+#include "AthContainers/ConstAccessor.h"
 
 #include "PathResolver/PathResolver.h"
 
@@ -282,12 +283,18 @@ namespace InDet {
     }
 
     if(m_doLRTSystematics) {
-      const ElementLink< xAOD::TruthParticleContainer > &truthParticleLink = track->auxdata< ElementLink< xAOD::TruthParticleContainer > >("truthParticleLink");
+      static const SG::ConstAccessor<ElementLink< xAOD::TruthParticleContainer > >
+        truthParticleLinkAcc ("truthParticleLink");
+      const ElementLink< xAOD::TruthParticleContainer > &truthParticleLink =
+        truthParticleLinkAcc (*track);
       if(truthParticleLink.isValid()) {
         const xAOD::TruthParticle *truthParticle = *truthParticleLink;
         double eta = truthParticle->eta();
 
-        const ElementLink< xAOD::TruthVertexContainer > &truthVertexLink = truthParticle->auxdata< ElementLink< xAOD::TruthVertexContainer > >("prodVtxLink");
+        static const SG::ConstAccessor<ElementLink< xAOD::TruthVertexContainer > >
+          prodVtxLinkAcc ("prodVtxLink");
+        const ElementLink< xAOD::TruthVertexContainer > &truthVertexLink =
+          prodVtxLinkAcc (*truthParticle);
         if(truthVertexLink.isValid()) {
           const xAOD::TruthVertex *truthVertex = *truthVertexLink;
           double prodR = truthVertex->perp();
diff --git a/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthOriginTool.cxx b/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthOriginTool.cxx
index 770f254409d2..69a850ecf302 100644
--- a/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthOriginTool.cxx
+++ b/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InDetTrackTruthOriginTool.cxx
@@ -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
 */
 
 #include "InDetTrackSystematicsTools/InDetTrackTruthOriginTool.h"
@@ -8,6 +8,7 @@
 #include "xAODTruth/TruthParticleContainer.h"
 #include "xAODTruth/TruthEventContainer.h"
 #include "TruthUtils/MagicNumbers.h"
+#include "AthContainers/ConstAccessor.h"
 
 #include <math.h>
 
@@ -42,12 +43,14 @@ namespace InDet {
       // in practice, all tracks seem to have a truth link, but we need to also
       // check whether it's valid
       typedef ElementLink<xAOD::TruthParticleContainer> TruthLink;
-      if ( !track->isAvailable<TruthLink>("truthParticleLink") ) { 
+      static const SG::ConstAccessor<TruthLink>
+        truthParticleLinkAcc ("truthParticleLink");
+      if ( !truthParticleLinkAcc.isAvailable(*track) ) { 
         return nullptr;
       }
 
       // retrieve the link and check its validity
-      const TruthLink &link = track->auxdata<TruthLink>("truthParticleLink");
+      const TruthLink &link = truthParticleLinkAcc(*track);
 
       // a missing or invalid link implies truth particle has been dropped from 
       // the truth record at some stage - probably it was from pilup which by
diff --git a/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InclusiveTrackFilterTool.cxx b/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InclusiveTrackFilterTool.cxx
index 0af38a9003b5..b0a838b1b6ce 100644
--- a/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InclusiveTrackFilterTool.cxx
+++ b/PhysicsAnalysis/TrackingID/InDetTrackSystematicsTools/Root/InclusiveTrackFilterTool.cxx
@@ -1,9 +1,10 @@
 /*
-  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 "InDetTrackSystematicsTools/InclusiveTrackFilterTool.h"
 #include "xAODTracking/TrackParticleContainer.h"
+#include "AthContainers/ConstAccessor.h"
 
 namespace InDet {
 
@@ -50,7 +51,8 @@ namespace InDet {
       return false;
     }
 
-    if (track->isAvailable<unsigned long>("patternRecoInfo") ) {
+    static const SG::ConstAccessor<unsigned long> patternRecoInfoAcc ("patternRecoInfo");
+    if (patternRecoInfoAcc.isAvailable(*track) ) {
       const std::bitset<xAOD::NumberOfTrackRecoInfo> patternReco = track->patternRecoInfo();
       if(not patternReco.test(49)) {
         ATH_MSG_DEBUG( "Applying LRT uncertainties to non-LRT track! Skipping" );
-- 
GitLab