From ad990145b0291ddecfc84fc1497e76a7dc0bd7db Mon Sep 17 00:00:00 2001
From: Goetz Gaycken <goetz.gaycken@cern.ch>
Date: Tue, 6 Oct 2020 19:17:03 +0200
Subject: [PATCH] Detect whether a cluster split prob map might be available by
 scanning all properties.

---
 .../InDetRecExample/python/TrackingCommon.py  | 39 +++++++++++++------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/InnerDetector/InDetExample/InDetRecExample/python/TrackingCommon.py b/InnerDetector/InDetExample/InDetRecExample/python/TrackingCommon.py
index 304d9511d61..9e51a95f703 100644
--- a/InnerDetector/InDetExample/InDetRecExample/python/TrackingCommon.py
+++ b/InnerDetector/InDetExample/InDetRecExample/python/TrackingCommon.py
@@ -1460,27 +1460,43 @@ def getSolenoidalIntersector(name="SolenoidalIntersector", **kwargs) :
     from TrkExSolenoidalIntersector.TrkExSolenoidalIntersectorConf import Trk__SolenoidalIntersector
     return Trk__SolenoidalIntersector(the_name, **setDefaults(kwargs, SolenoidParameterizationKey = 'SolenoidParametrization'))
 
-def hasSplitProb(key) :
-    # @TODO find better solution,
-    import re
-    pat=re.compile('.*Dense.*')
-    from AthenaCommon.AppMgr import ToolSvc
-    for a_tool in ToolSvc.getChildren() :
-        if pat.match( a_tool.getFullName() ) != None :
-            print ('DEBUG split prob probabily set by %s' % a_tool.getFullName() )
-            return True
+def searchProb(prob_val) :
+    def iterateComp() :
+       from AthenaCommon.AppMgr import ToolSvc
+       from AthenaCommon.Configurable import ConfigurableAlgTool
+
+       for a_tool in ToolSvc.getChildren() :
+           yield a_tool
+       from AthenaCommon.AlgSequence import AlgSequence
+       topSequence = AlgSequence()
+       for an_alg in topSequence.getChildren() :
+           yield an_alg
+           for name,prop in an_alg.getProperties().items() :
+               if isinstance(prop,ConfigurableAlgTool) and not prop.isInToolSvc() :
+                   yield prop
+
+    for a_comp in iterateComp() :
+        for name,prop in a_comp.getProperties().items() :
+            if isinstance(prop ,str) and prop == prob_val :
+                return True
+    return False
 
+def hasSplitProb(key) :
+    # @TODO find better solution than searching through a huge number of properties
     from RecExConfig.AutoConfiguration import IsInInputFile
     if IsInInputFile('Trk::ClusterSplitProbabilityContainer',key) :
-        print ('DEBUG split prob  %s in inputfile ' % key )
         return True
 
-    print ('DEBUG split prob is not set.' )
+    if searchProb(key) :
+        return True
     return False
 
 def combinedClusterSplitProbName() :
   # precisely mimics the configuration in InDetRec_jobOptions
   # chaings in InDetRec_jobOptions to the ClusterSplitProbContainer also have to be implemented here
+  # To synchronise with InDetRec_jobOptions the logic can be extracted with
+  # grep "CombinedInDetClusterSplitProbContainer\|ClusterSplitProbContainer\|[[:space:]]\(el\|\)if\([[:space:]]\|(\)\|[[:space:]]else[[:space:]]*:\|ConfiguredNewTrackingCuts" 
+  #    InnerDetector/InDetExample/InDetRecExample/share/InDetRec_jobOptions.py
   # @TODO find a better way to provide the final name of ClusterSplitProbContainer used for the combined InDetTrackParticles
   from AthenaCommon.BeamFlags import jobproperties
   from InDetRecExample.InDetJobProperties import InDetFlags
@@ -1488,7 +1504,6 @@ def combinedClusterSplitProbName() :
   ClusterSplitProbContainer=''
   if InDetFlags.Enabled():
     from InDetRecExample.ConfiguredNewTrackingCuts import ConfiguredNewTrackingCuts
-    # --- ensure that Calo clustering is running if we run in calo seeded mode 
     if ('InDetNewTrackingCuts' not in dir()):
       if InDetFlags.doDBMstandalone():
         InDetNewTrackingCuts      = ConfiguredNewTrackingCuts("DBM")
-- 
GitLab