From 67f6ceb21d5903f0d12843f2dbb545a4acfc7c69 Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Sun, 6 Aug 2023 10:59:12 +0200 Subject: [PATCH] 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/cmssw#34563) - return cms.Process object in "loadHltConfiguration" (backward-compatible change) - add checks in both functions to catch errors in ConfDB queries --- HLTrigger/Configuration/python/Utilities.py | 52 ++++++++++++++------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/HLTrigger/Configuration/python/Utilities.py b/HLTrigger/Configuration/python/Utilities.py index 0bc2bf6f40ce3..95846c81f6ed0 100644 --- a/HLTrigger/Configuration/python/Utilities.py +++ b/HLTrigger/Configuration/python/Utilities.py @@ -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