Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update some HLT tests for python3 #34563

Merged
merged 6 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions FWCore/ParameterSet/scripts/edmConfigDump
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from __future__ import print_function
import sys
import os
import imp
from importlib.machinery import SourceFileLoader
import types
import argparse

# make the behaviour of 'cmsRun file.py' and 'edmConfigDump file.py' more consistent
Expand All @@ -19,11 +20,13 @@ parser.add_argument("--pruneVerbose", action="store_true",

options = parser.parse_args()
handle = open(options.filename, 'r')
cfo = imp.load_source("pycfg", options.filename, handle)
cmsProcess = cfo.process
handle.close()
loader=SourceFileLoader("pycfg", options.filename)
mod=types.ModuleType(loader.name)
loader.exec_module(mod)
cmsProcess= mod.process

if options.prune:
cmsProcess.prune(options.pruneVerbose)

print(cmsProcess.dumpPython())

1 change: 0 additions & 1 deletion HLTrigger/Configuration/python/Tools/confdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
import re
import os
import urllib, urllib2
from .pipe import pipe as _pipe
from .options import globalTag
from itertools import islice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys, os
import os.path
import tempfile
import urllib
import urllib.request
import shutil
import subprocess
import atexit
Expand Down Expand Up @@ -97,7 +97,7 @@ def __init__(self, version = 'v2', database = 'offline', url = None, verbose = F
# download to a temporay name and use an atomic rename (in case an other istance is downloading the same file
handle, temp = tempfile.mkstemp(dir = self.workDir, prefix = jar + '.')
os.close(handle)
urllib.urlretrieve(self.baseUrl + '/' + jar, temp)
urllib.request.urlretrieve(self.baseUrl + '/' + jar, temp)
if not os.path.exists(self.workDir + '/' + jar):
os.rename(temp, self.workDir + '/' + jar)
else:
Expand Down
4 changes: 2 additions & 2 deletions HLTrigger/Configuration/python/Utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import imp as _imp
import types

import HLTrigger.Configuration.Tools.options as _options
import HLTrigger.Configuration.Tools.confdb as _confdb
Expand Down Expand Up @@ -26,7 +26,7 @@ def loadHltConfiguration(process, menu, **args):
args['fragment'] = True
options = _build_options(**args)

hlt = _imp.new_module('hlt')
hlt = types.ModuleType('hlt')
exec(_confdb.HLTProcess(options).dump(), globals(), hlt.__dict__)
process.extend( hlt )

Expand Down
5 changes: 3 additions & 2 deletions HLTrigger/Configuration/scripts/edmPluginCoverage
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Author: Andrea 'fwyzard' Bocci <andrea.bocci@cern.ch>, Università di Pisa

from __future__ import print_function
import os, sys
import re

Expand Down Expand Up @@ -210,7 +211,7 @@ index.sort()

for lib in index:
if lib in packagemap:
print "%-80s\t%s" % (libs[lib], packagemap[lib][0])
print("%-80s\t%s" % (libs[lib], packagemap[lib][0]))
else:
print "%-80s\t*** not found ***" % libs[lib]
print("%-80s\t*** not found ***" % libs[lib])

23 changes: 12 additions & 11 deletions HLTrigger/Configuration/scripts/hltCheckPrescaleModules
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! /usr/bin/env python
#! /usr/bin/env python3

from __future__ import print_function
import sys
import imp
import types
import re

# global options
Expand All @@ -12,16 +13,16 @@ if '-w' in sys.argv:
enableWarnings = True

if len(sys.argv) != 2:
print "usage: %s [-w] menu.py" % sys.argv[0]
print("usage: %s [-w] menu.py" % sys.argv[0])
sys.exit(1)

# whitelist paths exempt from validation
whitelist = ('HLTriggerFirstPath', 'HLTriggerFinalPath')

# load the menu and get the "process" object
menu = imp.new_module('menu')
menu = types.ModuleType('menu')
name = sys.argv[1]
execfile(name, globals(), menu.__dict__)
exec(open(name).read(), globals(), menu.__dict__)
process = menu.process

# get all paths
Expand All @@ -46,23 +47,23 @@ for path in paths:
if module in process.filters_(): # found a filter
if process.filters_()[module].type_() == 'HLTPrescaler': # it's a prescaler
if found:
print 'ERROR: path %s has more than one HLTPrescaler module' % path
print('ERROR: path %s has more than one HLTPrescaler module' % path)
found = True
label = process.filters_()[module].label()
if enableWarnings and label != goodLabel:
print 'WARNING: path %s has an HLTPrescaler module labaled "%s", while the suggested label is "%s"' % (path, label, goodLabel)
print('WARNING: path %s has an HLTPrescaler module labaled "%s", while the suggested label is "%s"' % (path, label, goodLabel))
if label in prescalerNames:
duplicateNames.add(label)
else:
prescalerNames.add(label)
if not found:
print 'ERROR: path %s dos not have an HLTPrescaler module' % path
print('ERROR: path %s dos not have an HLTPrescaler module' % path)

# print the duplicate prescales, and the affected paths
for label in duplicateNames:
print 'ERROR: prescale "%s" is shared by the paths' % label
print('ERROR: prescale "%s" is shared by the paths' % label)
for path in paths:
if label in paths[path].moduleNames():
print '\t%s' % path
print
print('\t%s' % path)
print()

2 changes: 1 addition & 1 deletion HLTrigger/Configuration/scripts/hltConfigFromDB
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env python
#! /usr/bin/env python3

from HLTrigger.Configuration.Tools.confdbOfflineConverter import main

Expand Down
25 changes: 13 additions & 12 deletions HLTrigger/Configuration/scripts/hltDumpStream
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env python
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from __future__ import print_function
import sys, imp, re
import operator
import FWCore.ParameterSet.Config as cms
Expand All @@ -21,7 +22,7 @@ except:
config = sys.stdin
else:
config = open(configname)
exec config in globals(), hlt.__dict__
exec(config, globals(), hlt.__dict__)
config.close()

if 'process' in hlt.__dict__:
Expand Down Expand Up @@ -263,15 +264,15 @@ def getEndPath(output):

def dumpHeader():
if mode == 'csv':
print 'stream, dataset, path, %s, L1 trigger' % getPrescaleNames()
print('stream, dataset, path, %s, L1 trigger' % getPrescaleNames())


def dumpStream(stream):
assigned = set()
allpaths = set()

if mode == 'text':
print 'stream', stream
print('stream', stream)
out = 'hltOutput%s' % stream
end = getEndPath(out)
if end:
Expand All @@ -281,32 +282,32 @@ def dumpStream(stream):
pds = sorted( process.streams.__dict__[stream] )
for pd in pds:
if mode == 'text':
print ' dataset', pd
print(' dataset', pd)
if pd in process.datasets.__dict__:
paths = sorted( path for path in process.datasets.__dict__[pd] )
assigned.update( paths )
for path in paths:
print dumpPath(stream, pd, path, out, end)
print(dumpPath(stream, pd, path, out, end))
else:
if mode == 'text':
print ' *** not found ***'
print(' *** not found ***')

unassigned = allpaths - assigned
if unassigned:
if mode == 'text':
print ' *** unassigned paths ***'
print(' *** unassigned paths ***')
for path in sorted(unassigned):
print dumpPath(stream, '(unassigned)', path, out, end)
print(dumpPath(stream, '(unassigned)', path, out, end))

if not end:
print ' *** corresponding EndPath not found ***'
print(' *** corresponding EndPath not found ***')
else:
missing = assigned - allpaths
if missing:
if mode == 'text':
print ' *** paths missing from the EndPath\'s output module ***'
print(' *** paths missing from the EndPath\'s output module ***')
for path in sorted(missing):
print dumpPath(stream, '(missing)', path, out, end)
print(dumpPath(stream, '(missing)', path, out, end))


# read the list of streams
Expand Down
15 changes: 8 additions & 7 deletions HLTrigger/Configuration/scripts/hltFindDuplicates
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python
#! /usr/bin/env python3

from __future__ import print_function
import sys, imp, re, itertools
from HLTrigger.Configuration.Tools.frozendict import frozendict
import FWCore.ParameterSet.Config as cms
Expand Down Expand Up @@ -145,11 +146,11 @@ class ModuleList(object):

def dump(self):
for m in self.modules:
print "%s = (%s) {" % (m.label, m.type)
print("%s = (%s) {" % (m.label, m.type))
for k, v in m.params.iteritems():
print "\t%s = %s" % (k, v)
print '}'
print
print("\t%s = %s" % (k, v))
print('}')
print()



Expand All @@ -175,7 +176,7 @@ def findDuplicates(process):
for target, (group, regexp) in groups.iteritems():
dump.write('#%s\n%s\n\n' % ( target, '\n'.join(group)))
dump.close()
print "found %3d duplicates in %3d groups" % (dups, len(groups))
print("found %3d duplicates in %3d groups" % (dups, len(groups)))
oldups = dups
modules.apply_rename(groups)
groups = modules.group()
Expand Down Expand Up @@ -203,7 +204,7 @@ def main():
config = sys.stdin
else:
config = open(configname)
exec config in globals(), hlt.__dict__
exec(config, globals(), hlt.__dict__)
config.close()
findDuplicates(hlt.process)

Expand Down
9 changes: 5 additions & 4 deletions HLTrigger/Configuration/scripts/hltGetConfiguration
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from __future__ import print_function
import sys, os
import argparse
from HLTrigger.Configuration.extend_argparse import *
Expand Down Expand Up @@ -227,6 +228,6 @@ config = parser.parse_args(namespace = options.HLTProcessOptions())
cmdArgs = sys.argv
cmdArgs[0] = os.path.basename(sys.argv[0])
cmdLine = ' '.join(cmdArgs)
print '# ' + cmdLine
print
print confdb.HLTProcess(config).dump()
print('# ' + cmdLine)
print()
print(confdb.HLTProcess(config).dump())
7 changes: 4 additions & 3 deletions HLTrigger/Configuration/scripts/hltListPaths
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from __future__ import print_function
import os
import re
import argparse
Expand All @@ -19,7 +20,7 @@ def _build_query(menu):

def getPathList(menu, selection):
cmdline = 'hltConfigFromDB --cff %s --noedsources --noes --noservices --nosequences --nomodules' % _build_query(menu)
data = pipe.pipe(cmdline)
data = pipe.pipe(cmdline).decode()
if 'Exhausted Resultset' in data or 'CONFIG_NOT_FOUND' in data:
raise ImportError('%s is not a valid HLT menu' % menu.value)

Expand Down Expand Up @@ -83,5 +84,5 @@ parser.add_argument('-h', '--help',
config = parser.parse_args()
paths = getPathList(config.menu, config.selection)
for path in paths:
print path
print(path)

4 changes: 2 additions & 2 deletions HLTrigger/Configuration/test/getDatasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
import subprocess
import imp
import types
import re
import FWCore.ParameterSet.Config as cms

Expand All @@ -18,7 +18,7 @@ def extractDatasets(version, database, config):
(out, err) = proc.communicate()

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

return hlt.process
Expand Down