Skip to content

Commit

Permalink
fix function "getHltConfiguration"
Browse files Browse the repository at this point in the history
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 #34563)
 - return cms.Process object in "loadHltConfiguration" (backward-compatible change)
 - add checks in both functions to catch errors in ConfDB queries
  • Loading branch information
missirol committed Aug 6, 2023
1 parent afefb83 commit 67f6ceb
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions HLTrigger/Configuration/python/Utilities.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
import types
import FWCore.ParameterSet.Config as cms

import HLTrigger.Configuration.Tools.options as _options
import HLTrigger.Configuration.Tools.confdb as _confdb

def _build_options(**args):
options = _options.HLTProcessOptions()
for key, val in args.items():
setattr(options, key, val)
return options
options = _options.HLTProcessOptions()
for key, val in args.items():
setattr(options, key, val)
return options


def getHltConfiguration(menu, **args):
args['menu'] = menu
args['fragment'] = False
options = _build_options(**args)
args['menu'] = menu
args['fragment'] = False
options = _build_options(**args)

hlt = _imp.new_module('hlt')
exec(_confdb.HLTProcess(options).dump(), globals(), hlt.__dict__)
return hlt.process
try:
foo = {'process': None}
exec(_confdb.HLTProcess(options).dump(), globals(), foo)
process = foo['process']
except:
raise Exception(f'query to ConfDB failed (output is not a valid python file)\n args={args}')

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

return process


def loadHltConfiguration(process, menu, **args):
args['menu'] = menu
args['fragment'] = True
options = _build_options(**args)
args['menu'] = menu
args['fragment'] = True
options = _build_options(**args)

try:
hlt = {'fragment': None}
exec(_confdb.HLTProcess(options).dump(), globals(), hlt)
process2 = hlt['fragment']
except:
raise Exception(f'query to ConfDB failed (output is not a valid python file)\n args={args}')

if not isinstance(process2, cms.Process):
raise Exception(f'query to ConfDB did not return a valid HLT menu (cms.Process not found)\n args={args}')

process.extend( process2 )

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


import FWCore.ParameterSet.Config as _cms
Expand Down

0 comments on commit 67f6ceb

Please sign in to comment.