File indexing completed on 2024-04-06 12:15:59
0001 import FWCore.ParameterSet.Config as cms
0002
0003 from FWCore.ParameterSet.MassReplace import massReplaceInputTag,massSearchReplaceAnyInputTag
0004 from HLTrigger.Configuration.common import producers_by_type
0005
0006 def ProcessName(process):
0007
0008
0009 if 'hltTrigReport' in process.__dict__:
0010 process.hltTrigReport.HLTriggerResults = cms.InputTag( 'TriggerResults','',process.name_() )
0011
0012 return(process)
0013
0014
0015 def Base(process):
0016
0017
0018 process.options.wantSummary = True
0019 process.options.numberOfThreads = 4
0020 process.options.numberOfStreams = 0
0021 process.options.sizeOfStackForThreadsInKB = 10*1024
0022
0023 process.MessageLogger.TriggerSummaryProducerAOD = cms.untracked.PSet()
0024 process.MessageLogger.L1GtTrigReport = cms.untracked.PSet()
0025 process.MessageLogger.L1TGlobalSummary = cms.untracked.PSet()
0026 process.MessageLogger.HLTrigReport = cms.untracked.PSet()
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 process=ProcessName(process)
0037
0038 return(process)
0039
0040
0041 def L1T(process):
0042
0043
0044 def _legacyStage1(process):
0045 labels = ['gtDigis','simGtDigis','newGtDigis','hltGtDigis']
0046 for label in labels:
0047 if label in process.__dict__:
0048 process.load('L1Trigger.GlobalTriggerAnalyzer.l1GtTrigReport_cfi')
0049 process.l1GtTrigReport.L1GtRecordInputTag = cms.InputTag( label )
0050 process.L1AnalyzerEndpath = cms.EndPath( process.l1GtTrigReport )
0051 process.schedule.append(process.L1AnalyzerEndpath)
0052
0053 def _stage2(process):
0054 labels = ['gtStage2Digis','simGtStage2Digis','newGtStage2Digis','hltGtStage2Digis']
0055 for label in labels:
0056 if label in process.__dict__:
0057 process.load('L1Trigger.L1TGlobal.L1TGlobalSummary_cfi')
0058 process.L1TGlobalSummary.AlgInputTag = cms.InputTag( label )
0059 process.L1TGlobalSummary.ExtInputTag = cms.InputTag( label )
0060 process.L1TAnalyzerEndpath = cms.EndPath(process.L1TGlobalSummary )
0061 process.schedule.append(process.L1TAnalyzerEndpath)
0062
0063 from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
0064 (~stage2L1Trigger).toModify(process, _legacyStage1)
0065 stage2L1Trigger.toModify(process, _stage2)
0066
0067 if hasattr(process,'TriggerMenu'):
0068 delattr(process,'TriggerMenu')
0069
0070 process=Base(process)
0071
0072 return(process)
0073
0074
0075 def L1THLT(process):
0076
0077
0078 if not ('HLTAnalyzerEndpath' in process.__dict__) :
0079 def _legacyStage1(process):
0080 if 'hltGtDigis' in process.__dict__:
0081 from HLTrigger.Configuration.HLT_Fake_cff import fragment
0082 process.hltL1GtTrigReport = fragment.hltL1GtTrigReport
0083 process.hltTrigReport = fragment.hltTrigReport
0084 process.HLTAnalyzerEndpath = cms.EndPath(process.hltGtDigis + process.hltL1GtTrigReport + process.hltTrigReport)
0085 process.schedule.append(process.HLTAnalyzerEndpath)
0086
0087 def _stage2(process):
0088 if 'hltGtStage2ObjectMap' in process.__dict__:
0089 from HLTrigger.Configuration.HLT_FULL_cff import fragment
0090 process.hltL1TGlobalSummary = fragment.hltL1TGlobalSummary
0091 process.hltTrigReport = fragment.hltTrigReport
0092 process.HLTAnalyzerEndpath = cms.EndPath(process.hltGtStage2Digis + process.hltL1TGlobalSummary + process.hltTrigReport)
0093 process.schedule.append(process.HLTAnalyzerEndpath)
0094
0095 from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
0096 (~stage2L1Trigger).toModify(process, _legacyStage1)
0097 stage2L1Trigger.toModify(process, _stage2)
0098
0099 if hasattr(process,'TriggerMenu'):
0100 delattr(process,'TriggerMenu')
0101
0102 process=Base(process)
0103
0104 return(process)
0105
0106
0107 def HLTRECO(process):
0108 '''
0109 Customisations for running HLT+RECO in the same job,
0110 removing ESSources and ESProducers from Tasks (needed to run HLT+RECO tests on GPU)
0111 - when Reconstruction_cff is loaded, it brings in Tasks that include
0112 GPU-related ES modules with the same names as they have in HLT configs
0113 - in TSG tests, these GPU-related RECO Tasks are not included in the Schedule
0114 (because the "gpu" process-modifier is not used);
0115 this causes the ES modules not to be executed, thus making them unavailable to HLT producers
0116 - this workaround removes ES modules from Tasks, making their execution independent of the content of the Schedule;
0117 with reference to https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideAboutPythonConfigFile?rev=92#Behavior_when_an_ESProducer_ESSo,
0118 this workaround avoids "Case 3" by reverting to "Case 2"
0119 - this workaround only affects Tasks of non-HLT steps, as the addition of ES modules to Tasks is not supported in ConfDB
0120 (none of the Tasks used in the HLT step can contain ES modules in the first place, modulo customisations outside ConfDB)
0121 '''
0122 for taskName in process.tasks_():
0123 task = process.tasks_()[taskName]
0124 esModulesToRemove = set()
0125 for modName in task.moduleNames():
0126 module = getattr(process, modName)
0127 if isinstance(module, cms.ESSource) or isinstance(module, cms.ESProducer):
0128 esModulesToRemove.add(module)
0129 for esModule in esModulesToRemove:
0130 task.remove(esModule)
0131
0132 return process
0133
0134
0135 def customiseGlobalTagForOnlineBeamSpot(process):
0136 '''
0137 Customisation of GlobalTag for Online BeamSpot
0138 - edits the GlobalTag ESSource to load the tags used to produce the HLT beamspot
0139 - these tags are not available in the Offline GT, which is the GT presently used in HLT+RECO tests
0140 - not loading these tags (i.e. not using this customisation) does not result in a runtime error,
0141 but it leads to an HLT beamspot different to the one obtained when running HLT alone
0142 '''
0143 if hasattr(process, 'GlobalTag'):
0144 if not hasattr(process.GlobalTag, 'toGet'):
0145 process.GlobalTag.toGet = cms.VPSet()
0146 process.GlobalTag.toGet += [
0147 cms.PSet(
0148 record = cms.string('BeamSpotOnlineLegacyObjectsRcd'),
0149 tag = cms.string('BeamSpotOnlineLegacy')
0150 ),
0151 cms.PSet(
0152 record = cms.string('BeamSpotOnlineHLTObjectsRcd'),
0153 tag = cms.string('BeamSpotOnlineHLT')
0154 )
0155 ]
0156
0157 return process
0158
0159
0160 def HLTDropPrevious(process):
0161
0162 process.source.inputCommands = cms.untracked.vstring (
0163 'keep *',
0164 'drop *_hltL1GtObjectMap_*_*',
0165 'drop *_TriggerResults_*_*',
0166 'drop *_hltTriggerSummaryAOD_*_*',
0167 )
0168
0169 process = Base(process)
0170
0171 return(process)
0172
0173
0174 def L1REPACK(process, sequence="Full"):
0175
0176 from Configuration.Eras.Era_Run3_cff import Run3
0177 l1repack = cms.Process('L1REPACK', Run3)
0178 l1repack.load('Configuration.StandardSequences.SimL1EmulatorRepack_'+sequence+'_cff')
0179
0180 for module in l1repack.es_sources_():
0181 if not hasattr(process, module):
0182 setattr(process, module, getattr(l1repack, module))
0183 for module in l1repack.es_producers_():
0184 if not hasattr(process, module):
0185 setattr(process, module, getattr(l1repack, module))
0186
0187 for module in l1repack.SimL1Emulator.expandAndClone().moduleNames():
0188 setattr(process, module, getattr(l1repack, module))
0189 for taskName, task in l1repack.tasks_().items():
0190 if l1repack.SimL1Emulator.contains(task):
0191 setattr(process, taskName, task)
0192 for sequenceName, sequence in l1repack.sequences_().items():
0193 if l1repack.SimL1Emulator.contains(sequence):
0194 setattr(process, sequenceName, sequence)
0195
0196 process.SimL1Emulator = l1repack.SimL1Emulator
0197
0198 for path in process.paths_():
0199 getattr(process,path).insert(0,process.SimL1Emulator)
0200 for path in process.endpaths_():
0201 getattr(process,path).insert(0,process.SimL1Emulator)
0202
0203
0204 for obj in [
0205 'l1tHGCalTriggerGeometryESProducer',
0206 ]:
0207 if hasattr(process, obj):
0208 delattr(process, obj)
0209
0210 return process
0211
0212
0213 def L1XML(process,xmlFile=None):
0214
0215
0216
0217 if ((xmlFile is None) or (xmlFile=="")):
0218 return process
0219
0220 process.L1TriggerMenu= cms.ESProducer("L1TUtmTriggerMenuESProducer",
0221 L1TriggerMenuFile= cms.string(xmlFile)
0222 )
0223 process.ESPreferL1TXML = cms.ESPrefer("L1TUtmTriggerMenuESProducer","L1TriggerMenu")
0224
0225 return process
0226
0227
0228 def customiseL1TforHIonRepackedRAW(process, l1tSequenceLabel = 'SimL1Emulator'):
0229 '''
0230 Customise the L1REPACK step (re-emulation of L1-Trigger) to run on the repacked RAW data
0231 produced at HLT during Heavy-Ion data-taking (collection: "rawDataRepacker")
0232 - replace "rawDataCollector" with "rawDataRepacker" in the L1T-emulation sequence
0233 '''
0234 if hasattr(process, l1tSequenceLabel) and isinstance(getattr(process, l1tSequenceLabel), cms.Sequence):
0235 massSearchReplaceAnyInputTag(
0236 sequence = getattr(process, l1tSequenceLabel),
0237 oldInputTag = 'rawDataCollector',
0238 newInputTag = 'rawDataRepacker',
0239 verbose = False,
0240 moduleLabelOnly = True,
0241 skipLabelTest = False
0242 )
0243 else:
0244 warnMsg = 'no customisation applied, because the cms.Sequence "'+l1tSequenceLabel+'" is not available.'
0245 print('# WARNING -- customiseL1TforHIonRepackedRAW: '+warnMsg)
0246 return process
0247
0248 def customiseL1TforHIonRepackedRAWPrime(process, l1tSequenceLabel = 'SimL1Emulator'):
0249 '''
0250 Customise the L1REPACK step (re-emulation of L1-Trigger) to run on the repacked RAWPrime data
0251 produced at HLT during Heavy-Ion data-taking (collection: "rawPrimeDataRepacker")
0252 - replace "rawDataCollector" with "rawPrimeDataRepacker" in the L1T-emulation sequence
0253 (in terms of L1T information, "rawDataRepacker" and "rawPrimeDataRepacker" are equivalent)
0254 '''
0255 if hasattr(process, l1tSequenceLabel) and isinstance(getattr(process, l1tSequenceLabel), cms.Sequence):
0256 massSearchReplaceAnyInputTag(
0257 sequence = getattr(process, l1tSequenceLabel),
0258 oldInputTag = 'rawDataCollector',
0259 newInputTag = 'rawPrimeDataRepacker',
0260 verbose = False,
0261 moduleLabelOnly = True,
0262 skipLabelTest = False
0263 )
0264 else:
0265 warnMsg = 'no customisation applied, because the cms.Sequence "'+l1tSequenceLabel+'" is not available.'
0266 print('# WARNING -- customiseL1TforHIonRepackedRAWPrime: '+warnMsg)
0267 return process
0268
0269 def customiseHLTforHIonRepackedRAW(process):
0270 '''
0271 Customise a HLT menu to run on the repacked RAW data
0272 produced at HLT during Heavy-Ion data-taking (collection: "rawDataRepacker")
0273 - replace "rawDataCollector" with "rawDataRepacker::@skipCurrentProcess"
0274 '''
0275 massReplaceInputTag(
0276 process = process,
0277 old = 'rawDataCollector',
0278 new = 'rawDataRepacker::@skipCurrentProcess',
0279 verbose = False,
0280 moduleLabelOnly = False,
0281 skipLabelTest = False
0282 )
0283 return process
0284
0285 def customiseHLTforHIonRepackedRAWPrime(process, useRawDataCollector = False, siStripApproxClustersModuleLabel = 'hltSiStripClusters2ApproxClusters'):
0286 '''
0287 Customise a HLT menu to run on the repacked RAWPrime data
0288 produced at HLT during Heavy-Ion data-taking (collections: "rawPrimeDataRepacker" + "hltSiStripClusters2ApproxClusters")
0289 - delete modules of type 'SiStripRawToDigiModule', 'SiStripDigiToRawModule' and 'SiStripZeroSuppression'
0290 - delete SiStripApproxClusters producer and HLT-HIon RAW-data repackers (e.g. "rawPrimeDataRepacker")
0291 - replace SiStripClusterizers with SiStripClusters built from SiStripApproxClusters
0292 '''
0293 if not useRawDataCollector:
0294 massReplaceInputTag(
0295 process = process,
0296 old = 'rawDataCollector',
0297 new = 'rawPrimeDataRepacker::@skipCurrentProcess',
0298 verbose = False,
0299 moduleLabelOnly = False,
0300 skipLabelTest = False
0301 )
0302
0303
0304 moduleLabels = set()
0305 for foo in ['SiStripRawToDigiModule', 'SiStripDigiToRawModule', 'SiStripZeroSuppression']:
0306 for mod in producers_by_type(process, foo):
0307 moduleLabels.add(mod.label())
0308 for foo in moduleLabels:
0309 delattr(process, foo)
0310
0311
0312 for foo in [
0313 siStripApproxClustersModuleLabel,
0314 'rawDataRepacker',
0315 'rawPrimeDataRepacker',
0316 'rawDataReducedFormat',
0317 ]:
0318 if hasattr(process, foo):
0319 delattr(process, foo)
0320
0321
0322 moduleLabels = set()
0323 for mod in producers_by_type(process, 'SiStripClusterizer'):
0324 moduleLabels.add(mod.label())
0325 for foo in moduleLabels:
0326 setattr(process, foo, cms.EDProducer('SiStripApprox2Clusters',
0327 inputApproxClusters = cms.InputTag(siStripApproxClustersModuleLabel)
0328 ))
0329
0330 return process
0331
0332 def customiseL1THLTforHIonRepackedRAW(process):
0333 '''
0334 Customise a configuration with L1T+HLT steps to run on the repacked RAW data
0335 produced at HLT during Heavy-Ion data-taking (collection: "rawDataRepacker")
0336 - in the L1T step, replace "rawDataCollector" with "rawDataRepacker"
0337 - no customisation needed for the HLT step
0338 (the HLT modules consume the "rawDataCollector" produced by the L1T step)
0339 '''
0340 process = customiseL1TforHIonRepackedRAW(process)
0341 return process
0342
0343 def customiseL1THLTforHIonRepackedRAWPrime(process):
0344 '''
0345 Customise a configuration with L1T+HLT steps to run on the repacked RAWPrime data
0346 produced at HLT during Heavy-Ion data-taking (collections: "rawPrimeDataRepacker" + "hltSiStripClusters2ApproxClusters")
0347 - in the L1T step, replace "rawDataCollector" with "rawPrimeDataRepacker"
0348 - in the HLT step, apply the customisations needed for the SiStripApproxClusters
0349 (the HLT modules consume the "rawDataCollector" produced by the L1T step)
0350 '''
0351 process = customiseL1TforHIonRepackedRAWPrime(process)
0352 process = customiseHLTforHIonRepackedRAWPrime(process, useRawDataCollector = True)
0353 return process