From e79743c30955969bd00788d13d903b8746096592 Mon Sep 17 00:00:00 2001
From: John Derek Chapman <chapman@hep.phy.cam.ac.uk>
Date: Wed, 11 May 2016 14:08:31 +0200
Subject: [PATCH] share/atlfast2/preInclude.FastMBKiller.py,
 share/atlfast2/preInclude.FastIDKiller.py,
 share/specialConfig/preInclude.Rhadrons.py,
 share/specialConfig/preInclude.Monopole.py,
 share/specialConfig/preInclude.Qball.py,
 share/g4/preInclude.ScoringVolumeKiller.py,
 share/g4/preInclude.VerboseSelectorArea.py,
 share/g4/preInclude.HyperspaceCatcher.py,
 share/g4/preInclude.VerboseSelector.py,
 share/cavern/preInclude.G4ReadCavern75.py,
 share/cavern/preInclude.G4ReadCavern50.py,
 share/cavern/preInclude.G4ReadCavern150.py,
 share/cavern/preInclude.G4ReadCavern1600.py,
 share/cavern/preInclude.G4ReadCavern900.py - update to support revised V1
 UserAction syntax. ATLASSIM-2226. Tagging: SimulationJobOptions-00-07-09
 (SimulationJobOptions-00-07-09)

	* Tagging: SimulationJobOptions-00-07-09
	* share/atlfast2/preInclude.FastMBKiller.py,
	share/atlfast2/preInclude.FastIDKiller.py,
	share/specialConfig/preInclude.Rhadrons.py,
	share/specialConfig/preInclude.Monopole.py,
	share/specialConfig/preInclude.Qball.py,
	share/g4/preInclude.ScoringVolumeKiller.py,
	share/g4/preInclude.VerboseSelectorArea.py,
	share/g4/preInclude.HyperspaceCatcher.py,
	share/g4/preInclude.VerboseSelector.py,
	share/cavern/preInclude.G4ReadCavern75.py,
	share/cavern/preInclude.G4ReadCavern50.py,
	share/cavern/preInclude.G4ReadCavern150.py,
	share/cavern/preInclude.G4ReadCavern1600.py,
	share/cavern/preInclude.G4ReadCavern900.py - update to support
	revised V1 UserAction syntax. ATLASSIM-2226

2016-03-14  John Chapman  <John.Chapman@cern.ch>
...
(Long ChangeLog diff - truncated)
---
 .../SimulationJobOptions/CMakeLists.txt       |  2 +-
 .../SimulationJobOptions/cmt/requirements     |  2 +-
 .../share/atlfast2/preInclude.FastIDKiller.py |  5 +-
 .../share/atlfast2/preInclude.FastMBKiller.py |  5 +-
 .../cavern/preInclude.G4ReadCavern150.py      |  7 +-
 .../cavern/preInclude.G4ReadCavern1600.py     |  5 +-
 .../share/cavern/preInclude.G4ReadCavern50.py |  5 +-
 .../share/cavern/preInclude.G4ReadCavern75.py |  5 +-
 .../cavern/preInclude.G4ReadCavern900.py      |  5 +-
 .../share/cosmics/preInclude.Cosmics.py       | 56 ++----------
 .../share/g4/preInclude.CalHits.py            |  2 -
 .../share/g4/preInclude.HyperspaceCatcher.py  |  5 +-
 .../g4/preInclude.ScoringVolumeKiller.py      |  5 +-
 .../share/g4/preInclude.VerboseSelector.py    | 13 +--
 .../g4/preInclude.VerboseSelectorArea.py      |  5 +-
 .../share/hive/postInclude.GaudiHive.py       | 22 +++++
 .../share/hive/preInclude.GaudiHive.py        | 86 +++++++++++++++++++
 .../specialConfig/postInclude.Monopole.py     | 13 +++
 .../share/specialConfig/postInclude.Qball.py  | 13 +++
 .../specialConfig/preInclude.Monopole.py      | 33 ++++---
 .../share/specialConfig/preInclude.Qball.py   | 38 ++++----
 .../specialConfig/preInclude.Rhadrons.py      | 82 +++++++++---------
 22 files changed, 266 insertions(+), 148 deletions(-)
 create mode 100644 Simulation/SimulationJobOptions/share/hive/postInclude.GaudiHive.py
 create mode 100644 Simulation/SimulationJobOptions/share/hive/preInclude.GaudiHive.py
 create mode 100644 Simulation/SimulationJobOptions/share/specialConfig/postInclude.Monopole.py
 create mode 100644 Simulation/SimulationJobOptions/share/specialConfig/postInclude.Qball.py

diff --git a/Simulation/SimulationJobOptions/CMakeLists.txt b/Simulation/SimulationJobOptions/CMakeLists.txt
index 52bf834a2f42..6ae88b4a7ea0 100644
--- a/Simulation/SimulationJobOptions/CMakeLists.txt
+++ b/Simulation/SimulationJobOptions/CMakeLists.txt
@@ -6,5 +6,5 @@
 atlas_subdir( SimulationJobOptions )
 
 # Install files from the package:
-atlas_install_joboptions( share/*.py share/atlfast2/*.py share/heavyIons/*.py share/cosmics/*.py share/digitization/*.py share/subdetectors/*.py share/g4/*.py share/cavern/*.py share/pileup/*.py share/susy/*.py share/specialConfig/*.py )
+atlas_install_joboptions( share/*.py share/hive/*.py share/atlfast2/*.py share/heavyIons/*.py share/cosmics/*.py share/digitization/*.py share/subdetectors/*.py share/g4/*.py share/cavern/*.py share/pileup/*.py share/susy/*.py share/specialConfig/*.py )
 
diff --git a/Simulation/SimulationJobOptions/cmt/requirements b/Simulation/SimulationJobOptions/cmt/requirements
index b7e0c05d3a9f..3790df5fcacf 100644
--- a/Simulation/SimulationJobOptions/cmt/requirements
+++ b/Simulation/SimulationJobOptions/cmt/requirements
@@ -5,4 +5,4 @@ author John Chapman
 use AtlasPolicy		AtlasPolicy-*
 
 public
-apply_pattern declare_joboptions files="*.py atlfast2/*.py heavyIons/*.py cosmics/*.py digitization/*.py subdetectors/*.py g4/*.py cavern/*.py pileup/*.py susy/*.py specialConfig/*.py"
+apply_pattern declare_joboptions files="*.py hive/*.py atlfast2/*.py heavyIons/*.py cosmics/*.py digitization/*.py subdetectors/*.py g4/*.py cavern/*.py pileup/*.py susy/*.py specialConfig/*.py"
diff --git a/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastIDKiller.py b/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastIDKiller.py
index bf739ae79cd3..e2d208c5dac1 100644
--- a/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastIDKiller.py
+++ b/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastIDKiller.py
@@ -10,5 +10,8 @@
 # energy above a certain threshold.
 #########################################################
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 UAStore.addAction('FastIDKiller', ['BeginOfRun','Step'])
diff --git a/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastMBKiller.py b/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastMBKiller.py
index 84024526dc2b..a1256369409e 100644
--- a/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastMBKiller.py
+++ b/Simulation/SimulationJobOptions/share/atlfast2/preInclude.FastMBKiller.py
@@ -6,7 +6,10 @@
 # Requested for the Atlfast-II and MinBias groups
 #########################################################
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
 FastMBKiller=getPublicTool('FastIDKiller/FastMBKiller',tryDefaultConfigurable=True)
diff --git a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern150.py b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern150.py
index f3fae6a44d04..0f5fa9972838 100644
--- a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern150.py
+++ b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern150.py
@@ -1,8 +1,11 @@
 # Modify the hit wrapping action to wrap on 150 ns
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
 getPublicTool('HitWrapper',tryDefaultConfigurable=True).WrapTime=150
-UAStore.addAction('HitWrapper',['EndOfEvent']) 
+UAStore.addAction('HitWrapper',['EndOfEvent'])
 
diff --git a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern1600.py b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern1600.py
index 2bf0cc7632f1..be9b71a892e6 100644
--- a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern1600.py
+++ b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern1600.py
@@ -1,7 +1,10 @@
 # Modify the hit wrapping action to wrap on 1600 ns
 
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
 getPublicTool('HitWrapper',tryDefaultConfigurable=True).WrapTime=1600
diff --git a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern50.py b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern50.py
index 3007da50ad91..2d85250f4fe7 100644
--- a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern50.py
+++ b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern50.py
@@ -1,6 +1,9 @@
 # Modify the hit wrapping action to wrap on 50 ns
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
 getPublicTool('HitWrapper',tryDefaultConfigurable=True).WrapTime=50
diff --git a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern75.py b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern75.py
index 2dd385e70db0..5a90a6a25b46 100644
--- a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern75.py
+++ b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern75.py
@@ -1,6 +1,9 @@
 # Modify the hit wrapping action to wrap on 75 ns
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
 getPublicTool('HitWrapper',tryDefaultConfigurable=True).WrapTime=75
diff --git a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern900.py b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern900.py
index 190e024a41fd..344a8d3aaf5f 100644
--- a/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern900.py
+++ b/Simulation/SimulationJobOptions/share/cavern/preInclude.G4ReadCavern900.py
@@ -1,7 +1,10 @@
 # Modify the hit wrapping action to wrap on 50 ns
 
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
 getPublicTool('HitWrapper',tryDefaultConfigurable=True).WrapTime=900
diff --git a/Simulation/SimulationJobOptions/share/cosmics/preInclude.Cosmics.py b/Simulation/SimulationJobOptions/share/cosmics/preInclude.Cosmics.py
index 02b174871334..12945fd5ddf8 100644
--- a/Simulation/SimulationJobOptions/share/cosmics/preInclude.Cosmics.py
+++ b/Simulation/SimulationJobOptions/share/cosmics/preInclude.Cosmics.py
@@ -17,58 +17,13 @@ print "Cosmics-specific configuration of Simulation and Digitization requested"
 from G4AtlasApps.SimFlags import simFlags
 simFlags.EventFilter.set_Off()
 
-## Now make the cosmics setup via callback functions
+## Ensure that at least the first filter volume is switched on.
+if not simFlags.CosmicFilterVolumeName.statusOn:
+    print "CosmicFilterVolumeName not set. Using default = %s" % simFlags.CosmicFilterVolumeName.get_Value()
+    simFlags.CosmicFilterVolumeName.set_On()
 
-def cosmics_setup_filters():
-    ## Define volumes
-    atlasG4log.info("Setting up filter parameters")
-    from G4AtlasApps import PyG4Atlas, AtlasG4Eng
-    MenuRecordEnvelopes = AtlasG4Eng.G4Eng.menu_RecordEnvelope()
-    trt = PyG4Atlas.RecEnvelope('TRTBarrelEntryLayer', 'TRT::BarrelOuterSupport', 6)
-    trteca = PyG4Atlas.RecEnvelope('TRTECAEntryLayer', 'TRT::WheelA', 6)
-    trtecb = PyG4Atlas.RecEnvelope('TRTECBEntryLayer', 'TRT::WheelB', 6)
-    sct = PyG4Atlas.RecEnvelope('SCTBarrelEntryLayer', 'SCT::ThShieldOuterCly', 6) # could be ThShieldInnerCly or Cyl..
-    pixel = PyG4Atlas.RecEnvelope('PixelEntryLayer', 'Pixel::Pixel', 4)
-
-    ## First filter volume
-    if not simFlags.CosmicFilterVolumeName.statusOn:
-        atlasG4log.warning("CosmicFilterVolumeName not set. Using default = %s" % simFlags.CosmicFilterVolumeName.get_Value())
-        simFlags.CosmicFilterVolumeName.set_On()
-
-    if simFlags.CosmicFilterVolumeName == "TRT_Barrel":
-        atlasG4log.info('Setting recenv for TRT_Barrel')
-        MenuRecordEnvelopes.add_RecEnvelope(trt)
-    elif simFlags.CosmicFilterVolumeName == "TRT_EC":
-        atlasG4log.info('Setting recenv for TRT_Endcaps')
-        MenuRecordEnvelopes.add_RecEnvelope(trteca)
-        MenuRecordEnvelopes.add_RecEnvelope(trtecb)
-    elif simFlags.CosmicFilterVolumeName == "SCT_Barrel":
-        atlasG4log.info('Setting recenv for SCT_Barrel')
-        MenuRecordEnvelopes.add_RecEnvelope(sct)
-    elif simFlags.CosmicFilterVolumeName == "Pixel":
-        atlasG4log.info('Setting recenv for Pixel')
-        MenuRecordEnvelopes.add_RecEnvelope(pixel)
-
-    ## If second volume requested
-    if simFlags.CosmicFilterVolumeName2.statusOn:
-        if simFlags.CosmicFilterVolumeName2 == "TRT_Barrel":
-            atlasG4log.info('Setting recenv2 for TRT_Barrel')
-            MenuRecordEnvelopes.add_RecEnvelope(trt)
-        elif simFlags.CosmicFilterVolumeName2 == "TRT_EC":
-            atlasG4log.info('Setting recenv2 for TRT_Endcaps')
-            MenuRecordEnvelopes.add_RecEnvelope(trteca)
-            MenuRecordEnvelopes.add_RecEnvelope(trtecb)
-        elif simFlags.CosmicFilterVolumeName2 == "SCT_Barrel":
-            atlasG4log.info('Setting recenv2 for SCT_Barrel')
-            MenuRecordEnvelopes.add_RecEnvelope(sct)
-        elif simFlags.CosmicFilterVolumeName2 == "Pixel":
-            atlasG4log.info('Setting recenv2 for Pixel')
-            MenuRecordEnvelopes.add_RecEnvelope(pixel)
-
-    # TODO: Does this work in a callback?
-    if not simFlags.ISFRun:
-        include("G4CosmicFilter/G4CosmicFilter.py")
 
+## Now setup cosmics truth strategies via callback functions
 
 def cosmics_modify_truth_strategies():
     ## Modifying truth strategies as requested by e/gamma group
@@ -83,5 +38,4 @@ def cosmics_modify_truth_strategies():
 
 
 ## Register the callbacks (at two different levels)
-simFlags.InitFunctions.add_function("preInitG4", cosmics_setup_filters)
 simFlags.InitFunctions.add_function("postInit", cosmics_modify_truth_strategies)
diff --git a/Simulation/SimulationJobOptions/share/g4/preInclude.CalHits.py b/Simulation/SimulationJobOptions/share/g4/preInclude.CalHits.py
index b2bf901c088e..27941cd69c9c 100644
--- a/Simulation/SimulationJobOptions/share/g4/preInclude.CalHits.py
+++ b/Simulation/SimulationJobOptions/share/g4/preInclude.CalHits.py
@@ -6,5 +6,3 @@
 
 from G4AtlasApps.SimFlags import simFlags
 simFlags.CalibrationRun = 'LAr+Tile'
-
-include("CaloG4Sim/CalibrationDefaultProcessing_jobOptions.py") #FIXME temporarily required for release 20.3.5
diff --git a/Simulation/SimulationJobOptions/share/g4/preInclude.HyperspaceCatcher.py b/Simulation/SimulationJobOptions/share/g4/preInclude.HyperspaceCatcher.py
index 3d6a9ed13281..a4e368d059ef 100644
--- a/Simulation/SimulationJobOptions/share/g4/preInclude.HyperspaceCatcher.py
+++ b/Simulation/SimulationJobOptions/share/g4/preInclude.HyperspaceCatcher.py
@@ -3,7 +3,10 @@
 # This is VERY handy for looking into problems in G4 - it should NOT be used for standard production.
 # Set "killAfter" in order to crash the job after a certain number of hyperspace particles
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
 catcher=getPublicTool('HyperspaceCatcher',tryDefaultConfigurable=True)
diff --git a/Simulation/SimulationJobOptions/share/g4/preInclude.ScoringVolumeKiller.py b/Simulation/SimulationJobOptions/share/g4/preInclude.ScoringVolumeKiller.py
index 191b88f3f56e..ddd009440fb0 100644
--- a/Simulation/SimulationJobOptions/share/g4/preInclude.ScoringVolumeKiller.py
+++ b/Simulation/SimulationJobOptions/share/g4/preInclude.ScoringVolumeKiller.py
@@ -19,6 +19,9 @@ getService('DetectorGeometrySvc').RegionCreators += [getPublicTool('MuonPhysicsR
 #currently initializing the DetectorGeometrySvc too early causes
 #problems with the GeoModelSvc configuration.
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 svkiller=getPublicTool('ScoringVolumeTrackKiller',tryDefaultConfigurable=True)
 UAStore.addAction(svkiller,['EndOfEvent', 'Step'])
diff --git a/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelector.py b/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelector.py
index 1f9bdc1723d0..97598bb4a974 100644
--- a/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelector.py
+++ b/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelector.py
@@ -2,12 +2,15 @@
 # Very handy for debugging crashes on the grid when you know what track caused the crash
 # Most powerful in conjunction with the verbose selector area
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicTool
 
-getPublicTool('VerboseSelector',tryDefaultConfigurable=True).TargetEvent=1
-getPublicTool('VerboseSelector').TargetTrack=15932
-getPublicTool('VerboseSelector').VerboseLevel=2
-getPublicTool('VerboseSelector').TargetBarcode=-1
+verboseSelector= getPublicTool('VerboseSelector',tryDefaultConfigurable=True).TargetEvent=1
+verboseSelector.TargetTrack=15932
+verboseSelector.VerboseLevel=2
+verboseSelector.TargetBarcode=-1
 
 UAStore.addAction('VerboseSelector',['EndOfEvent','BeginOfTracking','EndOfTracking'])
diff --git a/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelectorArea.py b/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelectorArea.py
index 8c44a86a050a..dbb16aa62dbe 100644
--- a/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelectorArea.py
+++ b/Simulation/SimulationJobOptions/share/g4/preInclude.VerboseSelectorArea.py
@@ -4,7 +4,10 @@
 # Verbose level is transmitted to several G4 classes to increase their verbosity.
 # Note that the event number is the number of events into the G4 run, rather than the ATLAS event number.
 
-from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+try:
+    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+except ImportError:
+    from G4AtlasServices.UserActionStore import UAStore
 from AthenaCommon.CfgGetter import getPublicToolClone,getPublicTool
 
 vsArea=getPublicTool('VerboseSelector/VerboseSelectorArea',tryDefaultConfigurable=True)
diff --git a/Simulation/SimulationJobOptions/share/hive/postInclude.GaudiHive.py b/Simulation/SimulationJobOptions/share/hive/postInclude.GaudiHive.py
new file mode 100644
index 000000000000..86ecccf09fd0
--- /dev/null
+++ b/Simulation/SimulationJobOptions/share/hive/postInclude.GaudiHive.py
@@ -0,0 +1,22 @@
+# TODO: make this declaration more automatic
+
+topSeq.G4AtlasAlg.ExtraInputs =  [('McEventCollection','GEN_EVENT')]
+topSeq.G4AtlasAlg.ExtraOutputs = [('SiHitCollection','SCT_Hits'),('RecoTimingObj','EVNTtoHITS_timings')]
+
+topSeq.StreamHITS.ExtraInputs += topSeq.G4AtlasAlg.ExtraOutputs
+# Disable alg filtering - doesn't work in multi-threading
+topSeq.StreamHITS.AcceptAlgs = []
+algCardinality = jp.ConcurrencyFlags.NumThreads()
+
+if (algCardinality != 1):
+    for alg in topSeq:
+        name = alg.name()
+#        if name in ["SGInputLoader", "StreamHITS"]:
+        if name in ["StreamHITS"]:
+            print 'Disabling cloning/cardinality for', name
+            # Don't clone these algs
+            alg.Cardinality = 1
+            alg.IsClonable = False
+        else:
+            alg.Cardinality = algCardinality
+            alg.IsClonable = True
diff --git a/Simulation/SimulationJobOptions/share/hive/preInclude.GaudiHive.py b/Simulation/SimulationJobOptions/share/hive/preInclude.GaudiHive.py
new file mode 100644
index 000000000000..cb2f2a6cc55e
--- /dev/null
+++ b/Simulation/SimulationJobOptions/share/hive/preInclude.GaudiHive.py
@@ -0,0 +1,86 @@
+
+## Detector flags
+from AthenaCommon.DetFlags import DetFlags
+DetFlags.ID_setOn()
+DetFlags.Calo_setOff()
+DetFlags.Muon_setOn()
+DetFlags.Lucid_setOff()
+DetFlags.Truth_setOn()
+
+
+
+from AthenaCommon.ConcurrencyFlags import jobproperties as jp
+nThreads = jp.ConcurrencyFlags.NumThreads()
+if (nThreads < 1) :
+   from AthenaCommon.Logging import log as msg
+   msg.fatal('numThreads must be >0. Did you set the --threads=N option?')
+   sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR)
+
+# Thread pool service and initialization
+from GaudiHive.GaudiHiveConf import ThreadPoolSvc
+svcMgr += ThreadPoolSvc("ThreadPoolSvc")
+svcMgr.ThreadPoolSvc.ThreadInitTools = ["G4InitTool"]
+
+# Algorithm resource pool
+from GaudiHive.GaudiHiveConf import AlgResourcePool
+svcMgr += AlgResourcePool( OutputLevel = INFO );
+
+from AthenaCommon.AlgSequence import AlgSequence
+from PerfMonComps.PerfMonFlags import jobproperties	
+jobproperties.PerfMonFlags.doMonitoring.set_Value_and_Lock(False)
+jobproperties.PerfMonFlags.doDsoMonitoring.set_Value_and_Lock(False)
+#jobproperties.doPerfMon.set_Value_and_Lock(False)
+from RecExConfig.RecFlags import rec
+rec.doPerfMon.set_Value_and_Lock( False )
+rec.doDetailedPerfMon.set_Value_and_Lock( False )
+rec.doSemiDetailedPerfMon.set_Value_and_Lock( False )
+
+# check to see if we're running hybrid mp/mt
+nProc = jp.ConcurrencyFlags.NumProcs()
+if (nProc > 0) :
+
+   #
+   ## For MP/Hive we need to set the chunk size
+   #
+
+   from AthenaCommon.Logging import log as msg
+   if (evtMax == -1) :
+      msg.fatal('EvtMax must be >0 for hybrid configuration')
+      sys.exit(AthenaCommon.ExitCodes.CONFIGURATION_ERROR)
+
+   if ( evtMax % nProc != 0 ) :
+      msg.warning('EvtMax[%s] is not divisible by nProcs[%s]: ' +
+                  'MP Workers will not process all requested events',
+                  evtMax, nProc)
+
+   chunkSize = int (evtMax / nProc)
+
+   from AthenaMP.AthenaMPFlags import jobproperties as jps
+   jps.AthenaMPFlags.ChunkSize = chunkSize
+
+   msg.info('AthenaMP workers will process %s events each', chunkSize)
+
+## Simulation flags
+from G4AtlasApps.SimFlags import simFlags
+from G4AtlasApps import callbacks
+simFlags.load_atlas_flags()
+
+## No magnetic field
+simFlags.MagneticField.set_Off()
+
+# Currently, Hive requires an algorithm to load the initial data into the
+# whiteboard and kickstart the data dependency chain. This alg must be at the
+# front of the AlgSequence.
+topSeq = AlgSequence()
+from AthenaCommon import CfgMgr
+topSeq += CfgMgr.SGInputLoader(OutputLevel = INFO, ShowEventDump=False)
+
+# SGInputLoader is a module in SGComps that will do a typeless StoreGate read
+# of data on disk, to preload it in the Whiteboard for other Alorithms to use.
+# Is uses the same syntax as Algorithmic dependency declarations
+topSeq.SGInputLoader.Load = [('McEventCollection','GEN_EVENT')]
+
+## Add the G4 simulation service
+#from G4AtlasApps.PyG4Atlas import PyG4AtlasSvc
+#svcMgr += PyG4AtlasSvc()
+
diff --git a/Simulation/SimulationJobOptions/share/specialConfig/postInclude.Monopole.py b/Simulation/SimulationJobOptions/share/specialConfig/postInclude.Monopole.py
new file mode 100644
index 000000000000..124188dd1857
--- /dev/null
+++ b/Simulation/SimulationJobOptions/share/specialConfig/postInclude.Monopole.py
@@ -0,0 +1,13 @@
+
+# configure the looper killer
+# this configures the MT-friendly version of the looperKiller
+
+import G4UserActions.G4UserActionsConfig
+
+lkTool=CfgGetter.getPublicToolClone('MonopoleLooperKillerTool','G4UA::LooperKillerTool', PrintSteps=2, MaxSteps=2000000, VerboseLevel=0)
+G4UserActionsConfig.addLooperKillerTool(lkTool)
+# add default HIP killer
+G4UserActionsConfig.addHIPKillerTool()
+
+
+
diff --git a/Simulation/SimulationJobOptions/share/specialConfig/postInclude.Qball.py b/Simulation/SimulationJobOptions/share/specialConfig/postInclude.Qball.py
new file mode 100644
index 000000000000..2bafd31eb0d2
--- /dev/null
+++ b/Simulation/SimulationJobOptions/share/specialConfig/postInclude.Qball.py
@@ -0,0 +1,13 @@
+
+# configure the looper killer
+# this configures the MT-friendly version of the looperKiller
+
+import G4UserActions.G4UserActionsConfig
+
+lkTool=CfgGetter.getPublicToolClone('QballLooperKillerTool','G4UA::LooperKillerTool', PrintSteps=2, MaxSteps=2000000, VerboseLevel=0)
+G4UserActionsConfig.addLooperKillerTool(lkTool)
+# add default HIP killer
+G4UserActionsConfig.addHIPKillerTool()
+
+
+
diff --git a/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Monopole.py b/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Monopole.py
index 6d37c2d5cfb8..221e3de9aae9 100644
--- a/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Monopole.py
+++ b/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Monopole.py
@@ -51,7 +51,7 @@ try:
 except:
     from G4AtlasApps import AtlasG4Eng
     simdict = AtlasG4Eng.G4Eng.Dict_SpecialConfiguration
-    
+
 assert "MASS" in simdict
 assert "GCHARGE" in simdict
 load_files_for_monopole_scenario(simdict["MASS"], simdict["GCHARGE"])
@@ -61,31 +61,28 @@ if doG4SimConfig:
     AtlasG4Eng.G4Eng.log.info("Unlocking simFlags.EquationOfMotion to reset the value for Monopole simulation.")
     from G4AtlasApps.SimFlags import simFlags
     # FIXME ideally would include this file early enough, so that the unlocking is not required
-    simFlags.EquationOfMotion.unlock() 
+    simFlags.EquationOfMotion.unlock()
     simFlags.EquationOfMotion.set_On()
     simFlags.EquationOfMotion.set_Value_and_Lock("MonopoleEquationOfMotion")
+    simFlags.G4Stepper.set_Value_and_Lock('ClassicalRK4')
 
     def monopole_setupg4():
         from G4AtlasApps import PyG4Atlas, AtlasG4Eng
         AtlasG4Eng.G4Eng.load_Lib("Monopole")
-
     simFlags.InitFunctions.add_function("preInitPhysics", monopole_setupg4)
 
-    def setup_stepper_classicalrk4():
-        from G4AtlasApps import AtlasG4Eng
-        AtlasG4Eng.G4Eng._ctrl.fldMenu.UseStepper('ClassicalRK4')
-        AtlasG4Eng.G4Eng._ctrl.fldMenu.UseStepper('IDET::IDET', 'ClassicalRK4')
-
-    simFlags.InitFunctions.add_function("postInit", setup_stepper_classicalrk4)
-
-    # configure the looper killer
-    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
-    from AthenaCommon.CfgGetter import getPublicToolClone
-    # use specific configuration
-    lkAction = getPublicToolClone("LooperKillerMonopole", "LooperKiller", PrintSteps=2, MaxSteps=2000000, VerboseLevel=0)
-    UAStore.addAction(lkAction,['Step'])
-    # add HIP killer
-    UAStore.addAction('HIPKiller',['Step'])
+    if (not hasattr(simFlags, 'UseV2UserActions') or not simFlags.UseV2UserActions():
+        # this configures the non-MT UserActions
+        try:
+            from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+        except ImportError:
+            from G4AtlasServices.UserActionStore import UAStore
+            from AthenaCommon.CfgGetter import getPublicToolClone
+        # use specific configuration
+        lkAction = getPublicToolClone("MonopoleLooperKiller", "LooperKiller", PrintSteps=2, MaxSteps=2000000, VerboseLevel=0)
+        UAStore.addAction(lkAction,['Step'])
+        # add HIP killer
+        UAStore.addAction('HIPKiller',['Step'])
 
 
 
diff --git a/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Qball.py b/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Qball.py
index ac8c05aaff8d..9d2c39d3d6ae 100644
--- a/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Qball.py
+++ b/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Qball.py
@@ -53,7 +53,7 @@ try:
 except:
     from G4AtlasApps import AtlasG4Eng
     simdict = AtlasG4Eng.G4Eng.Dict_SpecialConfiguration
-    
+
 assert "MASS" in simdict
 assert "CHARGE" in simdict
 load_files_for_qball_scenario(simdict["MASS"], simdict["CHARGE"])
@@ -63,30 +63,32 @@ if doG4SimConfig:
     AtlasG4Eng.G4Eng.log.info("Unlocking simFlags.EquationOfMotion to reset the value for Monopole simulation.")
     from G4AtlasApps.SimFlags import simFlags
     # FIXME ideally would include this file early enough, so that the unlocking is not required
-    simFlags.EquationOfMotion.unlock() 
+    simFlags.EquationOfMotion.unlock()
     simFlags.EquationOfMotion.set_On()
     simFlags.EquationOfMotion.set_Value_and_Lock("MonopoleEquationOfMotion")
+    simFlags.G4Stepper.set_Value_and_Lock('ClassicalRK4')
 
     def monopole_setupg4():
         from G4AtlasApps import PyG4Atlas, AtlasG4Eng
         AtlasG4Eng.G4Eng.load_Lib("Monopole")
-
     simFlags.InitFunctions.add_function("preInitPhysics", monopole_setupg4)
 
-    def setup_stepper_classicalrk4():
-        from G4AtlasApps import AtlasG4Eng
-        AtlasG4Eng.G4Eng._ctrl.fldMenu.UseStepper('ClassicalRK4')
-        AtlasG4Eng.G4Eng._ctrl.fldMenu.UseStepper('IDET::IDET', 'ClassicalRK4')
-
-    simFlags.InitFunctions.add_function("postInit", setup_stepper_classicalrk4)
-
-    # configure the looper killer
-    from G4AtlasServices.G4AtlasUserActionConfig import UAStore
-    from AthenaCommon.CfgGetter import getPublicToolClone
-    # use specific configuration
-    lkAction = getPublicToolClone("LooperKillerQBall", "LooperKiller", PrintSteps=2, MaxSteps=2000000, VerboseLevel=0)
-    UAStore.addAction(lkAction,['Step'])
-    # add HIP killer
-    UAStore.addAction('HIPKiller',['Step'])
+    if (hasattr(simFlags, 'UseV2UserActions') and simFlags.UseV2UserActions()):
+        # MT-compatible UserActions
+        from G4AtlasServices.G4AtlasServicesConfig import addAction
+        addAction("LooperKillerTool",['Step'],False)
+        addAction("HIPKillerTool",['Step'],False)
+    else:
+        # this configures the non-MT UserActions
+        try:
+            from G4AtlasServices.G4AtlasUserActionConfig import UAStore
+        except ImportError:
+            from G4AtlasServices.UserActionStore import UAStore
+        from AthenaCommon.CfgGetter import getPublicToolClone
+        # use specific configuration
+        lkAction = getPublicToolClone("LooperKillerQBall", "LooperKiller", PrintSteps=2, MaxSteps=2000000, VerboseLevel=0)
+        UAStore.addAction(lkAction,['Step'])
+        # add HIP killer
+        UAStore.addAction('HIPKiller',['Step'])
 
 del doG4SimConfig, simdict
diff --git a/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Rhadrons.py b/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Rhadrons.py
index b4b0faead24e..a50c8b0b149b 100644
--- a/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Rhadrons.py
+++ b/Simulation/SimulationJobOptions/share/specialConfig/preInclude.Rhadrons.py
@@ -1,5 +1,5 @@
 #########################################################################
-#	preInclude.Rhadrons.py - Chiara Debenedetti, 3 Jun 2011	#
+#      preInclude.Rhadrons.py - Chiara Debenedetti, 3 Jun 2011 #
 #                              - Andy Haas, 4 Apr 2012
 #########################################################################
 
@@ -86,47 +86,47 @@ def create_rhadron_particles_file(CASE, MASS, MODEL, MASSX):
     "stop" : {
       "generic" :[
         '     1000006  %3.3f   # ~t_1'       % ( MASS + 100.000 ),
-      	'     1000612  %3.3f   # ~T+  '      % ( MASS + 100.325 ),
-      	'     1000622  %3.3f   # ~T0  '      % ( MASS + 100.325 ),
-      	'     1000632  %3.3f   # ~T_s+'      % ( MASS + 100.500 ),
-      	'     1000642  %3.3f   # ~T_c0'      % ( MASS + 101.500 ),
-      	'     1000652  %3.3f   # ~T_b+'      % ( MASS + 104.800 ),
-      	'     1006113  %3.3f   # ~T_dd10'    % ( MASS + 100.650 ),
-      	'     1006211  %3.3f   # ~T_ud0+'    % ( MASS + 100.650 ),
-      	'     1006213  %3.3f   # ~T_ud1+'    % ( MASS + 100.650 ),
-      	'     1006223  %3.3f   # ~T_uu1++ '  % ( MASS + 100.650 ),
-      	'     1006311  %3.3f   # ~T_sd00  '  % ( MASS + 100.825 ),
-      	'     1006313  %3.3f   # ~T_sd10  '  % ( MASS + 100.825 ),
-      	'     1006321  %3.3f   # ~T_su0+  '  % ( MASS + 100.825 ),
-      	'     1006323  %3.3f   # ~T_su1+  '  % ( MASS + 100.825 ),
-      	'     1006333  %3.3f   # ~T_ss10  '  % ( MASS + 101.000 ),
+        '     1000612  %3.3f   # ~T+  '      % ( MASS + 100.325 ),
+        '     1000622  %3.3f   # ~T0  '      % ( MASS + 100.325 ),
+        '     1000632  %3.3f   # ~T_s+'      % ( MASS + 100.500 ),
+        '     1000642  %3.3f   # ~T_c0'      % ( MASS + 101.500 ),
+        '     1000652  %3.3f   # ~T_b+'      % ( MASS + 104.800 ),
+        '     1006113  %3.3f   # ~T_dd10'    % ( MASS + 100.650 ),
+        '     1006211  %3.3f   # ~T_ud0+'    % ( MASS + 100.650 ),
+        '     1006213  %3.3f   # ~T_ud1+'    % ( MASS + 100.650 ),
+        '     1006223  %3.3f   # ~T_uu1++ '  % ( MASS + 100.650 ),
+        '     1006311  %3.3f   # ~T_sd00  '  % ( MASS + 100.825 ),
+        '     1006313  %3.3f   # ~T_sd10  '  % ( MASS + 100.825 ),
+        '     1006321  %3.3f   # ~T_su0+  '  % ( MASS + 100.825 ),
+        '     1006323  %3.3f   # ~T_su1+  '  % ( MASS + 100.825 ),
+        '     1006333  %3.3f   # ~T_ss10  '  % ( MASS + 101.000 ),
         '    -1000006  %3.3f   # ~t_1bar'    % ( MASS + 100.000 ),
-      	'    -1000612  %3.3f   # ~Tbar-  '   % ( MASS + 100.325 ),
-      	'    -1000622  %3.3f   # ~Tbar0  '   % ( MASS + 100.325 ),
-      	'    -1000632  %3.3f   # ~Tbar_s-'   % ( MASS + 100.500 ),
-      	'    -1000642  %3.3f   # ~Tbar_c0'   % ( MASS + 101.500 ),
-      	'    -1000652  %3.3f   # ~Tbar_b-'   % ( MASS + 104.800 ),
-      	'    -1006113  %3.3f   # ~Tbar_dd10' % ( MASS + 100.650 ),
-      	'    -1006211  %3.3f   # ~Tbar_ud0-' % ( MASS + 100.650 ),
-      	'    -1006213  %3.3f   # ~Tbar_ud1-' % ( MASS + 100.650 ),
-      	'    -1006223  %3.3f   # ~Tbar_uu1--'% ( MASS + 100.650 ),
-      	'    -1006311  %3.3f   # ~Tbar_sd00 '% ( MASS + 100.825 ),
-      	'    -1006313  %3.3f   # ~Tbar_sd10 '% ( MASS + 100.825 ),
-      	'    -1006321  %3.3f   # ~Tbar_su0- '% ( MASS + 100.825 ),
-      	'    -1006323  %3.3f   # ~Tbar_su1- '% ( MASS + 100.825 ),
-      	'    -1006333  %3.3f   # ~Tbar_ss10 '% ( MASS + 101.000 ),
+        '    -1000612  %3.3f   # ~Tbar-  '   % ( MASS + 100.325 ),
+        '    -1000622  %3.3f   # ~Tbar0  '   % ( MASS + 100.325 ),
+        '    -1000632  %3.3f   # ~Tbar_s-'   % ( MASS + 100.500 ),
+        '    -1000642  %3.3f   # ~Tbar_c0'   % ( MASS + 101.500 ),
+        '    -1000652  %3.3f   # ~Tbar_b-'   % ( MASS + 104.800 ),
+        '    -1006113  %3.3f   # ~Tbar_dd10' % ( MASS + 100.650 ),
+        '    -1006211  %3.3f   # ~Tbar_ud0-' % ( MASS + 100.650 ),
+        '    -1006213  %3.3f   # ~Tbar_ud1-' % ( MASS + 100.650 ),
+        '    -1006223  %3.3f   # ~Tbar_uu1--'% ( MASS + 100.650 ),
+        '    -1006311  %3.3f   # ~Tbar_sd00 '% ( MASS + 100.825 ),
+        '    -1006313  %3.3f   # ~Tbar_sd10 '% ( MASS + 100.825 ),
+        '    -1006321  %3.3f   # ~Tbar_su0- '% ( MASS + 100.825 ),
+        '    -1006323  %3.3f   # ~Tbar_su1- '% ( MASS + 100.825 ),
+        '    -1006333  %3.3f   # ~Tbar_ss10 '% ( MASS + 101.000 ),
         '     1000039  %3.3f   # ~Gravitino' % ( MASSX ),
         '     1000022  %3.3f   # ~chi_10'    % ( MASSX )
       ],
       "regge" : [
         '     1000006  %3.3f   # ~t_1'       % ( MASS +  100.000 ),
-      	'     1000612  %3.3f   # ~T+  '      % ( MASS +  100.325 ),
-      	'     1000622  %3.3f   # ~T0  '      % ( MASS +  100.325 ),
-      	'     1006211  %3.3f   # ~T_ud0+'    % ( MASS +  100.650 ),
+        '     1000612  %3.3f   # ~T+  '      % ( MASS +  100.325 ),
+        '     1000622  %3.3f   # ~T0  '      % ( MASS +  100.325 ),
+        '     1006211  %3.3f   # ~T_ud0+'    % ( MASS +  100.650 ),
         '    -1000006  %3.3f   # ~t_1bar'    % ( MASS +  100.000 ),
-      	'    -1000612  %3.3f   # ~Tbar-  '   % ( MASS +  100.325 ),
-      	'    -1000622  %3.3f   # ~Tbar0  '   % ( MASS +  100.325 ),
-      	'    -1006211  %3.3f   # ~Tbar_ud0-' % ( MASS +  100.650 ),
+        '    -1000612  %3.3f   # ~Tbar-  '   % ( MASS +  100.325 ),
+        '    -1000622  %3.3f   # ~Tbar0  '   % ( MASS +  100.325 ),
+        '    -1006211  %3.3f   # ~Tbar_ud0-' % ( MASS +  100.650 ),
         '     1000039  %3.3f   # ~Gravitino' % ( MASSX ),
         '     1000022  %3.3f   # ~chi_10'    % ( MASSX )
       ],
@@ -136,13 +136,13 @@ def create_rhadron_particles_file(CASE, MASS, MODEL, MASSX):
       "generic" : [],
       "regge" : [
         '     1000005  %3.3f   # ~b'         % ( MASS + 100.000 ),
-      	'     1000512  %3.3f   # ~B0  '      % ( MASS + 100.325 ),
-      	'     1000522  %3.3f   # ~B-  '      % ( MASS + 100.325 ),
-      	'     1005211  %3.3f   # ~B_ud0'     % ( MASS + 100.650 ),
+        '     1000512  %3.3f   # ~B0  '      % ( MASS + 100.325 ),
+        '     1000522  %3.3f   # ~B-  '      % ( MASS + 100.325 ),
+        '     1005211  %3.3f   # ~B_ud0'     % ( MASS + 100.650 ),
         '    -1000005  %3.3f   # ~bbar'      % ( MASS + 100.000 ),
-      	'    -1000512  %3.3f   # ~Bbar0  '   % ( MASS + 100.325 ),
-      	'    -1000522  %3.3f   # ~Bbar+  '   % ( MASS + 100.325 ),
-      	'    -1005211  %3.3f   # ~Bbar_ud0'  % ( MASS + 100.650 ),
+        '    -1000512  %3.3f   # ~Bbar0  '   % ( MASS + 100.325 ),
+        '    -1000522  %3.3f   # ~Bbar+  '   % ( MASS + 100.325 ),
+        '    -1005211  %3.3f   # ~Bbar_ud0'  % ( MASS + 100.650 ),
         '     1000039  %3.3f   # ~Gravitino' % ( MASSX ),
         '     1000022  %3.3f   # ~chi_10'    % ( MASSX )
         ],
-- 
GitLab