CMS 3D CMS Logo

CustomConfigs.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 from FWCore.ParameterSet.MassReplace import massReplaceInputTag,massSearchReplaceAnyInputTag
4 from HLTrigger.Configuration.common import producers_by_type
5 
6 def ProcessName(process):
7 # processname modifications
8 
9  if 'hltTrigReport' in process.__dict__:
10  process.hltTrigReport.HLTriggerResults = cms.InputTag( 'TriggerResults','',process.name_() )
11 
12  return(process)
13 
14 
15 def Base(process):
16 # default modifications
17 
18  process.options.wantSummary = True
19  process.options.numberOfThreads = 4
20  process.options.numberOfStreams = 0
21  process.options.sizeOfStackForThreadsInKB = 10*1024
22 
23  process.MessageLogger.TriggerSummaryProducerAOD = cms.untracked.PSet()
24  process.MessageLogger.L1GtTrigReport = cms.untracked.PSet()
25  process.MessageLogger.L1TGlobalSummary = cms.untracked.PSet()
26  process.MessageLogger.HLTrigReport = cms.untracked.PSet()
27 
28 # No longer override - instead use GT config as provided via cmsDriver
29 
35 
36  process=ProcessName(process)
37 
38  return(process)
39 
40 
41 def L1T(process):
42 # modifications when running L1T only
43 
44  def _legacyStage1(process):
45  labels = ['gtDigis','simGtDigis','newGtDigis','hltGtDigis']
46  for label in labels:
47  if label in process.__dict__:
48  process.load('L1Trigger.GlobalTriggerAnalyzer.l1GtTrigReport_cfi')
49  process.l1GtTrigReport.L1GtRecordInputTag = cms.InputTag( label )
50  process.L1AnalyzerEndpath = cms.EndPath( process.l1GtTrigReport )
51  process.schedule.append(process.L1AnalyzerEndpath)
52 
53  def _stage2(process):
54  labels = ['gtStage2Digis','simGtStage2Digis','newGtStage2Digis','hltGtStage2Digis']
55  for label in labels:
56  if label in process.__dict__:
57  process.load('L1Trigger.L1TGlobal.L1TGlobalSummary_cfi')
58  process.L1TGlobalSummary.AlgInputTag = cms.InputTag( label )
59  process.L1TGlobalSummary.ExtInputTag = cms.InputTag( label )
60  process.L1TAnalyzerEndpath = cms.EndPath(process.L1TGlobalSummary )
61  process.schedule.append(process.L1TAnalyzerEndpath)
62 
63  from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
64  (~stage2L1Trigger).toModify(process, _legacyStage1)
65  stage2L1Trigger.toModify(process, _stage2)
66 
67  if hasattr(process,'TriggerMenu'):
68  delattr(process,'TriggerMenu')
69 
70  process=Base(process)
71 
72  return(process)
73 
74 
75 def L1THLT(process):
76 # modifications when running L1T+HLT
77 
78  if not ('HLTAnalyzerEndpath' in process.__dict__) :
79  def _legacyStage1(process):
80  if 'hltGtDigis' in process.__dict__:
81  from HLTrigger.Configuration.HLT_Fake_cff import fragment
82  process.hltL1GtTrigReport = fragment.hltL1GtTrigReport
83  process.hltTrigReport = fragment.hltTrigReport
84  process.HLTAnalyzerEndpath = cms.EndPath(process.hltGtDigis + process.hltL1GtTrigReport + process.hltTrigReport)
85  process.schedule.append(process.HLTAnalyzerEndpath)
86 
87  def _stage2(process):
88  if 'hltGtStage2ObjectMap' in process.__dict__:
89  from HLTrigger.Configuration.HLT_FULL_cff import fragment
90  process.hltL1TGlobalSummary = fragment.hltL1TGlobalSummary
91  process.hltTrigReport = fragment.hltTrigReport
92  process.HLTAnalyzerEndpath = cms.EndPath(process.hltGtStage2Digis + process.hltL1TGlobalSummary + process.hltTrigReport)
93  process.schedule.append(process.HLTAnalyzerEndpath)
94 
95  from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
96  (~stage2L1Trigger).toModify(process, _legacyStage1)
97  stage2L1Trigger.toModify(process, _stage2)
98 
99  if hasattr(process,'TriggerMenu'):
100  delattr(process,'TriggerMenu')
101 
102  process=Base(process)
103 
104  return(process)
105 
106 
107 def HLTRECO(process):
108  '''
109  Customisations for running HLT+RECO in the same job,
110  removing ESSources and ESProducers from Tasks (needed to run HLT+RECO tests on GPU)
111  - when Reconstruction_cff is loaded, it brings in Tasks that include
112  GPU-related ES modules with the same names as they have in HLT configs
113  - in TSG tests, these GPU-related RECO Tasks are not included in the Schedule
114  (because the "gpu" process-modifier is not used);
115  this causes the ES modules not to be executed, thus making them unavailable to HLT producers
116  - this workaround removes ES modules from Tasks, making their execution independent of the content of the Schedule;
117  with reference to https://twiki.cern.ch/twiki/bin/view/CMSPublic/SWGuideAboutPythonConfigFile?rev=92#Behavior_when_an_ESProducer_ESSo,
118  this workaround avoids "Case 3" by reverting to "Case 2"
119  - this workaround only affects Tasks of non-HLT steps, as the addition of ES modules to Tasks is not supported in ConfDB
120  (none of the Tasks used in the HLT step can contain ES modules in the first place, modulo customisations outside ConfDB)
121  '''
122  for taskName in process.tasks_():
123  task = process.tasks_()[taskName]
124  esModulesToRemove = set()
125  for modName in task.moduleNames():
126  module = getattr(process, modName)
127  if isinstance(module, cms.ESSource) or isinstance(module, cms.ESProducer):
128  esModulesToRemove.add(module)
129  for esModule in esModulesToRemove:
130  task.remove(esModule)
131 
132  return process
133 
134 
136  '''
137  Customisation of GlobalTag for Online BeamSpot
138  - edits the GlobalTag ESSource to load the tags used to produce the HLT beamspot
139  - these tags are not available in the Offline GT, which is the GT presently used in HLT+RECO tests
140  - not loading these tags (i.e. not using this customisation) does not result in a runtime error,
141  but it leads to an HLT beamspot different to the one obtained when running HLT alone
142  '''
143  if hasattr(process, 'GlobalTag'):
144  if not hasattr(process.GlobalTag, 'toGet'):
145  process.GlobalTag.toGet = cms.VPSet()
146  process.GlobalTag.toGet += [
147  cms.PSet(
148  record = cms.string('BeamSpotOnlineLegacyObjectsRcd'),
149  tag = cms.string('BeamSpotOnlineLegacy')
150  ),
151  cms.PSet(
152  record = cms.string('BeamSpotOnlineHLTObjectsRcd'),
153  tag = cms.string('BeamSpotOnlineHLT')
154  )
155  ]
156 
157  return process
158 
159 
160 def HLTDropPrevious(process):
161 # drop on input the previous HLT results
162  process.source.inputCommands = cms.untracked.vstring (
163  'keep *',
164  'drop *_hltL1GtObjectMap_*_*',
165  'drop *_TriggerResults_*_*',
166  'drop *_hltTriggerSummaryAOD_*_*',
167  )
168 
169  process = Base(process)
170 
171  return(process)
172 
173 
174 def L1REPACK(process, sequence="Full"):
175 
176  from Configuration.Eras.Era_Run3_cff import Run3
177  l1repack = cms.Process('L1REPACK', Run3)
178  l1repack.load('Configuration.StandardSequences.SimL1EmulatorRepack_'+sequence+'_cff')
179 
180  for module in l1repack.es_sources_():
181  if not hasattr(process, module):
182  setattr(process, module, getattr(l1repack, module))
183  for module in l1repack.es_producers_():
184  if not hasattr(process, module):
185  setattr(process, module, getattr(l1repack, module))
186 
187  for module in l1repack.SimL1Emulator.expandAndClone().moduleNames():
188  setattr(process, module, getattr(l1repack, module))
189  for taskName, task in l1repack.tasks_().items():
190  if l1repack.SimL1Emulator.contains(task):
191  setattr(process, taskName, task)
192  for sequenceName, sequence in l1repack.sequences_().items():
193  if l1repack.SimL1Emulator.contains(sequence):
194  setattr(process, sequenceName, sequence)
195 
196  process.SimL1Emulator = l1repack.SimL1Emulator
197 
198  for path in process.paths_():
199  getattr(process,path).insert(0,process.SimL1Emulator)
200  for path in process.endpaths_():
201  getattr(process,path).insert(0,process.SimL1Emulator)
202 
203  # special L1T cleanup
204  for obj in [
205  'l1tHGCalTriggerGeometryESProducer',
206  ]:
207  if hasattr(process, obj):
208  delattr(process, obj)
209 
210  return process
211 
212 
213 def L1XML(process,xmlFile=None):
214 
215 # xmlFile="L1Menu_Collisions2016_dev_v3.xml"
216 
217  if ((xmlFile is None) or (xmlFile=="")):
218  return process
219 
220  process.L1TriggerMenu= cms.ESProducer("L1TUtmTriggerMenuESProducer",
221  L1TriggerMenuFile= cms.string(xmlFile)
222  )
223  process.ESPreferL1TXML = cms.ESPrefer("L1TUtmTriggerMenuESProducer","L1TriggerMenu")
224 
225  return process
226 
227 
228 def customiseL1TforHIonRepackedRAW(process, l1tSequenceLabel = 'SimL1Emulator'):
229  '''
230  Customise the L1REPACK step (re-emulation of L1-Trigger) to run on the repacked RAW data
231  produced at HLT during Heavy-Ion data-taking (collection: "rawDataRepacker")
232  - replace "rawDataCollector" with "rawDataRepacker" in the L1T-emulation sequence
233  '''
234  if hasattr(process, l1tSequenceLabel) and isinstance(getattr(process, l1tSequenceLabel), cms.Sequence):
236  sequence = getattr(process, l1tSequenceLabel),
237  oldInputTag = 'rawDataCollector',
238  newInputTag = 'rawDataRepacker',
239  verbose = False,
240  moduleLabelOnly = True,
241  skipLabelTest = False
242  )
243  else:
244  warnMsg = 'no customisation applied, because the cms.Sequence "'+l1tSequenceLabel+'" is not available.'
245  print('# WARNING -- customiseL1TforHIonRepackedRAW: '+warnMsg)
246  return process
247 
248 def customiseL1TforHIonRepackedRAWPrime(process, l1tSequenceLabel = 'SimL1Emulator'):
249  '''
250  Customise the L1REPACK step (re-emulation of L1-Trigger) to run on the repacked RAWPrime data
251  produced at HLT during Heavy-Ion data-taking (collection: "rawPrimeDataRepacker")
252  - replace "rawDataCollector" with "rawPrimeDataRepacker" in the L1T-emulation sequence
253  (in terms of L1T information, "rawDataRepacker" and "rawPrimeDataRepacker" are equivalent)
254  '''
255  if hasattr(process, l1tSequenceLabel) and isinstance(getattr(process, l1tSequenceLabel), cms.Sequence):
257  sequence = getattr(process, l1tSequenceLabel),
258  oldInputTag = 'rawDataCollector',
259  newInputTag = 'rawPrimeDataRepacker',
260  verbose = False,
261  moduleLabelOnly = True,
262  skipLabelTest = False
263  )
264  else:
265  warnMsg = 'no customisation applied, because the cms.Sequence "'+l1tSequenceLabel+'" is not available.'
266  print('# WARNING -- customiseL1TforHIonRepackedRAWPrime: '+warnMsg)
267  return process
268 
270  '''
271  Customise a HLT menu to run on the repacked RAW data
272  produced at HLT during Heavy-Ion data-taking (collection: "rawDataRepacker")
273  - replace "rawDataCollector" with "rawDataRepacker::@skipCurrentProcess"
274  '''
276  process = process,
277  old = 'rawDataCollector',
278  new = 'rawDataRepacker::@skipCurrentProcess',
279  verbose = False,
280  moduleLabelOnly = False,
281  skipLabelTest = False
282  )
283  return process
284 
285 def customiseHLTforHIonRepackedRAWPrime(process, useRawDataCollector = False, siStripApproxClustersModuleLabel = 'hltSiStripClusters2ApproxClusters'):
286  '''
287  Customise a HLT menu to run on the repacked RAWPrime data
288  produced at HLT during Heavy-Ion data-taking (collections: "rawPrimeDataRepacker" + "hltSiStripClusters2ApproxClusters")
289  - delete modules of type 'SiStripRawToDigiModule', 'SiStripDigiToRawModule' and 'SiStripZeroSuppression'
290  - delete SiStripApproxClusters producer and HLT-HIon RAW-data repackers (e.g. "rawPrimeDataRepacker")
291  - replace SiStripClusterizers with SiStripClusters built from SiStripApproxClusters
292  '''
293  if not useRawDataCollector:
295  process = process,
296  old = 'rawDataCollector',
297  new = 'rawPrimeDataRepacker::@skipCurrentProcess',
298  verbose = False,
299  moduleLabelOnly = False,
300  skipLabelTest = False
301  )
302 
303  # delete modules of type 'SiStripRawToDigiModule', 'SiStripDigiToRawModule' and 'SiStripZeroSuppression'
304  moduleLabels = set()
305  for foo in ['SiStripRawToDigiModule', 'SiStripDigiToRawModule', 'SiStripZeroSuppression']:
306  for mod in producers_by_type(process, foo):
307  moduleLabels.add(mod.label())
308  for foo in moduleLabels:
309  delattr(process, foo)
310 
311  # delete SiStripApproxClusters producer and HLT-HIon RAW-data repackers (e.g. "rawPrimeDataRepacker")
312  for foo in [
313  siStripApproxClustersModuleLabel,
314  'rawDataRepacker',
315  'rawPrimeDataRepacker',
316  'rawDataReducedFormat',
317  ]:
318  if hasattr(process, foo):
319  delattr(process, foo)
320 
321  # replace SiStripClusterizers with SiStripClusters built from SiStripApproxClusters
322  moduleLabels = set()
323  for mod in producers_by_type(process, 'SiStripClusterizer'):
324  moduleLabels.add(mod.label())
325  for foo in moduleLabels:
326  setattr(process, foo, cms.EDProducer('SiStripApprox2Clusters',
327  inputApproxClusters = cms.InputTag(siStripApproxClustersModuleLabel)
328  ))
329 
330  return process
331 
333  '''
334  Customise a configuration with L1T+HLT steps to run on the repacked RAW data
335  produced at HLT during Heavy-Ion data-taking (collection: "rawDataRepacker")
336  - in the L1T step, replace "rawDataCollector" with "rawDataRepacker"
337  - no customisation needed for the HLT step
338  (the HLT modules consume the "rawDataCollector" produced by the L1T step)
339  '''
340  process = customiseL1TforHIonRepackedRAW(process)
341  return process
342 
344  '''
345  Customise a configuration with L1T+HLT steps to run on the repacked RAWPrime data
346  produced at HLT during Heavy-Ion data-taking (collections: "rawPrimeDataRepacker" + "hltSiStripClusters2ApproxClusters")
347  - in the L1T step, replace "rawDataCollector" with "rawPrimeDataRepacker"
348  - in the HLT step, apply the customisations needed for the SiStripApproxClusters
349  (the HLT modules consume the "rawDataCollector" produced by the L1T step)
350  '''
351  process = customiseL1TforHIonRepackedRAWPrime(process)
352  process = customiseHLTforHIonRepackedRAWPrime(process, useRawDataCollector = True)
353  return process
def customiseL1TforHIonRepackedRAW(process, l1tSequenceLabel='SimL1Emulator')
def customiseHLTforHIonRepackedRAWPrime(process, useRawDataCollector=False, siStripApproxClustersModuleLabel='hltSiStripClusters2ApproxClusters')
def L1T(process)
def producers_by_type(process, types)
def massSearchReplaceAnyInputTag(sequence, oldInputTag, newInputTag, verbose=False, moduleLabelOnly=False, skipLabelTest=False)
Definition: MassReplace.py:79
def L1THLT(process)
return((rh ^ lh) &mask)
def customiseHLTforHIonRepackedRAW(process)
def Base(process)
def HLTDropPrevious(process)
def ProcessName(process)
Definition: CustomConfigs.py:6
def L1XML(process, xmlFile=None)
def customiseL1THLTforHIonRepackedRAWPrime(process)
def L1REPACK(process, sequence="Full")
def customiseL1TforHIonRepackedRAWPrime(process, l1tSequenceLabel='SimL1Emulator')
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def massReplaceInputTag(process, old="rawDataCollector", new="rawDataRepacker", verbose=False, moduleLabelOnly=False, skipLabelTest=False)
Definition: MassReplace.py:83
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
def customiseGlobalTagForOnlineBeamSpot(process)
def HLTRECO(process)
def customiseL1THLTforHIonRepackedRAW(process)