From e6dbb0eff6db130cde632487c69c4bf4aa66a8a8 Mon Sep 17 00:00:00 2001
From: Savanna Marie Shaw <savanna.marie.shaw@cern.ch>
Date: Tue, 4 Feb 2020 16:56:29 +0100
Subject: [PATCH] Make a few tools in CSC segemtn finding private

Making a few tools that were public to be private, and started to update the configuration to use private tools in a few place.
---
 .../python/MuonRIO_OnTrackCreatorConfig.py    | 12 ++++-------
 .../MuonConfig/python/MuonRecToolsConfig.py   |  2 +-
 .../python/MuonSegmentFindingConfig.py        |  3 +--
 .../python/MuonTrackBuildingConfig.py         |  4 ++--
 .../src/Csc2dSegmentMaker.cxx                 | 21 +++++++------------
 .../CscSegmentMakers/src/Csc2dSegmentMaker.h  | 12 ++++++-----
 .../src/CscSegmentUtilTool.cxx                |  4 +---
 .../CscSegmentMakers/src/CscSegmentUtilTool.h |  2 +-
 8 files changed, 24 insertions(+), 36 deletions(-)

diff --git a/MuonSpectrometer/MuonConfig/python/MuonRIO_OnTrackCreatorConfig.py b/MuonSpectrometer/MuonConfig/python/MuonRIO_OnTrackCreatorConfig.py
index 25a58d6bf827..113b5e96b761 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonRIO_OnTrackCreatorConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonRIO_OnTrackCreatorConfig.py
@@ -23,29 +23,25 @@ def CscClusterOnTrackCreatorCfg(flags,name="CscClusterOnTrackCreator", **kwargs)
 
     result=ComponentAccumulator()    
     acc = QratCscClusterFitterCfg(flags)
-    qrat = acc.getPrimary()
-    result.addPublicTool(qrat)
+    qrat = acc.popPrivateTools()
     result.merge(acc)
     kwargs.setdefault("CscClusterFitter", qrat )
     
     acc = CalibCscStripFitterCfg(flags)
-    strip_fitter = acc.getPrimary()
-    result.addPublicTool(strip_fitter)
+    strip_fitter = acc.popPrivateTools()
     result.merge(acc)
     kwargs.setdefault("CscStripFitter", strip_fitter)
     
     acc = CscClusterUtilToolCfg(flags)
-    cluster_util_tool = acc.getPrimary()
+    cluster_util_tool = acc.popPrivateTools()
     kwargs.setdefault("CscClusterUtilTool", cluster_util_tool )
-    result.addPublicTool(cluster_util_tool)
     result.merge(acc)
     
     if not flags.Input.isMC: # collisions real data or simulated first data
         # scale CSC and hit errors 
         kwargs.setdefault("ErrorScalerBeta", 0.070 )
 
-    csc_cluster_creator = Muon__CscClusterOnTrackCreator(name,**kwargs)
-    result.addPublicTool(csc_cluster_creator, primary=True)
+    result.setPrivateTools(Muon__CscClusterOnTrackCreator(name,**kwargs))
     
     return result
 
diff --git a/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py b/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py
index 91b1acbbb08a..3c50d1228efb 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonRecToolsConfig.py
@@ -388,7 +388,7 @@ def MuPatHitToolCfg(flags, name="MuPatHitTool",**kwargs):
     kwargs.setdefault("MdtRotCreator", mdt_creator)
     
     acc = CscClusterOnTrackCreatorCfg(flags)
-    csc_cluster_creator = acc.getPrimary()
+    csc_cluster_creator = acc.popPrivateTools()
     result.merge(acc)
     kwargs.setdefault("CscRotCreator", csc_cluster_creator)
     
diff --git a/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py b/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py
index 7477882d7cfd..2fc6e0e8b371 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py
@@ -400,7 +400,6 @@ def QratCscClusterFitterCfg(flags, **kwargs):
     kwargs.setdefault("qratcor_csl_eta",qratcor_csl_eta)
     kwargs.setdefault("qratcor_css_eta",qratcor_css_eta)
     csc_align_tool = CscAlignmentTool(flags)
-    result.addPublicTool(csc_align_tool) # TODO remove once private
     kwargs.setdefault("CscAlignmentTool", csc_align_tool )
     result.setPrivateTools(QratCscClusterFitter(**kwargs))
     
@@ -431,7 +430,7 @@ def CscSegmentUtilToolCfg(flags, name='CscSegmentUtilTool', **kwargs):
     from MuonConfig.MuonRIO_OnTrackCreatorConfig import CscClusterOnTrackCreatorCfg
     
     result=CscClusterOnTrackCreatorCfg(flags)
-    csc_cluster_creator = result.getPrimary()
+    csc_cluster_creator = result.popPrivateTools()
     kwargs.setdefault("rot_creator", csc_cluster_creator )
     
     result.setPrivateTools(CscSegmentUtilTool( name=name, **kwargs))
diff --git a/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py b/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
index 588177ef1d4c..f17bd640d7cc 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
@@ -325,7 +325,7 @@ def MuPatCandidateToolCfg(flags, name="MuPatCandidateTool", **kwargs):
     kwargs.setdefault("MdtRotCreator", mdt_dcot_creator)
     
     acc = CscClusterOnTrackCreatorCfg(flags)
-    csc_cluster_creator = acc.getPrimary()
+    csc_cluster_creator = acc.popPrivateTools()
     result.merge(acc)
     kwargs.setdefault("CscRotCreator", csc_cluster_creator)
         
@@ -344,7 +344,7 @@ def MuonChamberHoleRecoveryToolCfg(flags, name="MuonChamberHoleRecoveryTool", **
         if flags.Muon.enableErrorTuning or not flags.Input.isMC:
             extrakwargs["ErrorScalerBeta"] = 0.200
         acc = CscClusterOnTrackCreatorCfg(flags, **extrakwargs)
-        csc_cluster_creator = acc.getPrimary()
+        csc_cluster_creator = acc.popPrivateTools()
         result.merge(acc)
         kwargs.setdefault("CscRotCreator", csc_cluster_creator)
     else:
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.cxx b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.cxx
index 7e21a13e33a1..fc58507c470a 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.cxx
@@ -16,7 +16,6 @@
 #include "MuonRIO_OnTrack/CscClusterOnTrack.h"
 #include "MuonRIO_OnTrack/MdtDriftCircleOnTrack.h"
 #include "MuonRecToolInterfaces/IMuonClusterOnTrackCreator.h"
-#include "MuonIdHelpers/MuonIdHelperTool.h"
 
 #include "TrkEventPrimitives/FitQuality.h"
 #include "MuonSegment/MuonSegment.h"
@@ -25,7 +24,6 @@
 #include "TrkSegment/Segment.h"
 #include "TrkRoad/TrackRoad.h"
 
-#include "MuonRecHelperTools/MuonEDMPrinterTool.h" 
 
 #include "MuonCondInterface/ICSCConditionsSvc.h"
 
@@ -74,19 +72,9 @@ std::string chamber(int istation, int zsec, int phi) {
 
 Csc2dSegmentMaker::
 Csc2dSegmentMaker(const std::string& type, const std::string& aname, const IInterface* parent)
-  : AthAlgTool(type, aname, parent),
-    m_segmentTool("CscSegmentUtilTool/CscSegmentUtilTool", this),
-    m_cscClusterOnTrackCreator("Muon::CscClusterOnTrackCreator/CscClusterOnTrackCreator", this),
-    m_idHelper("Muon::MuonIdHelperTool/MuonIdHelperTool"),
-    m_printer("Muon::MuonEDMPrinterTool/MuonEDMPrinterTool")
-    //m_cscCoolStrSvc("MuonCalib::CscCoolStrSvc", aname)
-    //m_cscCondSvc("CSCCondSummarySvc",name())
+  : AthAlgTool(type, aname, parent)
 {
   declareInterface<ICscSegmentFinder>(this);
-  declareProperty("segmentTool", m_segmentTool);
-  declareProperty("cscRotCreator", m_cscClusterOnTrackCreator);
-  declareProperty("IdHelper", m_idHelper);
-  declareProperty("cscdig_sg_inkey", m_cscdig_sg_inkey = "CSC_Measurements");
 }
 
 //******************************************************************************
@@ -116,9 +104,14 @@ StatusCode Csc2dSegmentMaker::initialize(){
     return StatusCode::FAILURE;
   }
   if ( m_idHelper.retrieve().isFailure() ) {
-    ATH_MSG_ERROR ( "Unable to retrieve CscSegmentUtilTool " << m_idHelper );
+    ATH_MSG_ERROR ( "Unable to retrieve MuonIdHelperTool " << m_idHelper );
     return StatusCode::FAILURE;
   }  
+  if ( m_printer.retrieve().isFailure() ) {
+    ATH_MSG_ERROR ( "Unable to retrieve " << m_printer );
+    return StatusCode::FAILURE;
+  }  
+
   /*
   if ( m_cscCoolStrSvc.retrieve().isFailure() ) {
     ATH_MSG_FATAL ( "Unable to retrieve pointer to the CSC COLL Conditions Service" );
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.h b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.h
index 3eaae8e34293..1c583602b75c 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/Csc2dSegmentMaker.h
@@ -19,6 +19,8 @@
 #include "MuonIdHelpers/IMuonIdHelperSvc.h"
 #include "Identifier/Identifier.h"
 #include "CscSegmentMakers/ICscSegmentFinder.h"
+#include "MuonIdHelpers/MuonIdHelperTool.h"
+#include "MuonRecHelperTools/MuonEDMPrinterTool.h"
 //#include "MuonCondInterface/CscICoolStrSvc.h"
 // MuonSegmentCombination(Collection).h included
 // and "MuonPrepRawData/CscPrepDataContainer.h"
@@ -72,12 +74,12 @@ private:  // data
   //  MuonSegmentCombinationCollection* m_psegs;
   ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
 
-  std::string m_cscdig_sg_inkey;
+  Gaudi::Property<std::string> m_cscdig_sg_inkey{this, "scdig_sg_inkey", "CSC_Measurements"};
 
-  ToolHandle<ICscSegmentUtilTool> m_segmentTool;  
-  ToolHandle<Muon::IMuonClusterOnTrackCreator> m_cscClusterOnTrackCreator;  
-  ToolHandle<Muon::MuonIdHelperTool> m_idHelper;  
-  ToolHandle<Muon::MuonEDMPrinterTool> m_printer;
+  ToolHandle<ICscSegmentUtilTool> m_segmentTool{this, "segmentTool", "CscSegmentUtilTool/CscSegmentUtilTool"};  
+  ToolHandle<Muon::IMuonClusterOnTrackCreator> m_cscClusterOnTrackCreator{this, "cscRotCreator", "Muon::CscClusterOnTrackCreator/CscClusterOnTrackCreator"};  
+  ToolHandle<Muon::MuonIdHelperTool> m_idHelper{this, "IdHelper", "Muon::MuonIdHelperTool/MuonIdHelperTool"};  
+  ToolHandle<Muon::MuonEDMPrinterTool> m_printer{this, "printerTool", "Muon::MuonEDMPrinterTool/MuonEDMPrinterTool"};
   //ServiceHandle<MuonCalib::CscICoolStrSvc> m_cscCoolStrSvc;
   //ServiceHandle<ICSCConditionsSvc> m_cscCondSvc; //CSC conditions
 
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.cxx b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.cxx
index b08921b545d5..7728fc3468e0 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.cxx
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.cxx
@@ -93,8 +93,7 @@ namespace {
 // Constructor.
 CscSegmentUtilTool::CscSegmentUtilTool
 (const std::string& type, const std::string& name, const IInterface* parent)
-  : AthAlgTool(type,name,parent), 
-    m_rotCreator("Muon::CscClusterOnTrackCreator/CscClusterOnTrackCreator")
+  : AthAlgTool(type,name,parent)
 {
   declareInterface<ICscSegmentUtilTool>(this);
   declareProperty("max_chisquare_tight", m_max_chisquare_tight = 16.); // 16 for outlier removal...
@@ -114,7 +113,6 @@ CscSegmentUtilTool::CscSegmentUtilTool
   declareProperty("IPconstraint", m_IPconstraint = true);
   declareProperty("IPerror", m_IPerror = 250.);
   declareProperty("allEtaPhiMatches", m_allEtaPhiMatches = true);  
-  declareProperty("rot_creator", m_rotCreator);
   declareProperty("TightenChi2", m_TightenChi2 = true);
   declareProperty("Remove4Overlap", m_remove4Overlap = true);
   declareProperty("Remove3Overlap", m_remove3Overlap = true);
diff --git a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.h b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.h
index ba6ec5c13323..40f24ac6748f 100644
--- a/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.h
+++ b/MuonSpectrometer/MuonReconstruction/MuonSegmentMakers/MuonSegmentMakerAlgs/CscSegmentMakers/src/CscSegmentUtilTool.h
@@ -110,7 +110,7 @@ private:  // data
   bool m_remove3Overlap; 
   int  m_nunspoil;
  
-  ToolHandle<Muon::ICscClusterOnTrackCreator> m_rotCreator;
+  ToolHandle<Muon::ICscClusterOnTrackCreator> m_rotCreator{this, "rot_creator", "Muon::CscClusterOnTrackCreator/CscClusterOnTrackCreator"};
   ServiceHandle<Muon::IMuonIdHelperSvc> m_idHelperSvc {this, "MuonIdHelperSvc", "Muon::MuonIdHelperSvc/MuonIdHelperSvc"};
   
   SG::ReadCondHandleKey<CscCondDbData> m_readKey{this, "ReadKey", "CscCondDbData", "Key of CscCondDbData"};   
-- 
GitLab