From c0c1e8bebd4e573b1abfab525792844b014f46c4 Mon Sep 17 00:00:00 2001
From: Carlo Varni <carlo.varni@cern.ch>
Date: Thu, 28 Oct 2021 12:14:12 +0200
Subject: [PATCH] Add function decorator

---
 .../python/ActsSequenceConfiguration.py       | 32 +++++++++++++++++++
 .../python/ActsTrackingSequenceConfig.py      | 19 ++---------
 .../ActsTrackingSequenceFromAthenaConfig.py   | 19 ++---------
 3 files changed, 36 insertions(+), 34 deletions(-)
 create mode 100644 Tracking/Acts/ActsTrkFinding/python/ActsSequenceConfiguration.py

diff --git a/Tracking/Acts/ActsTrkFinding/python/ActsSequenceConfiguration.py b/Tracking/Acts/ActsTrkFinding/python/ActsSequenceConfiguration.py
new file mode 100644
index 000000000000..1f1f0ddab12c
--- /dev/null
+++ b/Tracking/Acts/ActsTrkFinding/python/ActsSequenceConfiguration.py
@@ -0,0 +1,32 @@
+# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+
+# Python's Decorator for ACTS algorithm sequence
+# This will set the debug level to the desired value
+# and change the name of all the sequences accordingly
+# to the environment
+
+def acts_sequence_configuration(func):
+    def wrapper(ConfigFlags, **kwargs):
+        acc = func(ConfigFlags, **kwargs)
+
+        # Set OutputLevel can be set with the following piece of code
+        # This will set the Outputl Level of all the algorithms and Tools to
+        # a defined value
+        # TO-DO: Add a flag (maybe in the config flags) that defines the output level
+        # for our algorithms/tools
+        #
+        # from AthenaCommon.Constants import DEBUG
+        # for el in acc._allSequences:
+        #     for member in el.Members:
+        #         member.OutputLevel = DEBUG
+                
+        # the following is needed to reliably determine whether we're really being steered from an old-style job option
+        # assume we're running CPython
+        import inspect
+        stack = inspect.stack()
+        if len(stack) >= 2 and stack[1].function == 'CAtoGlobalWrapper':
+            for el in acc._allSequences:
+                el.name = "TopAlg"
+
+        return acc
+    return wrapper
diff --git a/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceConfig.py b/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceConfig.py
index aa7ab817c00c..06ebc748f150 100644
--- a/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceConfig.py
+++ b/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceConfig.py
@@ -4,7 +4,9 @@ from AthenaCommon.Configurable import ConfigurableRun3Behavior
 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
 from AthenaConfiguration.ComponentAccumulator import CAtoGlobalWrapper
 from ActsTrkFinding.ActsSeedingAlgorithmConfig import ActsSeedingAlgorithmCfg
+from ActsTrkFinding.ActsSequenceConfiguration import acts_sequence_configuration
 
+@acts_sequence_configuration
 def ActsTrackingSequenceCfg(ConfigFlags, 
                             inputCollections: list = []):
     # prepare entire sequence
@@ -16,23 +18,6 @@ def ActsTrackingSequenceCfg(ConfigFlags,
                                               name = 'ActsSeedingAlgorithm', 
                                               inputCollection = i_collection,
                                               outputCollection = o_collection))
-            
-    # Set OutputLevel can be set with the following piece of code
-    # This will set the Outputl Level of all the algorithms and Tools to
-    # a defined value
-    #
-    # from AthenaCommon.Constants import DEBUG
-    # for el in acc._allSequences:
-    #     for member in el.Members:
-    #         member.OutputLevel = DEBUG
-            
-    # the following is needed to reliably determine whether we're really being steered from an old-style job option
-    # assume we're running CPython
-    import inspect
-    stack = inspect.stack()
-    if len(stack) >= 2 and stack[1].function == 'CAtoGlobalWrapper':
-        for el in acc._allSequences:
-            el.name = "TopAlg"
 
     return acc
 
diff --git a/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceFromAthenaConfig.py b/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceFromAthenaConfig.py
index da38ebea3c28..30b1d149be2b 100644
--- a/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceFromAthenaConfig.py
+++ b/Tracking/Acts/ActsTrkFinding/python/ActsTrackingSequenceFromAthenaConfig.py
@@ -4,8 +4,10 @@ from AthenaCommon.Configurable import ConfigurableRun3Behavior
 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
 from AthenaConfiguration.ComponentAccumulator import CAtoGlobalWrapper
 from ActsTrkFinding.ActsSeedingAlgorithmConfig import ActsSeedingAlgorithmCfg
+from ActsTrkFinding.ActsSequenceConfiguration import acts_sequence_configuration
 from ActsInterop import UnitConstants
 
+@acts_sequence_configuration
 def ActsTrackingSequenceFromAthenaCfg(ConfigFlags, 
                                       inputCollections: list = []):
     # prepare entire sequence
@@ -30,23 +32,6 @@ def ActsTrackingSequenceFromAthenaCfg(ConfigFlags,
                                               inputCollection = i_collection,
                                               outputCollection = o_collection,
                                               **seedingOptions))
-            
-    # Set OutputLevel can be set with the following piece of code
-    # This will set the Outputl Level of all the algorithms and Tools to
-    # a defined value
-    #
-    # from AthenaCommon.Constants import DEBUG
-    # for el in acc._allSequences:
-    #     for member in el.Members:
-    #         member.OutputLevel = DEBUG
-            
-    # the following is needed to reliably determine whether we're really being steered from an old-style job option
-    # assume we're running CPython
-    import inspect
-    stack = inspect.stack()
-    if len(stack) >= 2 and stack[1].function == 'CAtoGlobalWrapper':
-        for el in acc._allSequences:
-            el.name = "TopAlg"
 
     return acc
 
-- 
GitLab