Skip to content

Commit 1438ec3

Browse files
committed
fix function "getHltConfiguration"
Update of the functions "getHltConfiguration" and "loadHltConfiguration" defined in HLTrigger/Configuration/python/Utilities.py - remove unnecessary dependencies on external packages like "types" - fix "getHltConfiguration" (was broken since the changes in cms-sw#34563) - return cms.Process object in "loadHltConfiguration" (backward-compatible change) - add checks in both functions to catch errors in ConfDB queries
1 parent 699cc5d commit 1438ec3

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

HLTrigger/Configuration/python/Utilities.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
import types
1+
import FWCore.ParameterSet.Config as cms
22

33
import HLTrigger.Configuration.Tools.options as _options
44
import HLTrigger.Configuration.Tools.confdb as _confdb
55

66
def _build_options(**args):
7-
options = _options.HLTProcessOptions()
8-
for key, val in args.items():
9-
setattr(options, key, val)
10-
return options
7+
options = _options.HLTProcessOptions()
8+
for key, val in args.items():
9+
setattr(options, key, val)
10+
return options
1111

1212

1313
def getHltConfiguration(menu, **args):
14-
args['menu'] = menu
15-
args['fragment'] = False
16-
options = _build_options(**args)
14+
args['menu'] = menu
15+
args['fragment'] = False
16+
options = _build_options(**args)
1717

18-
hlt = _imp.new_module('hlt')
19-
exec(_confdb.HLTProcess(options).dump(), globals(), hlt.__dict__)
20-
return hlt.process
18+
try:
19+
foo = {'process': None}
20+
exec(_confdb.HLTProcess(options).dump(), globals(), foo)
21+
process = foo['process']
22+
except:
23+
raise Exception(f'query to ConfDB failed (output is not a valid python file)\n args={args}')
24+
25+
if not isinstance(process, cms.Process):
26+
raise Exception(f'query to ConfDB did not return a valid HLT menu (cms.Process not found)\n args={args}')
27+
28+
return process
2129

2230

2331
def loadHltConfiguration(process, menu, **args):
24-
args['menu'] = menu
25-
args['fragment'] = True
26-
options = _build_options(**args)
32+
args['menu'] = menu
33+
args['fragment'] = True
34+
options = _build_options(**args)
35+
36+
try:
37+
hlt = {'fragment': None}
38+
exec(_confdb.HLTProcess(options).dump(), globals(), hlt)
39+
process2 = hlt['fragment']
40+
except:
41+
raise Exception(f'query to ConfDB failed (output is not a valid python file)\n args={args}')
42+
43+
if not isinstance(process2, cms.Process):
44+
raise Exception(f'query to ConfDB did not return a valid HLT menu (cms.Process not found)\n args={args}')
45+
46+
process.extend( process2 )
2747

28-
hlt = types.ModuleType('hlt')
29-
exec(_confdb.HLTProcess(options).dump(), globals(), hlt.__dict__)
30-
process.extend( hlt )
48+
return process
3149

3250

3351
import FWCore.ParameterSet.Config as _cms

0 commit comments

Comments
 (0)