Warning, /HLTrigger/Configuration/scripts/utils/hltListPathsWithoutOwners is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env python3
0002 import os
0003 import json
0004 import argparse
0005 import subprocess
0006
0007 import FWCore.ParameterSet.Config as cms
0008
0009 import HLTrigger.Configuration.Tools.options as options
0010 from HLTrigger.Configuration.extend_argparse import *
0011
0012 def getHLTProcess(args):
0013 if args.menu.run:
0014 configline = f'--runNumber {args.menu.run}'
0015 else:
0016 configline = f'--{args.menu.database} --{args.menu.version} --configName {args.menu.name}'
0017
0018 # cmd to download HLT configuration
0019 cmdline = f'hltConfigFromDB {configline} --noedsources --noes --nooutput'
0020 if args.proxy:
0021 cmdline += f' --dbproxy --dbproxyhost {args.proxy_host} --dbproxyport {args.proxy_port}'
0022
0023 # download HLT configuration
0024 proc = subprocess.Popen(cmdline, shell = True, stdin = None, stdout = subprocess.PIPE, stderr = None)
0025 (out, err) = proc.communicate()
0026
0027 # load HLT configuration
0028 try:
0029 foo = {'process': None}
0030 exec(out, foo)
0031 process = foo['process']
0032 except:
0033 raise Exception(f'query did not return a valid python file:\n query="{cmdline}"')
0034
0035 if not isinstance(process, cms.Process):
0036 raise Exception(f'query did not return a valid HLT menu:\n query="{cmdline}"')
0037
0038 return process
0039
0040 def main():
0041 # define an argparse parser to parse our options
0042 textwidth = int( 80 )
0043 try:
0044 textwidth = int( os.popen("stty size", "r").read().split()[1] )
0045 except:
0046 pass
0047 formatter = FixedWidthFormatter( HelpFormatterRespectNewlines, width = textwidth )
0048
0049 # read defaults
0050 defaults = options.HLTProcessOptions()
0051
0052 parser = argparse.ArgumentParser(
0053 description = 'Create outputs to announce the release of a new HLT menu.',
0054 argument_default = argparse.SUPPRESS,
0055 formatter_class = formatter,
0056 add_help = False
0057 )
0058
0059 # required argument
0060 parser.add_argument('menu',
0061 action = 'store',
0062 type = options.ConnectionHLTMenu,
0063 metavar = 'MENU',
0064 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.' )
0065
0066 # options
0067 parser.add_argument('--dbproxy',
0068 dest = 'proxy',
0069 action = 'store_true',
0070 default = defaults.proxy,
0071 help = 'Use a socks proxy to connect outside CERN network (default: False)' )
0072 parser.add_argument('--dbproxyport',
0073 dest = 'proxy_port',
0074 action = 'store',
0075 metavar = 'PROXYPORT',
0076 default = defaults.proxy_port,
0077 help = 'Port of the socks proxy (default: 8080)' )
0078 parser.add_argument('--dbproxyhost',
0079 dest = 'proxy_host',
0080 action = 'store',
0081 metavar = 'PROXYHOST',
0082 default = defaults.proxy_host,
0083 help = 'Host of the socks proxy (default: "localhost")' )
0084
0085 parser.add_argument('--metadata-json',
0086 dest = 'metadata_json',
0087 action = 'store',
0088 default = 'hltPathOwners.json',
0089 help = 'Path to .json file with metadata on HLT Paths (online?, group-owners)' )
0090
0091 parser.add_argument('-o', '--output-json',
0092 dest = 'output_json',
0093 action = 'store',
0094 default = None,
0095 help = 'Path to name of new .json file (without triggers missing in MENU)' )
0096
0097 # redefine "--help" to be the last option, and use a customized message
0098 parser.add_argument('-h', '--help',
0099 action = 'help',
0100 help = 'Show this help message and exit' )
0101
0102 # parse command line arguments and options
0103 args = parser.parse_args()
0104
0105 if not os.path.isfile(args.metadata_json):
0106 raise RuntimeError(f'invalid path to metadata JSON file [--metadata-json]: {args.metadata_json}')
0107
0108 metadataDict = json.load(open(args.metadata_json))
0109
0110 process = getHLTProcess(args)
0111
0112 pathNames = sorted([pathName if '_v' not in pathName else pathName[:pathName.rfind('_v')]+'_v' for pathName, path in process.paths_().items() if not pathName.startswith('Dataset_')])
0113
0114 for pathName in pathNames:
0115 if pathName not in metadataDict:
0116 print(pathName)
0117
0118 if args.output_json != None:
0119 metadataDict_out = {}
0120 for pathName in metadataDict:
0121 if pathName in pathNames:
0122 metadataDict_out[pathName] = metadataDict[pathName]
0123 json.dump(metadataDict_out, open(args.output_json, 'w'), sort_keys = True, indent = 2)
0124
0125 ###
0126 ### main
0127 ###
0128 if __name__ == '__main__':
0129 main()