From 06e12d748643fd153fe91790188a630f468200fc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20K=C3=B6hler?= <nicolas.koehler@cern.ch>
Date: Sun, 12 Apr 2020 11:59:05 +0200
Subject: [PATCH 1/2] use ReadHandle in MCP packages

---
 .../MuonEfficiencyCorrections/CMakeLists.txt  |  7 +++---
 .../MuonEfficiencyScaleFactors.h              | 10 ++++----
 .../MuonTriggerScaleFactors.h                 |  5 +++-
 .../Root/MuonEfficiencyScaleFactors.cxx       | 12 +++++++---
 .../Root/MuonTriggerScaleFactors.cxx          | 11 ++++-----
 .../src/MuonEfficiencyCorrections_TestAlg.cxx |  4 ++--
 .../src/MuonEfficiencyCorrections_TestAlg.h   |  3 +++
 .../src/MuonTriggerSF_TestAlg.cxx             |  8 +++----
 .../src/MuonTriggerSF_TestAlg.h               |  3 +++
 .../MuonMomentumCorrections/CMakeLists.txt    |  7 +++---
 .../src/CalibratedMuonsProvider.cxx           | 24 ++++++++-----------
 .../src/CalibratedMuonsProvider.h             |  3 +++
 .../src/CalibratedTracksProvider.cxx          | 20 +++++++---------
 .../src/CalibratedTracksProvider.h            |  3 +++
 .../MuonID/MuonSelectorTools/CMakeLists.txt   |  9 +++----
 15 files changed, 74 insertions(+), 55 deletions(-)

diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt
index bd5584ba9876..133b2abcecd8 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt
@@ -27,6 +27,7 @@ atlas_depends_on_subdirs(
    PhysicsAnalysis/Interfaces/MuonAnalysisInterfaces
    PRIVATE
    Control/AthContainers
+   Control/StoreGate
    Event/xAOD/xAODTrigger
    Event/FourMomUtils
    Tools/PathResolver
@@ -42,14 +43,14 @@ atlas_add_library( MuonEfficiencyCorrectionsLib
    PUBLIC_HEADERS MuonEfficiencyCorrections
    INCLUDE_DIRS  ${ROOT_INCLUDE_DIRS}
    LINK_LIBRARIES  ${ROOT_LIBRARIES} AsgTools xAODMuon xAODEventInfo MuonAnalysisInterfacesLib PATInterfaces
-   PRIVATE_LINK_LIBRARIES xAODTrigger PathResolver )
+   PRIVATE_LINK_LIBRARIES xAODTrigger PathResolver StoreGateLib )
 
 if( NOT XAOD_STANDALONE )
    atlas_add_component( MuonEfficiencyCorrections
       src/*.h src/*.cxx src/components/*.cxx
       INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
       LINK_LIBRARIES ${ROOT_LIBRARIES} xAODMuon xAODJet PATInterfaces AthContainers MuonAnalysisInterfacesLib
-      AthenaBaseComps GaudiKernel MuonEfficiencyCorrectionsLib )
+      AthenaBaseComps GaudiKernel MuonEfficiencyCorrectionsLib StoreGateLib )
 endif()
 
 atlas_add_dictionary( MuonEfficiencyCorrectionsDict
@@ -63,7 +64,7 @@ macro( _add_exec name )
       util/${name}.cxx
       INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
       LINK_LIBRARIES ${ROOT_LIBRARIES} xAODRootAccess xAODEventInfo xAODMuon MuonAnalysisInterfacesLib
-      PATInterfaces xAODCore AsgAnalysisInterfaces PileupReweightingLib MuonEfficiencyCorrectionsLib )
+      PATInterfaces xAODCore AsgAnalysisInterfaces PileupReweightingLib MuonEfficiencyCorrectionsLib StoreGateLib )
 endmacro( _add_exec )
 
 if( XAOD_STANDALONE )
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonEfficiencyScaleFactors.h b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonEfficiencyScaleFactors.h
index 9fa6a6708e06..230f32bdfe85 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonEfficiencyScaleFactors.h
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonEfficiencyScaleFactors.h
@@ -5,15 +5,15 @@
 #ifndef MUONEFFICIENCYSCALEFACTORS_H_
 #define MUONEFFICIENCYSCALEFACTORS_H_
 
-
-
 #include "MuonAnalysisInterfaces/IMuonEfficiencyScaleFactors.h"
 #include "MuonEfficiencyCorrections/MuonEfficiencyType.h"
 #include "MuonEfficiencyCorrections/EfficiencyScaleFactor.h"
 #include "MuonEfficiencyCorrections/EffiCollection.h"
 
-#include <AsgTools/ToolHandle.h>
-#include <AsgTools/AsgTool.h>
+#include "AsgTools/ToolHandle.h"
+#include "AsgTools/AsgTool.h"
+#include "StoreGate/ReadHandleKey.h"
+#include "xAODEventInfo/EventInfo.h"
 
 #include <string>
 #include <memory>
@@ -73,6 +73,8 @@ namespace CP {
             unsigned int getRandomRunNumber(const xAOD::EventInfo* info) const;
             /// load the SF histos
             StatusCode LoadInputs();
+
+            SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{this, "EventInfoContName", "EventInfo", "event info key"};
            
             /// Scale-factor files since  Moriond2019 contain the breakdown of systematics into
             /// their individual components. This method loads all systematics and looks their
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonTriggerScaleFactors.h b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonTriggerScaleFactors.h
index 5b9474e277b9..54e7f0e8a676 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonTriggerScaleFactors.h
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/MuonTriggerScaleFactors.h
@@ -7,6 +7,8 @@
 #include "MuonAnalysisInterfaces/IMuonTriggerScaleFactors.h"
 #include "AsgTools/AsgTool.h"
 #include "AsgTools/ToolHandle.h"
+#include "StoreGate/ReadHandleKey.h"
+#include "xAODEventInfo/EventInfo.h"
 #include "PATInterfaces/ISystematicsTool.h"
 #include "PATInterfaces/SystematicRegistry.h"
 #include <stdexcept>
@@ -113,6 +115,8 @@ namespace CP {
             std::string getDataPeriod(unsigned int run) const;
             std::string getDataPeriod(unsigned int runNumber, unsigned int year) const;
        private:
+            SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{this, "EventInfoContName", "EventInfo", "event info key"};
+
             TDirectory* getTemporaryDirectory(void) const;
 
             //Generate replicas of h for Toys with each bin of h varied with Gaussian distribution
@@ -132,7 +136,6 @@ namespace CP {
             std::string m_calibration_version;
             std::string m_custom_dir;
             std::string m_binning;
-            std::string m_eventInfoContName;
             bool m_allowZeroSF;
             bool m_experimental;
             bool m_useRel207;
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx
index 32ac74fd432d..4c50185c2237 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx
@@ -145,6 +145,8 @@ namespace CP {
             ATH_MSG_FATAL("At least one of the decoration names for scale-factor/ data-efficiency / mc-efficiency is not uniquely defined... Please check your properties");
             return StatusCode::FAILURE;
         }
+
+        ATH_CHECK(m_eventInfo.initialize());
         
         if (!m_custom_dir.empty()) ATH_MSG_WARNING("Note: setting up with user specified input file location " << m_custom_dir << " - this is not encouraged!");
         if (!m_custom_file_Calo.empty()) ATH_MSG_WARNING("Note: setting up with user specified CaloTag input file " << m_custom_file_Calo << " - this is not encouraged!");
@@ -176,9 +178,13 @@ namespace CP {
         return StatusCode::SUCCESS;
     }
     unsigned int MuonEfficiencyScaleFactors::getRandomRunNumber(const xAOD::EventInfo* info) const {
-        if (!info && !evtStore()->retrieve(info, "EventInfo")) {
-            ATH_MSG_ERROR("Could not retrieve the xAOD::EventInfo. Return 999999");
-            return 999999;
+        if (!info) {
+            SG::ReadHandle<xAOD::EventInfo> evtInfo(m_eventInfo);
+            info = evtInfo.operator->();
+            if (!info) {
+                ATH_MSG_ERROR("Could not retrieve the xAOD::EventInfo. Return 999999");
+                return 999999;
+            }
         }
         if (!info->eventType(xAOD::EventInfo::IS_SIMULATION)) {
             ATH_MSG_DEBUG("The current event is a data event. Return runNumber instead.");
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonTriggerScaleFactors.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonTriggerScaleFactors.cxx
index ac9c347ed40b..866f427f0bde 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonTriggerScaleFactors.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonTriggerScaleFactors.cxx
@@ -9,7 +9,6 @@
 #include "xAODMuon/MuonAuxContainer.h"
 #include "xAODTrigger/MuonRoIContainer.h"
 #include "MuonEfficiencyCorrections/MuonTriggerScaleFactors.h"
-#include "xAODEventInfo/EventInfo.h"
 
 #include "PATInterfaces/SystematicCode.h"
 #include "PATInterfaces/SystematicRegistry.h"
@@ -38,7 +37,6 @@ namespace CP {
       m_calibration_version("190129_Winter_r21"),
       m_custom_dir(),
       m_binning("fine"),
-      m_eventInfoContName("EventInfo"),
       m_allowZeroSF(false),
       m_experimental(false),
       m_useRel207(false),
@@ -64,7 +62,6 @@ namespace CP {
         declareProperty("NReplicas", m_nReplicas, "Number of generated toy replicas, if replicas are required.");
         declareProperty("ReplicaRandomSeed", m_ReplicaRandomSeed, "Random seed for toy replica generation.");
         declareProperty("AllowZeroSF", m_allowZeroSF, "If a trigger is not available will return 0 instead of throwing an error. More difficult to spot configuration issues. Use at own risk");
-	declareProperty("EventInfoContName", m_eventInfoContName, "Overwrite default event info container name");
 	declareProperty("forceYear", m_forceYear, "Only for developers. Never use this in any analysis!!!!!!");
 	declareProperty("forcePeriod", m_forcePeriod, "Only for developers. Never use this in any analysis!!!!!!");
     }
@@ -212,6 +209,8 @@ namespace CP {
 	    ATH_MSG_INFO("experimental = " << m_experimental);
     	ATH_MSG_INFO("useRel27 = " << m_useRel207);
 
+        ATH_CHECK(m_eventInfo.initialize());
+
         if (registerSystematics() != CP::SystematicCode::Ok) {
             return StatusCode::FAILURE;
         }
@@ -805,9 +804,9 @@ namespace CP {
   
     unsigned int MuonTriggerScaleFactors::getRunNumber() const {
         static const SG::AuxElement::ConstAccessor<unsigned int> acc_rnd("RandomRunNumber");
-        const xAOD::EventInfo* info = nullptr;
-        if (!evtStore()->contains<xAOD::EventInfo>(m_eventInfoContName) || !evtStore()->retrieve(info, m_eventInfoContName).isSuccess()) {
-	  ATH_MSG_WARNING("Could not retrieve the xAOD::EventInfo with name: " << m_eventInfoContName << " Return "<<getFallBackRunNumber() );
+        SG::ReadHandle<xAOD::EventInfo> info(m_eventInfo);
+        if (info.operator->()==nullptr) {
+            ATH_MSG_WARNING("Could not retrieve the xAOD::EventInfo with name: " << m_eventInfo.key() << " Return "<<getFallBackRunNumber() );
             return getFallBackRunNumber() ;
         }
         if (!info->eventType(xAOD::EventInfo::IS_SIMULATION)) {
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.cxx
index 7adeb6dc5e35..a676f2f358a1 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.cxx
@@ -50,6 +50,7 @@ namespace CP {
 
     StatusCode MuonEfficiencyCorrections_TestAlg::initialize() {
         ATH_MSG_DEBUG("SGKey = " << m_sgKey);
+        ATH_CHECK(m_eventInfo.initialize());
         ATH_CHECK(m_prw_Tool.retrieve());
         ATH_CHECK(m_sel_tool.retrieve());
         ATH_MSG_DEBUG("PileupReweightingTool  = " << m_prw_Tool);
@@ -90,8 +91,7 @@ namespace CP {
         const xAOD::MuonContainer* muons = nullptr;
         ATH_CHECK(evtStore()->retrieve(muons, m_sgKey));
         // Retrieve the EventInfo:
-        const xAOD::EventInfo* ei = nullptr;
-        ATH_CHECK(evtStore()->retrieve(ei, "EventInfo"));
+        SG::ReadHandle<xAOD::EventInfo> ei(m_eventInfo);
        
         ATH_MSG_DEBUG("Start to run over event "<<ei->eventNumber()<<" in run" <<ei->runNumber());
        
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.h b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.h
index 6d527fbe3e24..53f4a93483d7 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.h
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonEfficiencyCorrections_TestAlg.h
@@ -9,6 +9,8 @@
 #include "AthenaBaseComps/AthAlgorithm.h"
 #include "GaudiKernel/ITHistSvc.h"
 #include "GaudiKernel/ToolHandle.h"
+#include "StoreGate/ReadHandleKey.h"
+#include "xAODEventInfo/EventInfo.h"
 
 #include "AsgTools/ToolHandleArray.h"
 
@@ -37,6 +39,7 @@ namespace CP {
             }
 
         private:
+            SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{this, "EventInfoContName", "EventInfo", "event info key"};
             /// muon container
             std::string m_sgKey;
             ServiceHandle<ITHistSvc> m_histSvc;
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.cxx
index 6875d4ac3835..ee430b81580d 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.cxx
@@ -32,6 +32,7 @@ namespace Trig{
 
     //=============================================================================
     StatusCode MuonTriggerSF_TestAlg::initialize() {
+        ATH_CHECK(m_eventInfo.initialize());
         CHECK(m_histSvc.retrieve());
         CHECK(m_trigEff.retrieve());
         CHECK(m_prwTool.retrieve());
@@ -61,10 +62,9 @@ namespace Trig{
     StatusCode MuonTriggerSF_TestAlg::execute() {
         
         //Retrieve the EventInfo to apply the prwTool before activating the trigger tool
-        const xAOD::EventInfo* Info;
-        ATH_CHECK(evtStore()->retrieve(Info,"EventInfo"));
-        ATH_CHECK(m_prwTool->apply(*Info));
-        m_runNumber = m_prwTool->getRandomRunNumber(*Info);
+        SG::ReadHandle<xAOD::EventInfo> evtInfo(m_eventInfo);
+        ATH_CHECK(m_prwTool->apply(*evtInfo));
+        m_runNumber = m_prwTool->getRandomRunNumber(*evtInfo);
         
         const xAOD::MuonContainer* Muons;
         ATH_CHECK(evtStore()->retrieve(Muons,"Muons"));
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.h b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.h
index cadee1e52ea5..bfc3bde42319 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.h
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/src/MuonTriggerSF_TestAlg.h
@@ -7,6 +7,8 @@
 #include "AthenaBaseComps/AthAlgorithm.h"
 #include "GaudiKernel/ITHistSvc.h"
 #include "GaudiKernel/ToolHandle.h"
+#include "StoreGate/ReadHandleKey.h"
+#include "xAODEventInfo/EventInfo.h"
 
 #include "AsgTools/ToolHandleArray.h"
 
@@ -28,6 +30,7 @@ namespace Trig{
             StatusCode execute();
             StatusCode finalize();
         private:
+            SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{this, "EventInfoContName", "EventInfo", "event info key"};
             // Properties:
             std::string m_outputStream;
             std::string m_inputContainerName;
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt
index c2e83642b6d6..f33aa990db5a 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt
@@ -22,6 +22,7 @@ atlas_depends_on_subdirs(
    PhysicsAnalysis/Interfaces/MuonAnalysisInterfaces
    PhysicsAnalysis/Interfaces/AsgAnalysisInterfaces
    PRIVATE
+   Control/StoreGate
    PhysicsAnalysis/MuonID/MuonSelectorTools
    Event/xAOD/xAODBase
    Event/xAOD/xAODCore
@@ -39,14 +40,14 @@ atlas_add_library( MuonMomentumCorrectionsLib
    INCLUDE_DIRS  ${ROOT_INCLUDE_DIRS}
    LINK_LIBRARIES  ${ROOT_LIBRARIES} AsgTools xAODMuon MuonAnalysisInterfacesLib AsgAnalysisInterfaces
    PATInterfaces
-   PRIVATE_LINK_LIBRARIES xAODEventInfo PathResolver )
+   PRIVATE_LINK_LIBRARIES xAODEventInfo PathResolver StoreGateLib )
 
 if( NOT XAOD_STANDALONE )
    atlas_add_component( MuonMomentumCorrections
       src/*.h src/*.cxx src/components/*.cxx
       INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
       LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps xAODMuon xAODCore MuonAnalysisInterfacesLib AsgAnalysisInterfaces
-      xAODBase GaudiKernel MuonSelectorToolsLib MuonMomentumCorrectionsLib )
+      xAODBase GaudiKernel MuonSelectorToolsLib MuonMomentumCorrectionsLib StoreGateLib )
 endif()
 
 atlas_add_dictionary( MuonMomentumCorrectionsDict
@@ -60,7 +61,7 @@ atlas_add_executable( MCAST_Tester
    INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
    LINK_LIBRARIES ${ROOT_LIBRARIES} xAODRootAccess
    xAODEventInfo xAODMuon xAODCore PATInterfaces xAODCore AsgTools AsgAnalysisInterfaces
-   MuonSelectorToolsLib MuonMomentumCorrectionsLib  MuonAnalysisInterfacesLib)
+   MuonSelectorToolsLib MuonMomentumCorrectionsLib  MuonAnalysisInterfacesLib StoreGateLib )
 
 # Install files from the package:
 atlas_install_joboptions( share/*.py )
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.cxx
index e2507dd82d41..6886b4898ff5 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.cxx
@@ -8,13 +8,12 @@
 #include "CalibratedMuonsProvider.h"
 #include "xAODCore/ShallowCopy.h"
 #include "xAODBase/IParticleHelpers.h"
-#include "xAODEventInfo/EventInfo.h"
 
 namespace CP {
 static SG::AuxElement::ConstAccessor<unsigned int> acc_rnd("RandomRunNumber");
  
 CalibratedMuonsProvider::CalibratedMuonsProvider( const std::string& name, ISvcLocator* svcLoc ):
-       AthAlgorithm( name, svcLoc ),
+         AthAlgorithm( name, svcLoc ),
          m_tool( "CP::MuonCalibrationPeriodTool/MuonCalibrationAndSmearingTool"),
          m_prwTool(""),
          m_useRndNumber(false) {
@@ -22,19 +21,17 @@ CalibratedMuonsProvider::CalibratedMuonsProvider( const std::string& name, ISvcL
       declareProperty( "Output", m_outputKey = "CalibratedMuons"); 
       declareProperty( "Tool", m_tool );
       declareProperty( "prwTool", m_prwTool );
-      
-
-
 }
 
 StatusCode CalibratedMuonsProvider::initialize() {
-      ATH_CHECK( m_tool.retrieve() );
-      if (!m_prwTool.empty()){
-         m_useRndNumber = true;
-         ATH_MSG_DEBUG("prwTool is given assume that the selection of the periods is based on the random run number");
-         ATH_CHECK(m_prwTool.retrieve());
-      }
-      return StatusCode::SUCCESS;
+    ATH_CHECK(m_eventInfo.initialize());
+    ATH_CHECK(m_tool.retrieve() );
+    if (!m_prwTool.empty()){
+        m_useRndNumber = true;
+        ATH_MSG_DEBUG("prwTool is given assume that the selection of the periods is based on the random run number");
+        ATH_CHECK(m_prwTool.retrieve());
+    }
+    return StatusCode::SUCCESS;
 }
 
 StatusCode CalibratedMuonsProvider::execute() {
@@ -60,8 +57,7 @@ StatusCode CalibratedMuonsProvider::execute() {
          }  
       }
       if (m_useRndNumber) {
-            const xAOD::EventInfo* evInfo = nullptr;
-            ATH_CHECK(evtStore()->retrieve(evInfo, "EventInfo"));
+            SG::ReadHandle<xAOD::EventInfo> evInfo(m_eventInfo);
             if (!evInfo->eventType(xAOD::EventInfo::IS_SIMULATION)) {
                 m_useRndNumber = false;
                 ATH_MSG_DEBUG("On data no random run number is needed.");
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.h b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.h
index b88531668eb8..84f6afc961c9 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.h
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedMuonsProvider.h
@@ -9,6 +9,8 @@
 // Gaudi/Athena include(s):
 #include "AthenaBaseComps/AthAlgorithm.h"
 #include "GaudiKernel/ToolHandle.h"
+#include "StoreGate/ReadHandleKey.h"
+#include "xAODEventInfo/EventInfo.h"
 
 #include "MuonAnalysisInterfaces/IMuonCalibrationAndSmearingTool.h"
 #include <AsgAnalysisInterfaces/IPileupReweightingTool.h>
@@ -29,6 +31,7 @@ namespace CP {
       virtual StatusCode execute();
 
    private:
+      SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{this, "EventInfoContName", "EventInfo", "event info key"};
       /// muon container
       std::string m_inputKey,m_outputKey;
 
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.cxx
index 577ce7461c33..fd13a6b13a8c 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.cxx
@@ -8,7 +8,6 @@
 #include "CalibratedTracksProvider.h"
 #include "xAODCore/ShallowCopy.h"
 #include "xAODBase/IParticleHelpers.h"
-#include "xAODEventInfo/EventInfo.h"
 
 namespace CP {
 
@@ -24,17 +23,17 @@ CalibratedTracksProvider::CalibratedTracksProvider( const std::string& name, ISv
       declareProperty( "Tool", m_tool );
       declareProperty( "prwTool", m_prwTool );      
       declareProperty( "DetType", m_detType );
-
 }
 
 StatusCode CalibratedTracksProvider::initialize() {
-      ATH_CHECK( m_tool.retrieve());
-       if (!m_prwTool.empty()){
-         m_useRndNumber = true;
-         ATH_MSG_DEBUG("prwTool is given assume that the selection of the periods is based on the random run number");
-         ATH_CHECK(m_prwTool.retrieve());
-      }
-      return StatusCode::SUCCESS;
+    ATH_CHECK(m_eventInfo.initialize());
+    ATH_CHECK(m_tool.retrieve());
+    if (!m_prwTool.empty()){
+        m_useRndNumber = true;
+        ATH_MSG_DEBUG("prwTool is given assume that the selection of the periods is based on the random run number");
+        ATH_CHECK(m_prwTool.retrieve());
+    }
+    return StatusCode::SUCCESS;
 }
 
 StatusCode CalibratedTracksProvider::execute() {
@@ -60,8 +59,7 @@ StatusCode CalibratedTracksProvider::execute() {
          }  
       }
       if (m_useRndNumber) {
-            const xAOD::EventInfo* evInfo = nullptr;
-            ATH_CHECK(evtStore()->retrieve(evInfo, "EventInfo"));
+            SG::ReadHandle<xAOD::EventInfo> evInfo(m_eventInfo);
             if (!evInfo->eventType(xAOD::EventInfo::IS_SIMULATION)) {
                 m_useRndNumber = false;
                 ATH_MSG_DEBUG("On data no random run number is needed.");
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.h b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.h
index ecd753191317..dacb70eb1fc4 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.h
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/src/CalibratedTracksProvider.h
@@ -8,6 +8,8 @@
 // Gaudi/Athena include(s):
 #include "AthenaBaseComps/AthAlgorithm.h"
 #include "GaudiKernel/ToolHandle.h"
+#include "StoreGate/ReadHandleKey.h"
+#include "xAODEventInfo/EventInfo.h"
 
 #include "MuonAnalysisInterfaces/IMuonCalibrationAndSmearingTool.h"
 #include <AsgAnalysisInterfaces/IPileupReweightingTool.h>
@@ -28,6 +30,7 @@ namespace CP {
       virtual StatusCode execute();
 
    private:
+      SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{this, "EventInfoContName", "EventInfo", "event info key"};
       /// track container
       std::string m_inputKey,m_outputKey;
 
diff --git a/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt b/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt
index b4e6f41c7dab..6bb708f31e31 100644
--- a/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt
+++ b/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt
@@ -21,6 +21,7 @@ atlas_depends_on_subdirs(
    PhysicsAnalysis/AnalysisCommon/PATCore
    PhysicsAnalysis/Interfaces/MuonAnalysisInterfaces
    PRIVATE
+   Control/StoreGate
    Event/xAOD/xAODCore
    Event/xAOD/xAODEventInfo
    Event/xAOD/xAODTracking
@@ -36,13 +37,13 @@ atlas_add_library( MuonSelectorToolsLib
    PUBLIC_HEADERS MuonSelectorTools
    INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
    LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools xAODEventInfo xAODMuon PATCoreLib MuonAnalysisInterfacesLib
-   PRIVATE_LINK_LIBRARIES xAODTracking PathResolver )
+   PRIVATE_LINK_LIBRARIES xAODTracking PathResolver StoreGateLib )
 
 if( NOT XAOD_STANDALONE )
    atlas_add_component( MuonSelectorTools
       src/*.h src/*.cxx src/components/*.cxx
       LINK_LIBRARIES AthenaBaseComps GaudiKernel xAODCore xAODEventInfo xAODMuon MuonAnalysisInterfacesLib
-      MuonSelectorToolsLib )
+      MuonSelectorToolsLib StoreGateLib )
 endif()
 
 atlas_add_dictionary( MuonSelectorToolsDict
@@ -56,7 +57,7 @@ if( XAOD_STANDALONE )
       util/MuonSelectorToolsTester.cxx
       INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
       LINK_LIBRARIES ${ROOT_LIBRARIES} xAODRootAccess xAODEventInfo xAODMuon
-      xAODTracking xAODCore MuonSelectorToolsLib )
+      xAODTracking xAODCore MuonSelectorToolsLib StoreGateLib )
 endif()
 
 
@@ -65,7 +66,7 @@ if( XAOD_STANDALONE )
    atlas_add_test( ut_MuonSelectorToolsTester_data
       SOURCES test/ut_MuonSelectorToolsTester_data.cxx
       INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
-      LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools )
+      LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools StoreGateLib )
 endif()
 
 # Install files from the package:
-- 
GitLab


From bfa981d1172cd9bd3832a5bc2782c393f5275fd9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20K=C3=B6hler?= <nicolas.koehler@cern.ch>
Date: Tue, 14 Apr 2020 10:21:46 +0200
Subject: [PATCH 2/2] make StoreGate depedency public

---
 .../MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt | 6 +++---
 .../MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt   | 6 +++---
 PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt     | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt
index 133b2abcecd8..4b08872a6b87 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/CMakeLists.txt
@@ -19,6 +19,7 @@ endif()
 atlas_depends_on_subdirs(
    PUBLIC
    Control/AthToolSupport/AsgTools
+   Control/StoreGate
    Event/xAOD/xAODEventInfo
    Event/xAOD/xAODMuon
    Event/xAOD/xAODJet
@@ -27,7 +28,6 @@ atlas_depends_on_subdirs(
    PhysicsAnalysis/Interfaces/MuonAnalysisInterfaces
    PRIVATE
    Control/AthContainers
-   Control/StoreGate
    Event/xAOD/xAODTrigger
    Event/FourMomUtils
    Tools/PathResolver
@@ -42,8 +42,8 @@ atlas_add_library( MuonEfficiencyCorrectionsLib
    MuonEfficiencyCorrections/*.h Root/*.cxx
    PUBLIC_HEADERS MuonEfficiencyCorrections
    INCLUDE_DIRS  ${ROOT_INCLUDE_DIRS}
-   LINK_LIBRARIES  ${ROOT_LIBRARIES} AsgTools xAODMuon xAODEventInfo MuonAnalysisInterfacesLib PATInterfaces
-   PRIVATE_LINK_LIBRARIES xAODTrigger PathResolver StoreGateLib )
+   LINK_LIBRARIES  ${ROOT_LIBRARIES} AsgTools xAODMuon xAODEventInfo MuonAnalysisInterfacesLib PATInterfaces StoreGateLib
+   PRIVATE_LINK_LIBRARIES xAODTrigger PathResolver )
 
 if( NOT XAOD_STANDALONE )
    atlas_add_component( MuonEfficiencyCorrections
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt
index f33aa990db5a..173710e86e10 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonMomentumCorrections/CMakeLists.txt
@@ -17,12 +17,12 @@ endif()
 atlas_depends_on_subdirs(
    PUBLIC
    Control/AthToolSupport/AsgTools
+   Control/StoreGate
    Event/xAOD/xAODMuon
    PhysicsAnalysis/AnalysisCommon/PATInterfaces
    PhysicsAnalysis/Interfaces/MuonAnalysisInterfaces
    PhysicsAnalysis/Interfaces/AsgAnalysisInterfaces
    PRIVATE
-   Control/StoreGate
    PhysicsAnalysis/MuonID/MuonSelectorTools
    Event/xAOD/xAODBase
    Event/xAOD/xAODCore
@@ -39,8 +39,8 @@ atlas_add_library( MuonMomentumCorrectionsLib
    PUBLIC_HEADERS MuonMomentumCorrections
    INCLUDE_DIRS  ${ROOT_INCLUDE_DIRS}
    LINK_LIBRARIES  ${ROOT_LIBRARIES} AsgTools xAODMuon MuonAnalysisInterfacesLib AsgAnalysisInterfaces
-   PATInterfaces
-   PRIVATE_LINK_LIBRARIES xAODEventInfo PathResolver StoreGateLib )
+   PATInterfaces StoreGateLib
+   PRIVATE_LINK_LIBRARIES xAODEventInfo PathResolver )
 
 if( NOT XAOD_STANDALONE )
    atlas_add_component( MuonMomentumCorrections
diff --git a/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt b/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt
index 6bb708f31e31..0b70706944c7 100644
--- a/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt
+++ b/PhysicsAnalysis/MuonID/MuonSelectorTools/CMakeLists.txt
@@ -17,11 +17,11 @@ endif()
 atlas_depends_on_subdirs(
    PUBLIC
    Control/AthToolSupport/AsgTools
+   Control/StoreGate
    Event/xAOD/xAODMuon
    PhysicsAnalysis/AnalysisCommon/PATCore
    PhysicsAnalysis/Interfaces/MuonAnalysisInterfaces
    PRIVATE
-   Control/StoreGate
    Event/xAOD/xAODCore
    Event/xAOD/xAODEventInfo
    Event/xAOD/xAODTracking
@@ -36,8 +36,8 @@ atlas_add_library( MuonSelectorToolsLib
    MuonSelectorTools/*.h Root/*.cxx
    PUBLIC_HEADERS MuonSelectorTools
    INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
-   LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools xAODEventInfo xAODMuon PATCoreLib MuonAnalysisInterfacesLib
-   PRIVATE_LINK_LIBRARIES xAODTracking PathResolver StoreGateLib )
+   LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools xAODEventInfo xAODMuon PATCoreLib MuonAnalysisInterfacesLib StoreGateLib
+   PRIVATE_LINK_LIBRARIES xAODTracking PathResolver )
 
 if( NOT XAOD_STANDALONE )
    atlas_add_component( MuonSelectorTools
-- 
GitLab