From 5996805c9399ad57d0a23f7eaec71cc7df21a10d Mon Sep 17 00:00:00 2001
From: John Chapman <jchapman@cern.ch>
Date: Thu, 9 Aug 2018 12:29:40 +0200
Subject: [PATCH] Fix warnings about attempting to add the LooperKiller twice
 in Simulation jobs.

The `LooperKiller` `G4UserAction` is added by default in Simulation jobs, but after
various configuration migrations it had ended up being added twice which caused
a warning. This commit changes the syntax in the affected job options to make
using the `LooperKiller` configurable, but avoid the warning.


Former-commit-id: 5208a35e3ef8b720f188f8d655f0fd82c0215ff7
---
 .../share/skeleton.combinedinput.py                        | 7 +++----
 .../SimuJobTransforms/share/skeleton.EVGENtoHIT_ISF.py     | 7 +++----
 .../SimuJobTransforms/share/skeleton.EVGENtoHIT_MC12.py    | 7 +++----
 Simulation/SimuJobTransforms/share/skeleton.TestBeam.py    | 7 +++----
 .../share/FastChainSkeleton.EVGENtoRDO.py                  | 7 +++----
 Tools/FullChainTransforms/share/skeleton.EVGENtoRDO.py     | 7 +++----
 6 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/Event/EventOverlay/EventOverlayJobTransforms/share/skeleton.combinedinput.py b/Event/EventOverlay/EventOverlayJobTransforms/share/skeleton.combinedinput.py
index 230785022c1..fd4bca4e826 100644
--- a/Event/EventOverlay/EventOverlayJobTransforms/share/skeleton.combinedinput.py
+++ b/Event/EventOverlay/EventOverlayJobTransforms/share/skeleton.combinedinput.py
@@ -152,10 +152,9 @@ if jobproperties.Beam.beamType.get_Value() != 'cosmics':
     else:
         simFlags.EventFilter.set_On()
 
-## Always enable the looper killer, unless it's been disabled
-if not hasattr(runArgs, "enableLooperKiller") or runArgs.enableLooperKiller:
-    simFlags.OptionalUserActionList.addAction('G4UA::LooperKillerTool')
-else:
+## The looper killer is on by default. Disable it if this is requested.
+if hasattr(runArgs, "enableLooperKiller") and not runArgs.enableLooperKiller:
+    simFlags.OptionalUserActionList.removeAction('G4UA::LooperKillerTool')
     atlasG4log.warning("The looper killer will NOT be run in this job.")
 
 include("G4AtlasApps/G4Atlas.flat.configuration.py")
diff --git a/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_ISF.py b/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_ISF.py
index 8f812a7425f..bb5445379fe 100644
--- a/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_ISF.py
+++ b/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_ISF.py
@@ -246,10 +246,9 @@ try:
 except:
     atlasG4log.warning('Could not add TimingAlg, no timing info will be written out.')
 
-## Always enable the looper killer, unless it's been disabled
-if not hasattr(runArgs, "enableLooperKiller") or runArgs.enableLooperKiller:
-    simFlags.OptionalUserActionList.addAction('G4UA::LooperKillerTool')
-else:
+## The looper killer is on by default. Disable it if this is requested.
+if hasattr(runArgs, "enableLooperKiller") and not runArgs.enableLooperKiller:
+    simFlags.OptionalUserActionList.removeAction('G4UA::LooperKillerTool')
     atlasG4log.warning("The looper killer will NOT be run in this job.")
 
 #### *********** import ISF_Example code here **************** ####
diff --git a/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_MC12.py b/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_MC12.py
index cc3c0a672ad..af14d358ac2 100644
--- a/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_MC12.py
+++ b/Simulation/SimuJobTransforms/share/skeleton.EVGENtoHIT_MC12.py
@@ -222,10 +222,9 @@ if jobproperties.Beam.beamType.get_Value() != 'cosmics':
 
 include("G4AtlasApps/G4Atlas.flat.configuration.py")
 
-## Always enable the looper killer, unless it's been disabled
-if not hasattr(runArgs, "enableLooperKiller") or runArgs.enableLooperKiller:
-    simFlags.OptionalUserActionList.addAction('G4UA::LooperKillerTool')
-else:
+## The looper killer is on by default. Disable it if this is requested.
+if hasattr(runArgs, "enableLooperKiller") and not runArgs.enableLooperKiller:
+    simFlags.OptionalUserActionList.removeAction('G4UA::LooperKillerTool')
     atlasG4log.warning("The looper killer will NOT be run in this job.")
 
 try:
diff --git a/Simulation/SimuJobTransforms/share/skeleton.TestBeam.py b/Simulation/SimuJobTransforms/share/skeleton.TestBeam.py
index 2c88541b26e..b31eb4228c5 100644
--- a/Simulation/SimuJobTransforms/share/skeleton.TestBeam.py
+++ b/Simulation/SimuJobTransforms/share/skeleton.TestBeam.py
@@ -216,10 +216,9 @@ except:
 
 include('G4AtlasApps/Tile2000_2003.flat.configuration.py')#HACK - has to be here for TBDetDescrLoader
 
-## Always enable the looper killer, unless it's been disabled
-if not hasattr(runArgs, "enableLooperKiller") or runArgs.enableLooperKiller:
-    simFlags.OptionalUserActionList.addAction('G4UA::LooperKillerTool')
-else:
+## The looper killer is on by default. Disable it if this is requested.
+if hasattr(runArgs, "enableLooperKiller") and not runArgs.enableLooperKiller:
+    simFlags.OptionalUserActionList.removeAction('G4UA::LooperKillerTool')
     atlasG4log.warning("The looper killer will NOT be run in this job.")
 
 ## Add G4 alg to alg sequence
diff --git a/Tools/FullChainTransforms/share/FastChainSkeleton.EVGENtoRDO.py b/Tools/FullChainTransforms/share/FastChainSkeleton.EVGENtoRDO.py
index 2f9bd99f866..fde12ad917f 100644
--- a/Tools/FullChainTransforms/share/FastChainSkeleton.EVGENtoRDO.py
+++ b/Tools/FullChainTransforms/share/FastChainSkeleton.EVGENtoRDO.py
@@ -290,10 +290,9 @@ else:
 ## Don't use the SeedsG4 override
 simFlags.SeedsG4.set_Off()
 
-## Always enable the looper killer, unless it's been disabled
-if not hasattr(runArgs, "enableLooperKiller") or runArgs.enableLooperKiller:
-    simFlags.OptionalUserActionList.addAction('G4UA::LooperKillerTool', ['Step'])
-else:
+## The looper killer is on by default. Disable it if this is requested.
+if hasattr(runArgs, "enableLooperKiller") and not runArgs.enableLooperKiller:
+    simFlags.OptionalUserActionList.removeAction('G4UA::LooperKillerTool')
     fast_chain_log.warning("The looper killer will NOT be run in this job.")
 
 
diff --git a/Tools/FullChainTransforms/share/skeleton.EVGENtoRDO.py b/Tools/FullChainTransforms/share/skeleton.EVGENtoRDO.py
index 946160525a8..422b4986599 100644
--- a/Tools/FullChainTransforms/share/skeleton.EVGENtoRDO.py
+++ b/Tools/FullChainTransforms/share/skeleton.EVGENtoRDO.py
@@ -172,10 +172,9 @@ else:
 ## Don't use the SeedsG4 override
 simFlags.SeedsG4.set_Off()
 
-## Always enable the looper killer, unless it's been disabled
-if not hasattr(runArgs, "enableLooperKiller") or runArgs.enableLooperKiller:
-    simFlags.OptionalUserActionList.addAction('G4UA::LooperKillerTool')
-else:
+## The looper killer is on by default. Disable it if this is requested.
+if hasattr(runArgs, "enableLooperKiller") and not runArgs.enableLooperKiller:
+    simFlags.OptionalUserActionList.removeAction('G4UA::LooperKillerTool')
     fast_chain_log.warning("The looper killer will NOT be run in this job.")
 
 
-- 
GitLab