CMS 3D CMS Logo

confdb.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import absolute_import
4 import sys
5 import re
6 import os
7 from .pipe import pipe as _pipe
8 from .options import globalTag
9 from itertools import islice
10 
11 def splitter(iterator, n):
12  i = iterator.__iter__()
13  while True:
14  l = list(islice(i, n))
15  if l:
16  yield l
17  else:
18  break
19 
20 
22 
23  def __init__(self, configuration):
24  self.config = configuration
25  self.data = None
26  self.source = []
27  self.parent = []
28 
29  self.options = {
30  'essources' : [],
31  'esmodules' : [],
32  'modules' : [],
33  'sequences' : [],
34  'services' : [],
35  'paths' : [],
36  'psets' : [],
37  'blocks' : [],
38  }
39 
40  self.labels = {}
41  if self.config.fragment:
42  self.labels['process'] = 'fragment'
43  self.labels['dict'] = 'fragment.__dict__'
44  else:
45  self.labels['process'] = 'process'
46  self.labels['dict'] = 'process.__dict__'
47 
48  if self.config.prescale and (self.config.prescale.lower() != 'none'):
49  self.labels['prescale'] = self.config.prescale
50 
51  # get the configuration from ConfdB
52  from .confdbOfflineConverter import OfflineConverter
53  self.converter = OfflineConverter(version = self.config.menu.version, database = self.config.menu.database, proxy = self.config.proxy, proxyHost = self.config.proxy_host, proxyPort = self.config.proxy_port, tunnel = self.config.tunnel, tunnelPort = self.config.tunnel_port)
54  self.buildPathList()
55  self.buildOptions()
58  self.customize()
59 
61  if not self.config.setup:
62  return
63 
64  if ".py" in self.config.setup:
65  self.config.setupFile = self.config.setup.split(".py")[0]
66  return
67  args = ['--configName', self.config.setup ]
68  args.append('--noedsources')
69  args.append('--nopaths')
70  for key, vals in self.options.items():
71  if vals:
72  args.extend(('--'+key, ','.join(vals)))
73  args.append('--cff')
74  data, err = self.converter.query( *args )
75  if 'ERROR' in err or 'Exhausted Resultset' in err or 'CONFIG_NOT_FOUND' in err:
76  sys.stderr.write("%s: error while retrieving the HLT setup menu\n\n" % os.path.basename(sys.argv[0]))
77  sys.stderr.write(err + "\n\n")
78  sys.exit(1)
79  self.config.setupFile = "setup_"+self.config.setup[1:].replace("/","_")+"_cff"
80  outfile = open(self.config.setupFile+".py","w+")
81  outfile.write("# This file is automatically generated by hltGetConfiguration.\n" + data)
82 
84  if self.config.menu.run:
85  args = ['--runNumber', self.config.menu.run]
86  else:
87  args = ['--configName', self.config.menu.name ]
88  if not self.config.hilton:
89  # keep the original Source when running on Hilton
90  args.append('--noedsources')
91  for key, vals in self.options.items():
92  if vals:
93  args.extend(('--'+key, ','.join(vals)))
94  data, err = self.converter.query( *args )
95  if 'ERROR' in err or 'Exhausted Resultset' in err or 'CONFIG_NOT_FOUND' in err:
96  sys.stderr.write("%s: error while retrieving the HLT menu\n\n" % os.path.basename(sys.argv[0]))
97  sys.stderr.write(err + "\n\n")
98  sys.exit(1)
99  self.data = data
100 
101  def getPathList(self):
102  if self.config.menu.run:
103  args = ['--runNumber', self.config.menu.run]
104  else:
105  args = ['--configName', self.config.menu.name]
106  args.extend( (
107  '--cff',
108  '--noedsources',
109  '--noes',
110  '--noservices',
111  '--nosequences',
112  '--nomodules'
113  ) )
114 
115  data, err = self.converter.query( *args )
116  if 'ERROR' in err or 'Exhausted Resultset' in err or 'CONFIG_NOT_FOUND' in err:
117  sys.stderr.write("%s: error while retrieving the list of paths from the HLT menu\n\n" % os.path.basename(sys.argv[0]))
118  sys.stderr.write(err + "\n\n")
119  sys.exit(1)
120  filter = re.compile(r' *= *cms.(End|Final)?Path.*')
121  paths = [ filter.sub('', line) for line in data.splitlines() if filter.search(line) ]
122  return paths
123 
124 
125  @staticmethod
126  def expandWildcards(globs, collection):
127  # expand a list of unix-style wildcards matching a given collection
128  # wildcards with no matches are silently discarded
129  matches = []
130  for glob in globs:
131  negate = ''
132  if glob[0] == '-':
133  negate = '-'
134  glob = glob[1:]
135  # translate a unix-style glob expression into a regular expression
136  filter = re.compile(r'^' + glob.replace('?', '.').replace('*', '.*').replace('[!', '[^') + r'$')
137  matches.extend( negate + element for element in collection if filter.match(element) )
138  return matches
139 
140 
141  @staticmethod
142  def consolidateNegativeList(elements):
143  # consolidate a list of path exclusions and re-inclusions
144  # the result is the list of paths to be removed from the dump
145  result = set()
146  for element in elements:
147  if element[0] == '-':
148  result.add( element )
149  else:
150  result.discard( '-' + element )
151  return sorted( element for element in result )
152 
153  @staticmethod
154  def consolidatePositiveList(elements):
155  # consolidate a list of path selection and re-exclusions
156  # the result is the list of paths to be included in the dump
157  result = set()
158  for element in elements:
159  if element[0] == '-':
160  result.discard( element[1:] )
161  else:
162  result.add( element )
163  return sorted( element for element in result )
164 
165 
166  # dump the final configuration
167  def dump(self):
168  self.data = self.data % self.labels
169  if self.config.fragment:
170  self.data = re.sub( r'\bprocess\b', 'fragment', self.data )
171  self.data = re.sub( r'\bProcess\b', 'ProcessFragment', self.data )
172  return self.data
173 
174 
175  # add specific customizations
176  def specificCustomize(self):
177  # specific customizations now live in HLTrigger.Configuration.customizeHLTforALL.customizeHLTforAll(.,.)
178  if self.config.fragment:
179  self.data += """
180 # add specific customizations
181 from HLTrigger.Configuration.customizeHLTforALL import customizeHLTforAll
182 fragment = customizeHLTforAll(fragment,"%s")
183 """ % (self.config.type)
184  elif self.config.hilton:
185  # do not apply the STORM-specific customisation
186  pass
187  else:
188  if self.config.type=="Fake":
189  prefix = "run1"
190  elif self.config.type in ("Fake1","Fake2","2018"):
191  prefix = "run2"
192  else:
193  prefix = "run3"
194  _gtData = "auto:"+prefix+"_hlt_"+self.config.type
195  _gtMc = "auto:"+prefix+"_mc_" +self.config.type
196  self.data += """
197 # add specific customizations
198 _customInfo = {}
199 _customInfo['menuType' ]= "%s"
200 _customInfo['globalTags']= {}
201 _customInfo['globalTags'][True ] = "%s"
202 _customInfo['globalTags'][False] = "%s"
203 _customInfo['inputFiles']={}
204 _customInfo['inputFiles'][True] = "file:RelVal_Raw_%s_DATA.root"
205 _customInfo['inputFiles'][False] = "file:RelVal_Raw_%s_MC.root"
206 _customInfo['maxEvents' ]= %s
207 _customInfo['globalTag' ]= "%s"
208 _customInfo['inputFile' ]= %s
209 _customInfo['realData' ]= %s
210 
211 from HLTrigger.Configuration.customizeHLTforALL import customizeHLTforAll
212 %%(process)s = customizeHLTforAll(%%(process)s,"%s",_customInfo)
213 """ % (self.config.type,_gtData,_gtMc,self.config.type,self.config.type,self.config.events,self.config.globaltag,self.source,self.config.data,self.config.type)
214 
215  self.data += """
216 from HLTrigger.Configuration.customizeHLTforCMSSW import customizeHLTforCMSSW
217 %%(process)s = customizeHLTforCMSSW(%%(process)s,"%s")
218 """ % (self.config.type)
219 
220  # Eras-based customisations
221  self.data += """
222 # Eras-based customisations
223 from HLTrigger.Configuration.Eras import modifyHLTforEras
224 modifyHLTforEras(%(process)s)
225 """
226  # add the user-defined customization functions, if any
227  if self.config.customise:
228  self.data += "\n"
229  self.data += "#User-defined customization functions\n"
230  for customise in self.config.customise.split(","):
231  customiseValues = customise.split(".")
232  if len(customiseValues)>=3: raise Exception("--customise option cannot contain more than one dot.")
233  if len(customiseValues)==1:
234  customiseValues.append("customise")
235  customiseValues[0] = customiseValues[0].replace("/",".")
236  self.data += "from "+customiseValues[0]+" import "+customiseValues[1]+"\n"
237  self.data += "process = "+customiseValues[1]+"(process)\n"
238 
239 
240  # customize the configuration according to the options
241  def customize(self):
242 
243  # adapt the source to the current scenario
244  if not self.config.fragment:
245  self.build_source()
246 
247  # if requested, remove the HLT prescales
248  self.fixPrescales()
249 
250  # if requested, override all ED/HLTfilters to always pass ("open" mode)
251  self.instrumentOpenMode()
252 
253  # if requested, change all HLTTriggerTypeFilter EDFilters to accept only error events (SelectedTriggerType = 0)
255 
256  # if requested, instrument the self with the modules and EndPath needed for timing studies
257  self.instrumentTiming()
258 
259  # if requested, override the L1 self from the GlobalTag (Xml)
260  self.overrideL1MenuXml()
261 
262  # if requested, run the L1 emulator
263  self.runL1Emulator()
264 
265  # add process.load("setup_cff")
266  self.loadSetupCff()
267 
268  if self.config.fragment:
269  self.data += """
270 # dummify hltGetConditions in cff's
271 if 'hltGetConditions' in %(dict)s and 'HLTriggerFirstPath' in %(dict)s :
272  %(process)s.hltDummyConditions = cms.EDFilter( "HLTBool",
273  result = cms.bool( True )
274  )
275  %(process)s.HLTriggerFirstPath.replace(%(process)s.hltGetConditions,%(process)s.hltDummyConditions)
276 """
277 
278  # the scouting path issue:
279  # 1) for config fragments, we remove all output modules
280  # 2) however in old style datasets, the scouting output paths also run the unpackers which are needed
281  # 3) therefore they have to keep the scouting path but remove the scouting output module
282  # 4) in new style datasets, aka datasetpaths & finalpaths, the scouting unpackers are on another path and all of this is unnecessary
283  # 5) however its hard to detect whether we have new style or old style so we run this for both
284  # 6) therefore we end up with a superfluous Scouting*OutputPaths which are empty
285  for path in self.all_paths:
286  match = re.match(r'(Scouting\w+)Output$', path)
287  if match:
288  module = 'hltOutput' + match.group(1)
289  self.data = self.data.replace(path+' = cms.EndPath', path+' = cms.Path')
290  self.data = self.data.replace(' + process.'+module, '')
291  self.data = self.data.replace(' process.'+module, '')
292  else:
293 
294  # override the process name and adapt the relevant filters
295  self.overrideProcessName()
296 
297  # select specific Eras
298  self.addEras()
299 
300  # override the output modules to output root files
301  self.overrideOutput()
302 
303  # add global options
304  self.addGlobalOptions()
305 
306  # if requested or necessary, override the GlobalTag and connection strings (incl. L1!)
307  self.overrideGlobalTag()
308 
309  # request summary informations from the MessageLogger
310  self.updateMessageLogger()
311 
312  # replace DQMStore and DQMRootOutputModule with a configuration suitable for running offline
313  self.instrumentDQM()
314 
315  # add specific customisations
316  self.specificCustomize()
317 
318 
319  def addGlobalOptions(self):
320  # add global options
321  self.data += """
322 # limit the number of events to be processed
323 %%(process)s.maxEvents = cms.untracked.PSet(
324  input = cms.untracked.int32( %d )
325 )
326 """ % self.config.events
327 
328  self.data += """
329 # enable TrigReport, TimeReport and MultiThreading
330 %(process)s.options.wantSummary = True
331 %(process)s.options.numberOfThreads = 4
332 %(process)s.options.numberOfStreams = 0
333 """
334 
335  def _fix_parameter(self, **args):
336  """arguments:
337  name: parameter name (optional)
338  type: parameter type (look for tracked and untracked variants)
339  value: original value
340  replace: replacement value
341  """
342  if 'name' in args:
343  self.data = re.sub(
344  r'%(name)s = cms(?P<tracked>(?:\.untracked)?)\.%(type)s\( (?P<quote>["\']?)%(value)s(?P=quote)' % args,
345  r'%(name)s = cms\g<tracked>.%(type)s( \g<quote>%(replace)s\g<quote>' % args,
346  self.data)
347  else:
348  self.data = re.sub(
349  r'cms(?P<tracked>(?:\.untracked)?)\.%(type)s\( (?P<quote>["\']?)%(value)s(?P=quote)' % args,
350  r'cms\g<tracked>.%(type)s( \g<quote>%(replace)s\g<quote>' % args,
351  self.data)
352 
353 
354  def fixPrescales(self):
355  # update the PrescaleService to match the new list of paths
356  if self.options['paths']:
357  if self.options['paths'][0][0] == '-':
358  # drop requested paths
359  for minuspath in self.options['paths']:
360  path = minuspath[1:]
361  self.data = re.sub(r' cms.PSet\( pathName = cms.string\( "%s" \),\n prescales = cms.vuint32\( .* \)\n \),?\n' % path, '', self.data)
362  else:
363  # keep requested paths
364  for path in self.all_paths:
365  if path not in self.options['paths']:
366  self.data = re.sub(r' cms.PSet\( pathName = cms.string\( "%s" \),\n prescales = cms.vuint32\( .* \)\n \),?\n' % path, '', self.data)
367 
368  if self.config.prescale and (self.config.prescale.lower() != 'none'):
369  # TO DO: check that the requested prescale column is valid
370  self.data += """
371 # force the use of a specific HLT prescale column
372 if 'PrescaleService' in %(dict)s:
373  %(process)s.PrescaleService.forceDefault = True
374  %(process)s.PrescaleService.lvl1DefaultLabel = '%(prescale)s'
375 """
376 
377 
379  if self.config.open:
380  # find all EDfilters
381  filters = [ match[1] for match in re.findall(r'(process\.)?\b(\w+) = cms.EDFilter', self.data) ]
382  re_sequence = re.compile( r'cms\.(Path|Sequence)\((.*)\)' )
383  # remove existing 'cms.ignore' and '~' modifiers
384  self.data = re_sequence.sub( lambda line: re.sub( r'cms\.ignore *\( *((process\.)?\b(\w+)) *\)', r'\1', line.group(0) ), self.data )
385  self.data = re_sequence.sub( lambda line: re.sub( r'~', '', line.group(0) ), self.data )
386  # wrap all EDfilters with "cms.ignore( ... )", 1000 at a time (python 2.6 complains for too-big regular expressions)
387  for some in splitter(filters, 1000):
388  re_filters = re.compile( r'\b((process\.)?(' + r'|'.join(some) + r'))\b' )
389  self.data = re_sequence.sub( lambda line: re_filters.sub( r'cms.ignore( \1 )', line.group(0) ), self.data )
390 
391 
393  if self.config.errortype:
394  # change all HLTTriggerTypeFilter EDFilters to accept only error events (SelectedTriggerType = 0)
395  self._fix_parameter(name = 'SelectedTriggerType', type ='int32', value = '1', replace = '0')
396  self._fix_parameter(name = 'SelectedTriggerType', type ='int32', value = '2', replace = '0')
397  self._fix_parameter(name = 'SelectedTriggerType', type ='int32', value = '3', replace = '0')
398 
399 
400  def overrideGlobalTag(self):
401  # overwrite GlobalTag
402  # the logic is:
403  # - if a GlobalTag is specified on the command line:
404  # - override the global tag
405  # - if the GT is "auto:...", insert the code to read it from Configuration.AlCa.autoCond
406  # - if a GlobalTag is NOT specified on the command line:
407  # - when running on data, do nothing, and keep the global tag in the menu
408  # - when running on mc, take the GT from the configuration.type
409 
410  # override the GlobalTag connection string and pfnPrefix
411 
412  # when running on MC, override the global tag even if not specified on the command line
413  if not self.config.data and not self.config.globaltag:
414  if self.config.type in globalTag:
415  self.config.globaltag = globalTag[self.config.type]
416  else:
417  self.config.globaltag = globalTag['GRun']
418 
419  # if requested, override the L1 menu from the GlobalTag
420  if self.config.l1.override:
421  self.config.l1.tag = self.config.l1.override
422  self.config.l1.record = 'L1TUtmTriggerMenuRcd'
423  self.config.l1.connect = ''
424  self.config.l1.label = ''
425  if not self.config.l1.snapshotTime:
426  self.config.l1.snapshotTime = '9999-12-31 23:59:59.000'
427  self.config.l1cond = '%(tag)s,%(record)s,%(connect)s,%(label)s,%(snapshotTime)s' % self.config.l1.__dict__
428  else:
429  self.config.l1cond = None
430 
431  if self.config.globaltag or self.config.l1cond:
432  text = """
433 # override the GlobalTag, connection string and pfnPrefix
434 if 'GlobalTag' in %(dict)s:
435  from Configuration.AlCa.GlobalTag import GlobalTag as customiseGlobalTag
436  %(process)s.GlobalTag = customiseGlobalTag(%(process)s.GlobalTag"""
437  if self.config.globaltag:
438  text += ", globaltag = %s" % repr(self.config.globaltag)
439  if self.config.l1cond:
440  text += ", conditions = %s" % repr(self.config.l1cond)
441  text += ")\n"
442  self.data += text
443 
444  def overrideL1MenuXml(self):
445  # if requested, override the GlobalTag's L1T menu from an Xml file
446  if self.config.l1Xml.XmlFile:
447  text = """
448 # override the GlobalTag's L1T menu from an Xml file
449 from HLTrigger.Configuration.CustomConfigs import L1XML
450 %%(process)s = L1XML(%%(process)s,"%s")
451 """ % (self.config.l1Xml.XmlFile)
452  self.data += text
453 
454  def runL1Emulator(self):
455  # if requested, run the Full L1T emulator, then repack the data into a new RAW collection, to be used by the HLT
456  if self.config.emulator:
457  text = """
458 # run the Full L1T emulator, then repack the data into a new RAW collection, to be used by the HLT
459 from HLTrigger.Configuration.CustomConfigs import L1REPACK
460 %%(process)s = L1REPACK(%%(process)s,"%s")
461 """ % (self.config.emulator)
462  self.data += text
463 
464  def overrideOutput(self):
465  # if not running on Hilton, override the "online" output modules with the "offline" one (i.e. PoolOutputModule)
466  # in Run 1 and Run 2, the online output modules were instances of ShmStreamConsumer
467  # in Run 3, ShmStreamConsumer has been replaced with EvFOutputModule, and later GlobalEvFOutputModule
468  if not self.config.hilton:
469  self.data = re.sub(
470  r'\b(process\.)?hltOutput(\w+) *= *cms\.OutputModule\( *"(ShmStreamConsumer)" *,',
471  r'%(process)s.hltOutput\2 = cms.OutputModule( "PoolOutputModule",\n fileName = cms.untracked.string( "output\2.root" ),\n fastCloning = cms.untracked.bool( False ),\n dataset = cms.untracked.PSet(\n filterName = cms.untracked.string( "" ),\n dataTier = cms.untracked.string( "RAW" )\n ),',
472  self.data
473  )
474 
475  self.data = re.sub("""\
476 \\b(process\.)?hltOutput(\w+) *= *cms\.OutputModule\( *['"](EvFOutputModule|GlobalEvFOutputModule)['"] *,
477  use_compression = cms.untracked.bool\( (True|False) \),
478  compression_algorithm = cms.untracked.string\( ['"](.+?)['"] \),
479  compression_level = cms.untracked.int32\( (-?\d+) \),
480  lumiSection_interval = cms.untracked.int32\( (-?\d+) \),
481 (.+?),
482  psetMap = cms.untracked.InputTag\( ['"]hltPSetMap['"] \)
483 ""","""\
484 %(process)s.hltOutput\g<2> = cms.OutputModule( "PoolOutputModule",
485  fileName = cms.untracked.string( "output\g<2>.root" ),
486  compressionAlgorithm = cms.untracked.string( "\g<5>" ),
487  compressionLevel = cms.untracked.int32( \g<6> ),
488  fastCloning = cms.untracked.bool( False ),
489  dataset = cms.untracked.PSet(
490  filterName = cms.untracked.string( "" ),
491  dataTier = cms.untracked.string( "RAW" )
492  ),
493 \g<8>
494 """, self.data, 0, re.DOTALL)
495 
496  if not self.config.fragment and self.config.output == 'minimal':
497  # add a single output to keep the TriggerResults and TriggerEvent
498  self.data += """
499 # add a single "keep *" output
500 %(process)s.hltOutputMinimal = cms.OutputModule( "PoolOutputModule",
501  fileName = cms.untracked.string( "output.root" ),
502  fastCloning = cms.untracked.bool( False ),
503  dataset = cms.untracked.PSet(
504  dataTier = cms.untracked.string( 'AOD' ),
505  filterName = cms.untracked.string( '' )
506  ),
507  outputCommands = cms.untracked.vstring( 'drop *',
508  'keep edmTriggerResults_*_*_*',
509  'keep triggerTriggerEvent_*_*_*',
510  'keep GlobalAlgBlkBXVector_*_*_*',
511  'keep GlobalExtBlkBXVector_*_*_*',
512  'keep l1tEGammaBXVector_*_EGamma_*',
513  'keep l1tEtSumBXVector_*_EtSum_*',
514  'keep l1tJetBXVector_*_Jet_*',
515  'keep l1tMuonBXVector_*_Muon_*',
516  'keep l1tTauBXVector_*_Tau_*',
517  )
518 )
519 %(process)s.MinimalOutput = cms.FinalPath( %(process)s.hltOutputMinimal )
520 %(process)s.schedule.append( %(process)s.MinimalOutput )
521 """
522  elif not self.config.fragment and self.config.output == 'full':
523  # add a single "keep *" output
524  self.data += """
525 # add a single "keep *" output
526 %(process)s.hltOutputFull = cms.OutputModule( "PoolOutputModule",
527  fileName = cms.untracked.string( "output.root" ),
528  fastCloning = cms.untracked.bool( False ),
529  dataset = cms.untracked.PSet(
530  dataTier = cms.untracked.string( 'RECO' ),
531  filterName = cms.untracked.string( '' )
532  ),
533  outputCommands = cms.untracked.vstring( 'keep *' )
534 )
535 %(process)s.FullOutput = cms.FinalPath( %(process)s.hltOutputFull )
536 %(process)s.schedule.append( %(process)s.FullOutput )
537 """
538 
539  # select specific Eras
540  def addEras(self):
541  if self.config.eras is None:
542  return
543  from Configuration.StandardSequences.Eras import eras
544  erasSplit = self.config.eras.split(',')
545  self.data = re.sub(r'process = cms.Process\( *"\w+"', '\n'.join(eras.pythonCfgLines[era] for era in erasSplit)+'\n\g<0>, '+', '.join(era for era in erasSplit), self.data)
546 
547  # select specific Eras
548  def loadSetupCff(self):
549  if self.config.setup is None:
550  return
551  processLine = self.data.find("\n",self.data.find("cms.Process"))
552  self.data = self.data[:processLine]+'\nprocess.load("%s")'%self.config.setupFile+self.data[processLine:]
553 
554  # override the process name and adapt the relevant filters
556  if self.config.name is None:
557  return
558 
559  # sanitise process name
560  self.config.name = self.config.name.replace("_","")
561  # override the process name
562  quote = '[\'\"]'
563  self.data = re.compile(r'^(process\s*=\s*cms\.Process\(\s*' + quote + r')\w+(' + quote + r'\s*\).*)$', re.MULTILINE).sub(r'\1%s\2' % self.config.name, self.data, 1)
564 
565  # when --setup option is used, remove possible errors from PrescaleService due to missing HLT paths.
566  if self.config.setup: self.data += """
567 # avoid PrescaleService error due to missing HLT paths
568 if 'PrescaleService' in process.__dict__:
569  for pset in reversed(process.PrescaleService.prescaleTable):
570  if not hasattr(process,pset.pathName.value()):
571  process.PrescaleService.prescaleTable.remove(pset)
572 """
573 
574 
576  # request summary informations from the MessageLogger
577  self.data += """
578 # show summaries from trigger analysers used at HLT
579 if 'MessageLogger' in %(dict)s:
580  %(process)s.MessageLogger.TriggerSummaryProducerAOD = cms.untracked.PSet()
581  %(process)s.MessageLogger.L1GtTrigReport = cms.untracked.PSet()
582  %(process)s.MessageLogger.L1TGlobalSummary = cms.untracked.PSet()
583  %(process)s.MessageLogger.HLTrigReport = cms.untracked.PSet()
584  %(process)s.MessageLogger.FastReport = cms.untracked.PSet()
585  %(process)s.MessageLogger.ThroughputService = cms.untracked.PSet()
586 """
587 
588 
589  def loadAdditionalConditions(self, comment, *conditions):
590  # load additional conditions
591  self.data += """
592 # %s
593 if 'GlobalTag' in %%(dict)s:
594 """ % comment
595  for condition in conditions:
596  self.data += """ %%(process)s.GlobalTag.toGet.append(
597  cms.PSet(
598  record = cms.string( '%(record)s' ),
599  tag = cms.string( '%(tag)s' ),
600  label = cms.untracked.string( '%(label)s' ),
601  )
602  )
603 """ % condition
604 
605 
606  def loadCffCommand(self, module):
607  # load a cfi or cff module
608  if self.config.fragment:
609  return 'from %s import *\n' % module
610  else:
611  return 'process.load( "%s" )\n' % module
612 
613  def loadCff(self, module):
614  self.data += self.loadCffCommand(module)
615 
616 
617  def overrideParameters(self, module, parameters):
618  # override a module's parameter if the module is present in the configuration
619  self.data += "if '%s' in %%(dict)s:\n" % module
620  for (parameter, value) in parameters:
621  self.data += " %%(process)s.%s.%s = %s\n" % (module, parameter, value)
622  self.data += "\n"
623 
624 
626  if label in self.data:
627  label_re = r'\b(process\.)?' + label
628  self.data = re.sub(r' *(\+|,) *' + label_re, '', self.data)
629  self.data = re.sub(label_re + r' *(\+|,) *', '', self.data)
630  self.data = re.sub(label_re, '', self.data)
631 
632 
633  def instrumentTiming(self):
634 
635  if self.config.timing:
636  self.data += """
637 # instrument the menu with the modules and EndPath needed for timing studies
638 """
639 
640  self.data += '\n# configure the FastTimerService\n'
641  self.loadCff('HLTrigger.Timer.FastTimerService_cfi')
642 
643  self.data += """# print a text summary at the end of the job
644 %(process)s.FastTimerService.printEventSummary = False
645 %(process)s.FastTimerService.printRunSummary = False
646 %(process)s.FastTimerService.printJobSummary = True
647 
648 # enable DQM plots
649 %(process)s.FastTimerService.enableDQM = True
650 
651 # enable per-path DQM plots
652 %(process)s.FastTimerService.enableDQMbyPath = True
653 
654 # enable per-module DQM plots
655 %(process)s.FastTimerService.enableDQMbyModule = True
656 
657 # enable per-event DQM plots vs lumisection
658 %(process)s.FastTimerService.enableDQMbyLumiSection = True
659 %(process)s.FastTimerService.dqmLumiSectionsRange = 2500
660 
661 # set the time resolution of the DQM plots
662 %(process)s.FastTimerService.dqmTimeRange = 2000.
663 %(process)s.FastTimerService.dqmTimeResolution = 10.
664 %(process)s.FastTimerService.dqmPathTimeRange = 1000.
665 %(process)s.FastTimerService.dqmPathTimeResolution = 5.
666 %(process)s.FastTimerService.dqmModuleTimeRange = 200.
667 %(process)s.FastTimerService.dqmModuleTimeResolution = 1.
668 
669 # set the base DQM folder for the DQM plots
670 %(process)s.FastTimerService.dqmPath = 'HLT/TimerService'
671 %(process)s.FastTimerService.enableDQMbyProcesses = False
672 
673 # write a JSON file with the information to be displayed in a pie chart
674 %(process)s.FastTimerService.writeJSONSummary = True
675 %(process)s.FastTimerService.jsonFileName = 'resources.json'
676 """
677 
678  self.data += '\n# configure the ThroughputService\n'
679  self.loadCff('HLTrigger.Timer.ThroughputService_cfi')
680 
681  self.data += """# enable DQM plots
682 %(process)s.ThroughputService.enableDQM = True
683 
684 # set the resolution of the DQM plots
685 %(process)s.ThroughputService.eventRange = 10000
686 %(process)s.ThroughputService.eventResolution = 1
687 %(process)s.ThroughputService.timeRange = 60000
688 %(process)s.ThroughputService.timeResolution = 10
689 
690 # set the base DQM folder for the DQM plots
691 %(process)s.ThroughputService.dqmPath = 'HLT/Throughput'
692 %(process)s.ThroughputService.dqmPathByProcesses = False
693 """
694 
695 
696  def instrumentDQM(self):
697  if not self.config.hilton:
698  # remove any reference to the hltDQMFileSaver and hltDQMFileSaverPB:
699  # note the convert options remove the module itself,
700  # here we are just removing the references in paths, sequences, etc
701  self.removeElementFromSequencesTasksAndPaths('hltDQMFileSaverPB')
702  self.removeElementFromSequencesTasksAndPaths('hltDQMFileSaver')
703 
704  # instrument the HLT menu with DQMStore and DQMRootOutputModule suitable for running offline
705  dqmstore = "\n# load the DQMStore and DQMRootOutputModule\n"
706  dqmstore += self.loadCffCommand('DQMServices.Core.DQMStore_cfi')
707  dqmstore += """
708 %(process)s.dqmOutput = cms.OutputModule("DQMRootOutputModule",
709  fileName = cms.untracked.string("DQMIO.root")
710 )
711 """
712  empty_path = re.compile(r'.*\b(process\.)?DQMOutput = cms\.(Final|End)Path\( *\).*')
713  other_path = re.compile(r'(.*\b(process\.)?DQMOutput = cms\.(Final|End)Path\()(.*)')
714  if empty_path.search(self.data):
715  # replace an empty DQMOutput path
716  self.data = empty_path.sub(dqmstore + '\n%(process)s.DQMOutput = cms.FinalPath( %(process)s.dqmOutput )\n', self.data)
717  elif other_path.search(self.data):
718  # prepend the dqmOutput to the DQMOutput path
719  self.data = other_path.sub(dqmstore + r'\g<1> %(process)s.dqmOutput +\g<4>', self.data)
720  else:
721  # create a new DQMOutput path with the dqmOutput module
722  self.data += dqmstore
723  self.data += '\n%(process)s.DQMOutput = cms.FinalPath( %(process)s.dqmOutput )\n'
724  self.data += '%(process)s.schedule.append( %(process)s.DQMOutput )\n'
725 
726 
727  @staticmethod
728  def dumppaths(paths):
729  sys.stderr.write('Path selection:\n')
730  for path in paths:
731  sys.stderr.write('\t%s\n' % path)
732  sys.stderr.write('\n\n')
733 
734  def buildPathList(self):
735  self.all_paths = self.getPathList()
736 
737  if self.config.paths:
738  # no path list was requested, dump the full table, minus unsupported / unwanted paths
739  paths = self.config.paths.split(',')
740  else:
741  # dump only the requested paths, plus the eventual output endpaths
742  paths = []
743 
744  # 'none' should remove all outputs
745  # 'dqm' should remove all outputs but DQMHistograms
746  # 'minimal' should remove all outputs but DQMHistograms, and add a single output module to keep the TriggerResults and TriggerEvent
747  # 'full' should remove all outputs but DQMHistograms, and add a single output module to "keep *"
748  # See also the `overrideOutput` method
749  if self.config.fragment or self.config.output in ('none', ):
750  if self.config.paths:
751  # keep only the Paths and EndPaths requested explicitly
752  pass
753  else:
754  # drop all output EndPaths but the Scouting ones, and drop the RatesMonitoring and DQMHistograms
755  paths.append( "-*Output" )
756  paths.append( "-RatesMonitoring")
757  paths.append( "-DQMHistograms")
758  if self.config.fragment: paths.append( "Scouting*Output" )
759 
760  elif self.config.output in ('dqm', 'minimal', 'full'):
761  if self.config.paths:
762  # keep only the Paths and EndPaths requested explicitly, and the DQMHistograms
763  paths.append( "DQMHistograms" )
764  else:
765  # drop all output EndPaths but the Scouting ones, and drop the RatesMonitoring
766  paths.append( "-*Output" )
767  paths.append( "-RatesMonitoring")
768  if self.config.fragment: paths.append( "Scouting*Output" )
769 
770  else:
771  if self.config.paths:
772  # keep all output EndPaths, including the DQMHistograms
773  paths.append( "*Output" )
774  paths.append( "DQMHistograms" )
775  else:
776  # keep all Paths and EndPaths
777  pass
778 
779  # drop unwanted paths for profiling (and timing studies)
780  if self.config.profiling:
781  paths.append( "-HLTAnalyzerEndpath" )
782 
783  # this should never be in any dump (nor online menu)
784  paths.append( "-OfflineOutput" )
785 
786  # expand all wildcards
787  paths = self.expandWildcards(paths, self.all_paths)
788 
789  if self.config.paths:
790  # do an "additive" consolidation
791  paths = self.consolidatePositiveList(paths)
792  if not paths:
793  raise RuntimeError('Error: option "--paths %s" does not select any valid paths' % self.config.paths)
794  else:
795  # do a "subtractive" consolidation
796  paths = self.consolidateNegativeList(paths)
797  self.options['paths'] = paths
798 
799  def buildOptions(self):
800  # common configuration for all scenarios
801  self.options['services'].append( "-DQM" )
802  self.options['services'].append( "-FUShmDQMOutputService" )
803  self.options['services'].append( "-MicroStateService" )
804  self.options['services'].append( "-ModuleWebRegistry" )
805  self.options['services'].append( "-TimeProfilerService" )
806 
807  # remove the DAQ modules and the online definition of the DQMStore and DQMFileSaver
808  # unless a hilton-like configuration has been requested
809  if not self.config.hilton:
810  self.options['services'].append( "-EvFDaqDirector" )
811  self.options['services'].append( "-FastMonitoringService" )
812  self.options['services'].append( "-DQMStore" )
813  self.options['modules'].append( "-hltDQMFileSaver" )
814  self.options['modules'].append( "-hltDQMFileSaverPB" )
815 
816  if self.config.fragment:
817  # extract a configuration file fragment
818  self.options['essources'].append( "-GlobalTag" )
819  self.options['essources'].append( "-HepPDTESSource" )
820  self.options['essources'].append( "-XMLIdealGeometryESSource" )
821  self.options['essources'].append( "-eegeom" )
822  self.options['essources'].append( "-es_hardcode" )
823  self.options['essources'].append( "-magfield" )
824 
825  self.options['esmodules'].append( "-SlaveField0" )
826  self.options['esmodules'].append( "-SlaveField20" )
827  self.options['esmodules'].append( "-SlaveField30" )
828  self.options['esmodules'].append( "-SlaveField35" )
829  self.options['esmodules'].append( "-SlaveField38" )
830  self.options['esmodules'].append( "-SlaveField40" )
831  self.options['esmodules'].append( "-VBF0" )
832  self.options['esmodules'].append( "-VBF20" )
833  self.options['esmodules'].append( "-VBF30" )
834  self.options['esmodules'].append( "-VBF35" )
835  self.options['esmodules'].append( "-VBF38" )
836  self.options['esmodules'].append( "-VBF40" )
837  self.options['esmodules'].append( "-CSCGeometryESModule" )
838  self.options['esmodules'].append( "-CaloGeometryBuilder" )
839  self.options['esmodules'].append( "-CaloTowerHardcodeGeometryEP" )
840  self.options['esmodules'].append( "-CastorHardcodeGeometryEP" )
841  self.options['esmodules'].append( "-DTGeometryESModule" )
842  self.options['esmodules'].append( "-EcalBarrelGeometryEP" )
843  self.options['esmodules'].append( "-EcalElectronicsMappingBuilder" )
844  self.options['esmodules'].append( "-EcalEndcapGeometryEP" )
845  self.options['esmodules'].append( "-EcalLaserCorrectionService" )
846  self.options['esmodules'].append( "-EcalPreshowerGeometryEP" )
847  self.options['esmodules'].append( "-GEMGeometryESModule" )
848  self.options['esmodules'].append( "-HcalHardcodeGeometryEP" )
849  self.options['esmodules'].append( "-HcalTopologyIdealEP" )
850  self.options['esmodules'].append( "-MuonNumberingInitialization" )
851  self.options['esmodules'].append( "-ParametrizedMagneticFieldProducer" )
852  self.options['esmodules'].append( "-RPCGeometryESModule" )
853  self.options['esmodules'].append( "-SiStripGainESProducer" )
854  self.options['esmodules'].append( "-SiStripRecHitMatcherESProducer" )
855  self.options['esmodules'].append( "-SiStripQualityESProducer" )
856  self.options['esmodules'].append( "-StripCPEfromTrackAngleESProducer" )
857  self.options['esmodules'].append( "-TrackerAdditionalParametersPerDetESModule" )
858  self.options['esmodules'].append( "-TrackerDigiGeometryESModule" )
859  self.options['esmodules'].append( "-TrackerGeometricDetESModule" )
860  self.options['esmodules'].append( "-VolumeBasedMagneticFieldESProducer" )
861  self.options['esmodules'].append( "-ZdcHardcodeGeometryEP" )
862  self.options['esmodules'].append( "-hcal_db_producer" )
863  self.options['esmodules'].append( "-L1GtTriggerMaskAlgoTrigTrivialProducer" )
864  self.options['esmodules'].append( "-L1GtTriggerMaskTechTrigTrivialProducer" )
865  self.options['esmodules'].append( "-hltESPEcalTrigTowerConstituentsMapBuilder" )
866  self.options['esmodules'].append( "-hltESPGlobalTrackingGeometryESProducer" )
867  self.options['esmodules'].append( "-hltESPMuonDetLayerGeometryESProducer" )
868  self.options['esmodules'].append( "-hltESPTrackerRecoGeometryESProducer" )
869  self.options['esmodules'].append( "-trackerTopology" )
870 
871  self.options['esmodules'].append( "-CaloTowerGeometryFromDBEP" )
872  self.options['esmodules'].append( "-CastorGeometryFromDBEP" )
873  self.options['esmodules'].append( "-EcalBarrelGeometryFromDBEP" )
874  self.options['esmodules'].append( "-EcalEndcapGeometryFromDBEP" )
875  self.options['esmodules'].append( "-EcalPreshowerGeometryFromDBEP" )
876  self.options['esmodules'].append( "-HcalGeometryFromDBEP" )
877  self.options['esmodules'].append( "-ZdcGeometryFromDBEP" )
878  self.options['esmodules'].append( "-XMLFromDBSource" )
879  self.options['esmodules'].append( "-sistripconn" )
880 
881  self.options['services'].append( "-MessageLogger" )
882 
883  self.options['psets'].append( "-maxEvents" )
884  self.options['psets'].append( "-options" )
885 
886  # remove Scouting OutputModules even though the EndPaths are kept
887  self.options['modules'].append( "-hltOutputScoutingCaloMuon" )
888  self.options['modules'].append( "-hltOutputScoutingPF" )
889 
890  if self.config.fragment or (self.config.prescale and (self.config.prescale.lower() == 'none')):
891  self.options['services'].append( "-PrescaleService" )
892 
893  if self.config.fragment or self.config.timing:
894  self.options['services'].append( "-FastTimerService" )
895  self.options['services'].append( "-ThroughputService" )
896 
897 
898  def append_filenames(self, name, filenames):
899  if len(filenames) > 255:
900  token_open = "( *("
901  token_close = ") )"
902  else:
903  token_open = "("
904  token_close = ")"
905 
906  self.data += " %s = cms.untracked.vstring%s\n" % (name, token_open)
907  for line in filenames:
908  self.data += " '%s',\n" % line
909  self.data += " %s,\n" % (token_close)
910 
911 
912  def expand_filenames(self, input):
913  # check if the input is a dataset or a list of files
914  if input[0:8] == 'dataset:':
915  from .dasFileQuery import dasFileQuery
916  # extract the dataset name, and use DAS to fine the list of LFNs
917  dataset = input[8:]
918  files = dasFileQuery(dataset)
919  else:
920  # assume a comma-separated list of input files
921  files = input.split(',')
922  return files
923 
924  def build_source(self):
925  if self.config.hilton:
926  # use the DAQ source
927  return
928 
929  if self.config.input:
930  # if a dataset or a list of input files was given, use it
931  self.source = self.expand_filenames(self.config.input)
932  elif self.config.data:
933  # offline we can run on data...
934  self.source = [ "file:RelVal_Raw_%s_DATA.root" % self.config.type ]
935  else:
936  # ...or on mc
937  self.source = [ "file:RelVal_Raw_%s_MC.root" % self.config.type ]
938 
939  if self.config.parent:
940  # if a dataset or a list of input files was given for the parent data, use it
941  self.parent = self.expand_filenames(self.config.parent)
942 
943  self.data += """
944 # source module (EDM inputs)
945 %(process)s.source = cms.Source( "PoolSource",
946 """
947  self.append_filenames("fileNames", self.source)
948  if (self.parent):
949  self.append_filenames("secondaryFileNames", self.parent)
950  self.data += """\
951  inputCommands = cms.untracked.vstring(
952  'keep *'
953  )
954 )
955 """
def removeElementFromSequencesTasksAndPaths(self, label)
Definition: confdb.py:625
def __init__(self, configuration)
Definition: confdb.py:23
def splitter(iterator, n)
Definition: confdb.py:11
def loadSetupCff(self)
Definition: confdb.py:548
def addGlobalOptions(self)
Definition: confdb.py:319
def getSetupConfigurationFromDB(self)
Definition: confdb.py:60
def overrideProcessName(self)
Definition: confdb.py:555
def runL1Emulator(self)
Definition: confdb.py:454
def instrumentErrorEventType(self)
Definition: confdb.py:392
def buildOptions(self)
Definition: confdb.py:799
def replace(string, replacements)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
def overrideOutput(self)
Definition: confdb.py:464
def dump(self)
Definition: confdb.py:167
def getPathList(self)
Definition: confdb.py:101
def customize(self)
Definition: confdb.py:241
Definition: query.py:1
def addEras(self)
Definition: confdb.py:540
def expand_filenames(self, input)
Definition: confdb.py:912
def updateMessageLogger(self)
Definition: confdb.py:575
def overrideL1MenuXml(self)
Definition: confdb.py:444
def overrideGlobalTag(self)
Definition: confdb.py:400
def specificCustomize(self)
Definition: confdb.py:176
def consolidatePositiveList(elements)
Definition: confdb.py:154
def overrideParameters(self, module, parameters)
Definition: confdb.py:617
def instrumentOpenMode(self)
Definition: confdb.py:378
def dumppaths(paths)
Definition: confdb.py:728
def getRawConfigurationFromDB(self)
Definition: confdb.py:83
def loadAdditionalConditions(self, comment, conditions)
Definition: confdb.py:589
def build_source(self)
Definition: confdb.py:924
def loadCffCommand(self, module)
Definition: confdb.py:606
def instrumentDQM(self)
Definition: confdb.py:696
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def loadCff(self, module)
Definition: confdb.py:613
def buildPathList(self)
Definition: confdb.py:734
def fixPrescales(self)
Definition: confdb.py:354
def consolidateNegativeList(elements)
Definition: confdb.py:142
def instrumentTiming(self)
Definition: confdb.py:633
def expandWildcards(globs, collection)
Definition: confdb.py:126
def _fix_parameter(self, args)
Definition: confdb.py:335
def append_filenames(self, name, filenames)
Definition: confdb.py:898