From 7e7da942ccef58a9ac82144488a80a16cecf46ed Mon Sep 17 00:00:00 2001
From: Edward Moyse <edward.moyse@cern.ch>
Date: Thu, 7 Nov 2019 17:38:02 +0100
Subject: [PATCH] Adding new argument to control whether cardinality is
 overridden or not.

This new argument is off by default, because actually for initial tests it's okay if we cannot clone muon algorithms. So let's make the standard tests a bit easier.
Also code cleanup:
- changed message formatting to show slot/event
- moved this into the args.run check (since for pickling it doesn't work)
---
 .../python/MuonSegmentFindingConfig.py        | 14 +++++++----
 .../python/MuonTrackBuildingConfig.py         | 24 ++++++++-----------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py b/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py
index 8ff6f8b03bd..4055d3e20dc 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonSegmentFindingConfig.py
@@ -722,6 +722,9 @@ if __name__=="__main__":
     parser.add_argument("--run", help="Run directly from the python. If false, just stop once the pickle is written.",
                         action="store_true")
                         
+    parser.add_argument("--forceclone", help="Override default cloneability of algorithms to force them to run in parallel",
+                        action="store_true")
+
     args = parser.parse_args()
     
     from AthenaCommon.Configurable import Configurable
@@ -757,6 +760,8 @@ if __name__=="__main__":
     if args.run:
         from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
         cfg = MainServicesThreadedCfg(ConfigFlags)
+        msgService = cfg.getService('MessageSvc')
+        msgService.Format = "S:%s E:%e % F%58W%S%7W%R%T  %0W%M"
     else:
         cfg=ComponentAccumulator()
 
@@ -766,10 +771,13 @@ if __name__=="__main__":
     acc = MuonSegmentFindingCfg(ConfigFlags, cardinality=args.threads)
     cfg.merge(acc)
     
-    if args.threads>1:
+    if args.threads>1 and args.forceclone:
+        log.info('Forcing segment finding cardinality to be equal to '+str(args.threads))
         # We want to force the algorithms to run in parallel (eventually the algorithm will be marked as cloneable in the source code)
         from GaudiHive.GaudiHiveConf import AlgResourcePool
         cfg.addService(AlgResourcePool( OverrideUnClonable=True ) )
+        segment_finder = acc.getPrimary()
+        segment_finder.Cardinality=args.threads
 
     # This is a temporary fix - it should go someplace central as it replaces the functionality of addInputRename from here:
     # https://gitlab.cern.ch/atlas/athena/blob/master/Control/SGComps/python/AddressRemappingSvc.py
@@ -792,10 +800,6 @@ if __name__=="__main__":
     # outstream.OutputLevel=DEBUG
     outstream.ForceRead = True
 
-    # Show slots & events
-    # msgService = cfg.getService('MessageSvc')
-    # msgService.Format = "S:%s E:%e % F%48W%S%7W%R%T  %0W%M"
-
     # Fix for ATLASRECTS-5151
     from  TrkEventCnvTools.TrkEventCnvToolsConf import Trk__EventCnvSuperTool
     cnvTool = Trk__EventCnvSuperTool(name = 'EventCnvSuperTool')
diff --git a/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py b/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
index 1bbf5bd4e03..58872225c0e 100644
--- a/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
+++ b/MuonSpectrometer/MuonConfig/python/MuonTrackBuildingConfig.py
@@ -361,16 +361,19 @@ if __name__=="__main__":
     
     from argparse import ArgumentParser    
     parser = ArgumentParser()
-    parser.add_argument("-t", "--threads", dest="threads", type=int,
+    parser.add_argument("-t", "--threads", type=int,
                         help="number of threads", default=1)
                         
-    parser.add_argument("-o", "--output", dest="output", default='newESD.pool.root',
+    parser.add_argument("-o", "--output", default='newESD.pool.root',
                         help="write ESD to FILE", metavar="FILE")
                         
     parser.add_argument("--run", help="Run directly from the python. If false, just stop once the pickle is written.",
                         action="store_true")
+
+    parser.add_argument("--forceclone", help="Override default cloneability of algorithms to force them to run in parallel",
+                        action="store_true")
                         
-    args = parser.parse_args()
+    args = parser.parse_args()    
     
     from AthenaCommon.Configurable import Configurable
     Configurable.configurableRun3Behavior=1
@@ -403,6 +406,8 @@ if __name__=="__main__":
     if args.run:
         from AthenaConfiguration.MainServicesConfig import MainServicesThreadedCfg
         cfg = MainServicesThreadedCfg(ConfigFlags)
+        msgService = cfg.getService('MessageSvc')
+        msgService.Format = "S:%s E:%e % F%58W%S%7W%R%T  %0W%M"
     else:
         cfg=ComponentAccumulator()
     
@@ -413,7 +418,8 @@ if __name__=="__main__":
     acc = MuonTrackBuildingCfg(ConfigFlags)
     cfg.merge(acc)
     
-    if args.threads>1:
+    if args.threads>1 and args.forceclone:
+        log.info('Forcing track building cardinality to be equal to '+str(args.threads))
         # We want to force the algorithms to run in parallel (eventually the algorithm will be marked as cloneable in the source code)
         from GaudiHive.GaudiHiveConf import AlgResourcePool
         cfg.addService(AlgResourcePool( OverrideUnClonable=True ) )
@@ -440,22 +446,12 @@ if __name__=="__main__":
     # outstream.OutputLevel=DEBUG
     outstream.ForceRead = True
     
-    # Show slots & events
-    # msgService = cfg.getService('MessageSvc')
-    # msgService.Format = "S:%s E:%e % F%48W%S%7W%R%T  %0W%M"
-    # msgService.OutputLevel=DEBUG
-    
     # Fix for ATLASRECTS-5151
     from  TrkEventCnvTools.TrkEventCnvToolsConf import Trk__EventCnvSuperTool
     cnvTool = Trk__EventCnvSuperTool(name = 'EventCnvSuperTool')
     cnvTool.MuonCnvTool.FixTGCs = True
     cfg.addPublicTool(cnvTool)
     
-    # from MuonEventCnvTools.MuonEventCnvToolsConf import Muon__MuonEventCnvTool
-    # cnvTool = Muon__MuonEventCnvTool(name='MuonEventCnvTool')
-    # cnvTool.FixTGCs = True
-    # cfg.addPublicTool(cnvTool)
-    
     cfg.printConfig(withDetails = True, summariseProps = True)
               
     f=open("MuonTrackBuilding.pkl","w")
-- 
GitLab