Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
#!/usr/bin/env python3
import sys
import os
import argparse

from HLTrigger.Configuration.extend_argparse import *
import HLTrigger.Configuration.Tools.confdb as confdb
import HLTrigger.Configuration.Tools.options as options

# define an argparse parser to parse our options
textwidth = int( 80 )
try:
    textwidth = int( os.popen("stty size 2> /dev/null", "r").read().split()[1] )
except:
    pass
formatter = FixedWidthFormatter( HelpFormatterRespectNewlines, width = textwidth )

parser = argparse.ArgumentParser(
  description       = 'Extract an HLT configuration (or fragment thereof) from the ConfDB database.''',
  argument_default  = argparse.SUPPRESS,
  formatter_class   = formatter,
  add_help          = False )

# read defaults
defaults = options.HLTProcessOptions()

# required argument
parser.add_argument('menu',
                    action  = 'store',
                    type    = options.ConnectionHLTMenu,
                    metavar = 'MENU',
		    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.' )

# options
parser.add_argument('--process',
                    dest    = 'name',
                    action  = 'store',
                    default = defaults.name,
                    metavar = 'PROCESS',
                    help    = 'Override the process name (the default is %(default)s)' )
parser.add_argument('--type',
                    dest    = 'type',
                    action  = 'store',
                    metavar = 'TYPE',
                    choices = options.globalTag,
                    default = defaults.type,
                    help    = 'Set global options according to a specific HLT luminosity and type (%(choices)s).' )
parser.add_argument('--globaltag',
                    dest    = 'globaltag',
                    action  = 'store',
                    metavar = 'TAG',
                    default = defaults.globaltag,
                    help    = 'Override the GlobalTag in the HLT menu:\n- when running on data, the default behaviour is to not override the GobalTag in the HLT menu\n- when running on MC, the default behaviour is to use the GlobalTag from "type" and the current PyRelVal configuration.\nTo run on data with a different release than the menu was designed for, try "auto:hltonline"' )
parser.add_argument('--l1',
                    dest    = 'l1',
                    action  = 'store',
                    type    = options.ConnectionL1TMenu,
                    default = defaults.l1,
                    metavar = 'MENU',
                    help    = 'Override the L1 menu, using the given payload from the database. %(metavar)s should have the format "L1GtTriggerMenu_MENU_mc".\nThe default behaviour is to run with the L1 menu from the GlobalTag' )
parser.add_argument('--l1Xml',
                    dest    = 'l1Xml',
                    action  = 'store',
                    type    = options.ConnectionL1TMenuXml,
                    default = defaults.l1Xml,
                    metavar = 'MENU',
                    help    = 'Override the L1 menu, using the given Xml file. %(metavar)s should have the format "L1Menu_Collisions2012_v0_L1T_Scales_20101224_Imp0_0x1027.xml".\nThe default behaviour is to run with the L1 menu from the GlobalTag' )
parser.add_argument('--l1-emulator',
                    dest    = 'emulator',
                    action  = 'store',
                    metavar = 'EMULATOR',
                    nargs   = '?',
                    choices = [ 'Full', 'FullMC', 'Full2015Data', 'uGT' ],
                    default = defaults.emulator,
                    const   = 'Full',
                    help    = 'Run the Full stage-2 L1T emulator.' )

group = parser.add_mutually_exclusive_group()
group.add_argument('--dbproxy',
                    dest    = 'proxy',
                    action  = 'store_true',
                    default = defaults.proxy,
                    help    = 'Use a socks proxy to connect outside CERN network (default: False)' )
group.add_argument('--dbtunnel',
                    dest    = 'tunnel',
                    action  = 'store_true',
                    default = defaults.tunnel,
                    help    = 'Use direct tunnel to connect outside CERN network (default: False)' )

parser.add_argument('--dbproxyport',
                    dest    = 'proxy_port',
                    action  = 'store',
                    metavar = 'PROXYPORT',
                    default = defaults.proxy_port,
                    help    = 'Port of the socks proxy (default: 8080)' )
parser.add_argument('--dbproxyhost',
                    dest    = 'proxy_host',
                    action  = 'store',
                    metavar = 'PROXYHOST',
                    default = defaults.proxy_host,
                    help    = 'Host of the socks proxy (default: "localhost")' )
parser.add_argument('--dbtunnelport',
                    dest    = 'tunnel_port',
                    action  = 'store',
                    metavar = 'TUNNELPORT',
                    default = defaults.tunnel_port,
                    help    = 'Port when using a direct tunnel on localhost (default: 10121)' )

group = parser.add_mutually_exclusive_group()
group.add_argument('--prescale',
                    dest    = 'prescale',
                    action  = 'store',
                    default = defaults.prescale,
                    help    = 'Force using one specific prescale column.\nUse "--prescale none" to run without any HLT prescales' )
group.add_argument('--no-prescale',
                    dest    = 'prescale',
                    action  = 'store_const',
                    const   = 'none',
                    help    = 'Same as "--prescale none"' )
group.add_argument('--unprescale',
                    dest    = 'prescale',
                    action  = 'store_const',
                    const   = 'none',
                    help    = 'Same as "--prescale none"' )

parser.add_argument('--open',
                    dest    = 'open',
                    action  = 'store_true',
                    default = defaults.open,
                    help    = 'Run the HLT in "open" mode, overriding all ED/HLTFilters to always pass (overrides "--prescale" and implies "--prescale none")' )
parser.add_argument('--eras',
                    dest    = 'eras',
                    action  = 'store',
                    type    = str,
                    default = defaults.eras,
                    metavar = 'ERAS',
                    help    = 'Select the defined Eras in HLT configuration (e.g. phase1Pixel)' )
parser.add_argument('--customise',
                    dest    = 'customise',
                    action  = 'store',
                    type    = str,
                    default = defaults.customise,
                    metavar = 'CUSTOMISE',
                    help    = 'Apply the user-defined customization functions using the format HLTrigger/Configuration/customizeHLTTrackingForPhaseI2017.customizeHLTForPFTrackingPhaseI2017' )
parser.add_argument('--error-events',
                    dest    = 'errortype',
                    action  = 'store_true',
                    default = defaults.errortype,
                    help    = 'Modify all HLTTriggerTypeFilter EDFilters to accept only error events (SelectedTriggerType = 0)' )
parser.add_argument('--profiling',
                    dest    = 'profiling',
                    action  = 'store_true',
                    default = defaults.profiling,
                    help    = 'Instrument the menu with the modules for profiling studies (hltGetRaw and hltGetConditions), disable options' )
parser.add_argument('--timing',
                    dest    = 'timing',
                    action  = 'store_true',
                    default = defaults.timing,
                    help    = 'Instrument the menu with the Service, EDModules and EndPath needed for timing studies (implies --profiling)' )
parser.add_argument('--paths',
                    dest    = 'paths',
                    action  = 'store',
                    type    = str,
                    default = defaults.paths,
                    metavar = 'PATHS',
                    help    = 'Include only the given comma-separated-list of paths in the dump (wildcards are accepted)\nNote that in a full dump the "smart prescale" modules will likely fail, unless removed with "--output none" or "--output minimal"' )
parser.add_argument('--input',
                    dest    = 'input',
                    action  = 'store',
                    type    = str,
                    default = defaults.input,
                    metavar = 'SOURCE',
                    help    = 'If set, specify the SOURCE input file(s) or dataset, otherwise a default is chosen up depending on the other options.\nSOURCE can be a single file nane, a comma-separated list of file names, or have the format "dataset:DATASET" to query a DATASET definition from DAS' )
parser.add_argument('--parent',
                    dest    = 'parent',
                    action  = 'store',
                    type    = str,
                    default = defaults.parent,
                    metavar = 'PARENT',
                    help    = 'If set, specify the PARENT input file(s) or dataset, using the same syntax as SOURCE, above' )
parser.add_argument('--max-events',
                    dest    = 'events',
                    action  = 'store',
                    type    = int,
                    default = defaults.events,
                    metavar = 'EVENTS',
                    help    = 'Run on EVENTS events (-1 for unlimited)' )
parser.add_argument('--setup',
                    dest    = 'setup',
                    action  = 'store',
                    type    = str,
                    default = defaults.setup,
                    metavar = 'STORE',
                    help    = 'If set, download setup_cff from the specified configuration and load it. Note, it is forced to be the same database and converter as specified by primary menu configuration, in fact it is an error to specify a converter/database here and the command will fail' )

group = parser.add_mutually_exclusive_group()
group.add_argument('--output',
                    dest    = 'output',
                    action  = 'store',
                    metavar = 'OUTPUT',
                    choices = [ 'all', 'minimal', 'none', 'full' ],
                    default = defaults.output,
                    help    = 'Use:\n- "all" to output all output modules (default)\n- "minimal" to only output the TriggerResults\n- "none" to remove all output modules\n- "full" to output a single root file with "keep *" event content.' )
group.add_argument('--no-output',
                    dest    = 'output',
                    action  = 'store_const',
                    const   = 'none',
                    help    = 'Same as "--output none"' )

group = parser.add_mutually_exclusive_group()
group.add_argument('--data',
                    dest    = 'data',
                    action  = 'store_true',
                    default = defaults.data,
                    help    = 'Prepare a menu for running on data (raw events in "source") (default)' )
group.add_argument('--mc',
                    dest    = 'data',
                    action  = 'store_false',
                    default = not defaults.data,
                    help    = 'Prepare a menu for running on MC (raw events in "rawDataCollector")' )

parser.add_argument('--hilton',
                    dest    = 'hilton',
                    action  = 'store_true',
                    default = defaults.hilton,
                    help    = 'Keep the hilton-specific modules' )

group = parser.add_mutually_exclusive_group()
group.add_argument('--full',
                    dest    = 'fragment',
                    action  = 'store_false',
                    default = not defaults.fragment,
                    help    = 'Generate a full configuration file, with minimal modifications (default)' )
group.add_argument('--fragment', '--cff',
                    dest    = 'fragment',
                    action  = 'store_true',
                    default = defaults.fragment,
                    help    = 'Generate a stripped down configuration file fragment, for inclusion by e.g. cmsDriver.py (with no input or output sections)' )

group = parser.add_mutually_exclusive_group()
group.add_argument('--online',
                    dest    = 'unused',
                    action  = 'store_true',
                    help    = 'Ignored' )
group.add_argument('--offline',
                    dest    = 'unused',
                    action  = 'store_true',
                    help    = 'Ignored' )

# redefine "--help" to be the last option, and use a customized message
parser.add_argument('--help',
                    action  = 'help',
                    help    = 'Show this help message and exit' )

# parse command line arguments and options
config = parser.parse_args(namespace = options.HLTProcessOptions())

# do not include db-proxy/tunnel options in 1st-line comment
cmdArgs, skipNext = [], False
for cmdArg in sys.argv:
  if skipNext:
    skipNext = False
    continue
  if cmdArg.startswith('--dbproxy') or cmdArg.startswith('--dbtunnel'):
    if cmdArg.startswith('--dbproxyh') or cmdArg.startswith('--dbproxyp') or cmdArg.startswith('--dbtunnelp'):
      skipNext = '=' not in cmdArg
    continue
  cmdArgs += [cmdArg]
cmdArgs[0] = os.path.basename(cmdArgs[0])

cmdLine = ' '.join(cmdArgs)
print('# ' + cmdLine)
print()
print(confdb.HLTProcess(config).dump())