|
1 | | -import types |
| 1 | +import FWCore.ParameterSet.Config as cms |
2 | 2 |
|
3 | 3 | import HLTrigger.Configuration.Tools.options as _options |
4 | 4 | import HLTrigger.Configuration.Tools.confdb as _confdb |
5 | 5 |
|
6 | 6 | 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 |
11 | 11 |
|
12 | 12 |
|
13 | 13 | 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) |
17 | 17 |
|
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 |
21 | 29 |
|
22 | 30 |
|
23 | 31 | 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 ) |
27 | 47 |
|
28 | | - hlt = types.ModuleType('hlt') |
29 | | - exec(_confdb.HLTProcess(options).dump(), globals(), hlt.__dict__) |
30 | | - process.extend( hlt ) |
| 48 | + return process |
31 | 49 |
|
32 | 50 |
|
33 | 51 | import FWCore.ParameterSet.Config as _cms |
|
0 commit comments