Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-24 02:52:12

0001 #! /usr/bin/env python3
0002 
0003 import sys
0004 import subprocess
0005 import types
0006 import re
0007 import FWCore.ParameterSet.Config as cms
0008 
0009 def extractDatasets(version, database, config):
0010   # dump the streams and Datasets from the HLT configuration
0011   proc = subprocess.Popen(
0012     "hltConfigFromDB --%s --%s --configName %s --nopsets --noedsources --noes --noservices --nooutput --nopaths" % (version, database, config),
0013     shell  = True,
0014     stdin  = None,
0015     stdout = subprocess.PIPE,
0016     stderr = None,
0017   )
0018   (out, err) = proc.communicate()
0019 
0020   # load the streams and Datasets
0021   hlt = types.ModuleType('hlt')
0022   exec(out, globals(), hlt.__dict__)
0023 
0024   return hlt.process
0025 
0026 
0027 def dumpDataset(process, stream, dataset):
0028   if dataset in process.datasets.__dict__:
0029     name = 'stream%s_dataset%s_selector' % (stream, dataset)
0030     dump = '''from HLTrigger.HLTfilters.triggerResultsFilter_cfi import triggerResultsFilter as %s
0031 %s.hltResults = cms.InputTag('TriggerResults', '', 'HLT')
0032 %s.l1tResults = cms.InputTag('')
0033 %s.throw      = cms.bool(False)
0034 %s.triggerConditions = %s
0035 
0036 ''' % (name, name, name, name, name, process.datasets.__dict__[dataset])
0037   else:
0038     dump = '''# dataset %s not found
0039 
0040 ''' % (dataset, )
0041   return dump
0042 
0043 
0044 # split a "[version/]db:name" configuration into a (version, db, name) tuple 
0045 def splitConfigName(configName):
0046   from HLTrigger.Configuration.Tools.options import ConnectionHLTMenu
0047   menu = ConnectionHLTMenu(configName)
0048   return (menu.version, menu.database, menu.name)
0049 
0050 
0051 # get the configuration to parse and the file where to output the stream definitions from the command line
0052 config = sys.argv[1]
0053 
0054 # dump the expanded event content configurations to a python configuration fragment
0055 config  = splitConfigName(config)
0056 process = extractDatasets(* config)
0057 
0058 sys.stdout.write('''# %s
0059 
0060 import FWCore.ParameterSet.Config as cms
0061 
0062 ''' % config[2] )
0063 
0064 for stream in sorted(process.streams.__dict__):
0065   if re.match(r'^Physics|Parking', stream):
0066     sys.stdout.write('''
0067 # stream %s
0068 
0069 ''' % stream)
0070     ds = sorted(process.streams.__dict__[stream])
0071     for dataset in ds:
0072       sys.stdout.write(dumpDataset(process, stream, dataset))