From 87f3b16440d086ad39ac936b41288d4b2eea1f99 Mon Sep 17 00:00:00 2001
From: Tomasz Bold <tomasz.bold@gmail.com>
Date: Wed, 30 Dec 2020 11:11:17 +0000
Subject: [PATCH] Option to run part of the menu in newJO

---
 .../python/TriggerConfigFlags.py              |  4 ++++
 .../Menu/GenerateMenuMT_newJO.py              | 20 ++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py
index 40450fa9998b..43ec20c30fb5 100644
--- a/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py
+++ b/Trigger/TriggerCommon/TriggerJobOpts/python/TriggerConfigFlags.py
@@ -206,6 +206,10 @@ def createTriggerFlags():
     # name of the trigger menu
     flags.addFlag('Trigger.triggerMenuSetup', 'LS2_v1')
 
+    # modify the slection of chains that are run (default run all), see more in GenerateMenuMT_newJO
+
+    flags.addFlag('Trigger.triggerMenuModifier', ['all'])
+
     # name of the trigger menu
     flags.addFlag('Trigger.generateMenuDiagnostics', False)
 
diff --git a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT_newJO.py b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT_newJO.py
index 1ce863f74f56..d9622d9f6758 100644
--- a/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT_newJO.py
+++ b/Trigger/TriggerCommon/TriggerMenuMT/python/HLTMenuConfig/Menu/GenerateMenuMT_newJO.py
@@ -35,11 +35,28 @@ def obtainChainsOfMenu(flags):
     return setupMenuModule.setupMenu(flags)
 
 
+def acceptChain(chainDict, whichSignatures):
+    """
+    Helper to accept chains to be part of the menu depending on their name or which signatures they belong to.
 
+    If the keyword "all" is present all chains that are in the menu are accepted.
+    If the keyword "emptyMenu" is present other keywords are checked.
+      They can be name of signature: e.g. Muon or name of chain(s) HLT_j50_L1J30
+    Leaving the "emptyMenu" keyword only results in no chains that are configured. As a consequence would cause an issue somewhere downstream.
+    """
+    if "all" in whichSignatures:
+        return True
+    if "emptyMenu" in whichSignatures:
+        if chainDict["chainName"] in whichSignatures:  #explicit list of chains specified
+            return True
+        if all( [ sig in whichSignatures for sig in chainDict['signatures'] ]): # all signatures for the chain are mentioned 
+            return True
+    return False
 
 def generateMenu(flags):
     """
     Using flags generate appropriate Control Flow Graph wiht all HLT algorithms
+    
     """
 
     # convert to chainDefs
@@ -75,7 +92,8 @@ def generateMenu(flags):
         for chain in chains:
             # TODO topo threshold
             mainChainDict = dictFromChainName( chain )
-            
+            if not acceptChain( mainChainDict, flags.Trigger.triggerMenuModifier ):
+                continue
             counter += 1
             mainChainDict['chainCounter'] = counter
 
-- 
GitLab