Back to home page

Project CMSSW displayed by LXR

 
 

    


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   # cmd-line args to select HLT configuration
0013   if config.menu.run:
0014     configline = f'--runNumber {config.menu.run}'
0015   else:
0016     configline = f'--{config.menu.database} --{config.menu.version} --configName {config.menu.name}'
0017 
0018   # cmd to download HLT configuration
0019   cmdline = f'hltConfigFromDB {configline} --noedsources --noes --noservices'
0020   if config.proxy:
0021     cmdline += f' --dbproxy --dbproxyhost {config.proxy_host} --dbproxyport {config.proxy_port}'
0022 
0023   # load HLT configuration
0024   try:
0025     foo = {'process': None}
0026     exec(pipe.pipe(cmdline).decode(), foo)
0027     process = foo['process']
0028   except:
0029     raise Exception(f'query did not return a valid python file:\n query="{cmdline}"')
0030 
0031   if not isinstance(process, cms.Process):
0032     raise Exception(f'query did not return a valid HLT menu:\n query="{cmdline}"')
0033 
0034   # Paths only
0035   if config.selection == 'paths':
0036     pathDict = process.paths_()
0037 
0038   # EndPaths only
0039   elif config.selection == 'endpaths':
0040     pathDict = process.endpaths_()
0041 
0042   # FinalPaths only
0043   elif config.selection == 'finalpaths':
0044     pathDict = process.finalpaths_()
0045 
0046   # Paths, EndPaths, and FinalPaths ('all')
0047   else:
0048     pathDict = zip(process.paths_(), process.endpaths_(), process.finalpaths_())
0049 
0050   ret = []
0051   for pathName in pathDict:
0052 
0053     # skip if name of the path matches any of
0054     # the regular expressions listed in "--exclude"
0055     skipPath = False
0056     for excludeRegExpr in config.excludeRegExprs:
0057       if bool(re.search(excludeRegExpr, pathName)):
0058         skipPath = True
0059         break
0060     if skipPath:
0061       continue
0062 
0063     if config.no_dependent_paths:
0064       # do not include "dependent paths", i.e. paths that depend on the result of other paths in the same job
0065       # the current criterion to identify a path as "dependent" is that
0066       # (1) the path contains a "TriggerResultsFilter" module and
0067       # (2) the latter module uses the TriggerResults of the current process, and has a non-empty list of "triggerConditions"
0068       path = pathDict[pathName]
0069       pathIsDependent = False
0070       isPath = isinstance(path, cms.Path)
0071 
0072       for moduleName in path.moduleNames():
0073         module = getattr(process, moduleName)
0074         if module.type_() != 'TriggerResultsFilter' or (hasattr(module, 'triggerConditions') and len(module.triggerConditions) == 0):
0075           continue
0076 
0077         usesPathStatus = hasattr(module, 'usePathStatus') and module.usePathStatus
0078         usesTrigResOfCurrentProcess = hasattr(module, 'hltResults') and module.hltResults.getProcessName() in [process.name_(), '@currentProcess']+['']*(not isPath)
0079 
0080         if isPath:
0081           if usesPathStatus:
0082             pathIsDependent = True
0083           elif usesTrigResOfCurrentProcess:
0084             # The Path contains a TriggerResultsFilter with usePathStatus=False and forcing access to the TriggerResults of the current Process.
0085             #  - This is not supported, and should result in a runtime error when using cmsRun.
0086             #  - Here, a warning is returned to stderr, and the Path is omitted from the output list.
0087             warning_msg = 'WARNING -- the cms.Path named "'+pathName+'" will be ignored.'
0088             warning_msg += '\n'+' '*12+'- It contains a "TriggerResultsFilter" attempting to access the "TriggerResults" of the current Process (module: "'+moduleName+'").'
0089             warning_msg += '\n'+' '*12+'- This is not supported, and should result in a runtime error when using cmsRun. Please check again the HLT configuration.'
0090             print(warning_msg, file=sys.stderr)
0091             pathIsDependent = True
0092         else:
0093           pathIsDependent = usesPathStatus or usesTrigResOfCurrentProcess
0094 
0095         if pathIsDependent:
0096           break
0097 
0098       if pathIsDependent:
0099         continue
0100 
0101     ret.append(pathName)
0102 
0103   return ret
0104 
0105 # define an argparse parser to parse our options
0106 textwidth = int( 80 )
0107 try:
0108   textwidth = int( os.popen("stty size", "r").read().split()[1] )
0109 except:
0110   pass
0111 formatter = FixedWidthFormatter( HelpFormatterRespectNewlines, width = textwidth )
0112 
0113 # read defaults
0114 defaults = options.HLTProcessOptions()
0115 
0116 parser = argparse.ArgumentParser(
0117   description       = 'List all the Paths, EndPaths and FinalPaths of an HLT configuration in the ConfDB database.',
0118   argument_default  = argparse.SUPPRESS,
0119   formatter_class   = formatter,
0120   add_help          = False )
0121 
0122 # required argument
0123 parser.add_argument('menu',
0124                     action  = 'store',
0125                     type    = options.ConnectionHLTMenu,
0126                     metavar = 'MENU',
0127                     help    = 'HLT menu to dump from the database. 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.' )
0128 
0129 # options
0130 parser.add_argument('--dbproxy',
0131                     dest    = 'proxy',
0132                     action  = 'store_true',
0133                     default = defaults.proxy,
0134                     help    = 'Use a socks proxy to connect outside CERN network (default: False)' )
0135 parser.add_argument('--dbproxyport',
0136                     dest    = 'proxy_port',
0137                     action  = 'store',
0138                     metavar = 'PROXYPORT',
0139                     default = defaults.proxy_port,
0140                     help    = 'Port of the socks proxy (default: 8080)' )
0141 parser.add_argument('--dbproxyhost',
0142                     dest    = 'proxy_host',
0143                     action  = 'store',
0144                     metavar = 'PROXYHOST',
0145                     default = defaults.proxy_host,
0146                     help    = 'Host of the socks proxy (default: "localhost")' )
0147 
0148 group = parser.add_mutually_exclusive_group()
0149 group.add_argument('-p', '--only-paths',
0150                     dest    = 'selection',
0151                     action  = 'store_const',
0152                     const   = 'paths',
0153                     help    = 'List only Paths' )
0154 group.add_argument('-e', '--only-endpaths',
0155                     dest    = 'selection',
0156                     action  = 'store_const',
0157                     const   = 'endpaths',
0158                     help    = 'List only EndPaths' )
0159 group.add_argument('-f', '--only-finalpaths',
0160                     dest    = 'selection',
0161                     action  = 'store_const',
0162                     const   = 'finalpaths',
0163                     help    = 'List only FinalPaths' )
0164 group.add_argument('-a', '--all', 
0165                     dest    = 'selection',
0166                     action  = 'store_const',
0167                     const   = 'all',
0168                     default = 'all',
0169                     help    = 'List Paths, EndPaths and FinalPaths (default)' )
0170 
0171 parser.add_argument('--no-dependent-paths',
0172                     dest    = 'no_dependent_paths',
0173                     action  = 'store_true',
0174                     default = False,
0175                     help    = 'Do not list paths which depend on the result of other paths (default: false)' )
0176 
0177 parser.add_argument('--exclude',
0178                     dest    = 'excludeRegExprs',
0179                     nargs   = '+',
0180                     default = [],
0181                     help    = 'List of regular expressions to select names of paths to be ignored with re.search (default: empty)' )
0182 
0183 # redefine "--help" to be the last option, and use a customized message 
0184 parser.add_argument('-h', '--help', 
0185                     action  = 'help', 
0186                     help    = 'Show this help message and exit' )
0187 
0188 # parse command line arguments and options
0189 config = parser.parse_args()
0190 paths = getPathList(config)
0191 for path in paths:
0192   print(path)