Skip to content

Commit

Permalink
enable use of dbproxy in more HLT-dev tools
Browse files Browse the repository at this point in the history
  • Loading branch information
missirol committed Nov 16, 2022
1 parent ef263ea commit 46a9f81
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 444 deletions.
24 changes: 17 additions & 7 deletions HLTrigger/Configuration/scripts/hltGetConfiguration
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3

from __future__ import print_function
import sys, os
import sys
import os
import argparse
from HLTrigger.Configuration.extend_argparse import *

import HLTrigger.Configuration.Tools.confdb as confdb
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
Expand Down Expand Up @@ -243,8 +242,19 @@ parser.add_argument('--help',
# parse command line arguments and options
config = parser.parse_args(namespace = options.HLTProcessOptions())

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

cmdLine = ' '.join(cmdArgs)
print('# ' + cmdLine)
print()
Expand Down
70 changes: 42 additions & 28 deletions HLTrigger/Configuration/tables/subtables.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#! /bin/bash
#!/bin/bash
#
# utility functions used to generate HLT tables from master table in ConfDB
#

# db-proxy configuration
DBPROXY=""
DBPROXYHOST="localhost"
DBPROXYPORT="8080"
while [[ $# -gt 0 ]]; do
case "$1" in
--dbproxy) DBPROXY="--dbproxy"; shift;;
--dbproxyhost) DBPROXYHOST="$2"; shift; shift;;
--dbproxyport) DBPROXYPORT="$2"; shift; shift;;
*) shift;;
esac
done

# load common HLT functions
if [ -f "$CMSSW_BASE/src/HLTrigger/Configuration/common/utils.sh" ]; then
source "$CMSSW_BASE/src/HLTrigger/Configuration/common/utils.sh"
Expand Down Expand Up @@ -31,12 +44,14 @@ function cleanup() {
}

function getPathList() {
local DATA=$(hltConfigFromDB --$Vx --$DB --cff --configName $MASTER --noedsources --noes --noservices --nosequences --nomodules)
if echo "$DATA" | grep -q 'Exhausted Resultset\|CONFIG_NOT_FOUND'; then
[ "x${DBPROXY}" = "x" ] || local DBPROXYOPTS="${DBPROXY} --dbproxyhost ${DBPROXYHOST} --dbproxyport ${DBPROXYPORT}"
local DATA=$(hltConfigFromDB --${Vx} --${DB} --cff --configName ${MASTER} \
--noedsources --noes --noservices --nosequences --nomodules ${DBPROXYOPTS})
if echo "${DATA}" | grep -q 'Exhausted Resultset\|CONFIG_NOT_FOUND'; then
echo "Error: $MASTER is not a valid HLT menu"
exit 1
fi
echo "$DATA" | sed -ne's/ *= *cms.\(Final\|End\)\?Path.*//p'
echo "${DATA}" | sed -ne's/ *= *cms.\(Final\|End\)\?Path.*//p'
}

function checkJars() {
Expand Down Expand Up @@ -73,7 +88,7 @@ function makeCreateConfig() {
if [ -f $workDir/$JAR ]; then
continue
fi
# download to a temporay file and use an atomic move (in case an other istance is downloading the same file
# download to a temporary file and use an atomic move (in case another instance is downloading the same file)
local TMPJAR=$(mktemp -p "$workDir" .${JAR}.XXXXXXXXXX)
curl -s -L "$baseUrl/$JAR" -o "$TMPJAR"
mv -n "$TMPJAR" "$workDir/$JAR"
Expand All @@ -89,61 +104,60 @@ function makeCreateConfig() {

function loadConfiguration() {
case "$1" in
# v1 offline aka "hltdev"
"v1/offline" | "v1/hltdev")
# v1 offline aka "hltdev"
DBHOST="cmsr1-v.cern.ch"
DBHOST="cmsr1-s.cern.ch,cmsr2-s.cern.ch,cmsr3-s.cern.ch"
[ "x${DBPROXY}" = "x" ] || DBHOST="10.116.96.89,10.116.96.139,10.116.96.105"
DBNAME="cms_cond.cern.ch"
DBUSER="cms_hltdev_writer"
PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
;;
# v2 offline
"v2/offline")
# v2 offline
DBHOST="cmsr1-v.cern.ch"
DBHOST="cmsr1-s.cern.ch,cmsr2-s.cern.ch,cmsr3-s.cern.ch"
[ "x${DBPROXY}" = "x" ] || DBHOST="10.116.96.89,10.116.96.139,10.116.96.105"
DBNAME="cms_cond.cern.ch"
DBUSER="cms_hlt_gdr_w"
PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
;;
"v3/run3")
# v3 run3
DBHOST="cmsr1-s.cern.ch"
# converter=v3*, db=run3
"v3/run3" | "v3-beta/run3" | "v3-test/run3")
DBHOST="cmsr1-s.cern.ch,cmsr2-s.cern.ch,cmsr3-s.cern.ch"
[ "x${DBPROXY}" = "x" ] || DBHOST="10.116.96.89,10.116.96.139,10.116.96.105"
DBNAME="cms_hlt.cern.ch"
DBUSER="cms_hlt_v3_w"
PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
;;
"v3-test/dev")
# v3-test dev
DBHOST="cmsr1-s.cern.ch"
DBNAME="cms_hlt.cern.ch"
DBUSER="cms_hlt_gdrdev_w"
PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
;;
"v3/dev")
# v3 dev
DBHOST="cmsr1-s.cern.ch"
# converter=v3*, db=dev
"v3/dev" | "v3-beta/dev" | "v3-test/dev")
DBHOST="cmsr1-s.cern.ch,cmsr2-s.cern.ch,cmsr3-s.cern.ch"
[ "x${DBPROXY}" = "x" ] || DBHOST="10.116.96.89,10.116.96.139,10.116.96.105"
DBNAME="cms_hlt.cern.ch"
DBUSER="cms_hlt_gdrdev_w"
PWHASH="0196d34dd35b04c0f3597dc89fbbe6e2"
;;
*)
# see https://github.com/fwyzard/hlt-confdb/blob/confdbv2/test/runCreateConfig
echo "Error, unnown database \"$1\", exiting."
echo "Error, unknown database \"$1\", exiting."
exit 1
;;
esac
}

function runCreateConfig() {
[ "x${DBPROXY}" = "x" ] || local DBPROXYOPTS="-DsocksProxyHost=${DBPROXYHOST} -DsocksProxyPort=${DBPROXYPORT}"
loadConfiguration "$1"
java \
-Djava.security.egd=file:///dev/urandom \
-Doracle.jdbc.timezoneAsRegion=false \
${DBPROXYOPTS} \
-Xss32M \
-Xmx1024m \
-classpath "$CLASSPATH" \
-classpath "${CLASSPATH}" \
confdb.db.ConfDBCreateConfig \
--dbHost $DBHOST \
--dbName $DBNAME \
--dbUser $DBUSER \
--dbHost "${DBHOST}" \
--dbName "${DBNAME}" \
--dbUser "${DBUSER}" \
--dbPwrd $2 \
--master $3 \
--paths $4 \
Expand Down Expand Up @@ -219,7 +233,7 @@ function createSubtables() {
# ask the user for the database password
readPassword

# make sure the needed sripts are available
# make sure the needed scripts are available
makeCreateConfig

# extract each subtable
Expand Down
157 changes: 96 additions & 61 deletions HLTrigger/Configuration/test/getDatasets.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,107 @@
#! /usr/bin/env python3

import sys
#!/usr/bin/env python3
"""getDatasets.py: create Datasets-cff file of an HLT configuration from the ConfDB database
"""
import argparse
import subprocess
import types
import os
import re
import FWCore.ParameterSet.Config as cms

def extractDatasets(version, database, config):
# dump the streams and Datasets from the HLT configuration
proc = subprocess.Popen(
"hltConfigFromDB --%s --%s --configName %s --nopsets --noedsources --noes --noservices --nooutput --nopaths" % (version, database, config),
shell = True,
stdin = None,
stdout = subprocess.PIPE,
stderr = None,
)
(out, err) = proc.communicate()

# load the streams and Datasets
hlt = types.ModuleType('hlt')
exec(out, globals(), hlt.__dict__)

return hlt.process
import FWCore.ParameterSet.Config as cms
import HLTrigger.Configuration.Tools.pipe as pipe
import HLTrigger.Configuration.Tools.options as options

def getHLTProcess(config):
'''return cms.Process containing Streams and Datasets of the HLT configuration
'''
# cmd-line args to select HLT configuration
if config.menu.run:
configline = f'--runNumber {config.menu.run}'
else:
configline = f'--{config.menu.database} --{config.menu.version} --configName {config.menu.name}'

# cmd to download HLT configuration
cmdline = f'hltConfigFromDB {configline} --noedsources --noes --noservices --nopsets --nooutput --nopaths'
if config.proxy:
cmdline += f' --dbproxy --dbproxyhost {config.proxy_host} --dbproxyport {config.proxy_port}'

# load HLT configuration
try:
foo = {'process': None}
exec(pipe.pipe(cmdline).decode(), foo)
process = foo['process']
except:
raise Exception(f'query did not return a valid python file:\n query="{cmdline}"')

if not isinstance(process, cms.Process):
raise Exception(f'query did not return a valid HLT menu:\n query="{cmdline}"')

return process

###
### main
###
if __name__ == '__main__':

# defaults of cmd-line arguments
defaults = options.HLTProcessOptions()

parser = argparse.ArgumentParser(
prog = './'+os.path.basename(__file__),
formatter_class = argparse.RawDescriptionHelpFormatter,
description = __doc__)

# 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('--dbproxy',
dest = 'proxy',
action = 'store_true',
default = defaults.proxy,
help = 'Use a socks proxy 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")' )

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

process = getHLTProcess(config)

print('''# %s
import FWCore.ParameterSet.Config as cms
''' % config.menu.name)

def dumpDataset(process, stream, dataset):
if dataset in process.datasets.__dict__:
name = 'stream%s_dataset%s_selector' % (stream, dataset)
dump = '''from HLTrigger.HLTfilters.triggerResultsFilter_cfi import triggerResultsFilter as %s
for stream in sorted(process.streams.__dict__):
if re.match(r'^(Physics|Parking)', stream):
print('''
# stream %s
''' % stream)
ds = sorted(process.streams.__dict__[stream])
for dataset in ds:
if dataset in process.datasets.__dict__:
name = 'stream%s_dataset%s_selector' % (stream, dataset)
dump = '''from HLTrigger.HLTfilters.triggerResultsFilter_cfi import triggerResultsFilter as %s
%s.hltResults = cms.InputTag('TriggerResults', '', 'HLT')
%s.l1tResults = cms.InputTag('')
%s.throw = cms.bool(False)
%s.triggerConditions = %s
''' % (name, name, name, name, name, process.datasets.__dict__[dataset])
else:
dump = '''# dataset %s not found
else:
dump = '''# dataset %s not found
''' % (dataset, )
return dump


# split a "[version/]db:name" configuration into a (version, db, name) tuple
def splitConfigName(configName):
from HLTrigger.Configuration.Tools.options import ConnectionHLTMenu
menu = ConnectionHLTMenu(configName)
return (menu.version, menu.database, menu.name)


# get the configuration to parse and the file where to output the stream definitions from the command line
config = sys.argv[1]

# dump the expanded event content configurations to a python configuration fragment
config = splitConfigName(config)
process = extractDatasets(* config)

sys.stdout.write('''# %s
import FWCore.ParameterSet.Config as cms
''' % config[2] )

for stream in sorted(process.streams.__dict__):
if re.match(r'^Physics|Parking', stream):
sys.stdout.write('''
# stream %s
''' % stream)
ds = sorted(process.streams.__dict__[stream])
for dataset in ds:
sys.stdout.write(dumpDataset(process, stream, dataset))
print(dump)
Loading

0 comments on commit 46a9f81

Please sign in to comment.