Warning, /HLTrigger/Configuration/scripts/hltListPaths is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env python3
0002 import os
0003 import sys
0004 import argparse
0005 import re
0006 import FWCore.ParameterSet.Config as cms
0007 import HLTrigger.Configuration.Tools.pipe as pipe
0008 import HLTrigger.Configuration.Tools.options as options
0009 from HLTrigger.Configuration.extend_argparse import *
0010
0011 def getPathList(config):
0012
0013 if isinstance(config.menu, options.ConnectionHLTMenu):
0014 # cmd to download HLT configuration
0015 cmdline = 'hltConfigFromDB'
0016 if config.menu.run:
0017 cmdline += f' --runNumber {config.menu.run}'
0018 else:
0019 cmdline += f' --{config.menu.database} --{config.menu.version} --configName {config.menu.name}'
0020 cmdline += ' --noedsources --noes --noservices'
0021 if config.proxy:
0022 cmdline += f' --dbproxy --dbproxyhost {config.proxy_host} --dbproxyport {config.proxy_port}'
0023
0024 else:
0025 # use edmConfigDump to ensure the config can be executed
0026 cmdline = f'edmConfigDump {config.menu}'
0027
0028 # load HLT configuration
0029 try:
0030 foo = {'process': None}
0031 exec(pipe.pipe(cmdline).decode(), foo)
0032 process = foo['process']
0033 except:
0034 raise Exception(f'query did not return a valid python file:\n query="{cmdline}"')
0035
0036 if not isinstance(process, cms.Process):
0037 raise Exception(f'query did not return a valid HLT menu:\n query="{cmdline}"')
0038
0039 usePaths, useEndPaths, useFinalPaths = False, False, False
0040
0041 # Paths only
0042 if config.selection == 'paths':
0043 usePaths = True
0044
0045 # EndPaths only
0046 elif config.selection == 'endpaths':
0047 useEndPaths = True
0048
0049 # FinalPaths only
0050 elif config.selection == 'finalpaths':
0051 useFinalPaths = True
0052
0053 # Paths, EndPaths, and FinalPaths ('all')
0054 elif config.selection == 'all':
0055 usePaths, useEndPaths, useFinalPaths = True, True, True
0056
0057 # invalid value
0058 else:
0059 raise RuntimeError(f'ERROR: invalid value for option "--selection" (must be "paths", "endpaths", "finalpaths", or "all"): {config.selection}')
0060
0061 ret = []
0062 for pathDict in [
0063 process.paths_() if usePaths else None,
0064 process.endpaths_() if useEndPaths else None,
0065 process.finalpaths_() if useFinalPaths else None,
0066 ]:
0067 if pathDict == None:
0068 continue
0069
0070 for pathName in pathDict:
0071
0072 # skip if name of the path matches any of
0073 # the regular expressions listed in "--exclude"
0074 skipPath = False
0075 for excludeRegExpr in config.excludeRegExprs:
0076 if bool(re.search(excludeRegExpr, pathName)):
0077 skipPath = True
0078 break
0079 if skipPath:
0080 continue
0081
0082 if config.no_dependent_paths:
0083 # do not include "dependent paths", i.e. paths that depend on the result of other paths in the same job
0084 # the current criterion to identify a path as "dependent" is that
0085 # (1) the path contains a "TriggerResultsFilter" module and
0086 # (2) the latter module uses the TriggerResults of the current process, and has a non-empty list of "triggerConditions"
0087 path = pathDict[pathName]
0088 pathIsDependent = False
0089 isPath = isinstance(path, cms.Path)
0090
0091 for moduleName in path.moduleNames():
0092 module = getattr(process, moduleName)
0093 if module.type_() != 'TriggerResultsFilter' or (hasattr(module, 'triggerConditions') and len(module.triggerConditions) == 0):
0094 continue
0095
0096 usesPathStatus = hasattr(module, 'usePathStatus') and module.usePathStatus
0097 usesTrigResOfCurrentProcess = hasattr(module, 'hltResults') and module.hltResults.getProcessName() in [process.name_(), '@currentProcess']+['']*(not isPath)
0098
0099 if isPath:
0100 if usesPathStatus:
0101 pathIsDependent = True
0102 elif usesTrigResOfCurrentProcess:
0103 # The Path contains a TriggerResultsFilter with usePathStatus=False and forcing access to the TriggerResults of the current Process.
0104 # - This is not supported, and should result in a runtime error when using cmsRun.
0105 # - Here, a warning is returned to stderr, and the Path is omitted from the output list.
0106 warning_msg = 'WARNING -- the cms.Path named "'+pathName+'" will be ignored.'
0107 warning_msg += '\n'+' '*12+'- It contains a "TriggerResultsFilter" attempting to access the "TriggerResults" of the current Process (module: "'+moduleName+'").'
0108 warning_msg += '\n'+' '*12+'- This is not supported, and should result in a runtime error when using cmsRun. Please check again the HLT configuration.'
0109 print(warning_msg, file=sys.stderr)
0110 pathIsDependent = True
0111 else:
0112 pathIsDependent = usesPathStatus or usesTrigResOfCurrentProcess
0113
0114 if pathIsDependent:
0115 break
0116
0117 if pathIsDependent:
0118 continue
0119
0120 ret.append(pathName)
0121
0122 return ret
0123
0124 # define an argparse parser to parse our options
0125 textwidth = int( 80 )
0126 try:
0127 textwidth = int( os.popen("stty size", "r").read().split()[1] )
0128 except:
0129 pass
0130 formatter = FixedWidthFormatter( HelpFormatterRespectNewlines, width = textwidth )
0131
0132 # read defaults
0133 defaults = options.HLTProcessOptions()
0134
0135 def hltMenu(name):
0136 return name if os.path.isfile(name) else options.ConnectionHLTMenu(name)
0137
0138 parser = argparse.ArgumentParser(
0139 description = 'List all the Paths, EndPaths and FinalPaths of an HLT configuration.',
0140 argument_default = argparse.SUPPRESS,
0141 formatter_class = formatter,
0142 add_help = False )
0143
0144 # required argument
0145 parser.add_argument('menu',
0146 action = 'store',
0147 type = hltMenu,
0148 metavar = 'MENU',
0149 help = 'HLT menu (can be a local cmsRun configuration file, or the name of a configuration in the ConfDB database). For ConfDB configurations, supported formats are:\n - /path/to/configuration[/Vn]\n - [[{v1|v2|v3}/]{run3|run2|online|adg}:]/path/to/configuration[/Vn]\n - run:runnumber\nThe possible converters are "v1", "v2, and "v3" (default).\nThe possible databases are "run3" (default, used for offline development), "run2" (used for accessing run2 offline development menus), "online" (used to extract online menus within Point 5) and "adg" (used to extract the online menus outside Point 5).\nIf no menu version is specified, the latest one is automatically used.\nIf "run:" is used instead, the HLT menu used for the given run number is looked up and used.\nNote other converters and databases exist as options but they are only for expert/special use.' )
0150
0151 # options
0152 parser.add_argument('--dbproxy',
0153 dest = 'proxy',
0154 action = 'store_true',
0155 default = defaults.proxy,
0156 help = 'Use a socks proxy to connect outside CERN network (default: False)' )
0157 parser.add_argument('--dbproxyport',
0158 dest = 'proxy_port',
0159 action = 'store',
0160 metavar = 'PROXYPORT',
0161 default = defaults.proxy_port,
0162 help = 'Port of the socks proxy (default: 8080)' )
0163 parser.add_argument('--dbproxyhost',
0164 dest = 'proxy_host',
0165 action = 'store',
0166 metavar = 'PROXYHOST',
0167 default = defaults.proxy_host,
0168 help = 'Host of the socks proxy (default: "localhost")' )
0169
0170 group = parser.add_mutually_exclusive_group()
0171 group.add_argument('-p', '--only-paths',
0172 dest = 'selection',
0173 action = 'store_const',
0174 const = 'paths',
0175 help = 'List only Paths' )
0176 group.add_argument('-e', '--only-endpaths',
0177 dest = 'selection',
0178 action = 'store_const',
0179 const = 'endpaths',
0180 help = 'List only EndPaths' )
0181 group.add_argument('-f', '--only-finalpaths',
0182 dest = 'selection',
0183 action = 'store_const',
0184 const = 'finalpaths',
0185 help = 'List only FinalPaths' )
0186 group.add_argument('-a', '--all',
0187 dest = 'selection',
0188 action = 'store_const',
0189 const = 'all',
0190 default = 'all',
0191 help = 'List Paths, EndPaths and FinalPaths (default)' )
0192
0193 parser.add_argument('--no-dependent-paths',
0194 dest = 'no_dependent_paths',
0195 action = 'store_true',
0196 default = False,
0197 help = 'Do not list paths which depend on the result of other paths (default: false)' )
0198
0199 parser.add_argument('--exclude',
0200 dest = 'excludeRegExprs',
0201 nargs = '+',
0202 default = [],
0203 help = 'List of regular expressions to select names of paths to be ignored with re.search (default: empty)' )
0204
0205 # redefine "--help" to be the last option, and use a customized message
0206 parser.add_argument('-h', '--help',
0207 action = 'help',
0208 help = 'Show this help message and exit' )
0209
0210 # parse command line arguments and options
0211 config = parser.parse_args()
0212
0213 paths = getPathList(config)
0214 for path in paths:
0215 print(path)