CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConfigBuilder.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 __version__ = "$Revision: 1.19 $"
4 __source__ = "$Source: /local/reps/CMSSW/CMSSW/Configuration/Applications/python/ConfigBuilder.py,v $"
5 
6 import FWCore.ParameterSet.Config as cms
7 from FWCore.ParameterSet.Modules import _Module
8 import sys
9 import re
10 
11 class Options:
12  pass
13 
14 # the canonical defaults
15 defaultOptions = Options()
16 defaultOptions.datamix = 'DataOnSim'
17 defaultOptions.isMC=False
18 defaultOptions.isData=True
19 defaultOptions.step=''
20 defaultOptions.pileup='NoPileUp'
21 defaultOptions.pileup_input = None
22 defaultOptions.geometry = 'SimDB'
23 defaultOptions.geometryExtendedOptions = ['ExtendedGFlash','Extended','NoCastor']
24 defaultOptions.magField = '38T'
25 defaultOptions.conditions = None
26 defaultOptions.useCondDBv1 = False
27 defaultOptions.scenarioOptions=['pp','cosmics','nocoll','HeavyIons']
28 defaultOptions.harvesting= 'AtRunEnd'
29 defaultOptions.gflash = False
30 defaultOptions.himix = False
31 defaultOptions.number = -1
32 defaultOptions.number_out = None
33 defaultOptions.arguments = ""
34 defaultOptions.name = "NO NAME GIVEN"
35 defaultOptions.evt_type = ""
36 defaultOptions.filein = ""
37 defaultOptions.dasquery=""
38 defaultOptions.secondfilein = ""
39 defaultOptions.customisation_file = []
40 defaultOptions.customisation_file_unsch = []
41 defaultOptions.customise_commands = ""
42 defaultOptions.inline_custom=False
43 defaultOptions.particleTable = 'pythiapdt'
44 defaultOptions.particleTableList = ['pythiapdt','pdt']
45 defaultOptions.dirin = ''
46 defaultOptions.dirout = ''
47 defaultOptions.filetype = 'EDM'
48 defaultOptions.fileout = 'output.root'
49 defaultOptions.filtername = ''
50 defaultOptions.lazy_download = False
51 defaultOptions.custom_conditions = ''
52 defaultOptions.hltProcess = ''
53 defaultOptions.eventcontent = None
54 defaultOptions.datatier = None
55 defaultOptions.inlineEventContent = True
56 defaultOptions.inlineObjets =''
57 defaultOptions.hideGen=False
58 from Configuration.StandardSequences.VtxSmeared import VtxSmearedDefaultKey,VtxSmearedHIDefaultKey
59 defaultOptions.beamspot=None
60 defaultOptions.outputDefinition =''
61 defaultOptions.inputCommands = None
62 defaultOptions.outputCommands = None
63 defaultOptions.inputEventContent = ''
64 defaultOptions.dropDescendant = False
65 defaultOptions.relval = None
66 defaultOptions.slhc = None
67 defaultOptions.profile = None
68 defaultOptions.isRepacked = False
69 defaultOptions.restoreRNDSeeds = False
70 defaultOptions.donotDropOnInput = ''
71 defaultOptions.python_filename =''
72 defaultOptions.io=None
73 defaultOptions.lumiToProcess=None
74 defaultOptions.fast=False
75 defaultOptions.runsAndWeightsForMC = None
76 defaultOptions.runsScenarioForMC = None
77 defaultOptions.runUnscheduled = False
78 defaultOptions.timeoutOutput = False
79 
80 # some helper routines
81 def dumpPython(process,name):
82  theObject = getattr(process,name)
83  if isinstance(theObject,cms.Path) or isinstance(theObject,cms.EndPath) or isinstance(theObject,cms.Sequence):
84  return "process."+name+" = " + theObject.dumpPython("process")
85  elif isinstance(theObject,_Module) or isinstance(theObject,cms.ESProducer):
86  return "process."+name+" = " + theObject.dumpPython()+"\n"
87  else:
88  return "process."+name+" = " + theObject.dumpPython()+"\n"
89 def filesFromList(fileName,s=None):
90  import os
91  import FWCore.ParameterSet.Config as cms
92  prim=[]
93  sec=[]
94  for line in open(fileName,'r'):
95  if line.count(".root")>=2:
96  #two files solution...
97  entries=line.replace("\n","").split()
98  if not entries[0] in prim:
99  prim.append(entries[0])
100  if not entries[1] in sec:
101  sec.append(entries[1])
102  elif (line.find(".root")!=-1):
103  entry=line.replace("\n","")
104  if not entry in prim:
105  prim.append(entry)
106  if s:
107  if not hasattr(s,"fileNames"):
108  s.fileNames=cms.untracked.vstring(prim)
109  else:
110  s.fileNames.extend(prim)
111  if len(sec)!=0:
112  if not hasattr(s,"secondaryFileNames"):
113  s.secondaryFileNames=cms.untracked.vstring(sec)
114  else:
115  s.secondaryFileNames.extend(sec)
116  print "found files: ",prim
117  if len(prim)==0:
118  raise Exception("There are not files in input from the file list")
119  if len(sec)!=0:
120  print "found parent files:",sec
121  return (prim,sec)
122 
123 def filesFromDASQuery(query,s=None):
124  import os
125  import FWCore.ParameterSet.Config as cms
126  prim=[]
127  sec=[]
128  print "the query is",query
129  for line in os.popen('das_client.py --query "%s"'%(query)):
130  if line.count(".root")>=2:
131  #two files solution...
132  entries=line.replace("\n","").split()
133  if not entries[0] in prim:
134  prim.append(entries[0])
135  if not entries[1] in sec:
136  sec.append(entries[1])
137  elif (line.find(".root")!=-1):
138  entry=line.replace("\n","")
139  if not entry in prim:
140  prim.append(entry)
141  if s:
142  if not hasattr(s,"fileNames"):
143  s.fileNames=cms.untracked.vstring(prim)
144  else:
145  s.fileNames.extend(prim)
146  if len(sec)!=0:
147  if not hasattr(s,"secondaryFileNames"):
148  s.secondaryFileNames=cms.untracked.vstring(sec)
149  else:
150  s.secondaryFileNames.extend(sec)
151  print "found files: ",prim
152  if len(sec)!=0:
153  print "found parent files:",sec
154  return (prim,sec)
155 
156 def MassReplaceInputTag(aProcess,oldT="rawDataCollector",newT="rawDataRepacker"):
157  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
158  for s in aProcess.paths_().keys():
159  massSearchReplaceAnyInputTag(getattr(aProcess,s),oldT,newT)
160 
161 
162 class ConfigBuilder(object):
163  """The main building routines """
164 
165  def __init__(self, options, process = None, with_output = False, with_input = False ):
166  """options taken from old cmsDriver and optparse """
167 
168  options.outfile_name = options.dirout+options.fileout
169 
170  self._options = options
171 
172  if self._options.isData and options.isMC:
173  raise Exception("ERROR: You may specify only --data or --mc, not both")
174  #if not self._options.conditions:
175  # raise Exception("ERROR: No conditions given!\nPlease specify conditions. E.g. via --conditions=IDEAL_30X::All")
176 
177  if hasattr(self._options,"datatier") and self._options.datatier and 'DQMIO' in self._options.datatier and 'ENDJOB' in self._options.step:
178  self._options.step=self._options.step.replace(',ENDJOB','')
179 
180  # what steps are provided by this class?
181  stepList = [re.sub(r'^prepare_', '', methodName) for methodName in ConfigBuilder.__dict__ if methodName.startswith('prepare_')]
182  self.stepMap={}
183  self.stepKeys=[]
184  for step in self._options.step.split(","):
185  if step=='': continue
186  stepParts = step.split(":")
187  stepName = stepParts[0]
188  if stepName not in stepList and not stepName.startswith('re'):
189  raise ValueError("Step "+stepName+" unknown")
190  if len(stepParts)==1:
191  self.stepMap[stepName]=""
192  elif len(stepParts)==2:
193  self.stepMap[stepName]=stepParts[1].split('+')
194  elif len(stepParts)==3:
195  self.stepMap[stepName]=(stepParts[2].split('+'),stepParts[1])
196  else:
197  raise ValueError("Step definition "+step+" invalid")
198  self.stepKeys.append(stepName)
199 
200  #print "map of steps is:",self.stepMap
201 
202  if 'FASTSIM' in self.stepMap:
203  #overriding the --fast option to True
204  self._options.fast=True
205 
206  self.with_output = with_output
207  if hasattr(self._options,"no_output_flag") and self._options.no_output_flag:
208  self.with_output = False
209  self.with_input = with_input
210  if process == None:
211  self.process = cms.Process(self._options.name)
212  else:
213  self.process = process
214  self.imports = []
215  self.importsUnsch = []
216  self.define_Configs()
217  self.schedule = list()
218 
219  # we are doing three things here:
220  # creating a process to catch errors
221  # building the code to re-create the process
222 
223  self.additionalCommands = []
224  # TODO: maybe a list of to be dumped objects would help as well
225  self.blacklist_paths = []
226  self.addedObjects = []
227  self.additionalOutputs = {}
228 
229  self.productionFilterSequence = None
230  self.nextScheduleIsConditional=False
231  self.conditionalPaths=[]
232  self.excludedPaths=[]
233 
234  def profileOptions(self):
235  """
236  addIgProfService
237  Function to add the igprof profile service so that you can dump in the middle
238  of the run.
239  """
240  profileOpts = self._options.profile.split(':')
241  profilerStart = 1
242  profilerInterval = 100
243  profilerFormat = None
244  profilerJobFormat = None
245 
246  if len(profileOpts):
247  #type, given as first argument is unused here
248  profileOpts.pop(0)
249  if len(profileOpts):
250  startEvent = profileOpts.pop(0)
251  if not startEvent.isdigit():
252  raise Exception("%s is not a number" % startEvent)
253  profilerStart = int(startEvent)
254  if len(profileOpts):
255  eventInterval = profileOpts.pop(0)
256  if not eventInterval.isdigit():
257  raise Exception("%s is not a number" % eventInterval)
258  profilerInterval = int(eventInterval)
259  if len(profileOpts):
260  profilerFormat = profileOpts.pop(0)
261 
262 
263  if not profilerFormat:
264  profilerFormat = "%s___%s___%s___%s___%s___%s___%%I.gz" % (self._options.evt_type.replace("_cfi", ""),
265  self._options.step,
266  self._options.pileup,
267  self._options.conditions,
268  self._options.datatier,
269  self._options.profileTypeLabel)
270  if not profilerJobFormat and profilerFormat.endswith(".gz"):
271  profilerJobFormat = profilerFormat.replace(".gz", "_EndOfJob.gz")
272  elif not profilerJobFormat:
273  profilerJobFormat = profilerFormat + "_EndOfJob.gz"
274 
275  return (profilerStart,profilerInterval,profilerFormat,profilerJobFormat)
276 
277  def load(self,includeFile):
278  includeFile = includeFile.replace('/','.')
279  self.process.load(includeFile)
280  return sys.modules[includeFile]
281 
282  def loadAndRemember(self, includeFile,unsch=0):
283  """helper routine to load am memorize imports"""
284  # we could make the imports a on-the-fly data method of the process instance itself
285  # not sure if the latter is a good idea
286  includeFile = includeFile.replace('/','.')
287  if unsch==0:
288  self.imports.append(includeFile)
289  self.process.load(includeFile)
290  return sys.modules[includeFile]
291  else:
292  self.importsUnsch.append(includeFile)
293  return 0#sys.modules[includeFile]
294 
295  def executeAndRemember(self, command):
296  """helper routine to remember replace statements"""
297  self.additionalCommands.append(command)
298  if not command.strip().startswith("#"):
299  # substitute: process.foo = process.bar -> self.process.foo = self.process.bar
300  import re
301  exec(re.sub(r"([^a-zA-Z_0-9]|^)(process)([^a-zA-Z_0-9])",r"\1self.process\3",command))
302  #exec(command.replace("process.","self.process."))
303 
304  def addCommon(self):
305  if 'HARVESTING' in self.stepMap.keys() or 'ALCAHARVEST' in self.stepMap.keys():
306  self.process.options = cms.untracked.PSet( Rethrow = cms.untracked.vstring('ProductNotFound'),fileMode = cms.untracked.string('FULLMERGE'))
307  else:
308  self.process.options = cms.untracked.PSet( )
309 
310  if self._options.runUnscheduled:
311  self.process.options.allowUnscheduled=cms.untracked.bool(True)
312 
313  self.addedObjects.append(("","options"))
314 
315  if self._options.lazy_download:
316  self.process.AdaptorConfig = cms.Service("AdaptorConfig",
317  stats = cms.untracked.bool(True),
318  enable = cms.untracked.bool(True),
319  cacheHint = cms.untracked.string("lazy-download"),
320  readHint = cms.untracked.string("read-ahead-buffered")
321  )
322  self.addedObjects.append(("Setup lazy download","AdaptorConfig"))
323 
324  #self.process.cmsDriverCommand = cms.untracked.PSet( command=cms.untracked.string('cmsDriver.py '+self._options.arguments) )
325  #self.addedObjects.append(("what cmsDriver command was used","cmsDriverCommand"))
326 
327  if self._options.profile:
328  (start, interval, eventFormat, jobFormat)=self.profileOptions()
329  self.process.IgProfService = cms.Service("IgProfService",
330  reportFirstEvent = cms.untracked.int32(start),
331  reportEventInterval = cms.untracked.int32(interval),
332  reportToFileAtPostEvent = cms.untracked.string("| gzip -c > %s"%(eventFormat)),
333  reportToFileAtPostEndJob = cms.untracked.string("| gzip -c > %s"%(jobFormat)))
334  self.addedObjects.append(("Setup IGProf Service for profiling","IgProfService"))
335 
336  def addMaxEvents(self):
337  """Here we decide how many evts will be processed"""
338  self.process.maxEvents=cms.untracked.PSet(input=cms.untracked.int32(int(self._options.number)))
339  if self._options.number_out:
340  self.process.maxEvents.output = cms.untracked.int32(int(self._options.number_out))
341  self.addedObjects.append(("","maxEvents"))
342 
343  def addSource(self):
344  """Here the source is built. Priority: file, generator"""
345  self.addedObjects.append(("Input source","source"))
346 
347  def filesFromOption(self):
348  for entry in self._options.filein.split(','):
349  print "entry",entry
350  if entry.startswith("filelist:"):
351  filesFromList(entry[9:],self.process.source)
352  elif entry.startswith("dbs:") or entry.startswith("das:"):
353  filesFromDASQuery('file dataset = %s'%(entry[4:]),self.process.source)
354  else:
355  self.process.source.fileNames.append(self._options.dirin+entry)
356  if self._options.secondfilein:
357  if not hasattr(self.process.source,"secondaryFileNames"):
358  raise Exception("--secondfilein not compatible with "+self._options.filetype+"input type")
359  for entry in self._options.secondfilein.split(','):
360  print "entry",entry
361  if entry.startswith("filelist:"):
362  self.process.source.secondaryFileNames.extend((filesFromList(entry[9:]))[0])
363  elif entry.startswith("dbs:") or entry.startswith("das:"):
364  self.process.source.secondaryFileNames.extend((filesFromDASQuery('file dataset = %s'%(entry[4:])))[0])
365  else:
366  self.process.source.secondaryFileNames.append(self._options.dirin+entry)
367 
368  if self._options.filein or self._options.dasquery:
369  if self._options.filetype == "EDM":
370  self.process.source=cms.Source("PoolSource",
371  fileNames = cms.untracked.vstring(),
372  secondaryFileNames= cms.untracked.vstring())
373  filesFromOption(self)
374  elif self._options.filetype == "DAT":
375  self.process.source=cms.Source("NewEventStreamFileReader",fileNames = cms.untracked.vstring())
376  filesFromOption(self)
377  elif self._options.filetype == "LHE":
378  self.process.source=cms.Source("LHESource", fileNames = cms.untracked.vstring())
379  if self._options.filein.startswith("lhe:"):
380  #list the article directory automatically
381  args=self._options.filein.split(':')
382  article=args[1]
383  print 'LHE input from article ',article
384  location='/store/lhe/'
385  import os
386  textOfFiles=os.popen('cmsLHEtoEOSManager.py -l '+article)
387  for line in textOfFiles:
388  for fileName in [x for x in line.split() if '.lhe' in x]:
389  self.process.source.fileNames.append(location+article+'/'+fileName)
390  if len(args)>2:
391  self.process.source.skipEvents = cms.untracked.uint32(int(args[2]))
392  else:
393  filesFromOption(self)
394 
395 
396  elif self._options.filetype == "DQM":
397  self.process.source=cms.Source("DQMRootSource",
398  fileNames = cms.untracked.vstring())
399  filesFromOption(self)
400 
401  elif self._options.filetype == "DQMDAQ":
402  # FIXME: how to configure it if there are no input files specified?
403  self.process.source=cms.Source("DQMStreamerReader")
404 
405 
406  if ('HARVESTING' in self.stepMap.keys() or 'ALCAHARVEST' in self.stepMap.keys()) and (not self._options.filetype == "DQM"):
407  self.process.source.processingMode = cms.untracked.string("RunsAndLumis")
408 
409  if self._options.dasquery!='':
410  self.process.source=cms.Source("PoolSource", fileNames = cms.untracked.vstring(),secondaryFileNames = cms.untracked.vstring())
411  filesFromDASQuery(self._options.dasquery,self.process.source)
412 
413  if self._options.inputCommands:
414  if not hasattr(self.process.source,'inputCommands'): self.process.source.inputCommands=cms.untracked.vstring()
415  for command in self._options.inputCommands.split(','):
416  # remove whitespace around the keep/drop statements
417  command = command.strip()
418  if command=='': continue
419  self.process.source.inputCommands.append(command)
420  if not self._options.dropDescendant:
421  self.process.source.dropDescendantsOfDroppedBranches = cms.untracked.bool(False)
422 
423  if self._options.lumiToProcess:
424  import FWCore.PythonUtilities.LumiList as LumiList
425  self.process.source.lumisToProcess = cms.untracked.VLuminosityBlockRange( LumiList.LumiList(self._options.lumiToProcess).getCMSSWString().split(',') )
426 
427  if 'GEN' in self.stepMap.keys() or 'LHE' in self.stepMap or (not self._options.filein and hasattr(self._options, "evt_type")):
428  if self.process.source is None:
429  self.process.source=cms.Source("EmptySource")
430  # if option himix is active, drop possibly duplicate DIGI-RAW info:
431  if self._options.himix==True:
432  self.process.source.inputCommands = cms.untracked.vstring('drop *','keep *_generator_*_*','keep *_g4SimHits_*_*')
433  self.process.source.dropDescendantsOfDroppedBranches=cms.untracked.bool(False)
434 
435  # modify source in case of run-dependent MC
436  self.runsAndWeights=None
437  if self._options.runsAndWeightsForMC or self._options.runsScenarioForMC :
438  if not self._options.isMC :
439  raise Exception("options --runsAndWeightsForMC and --runsScenarioForMC are only valid for MC")
440  if self._options.runsAndWeightsForMC:
441  self.runsAndWeights = eval(self._options.runsAndWeightsForMC)
442  else:
443  from Configuration.StandardSequences.RunsAndWeights import RunsAndWeights
444  if type(RunsAndWeights[self._options.runsScenarioForMC])==str:
445  __import__(RunsAndWeights[self._options.runsScenarioForMC])
446  self.runsAndWeights = sys.modules[RunsAndWeights[self._options.runsScenarioForMC]].runProbabilityDistribution
447  else:
448  self.runsAndWeights = RunsAndWeights[self._options.runsScenarioForMC]
449 
450  if self.runsAndWeights:
451  import SimGeneral.Configuration.ThrowAndSetRandomRun as ThrowAndSetRandomRun
452  ThrowAndSetRandomRun.throwAndSetRandomRun(self.process.source,self.runsAndWeights)
453  self.additionalCommands.append('import SimGeneral.Configuration.ThrowAndSetRandomRun as ThrowAndSetRandomRun')
454  self.additionalCommands.append('ThrowAndSetRandomRun.throwAndSetRandomRun(process.source,%s)'%(self.runsAndWeights))
455 
456  return
457 
458  def addOutput(self):
459  """ Add output module to the process """
460  result=""
461  if self._options.outputDefinition:
462  if self._options.datatier:
463  print "--datatier & --eventcontent options ignored"
464 
465  def anyOf(listOfKeys,dict,opt=None):
466  for k in listOfKeys:
467  if k in dict:
468  toReturn=dict[k]
469  dict.pop(k)
470  return toReturn
471  if opt!=None:
472  return opt
473  else:
474  raise Exception("any of "+','.join(listOfKeys)+" are mandatory entries of --output options")
475 
476  #new output convention with a list of dict
477  outList = eval(self._options.outputDefinition)
478  for (id,outDefDict) in enumerate(outList):
479  outDefDictStr=outDefDict.__str__()
480  if not isinstance(outDefDict,dict):
481  raise Exception("--output needs to be passed a list of dict"+self._options.outputDefinition+" is invalid")
482  #requires option: tier
483  theTier=anyOf(['t','tier','dataTier'],outDefDict)
484  #optional option: eventcontent, filtername, selectEvents, moduleLabel, filename
485  ## event content
486  theStreamType=anyOf(['e','ec','eventContent','streamType'],outDefDict,theTier)
487  theFilterName=anyOf(['f','ftN','filterName'],outDefDict,'')
488  theSelectEvent=anyOf(['s','sE','selectEvents'],outDefDict,'')
489  theModuleLabel=anyOf(['l','mL','moduleLabel'],outDefDict,'')
490  theExtraOutputCommands=anyOf(['o','oC','outputCommands'],outDefDict,'')
491  # module label has a particular role
492  if not theModuleLabel:
493  tryNames=[theStreamType.replace(theTier.replace('-',''),'')+theTier.replace('-','')+'output',
494  theStreamType.replace(theTier.replace('-',''),'')+theTier.replace('-','')+theFilterName+'output',
495  theStreamType.replace(theTier.replace('-',''),'')+theTier.replace('-','')+theFilterName+theSelectEvent.split(',')[0].replace(':','for').replace(' ','')+'output'
496  ]
497  for name in tryNames:
498  if not hasattr(self.process,name):
499  theModuleLabel=name
500  break
501  if not theModuleLabel:
502  raise Exception("cannot find a module label for specification: "+outDefDictStr)
503  if id==0:
504  defaultFileName=self._options.outfile_name
505  else:
506  defaultFileName=self._options.outfile_name.replace('.root','_in'+theTier+'.root')
507 
508  theFileName=self._options.dirout+anyOf(['fn','fileName'],outDefDict,defaultFileName)
509  if not theFileName.endswith('.root'):
510  theFileName+='.root'
511 
512  if len(outDefDict.keys()):
513  raise Exception("unused keys from --output options: "+','.join(outDefDict.keys()))
514  if theStreamType=='DQMIO': theStreamType='DQM'
515  if theStreamType=='ALL':
516  theEventContent = cms.PSet(outputCommands = cms.untracked.vstring('keep *'))
517  else:
518  theEventContent = getattr(self.process, theStreamType+"EventContent")
519 
520  if theStreamType=='ALCARECO' and not theFilterName:
521  theFilterName='StreamALCACombined'
522 
523  CppType='PoolOutputModule'
524  if self._options.timeoutOutput:
525  CppType='TimeoutPoolOutputModule'
526  if theStreamType=='DQM' and theTier=='DQMIO': CppType='DQMRootOutputModule'
527  output = cms.OutputModule(CppType,
528  theEventContent.clone(),
529  fileName = cms.untracked.string(theFileName),
530  dataset = cms.untracked.PSet(
531  dataTier = cms.untracked.string(theTier),
532  filterName = cms.untracked.string(theFilterName))
533  )
534  if not theSelectEvent and hasattr(self.process,'generation_step') and theStreamType!='LHE':
535  output.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring('generation_step'))
536  if not theSelectEvent and hasattr(self.process,'filtering_step'):
537  output.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring('filtering_step'))
538  if theSelectEvent:
539  output.SelectEvents =cms.untracked.PSet(SelectEvents = cms.vstring(theSelectEvent))
540 
541  if hasattr(self.process,theModuleLabel):
542  raise Exception("the current process already has a module "+theModuleLabel+" defined")
543  #print "creating output module ",theModuleLabel
544  setattr(self.process,theModuleLabel,output)
545  outputModule=getattr(self.process,theModuleLabel)
546  setattr(self.process,theModuleLabel+'_step',cms.EndPath(outputModule))
547  path=getattr(self.process,theModuleLabel+'_step')
548  self.schedule.append(path)
549 
550  if not self._options.inlineEventContent and hasattr(self.process,theStreamType+"EventContent"):
551  def doNotInlineEventContent(instance,label = "cms.untracked.vstring(process."+theStreamType+"EventContent.outputCommands)"):
552  return label
553  outputModule.outputCommands.__dict__["dumpPython"] = doNotInlineEventContent
554  if theExtraOutputCommands:
555  if not isinstance(theExtraOutputCommands,list):
556  raise Exception("extra ouput command in --option must be a list of strings")
557  if hasattr(self.process,theStreamType+"EventContent"):
558  self.executeAndRemember('process.%s.outputCommands.extend(%s)'%(theModuleLabel,theExtraOutputCommands))
559  else:
560  outputModule.outputCommands.extend(theExtraOutputCommands)
561 
562  result+="\nprocess."+theModuleLabel+" = "+outputModule.dumpPython()
563 
564  ##ends the --output options model
565  return result
566 
567  streamTypes=self._options.eventcontent.split(',')
568  tiers=self._options.datatier.split(',')
569  if not self._options.outputDefinition and len(streamTypes)!=len(tiers):
570  raise Exception("number of event content arguments does not match number of datatier arguments")
571 
572  # if the only step is alca we don't need to put in an output
573  if self._options.step.split(',')[0].split(':')[0] == 'ALCA':
574  return "\n"
575 
576  for i,(streamType,tier) in enumerate(zip(streamTypes,tiers)):
577  if streamType=='': continue
578  if streamType=='DQMIO': streamType='DQM'
579  theEventContent = getattr(self.process, streamType+"EventContent")
580  if i==0:
581  theFileName=self._options.outfile_name
582  theFilterName=self._options.filtername
583  else:
584  theFileName=self._options.outfile_name.replace('.root','_in'+streamType+'.root')
585  theFilterName=self._options.filtername
586  CppType='PoolOutputModule'
587  if self._options.timeoutOutput:
588  CppType='TimeoutPoolOutputModule'
589  if streamType=='DQM' and tier=='DQMIO': CppType='DQMRootOutputModule'
590  output = cms.OutputModule(CppType,
591  theEventContent,
592  fileName = cms.untracked.string(theFileName),
593  dataset = cms.untracked.PSet(dataTier = cms.untracked.string(tier),
594  filterName = cms.untracked.string(theFilterName)
595  )
596  )
597  if hasattr(self.process,"generation_step") and streamType!='LHE':
598  output.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring('generation_step'))
599  if hasattr(self.process,"filtering_step"):
600  output.SelectEvents = cms.untracked.PSet(SelectEvents = cms.vstring('filtering_step'))
601 
602  if streamType=='ALCARECO':
603  output.dataset.filterName = cms.untracked.string('StreamALCACombined')
604 
605  if "MINIAOD" in streamType:
606  output.dropMetaData = cms.untracked.string('ALL')
607  output.fastCloning= cms.untracked.bool(False)
608  output.overrideInputFileSplitLevels = cms.untracked.bool(True)
609 
610  outputModuleName=streamType+'output'
611  setattr(self.process,outputModuleName,output)
612  outputModule=getattr(self.process,outputModuleName)
613  setattr(self.process,outputModuleName+'_step',cms.EndPath(outputModule))
614  path=getattr(self.process,outputModuleName+'_step')
615  self.schedule.append(path)
616 
617  if self._options.outputCommands and streamType!='DQM':
618  for evct in self._options.outputCommands.split(','):
619  if not evct: continue
620  self.executeAndRemember("process.%s.outputCommands.append('%s')"%(outputModuleName,evct.strip()))
621 
622  if not self._options.inlineEventContent:
623  def doNotInlineEventContent(instance,label = "process."+streamType+"EventContent.outputCommands"):
624  return label
625  outputModule.outputCommands.__dict__["dumpPython"] = doNotInlineEventContent
626 
627  result+="\nprocess."+outputModuleName+" = "+outputModule.dumpPython()
628 
629  return result
630 
632  """
633  Add selected standard sequences to the process
634  """
635  # load the pile up file
636  if self._options.pileup:
637  pileupSpec=self._options.pileup.split(',')[0]
638  from Configuration.StandardSequences.Mixing import Mixing,defineMixing
639  if not pileupSpec in Mixing and '.' not in pileupSpec and 'file:' not in pileupSpec:
640  raise Exception(pileupSpec+' is not a know mixing scenario:\n available are: '+'\n'.join(Mixing.keys()))
641  if '.' in pileupSpec:
642  mixingDict={'file':pileupSpec}
643  elif pileupSpec.startswith('file:'):
644  mixingDict={'file':pileupSpec[5:]}
645  else:
646  import copy
647  mixingDict=copy.copy(Mixing[pileupSpec])
648  if len(self._options.pileup.split(','))>1:
649  mixingDict.update(eval(self._options.pileup[self._options.pileup.find(',')+1:]))
650  if 'file:' in pileupSpec:
651  #the file is local
652  self.process.load(mixingDict['file'])
653  print "inlining mixing module configuration"
654  self._options.inlineObjets+=',mix'
655  else:
656  self.loadAndRemember(mixingDict['file'])
657  if self._options.fast:
658  self._options.customisation_file.append("FastSimulation/Configuration/MixingModule_Full2Fast.setVertexGeneratorPileUpProducer")
659 
660  mixingDict.pop('file')
661  if not "DATAMIX" in self.stepMap.keys(): # when DATAMIX is present, pileup_input refers to pre-mixed GEN-RAW
662  if self._options.pileup_input:
663  if self._options.pileup_input.startswith('dbs:') or self._options.pileup_input.startswith('das:'):
664  mixingDict['F']=filesFromDASQuery('file dataset = %s'%(self._options.pileup_input[4:],))[0]
665  else:
666  mixingDict['F']=self._options.pileup_input.split(',')
667  specialization=defineMixing(mixingDict,self._options.fast)
668  for command in specialization:
669  self.executeAndRemember(command)
670  if len(mixingDict)!=0:
671  raise Exception('unused mixing specification: '+mixingDict.keys().__str__())
672 
673  if self._options.fast and not 'SIM' in self.stepMap and not 'FASTSIM' in self.stepMap:
674  self.executeAndRemember('process.mix.playback= True')
675 
676 
677  # load the geometry file
678  try:
679  if len(self.stepMap):
680  self.loadAndRemember(self.GeometryCFF)
681  if ('SIM' in self.stepMap or 'reSIM' in self.stepMap) and not self._options.fast:
682  self.loadAndRemember(self.SimGeometryCFF)
683  if self.geometryDBLabel:
684  self.executeAndRemember('process.XMLFromDBSource.label = cms.string("%s")'%(self.geometryDBLabel))
685  except ImportError:
686  print "Geometry option",self._options.geometry,"unknown."
687  raise
688 
689  if len(self.stepMap):
690  self.loadAndRemember(self.magFieldCFF)
691 
692  for stepName in self.stepKeys:
693  stepSpec = self.stepMap[stepName]
694  print "Step:", stepName,"Spec:",stepSpec
695  if stepName.startswith('re'):
696  ##add the corresponding input content
697  if stepName[2:] not in self._options.donotDropOnInput:
698  self._options.inputEventContent='%s,%s'%(stepName.upper(),self._options.inputEventContent)
699  stepName=stepName[2:]
700  if stepSpec=="":
701  getattr(self,"prepare_"+stepName)(sequence = getattr(self,stepName+"DefaultSeq"))
702  elif type(stepSpec)==list:
703  getattr(self,"prepare_"+stepName)(sequence = '+'.join(stepSpec))
704  elif type(stepSpec)==tuple:
705  getattr(self,"prepare_"+stepName)(sequence = ','.join([stepSpec[1],'+'.join(stepSpec[0])]))
706  else:
707  raise ValueError("Invalid step definition")
708 
709  if self._options.restoreRNDSeeds!=False:
710  #it is either True, or a process name
711  if self._options.restoreRNDSeeds==True:
712  self.executeAndRemember('process.RandomNumberGeneratorService.restoreStateLabel=cms.untracked.string("randomEngineStateProducer")')
713  else:
714  self.executeAndRemember('process.RandomNumberGeneratorService.restoreStateTag=cms.untracked.InputTag("randomEngineStateProducer","","%s")'%(self._options.restoreRNDSeeds))
715  if self._options.inputEventContent or self._options.inputCommands:
716  if self._options.inputCommands:
717  self._options.inputCommands+='keep *_randomEngineStateProducer_*_*,'
718  else:
719  self._options.inputCommands='keep *_randomEngineStateProducer_*_*,'
720 
721 
723  if self._options.inputEventContent:
724  import copy
725  def dropSecondDropStar(iec):
726  #drop occurence of 'drop *' in the list
727  count=0
728  for item in iec:
729  if item=='drop *':
730  if count!=0:
731  iec.remove(item)
732  count+=1
733 
734 
735  ## allow comma separated input eventcontent
736  if not hasattr(self.process.source,'inputCommands'): self.process.source.inputCommands=cms.untracked.vstring()
737  for evct in self._options.inputEventContent.split(','):
738  if evct=='': continue
739  theEventContent = getattr(self.process, evct+"EventContent")
740  if hasattr(theEventContent,'outputCommands'):
741  self.process.source.inputCommands.extend(copy.copy(theEventContent.outputCommands))
742  if hasattr(theEventContent,'inputCommands'):
743  self.process.source.inputCommands.extend(copy.copy(theEventContent.inputCommands))
744 
745  dropSecondDropStar(self.process.source.inputCommands)
746 
747  if not self._options.dropDescendant:
748  self.process.source.dropDescendantsOfDroppedBranches = cms.untracked.bool(False)
749 
750 
751  return
752 
753  def addConditions(self):
754  """Add conditions to the process"""
755  if not self._options.conditions: return
756 
757  if 'FrontierConditions_GlobalTag' in self._options.conditions:
758  print 'using FrontierConditions_GlobalTag in --conditions is not necessary anymore and will be deprecated soon. please update your command line'
759  self._options.conditions = self._options.conditions.replace("FrontierConditions_GlobalTag,",'')
760 
761  self.loadAndRemember(self.ConditionsDefaultCFF)
762 
763  if self._options.useCondDBv1:
764  from Configuration.AlCa.GlobalTag import GlobalTag
765  else:
766  from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag
767 
768  self.process.GlobalTag = GlobalTag(self.process.GlobalTag, self._options.conditions, self._options.custom_conditions)
769 
770  if self._options.useCondDBv1:
771  self.additionalCommands.append('from Configuration.AlCa.GlobalTag import GlobalTag')
772  else:
773  self.additionalCommands.append('from Configuration.AlCa.GlobalTag_condDBv2 import GlobalTag')
774 
775  self.additionalCommands.append('process.GlobalTag = GlobalTag(process.GlobalTag, %s, %s)' % (repr(self._options.conditions), repr(self._options.custom_conditions)))
776 
777  if self._options.slhc:
778  self.loadAndRemember("SLHCUpgradeSimulations/Geometry/fakeConditions_%s_cff"%(self._options.slhc,))
779 
780 
781  def addCustomise(self,unsch=0):
782  """Include the customise code """
783 
784  custOpt=[]
785  if unsch==0:
786  for c in self._options.customisation_file:
787  custOpt.extend(c.split(","))
788  else:
789  for c in self._options.customisation_file_unsch:
790  custOpt.extend(c.split(","))
791 
792  custMap={}
793  for opt in custOpt:
794  if opt=='': continue
795  if opt.count('.')>1:
796  raise Exception("more than . in the specification:"+opt)
797  fileName=opt.split('.')[0]
798  if opt.count('.')==0: rest='customise'
799  else:
800  rest=opt.split('.')[1]
801  if rest=='py': rest='customise' #catch the case of --customise file.py
802 
803  if fileName in custMap:
804  custMap[fileName].extend(rest.split('+'))
805  else:
806  custMap[fileName]=rest.split('+')
807 
808  if len(custMap)==0:
809  final_snippet='\n'
810  else:
811  final_snippet='\n# customisation of the process.\n'
812 
813  allFcn=[]
814  for opt in custMap:
815  allFcn.extend(custMap[opt])
816  for fcn in allFcn:
817  if allFcn.count(fcn)!=1:
818  raise Exception("cannot specify twice "+fcn+" as a customisation method")
819 
820  for f in custMap:
821  # let python search for that package and do syntax checking at the same time
822  packageName = f.replace(".py","").replace("/",".")
823  __import__(packageName)
824  package = sys.modules[packageName]
825 
826  # now ask the package for its definition and pick .py instead of .pyc
827  customiseFile = re.sub(r'\.pyc$', '.py', package.__file__)
828 
829  final_snippet+='\n# Automatic addition of the customisation function from '+packageName+'\n'
830  if self._options.inline_custom:
831  for line in file(customiseFile,'r'):
832  if "import FWCore.ParameterSet.Config" in line:
833  continue
834  final_snippet += line
835  else:
836  final_snippet += 'from %s import %s \n'%(packageName,','.join(custMap[f]))
837  for fcn in custMap[f]:
838  print "customising the process with",fcn,"from",f
839  if not hasattr(package,fcn):
840  #bound to fail at run time
841  raise Exception("config "+f+" has no function "+fcn)
842  #execute the command
843  self.process=getattr(package,fcn)(self.process)
844  #and print it in the configuration
845  final_snippet += "\n#call to customisation function "+fcn+" imported from "+packageName
846  final_snippet += "\nprocess = %s(process)\n"%(fcn,)
847 
848  if len(custMap)!=0:
849  final_snippet += '\n# End of customisation functions\n'
850 
851  ### now for a usuful command
852  if self._options.customise_commands:
853  import string
854  final_snippet +='\n# Customisation from command line'
855  for com in self._options.customise_commands.split('\\n'):
856  com=string.lstrip(com)
857  self.executeAndRemember(com)
858  final_snippet +='\n'+com
859 
860  return final_snippet
861 
862  #----------------------------------------------------------------------------
863  # here the methods to define the python includes for each step or
864  # conditions
865  #----------------------------------------------------------------------------
866  def define_Configs(self):
867  if len(self.stepMap):
868  self.loadAndRemember('Configuration/StandardSequences/Services_cff')
869  if self._options.particleTable not in defaultOptions.particleTableList:
870  print 'Invalid particle table provided. Options are:'
871  print defaultOptions.particleTable
872  sys.exit(-1)
873  else:
874  if len(self.stepMap):
875  self.loadAndRemember('SimGeneral.HepPDTESSource.'+self._options.particleTable+'_cfi')
876 
877  self.loadAndRemember('FWCore/MessageService/MessageLogger_cfi')
878 
879  self.ALCADefaultCFF="Configuration/StandardSequences/AlCaRecoStreams_cff"
880  self.GENDefaultCFF="Configuration/StandardSequences/Generator_cff"
881  self.SIMDefaultCFF="Configuration/StandardSequences/Sim_cff"
882  self.DIGIDefaultCFF="Configuration/StandardSequences/Digi_cff"
883  self.DIGI2RAWDefaultCFF="Configuration/StandardSequences/DigiToRaw_cff"
884  self.L1EMDefaultCFF='Configuration/StandardSequences/SimL1Emulator_cff'
885  self.L1MENUDefaultCFF="Configuration/StandardSequences/L1TriggerDefaultMenu_cff"
886  self.HLTDefaultCFF="Configuration/StandardSequences/HLTtable_cff"
887  self.RAW2DIGIDefaultCFF="Configuration/StandardSequences/RawToDigi_Data_cff"
888  self.L1RecoDefaultCFF="Configuration/StandardSequences/L1Reco_cff"
889  self.L1TrackTriggerDefaultCFF="Configuration/StandardSequences/L1TrackTrigger_cff"
890  self.RECODefaultCFF="Configuration/StandardSequences/Reconstruction_Data_cff"
891  self.PATDefaultCFF="Configuration/StandardSequences/PAT_cff"
892  self.EIDefaultCFF=None
893  self.SKIMDefaultCFF="Configuration/StandardSequences/Skims_cff"
894  self.POSTRECODefaultCFF="Configuration/StandardSequences/PostRecoGenerator_cff"
895  self.VALIDATIONDefaultCFF="Configuration/StandardSequences/Validation_cff"
896  self.L1HwValDefaultCFF = "Configuration/StandardSequences/L1HwVal_cff"
897  self.DQMOFFLINEDefaultCFF="DQMOffline/Configuration/DQMOffline_cff"
898  self.HARVESTINGDefaultCFF="Configuration/StandardSequences/Harvesting_cff"
899  self.ALCAHARVESTDefaultCFF="Configuration/StandardSequences/AlCaHarvesting_cff"
900  self.ENDJOBDefaultCFF="Configuration/StandardSequences/EndOfProcess_cff"
901  if self._options.useCondDBv1:
902  self.ConditionsDefaultCFF = "Configuration/StandardSequences/FrontierConditions_GlobalTag_cff"
903  else:
904  self.ConditionsDefaultCFF = "Configuration/StandardSequences/FrontierConditions_GlobalTag_condDBv2_cff"
905  self.CFWRITERDefaultCFF = "Configuration/StandardSequences/CrossingFrameWriter_cff"
906  self.REPACKDefaultCFF="Configuration/StandardSequences/DigiToRaw_Repack_cff"
907 
908  if "DATAMIX" in self.stepMap.keys():
909  self.DATAMIXDefaultCFF="Configuration/StandardSequences/DataMixer"+self._options.datamix+"_cff"
910  if self._options.datamix == 'PreMix':
911  self.DIGIDefaultCFF="Configuration/StandardSequences/DigiDMPreMix_cff"
912  else:
913  self.DIGIDefaultCFF="Configuration/StandardSequences/DigiDM_cff"
914  self.DIGI2RAWDefaultCFF="Configuration/StandardSequences/DigiToRawDM_cff"
915  self.L1EMDefaultCFF='Configuration/StandardSequences/SimL1EmulatorDM_cff'
916 
917  if "DIGIPREMIX" in self.stepMap.keys():
918  self.DIGIDefaultCFF="Configuration/StandardSequences/Digi_PreMix_cff"
919 
920  self.ALCADefaultSeq=None
921  self.LHEDefaultSeq='externalLHEProducer'
922  self.GENDefaultSeq='pgen'
923  self.SIMDefaultSeq='psim'
924  self.DIGIDefaultSeq='pdigi'
925  self.DIGIPREMIXDefaultSeq='pdigi'
926  self.DIGIPREMIX_S2DefaultSeq='pdigi'
927  self.DATAMIXDefaultSeq=None
928  self.DIGI2RAWDefaultSeq='DigiToRaw'
929  self.HLTDefaultSeq='GRun'
930  self.L1DefaultSeq=None
931  self.L1REPACKDefaultSeq='GT'
932  self.HARVESTINGDefaultSeq=None
933  self.ALCAHARVESTDefaultSeq=None
934  self.CFWRITERDefaultSeq=None
935  self.RAW2DIGIDefaultSeq='RawToDigi'
936  self.L1RecoDefaultSeq='L1Reco'
937  self.L1TrackTriggerDefaultSeq='L1TrackTrigger'
938  if 'RAW2DIGI' in self.stepMap and 'RECO' in self.stepMap:
939  self.RECODefaultSeq='reconstruction'
940  else:
941  self.RECODefaultSeq='reconstruction_fromRECO'
942 
943  self.EIDefaultSeq='top'
944  self.POSTRECODefaultSeq=None
945  self.L1HwValDefaultSeq='L1HwVal'
946  self.DQMDefaultSeq='DQMOffline'
947  self.FASTSIMDefaultSeq='all'
948  self.VALIDATIONDefaultSeq=''
949  self.ENDJOBDefaultSeq='endOfProcess'
950  self.REPACKDefaultSeq='DigiToRawRepack'
951  self.PATDefaultSeq='miniAOD'
952 
953  self.EVTCONTDefaultCFF="Configuration/EventContent/EventContent_cff"
954 
955  if not self._options.beamspot:
956  self._options.beamspot=VtxSmearedDefaultKey
957 
958  # if its MC then change the raw2digi
959  if self._options.isMC==True:
960  self.RAW2DIGIDefaultCFF="Configuration/StandardSequences/RawToDigi_cff"
961  self.RECODefaultCFF="Configuration/StandardSequences/Reconstruction_cff"
962  self.PATDefaultCFF="Configuration/StandardSequences/PATMC_cff"
963  self.DQMOFFLINEDefaultCFF="DQMOffline/Configuration/DQMOfflineMC_cff"
964  self.ALCADefaultCFF="Configuration/StandardSequences/AlCaRecoStreamsMC_cff"
965  else:
966  self._options.beamspot = None
967 
968  #patch for gen, due to backward incompatibility
969  if 'reGEN' in self.stepMap:
970  self.GENDefaultSeq='fixGenInfo'
971 
972  if self._options.scenario=='cosmics':
973  self._options.pileup='Cosmics'
974  self.DIGIDefaultCFF="Configuration/StandardSequences/DigiCosmics_cff"
975  self.RECODefaultCFF="Configuration/StandardSequences/ReconstructionCosmics_cff"
976  self.SKIMDefaultCFF="Configuration/StandardSequences/SkimsCosmics_cff"
977  self.EVTCONTDefaultCFF="Configuration/EventContent/EventContentCosmics_cff"
978  self.DQMOFFLINEDefaultCFF="DQMOffline/Configuration/DQMOfflineCosmics_cff"
979  if self._options.isMC==True:
980  self.DQMOFFLINEDefaultCFF="DQMOffline/Configuration/DQMOfflineCosmicsMC_cff"
981  self.HARVESTINGDefaultCFF="Configuration/StandardSequences/HarvestingCosmics_cff"
982  self.RECODefaultSeq='reconstructionCosmics'
983  self.DQMDefaultSeq='DQMOfflineCosmics'
984 
985  if self._options.himix:
986  print "From the presence of the himix option, we have determined that this is heavy ions and will use '--scenario HeavyIons'."
987  self._options.scenario='HeavyIons'
988 
989  if self._options.scenario=='HeavyIons':
990  if not self._options.beamspot:
991  self._options.beamspot=VtxSmearedHIDefaultKey
992  self.HLTDefaultSeq = 'HIon'
993  if not self._options.himix:
994  self.GENDefaultSeq='pgen_hi'
995  else:
996  self.GENDefaultSeq='pgen_himix'
997  self.VALIDATIONDefaultCFF="Configuration/StandardSequences/ValidationHeavyIons_cff"
998  self.VALIDATIONDefaultSeq=''
999  self.EVTCONTDefaultCFF="Configuration/EventContent/EventContentHeavyIons_cff"
1000  self.RECODefaultCFF="Configuration/StandardSequences/ReconstructionHeavyIons_cff"
1001  self.RECODefaultSeq='reconstructionHeavyIons'
1002  self.ALCADefaultCFF = "Configuration/StandardSequences/AlCaRecoStreamsHeavyIons_cff"
1003  self.DQMOFFLINEDefaultCFF="DQMOffline/Configuration/DQMOfflineHeavyIons_cff"
1004  self.DQMDefaultSeq='DQMOfflineHeavyIons'
1005  self.SKIMDefaultCFF="Configuration/StandardSequences/SkimsHeavyIons_cff"
1006  self.HARVESTINGDefaultCFF="Configuration/StandardSequences/HarvestingHeavyIons_cff"
1007  if self._options.isMC==True:
1008  self.DQMOFFLINEDefaultCFF="DQMOffline/Configuration/DQMOfflineHeavyIonsMC_cff"
1009 
1010 
1011  self.RAW2RECODefaultSeq=','.join([self.RAW2DIGIDefaultSeq,self.RECODefaultSeq])
1012 
1013  self.USERDefaultSeq='user'
1014  self.USERDefaultCFF=None
1015 
1016  # the magnetic field
1017  if self._options.isData:
1018  if self._options.magField==defaultOptions.magField:
1019  print "magnetic field option forced to: AutoFromDBCurrent"
1020  self._options.magField='AutoFromDBCurrent'
1021  self.magFieldCFF = 'Configuration/StandardSequences/MagneticField_'+self._options.magField.replace('.','')+'_cff'
1022  self.magFieldCFF = self.magFieldCFF.replace("__",'_')
1023 
1024  # the geometry
1025  self.GeometryCFF='Configuration/StandardSequences/GeometryRecoDB_cff'
1026  self.geometryDBLabel=None
1027  simGeometry=''
1028  if self._options.fast:
1029  if 'start' in self._options.conditions.lower():
1030  self.GeometryCFF='FastSimulation/Configuration/Geometries_START_cff'
1031  else:
1032  self.GeometryCFF='FastSimulation/Configuration/Geometries_MC_cff'
1033  else:
1034  def inGeometryKeys(opt):
1035  from Configuration.StandardSequences.GeometryConf import GeometryConf
1036  if opt in GeometryConf:
1037  return GeometryConf[opt]
1038  else:
1039  return opt
1040 
1041  geoms=self._options.geometry.split(',')
1042  if len(geoms)==1: geoms=inGeometryKeys(geoms[0]).split(',')
1043  if len(geoms)==2:
1044  #may specify the reco geometry
1045  if '/' in geoms[1] or '_cff' in geoms[1]:
1046  self.GeometryCFF=geoms[1]
1047  else:
1048  self.GeometryCFF='Configuration/Geometry/Geometry'+geoms[1]+'_cff'
1049 
1050  if (geoms[0].startswith('DB:')):
1051  self.SimGeometryCFF='Configuration/StandardSequences/GeometrySimDB_cff'
1052  self.geometryDBLabel=geoms[0][3:]
1053  print "with DB:"
1054  else:
1055  if '/' in geoms[0] or '_cff' in geoms[0]:
1056  self.SimGeometryCFF=geoms[0]
1057  else:
1058  simGeometry=geoms[0]
1059  if self._options.gflash==True:
1060  self.SimGeometryCFF='Configuration/Geometry/Geometry'+geoms[0]+'GFlash_cff'
1061  else:
1062  self.SimGeometryCFF='Configuration/Geometry/Geometry'+geoms[0]+'_cff'
1063 
1064  # synchronize the geometry configuration and the FullSimulation sequence to be used
1065  if simGeometry not in defaultOptions.geometryExtendedOptions:
1066  self.SIMDefaultCFF="Configuration/StandardSequences/SimIdeal_cff"
1067 
1068  if self._options.scenario=='nocoll' or self._options.scenario=='cosmics':
1069  self.SIMDefaultCFF="Configuration/StandardSequences/SimNOBEAM_cff"
1070  self._options.beamspot='NoSmear'
1071 
1072  # if fastsim switch event content
1073  if self._options.fast:
1074  self.SIMDefaultCFF = 'FastSimulation.Configuration.FamosSequences_cff'
1075  self.SIMDefaultSeq='simulationWithFamos'
1076  self.RECODefaultCFF= 'FastSimulation.Configuration.FamosSequences_cff'
1077  self.RECODefaultSeq= 'reconstructionWithFamos'
1078  self.EVTCONTDefaultCFF = "FastSimulation.Configuration.EventContent_cff"
1079  self.VALIDATIONDefaultCFF = "FastSimulation.Configuration.Validation_cff"
1080 
1081 
1082 
1083  # Mixing
1084  if self._options.pileup=='default':
1085  from Configuration.StandardSequences.Mixing import MixingDefaultKey,MixingFSDefaultKey
1086  if self._options.fast:
1087  self._options.pileup=MixingFSDefaultKey
1088  else:
1089  self._options.pileup=MixingDefaultKey
1090 
1091  #not driven by a default cff anymore
1092  if self._options.isData:
1093  self._options.pileup=None
1094  if self._options.isMC==True and self._options.himix==False:
1095  if self._options.fast:
1096  self._options.pileup='FS_'+self._options.pileup
1097  elif self._options.isMC==True and self._options.himix==True:
1098  self._options.pileup='HiMix'
1099 
1100 
1101  if self._options.slhc:
1102  self.GeometryCFF='SLHCUpgradeSimulations.Geometry.%s_cmsSimIdealGeometryXML_cff'%(self._options.slhc,)
1103  if 'stdgeom' not in self._options.slhc:
1104  self.SimGeometryCFF='SLHCUpgradeSimulations.Geometry.%s_cmsSimIdealGeometryXML_cff'%(self._options.slhc,)
1105  self.DIGIDefaultCFF='SLHCUpgradeSimulations/Geometry/Digi_%s_cff'%(self._options.slhc,)
1106  if self._options.pileup!=defaultOptions.pileup:
1107  self._options.pileup='SLHC_%s_%s'%(self._options.pileup,self._options.slhc)
1108 
1109  self.REDIGIDefaultSeq=self.DIGIDefaultSeq
1110 
1111  # for alca, skims, etc
1112  def addExtraStream(self,name,stream,workflow='full'):
1113  # define output module and go from there
1114  output = cms.OutputModule("PoolOutputModule")
1115  if stream.selectEvents.parameters_().__len__()!=0:
1116  output.SelectEvents = stream.selectEvents
1117  else:
1118  output.SelectEvents = cms.untracked.PSet()
1119  output.SelectEvents.SelectEvents=cms.vstring()
1120  if isinstance(stream.paths,tuple):
1121  for path in stream.paths:
1122  output.SelectEvents.SelectEvents.append(path.label())
1123  else:
1124  output.SelectEvents.SelectEvents.append(stream.paths.label())
1125 
1126 
1127 
1128  if isinstance(stream.content,str):
1129  evtPset=getattr(self.process,stream.content)
1130  for p in evtPset.parameters_():
1131  setattr(output,p,getattr(evtPset,p))
1132  if not self._options.inlineEventContent:
1133  def doNotInlineEventContent(instance,label = "process."+stream.content+".outputCommands"):
1134  return label
1135  output.outputCommands.__dict__["dumpPython"] = doNotInlineEventContent
1136  else:
1137  output.outputCommands = stream.content
1138 
1139 
1140  output.fileName = cms.untracked.string(self._options.dirout+stream.name+'.root')
1141 
1142  output.dataset = cms.untracked.PSet( dataTier = stream.dataTier,
1143  filterName = cms.untracked.string(stream.name))
1144 
1145  if self._options.filtername:
1146  output.dataset.filterName= cms.untracked.string(self._options.filtername+"_"+stream.name)
1147 
1148  #add an automatic flushing to limit memory consumption
1149  output.eventAutoFlushCompressedSize=cms.untracked.int32(5*1024*1024)
1150 
1151  if workflow in ("producers,full"):
1152  if isinstance(stream.paths,tuple):
1153  for path in stream.paths:
1154  self.schedule.append(path)
1155  else:
1156  self.schedule.append(stream.paths)
1157 
1158 
1159  # in case of relvals we don't want to have additional outputs
1160  if (not self._options.relval) and workflow in ("full","output"):
1161  self.additionalOutputs[name] = output
1162  setattr(self.process,name,output)
1163 
1164  if workflow == 'output':
1165  # adjust the select events to the proper trigger results from previous process
1166  filterList = output.SelectEvents.SelectEvents
1167  for i, filter in enumerate(filterList):
1168  filterList[i] = filter+":"+self._options.triggerResultsProcess
1169 
1170  return output
1171 
1172  #----------------------------------------------------------------------------
1173  # here the methods to create the steps. Of course we are doing magic here ;)
1174  # prepare_STEPNAME modifies self.process and what else's needed.
1175  #----------------------------------------------------------------------------
1176 
1177  def loadDefaultOrSpecifiedCFF(self, sequence,defaultCFF,unsch=0):
1178  if ( len(sequence.split('.'))==1 ):
1179  l=self.loadAndRemember(defaultCFF,unsch)
1180  elif ( len(sequence.split('.'))==2 ):
1181  l=self.loadAndRemember(sequence.split('.')[0],unsch)
1182  sequence=sequence.split('.')[1]
1183  else:
1184  print "sub sequence configuration must be of the form dir/subdir/cff.a+b+c or cff.a"
1185  print sequence,"not recognized"
1186  raise
1187  return l
1188 
1189  def scheduleSequence(self,seq,prefix,what='Path'):
1190  if '*' in seq:
1191  #create only one path with all sequences in it
1192  for i,s in enumerate(seq.split('*')):
1193  if i==0:
1194  setattr(self.process,prefix,getattr(cms,what)( getattr(self.process, s) ))
1195  else:
1196  p=getattr(self.process,prefix)
1197  p+=getattr(self.process, s)
1198  self.schedule.append(getattr(self.process,prefix))
1199  return
1200  else:
1201  #create as many path as many sequences
1202  if not '+' in seq:
1203  if self.nextScheduleIsConditional:
1204  self.conditionalPaths.append(prefix)
1205  setattr(self.process,prefix,getattr(cms,what)( getattr(self.process, seq) ))
1206  self.schedule.append(getattr(self.process,prefix))
1207  else:
1208  for i,s in enumerate(seq.split('+')):
1209  sn=prefix+'%d'%(i)
1210  setattr(self.process,sn,getattr(cms,what)( getattr(self.process, s) ))
1211  self.schedule.append(getattr(self.process,sn))
1212  return
1213 
1214  def scheduleSequenceAtEnd(self,seq,prefix):
1215  self.scheduleSequence(seq,prefix,what='EndPath')
1216  return
1217 
1218  def prepare_ALCAPRODUCER(self, sequence = None):
1219  self.prepare_ALCA(sequence, workflow = "producers")
1220 
1221  def prepare_ALCAOUTPUT(self, sequence = None):
1222  self.prepare_ALCA(sequence, workflow = "output")
1223 
1224  def prepare_ALCA(self, sequence = None, workflow = 'full'):
1225  """ Enrich the process with alca streams """
1226  alcaConfig=self.loadDefaultOrSpecifiedCFF(sequence,self.ALCADefaultCFF)
1227  sequence = sequence.split('.')[-1]
1228 
1229  # decide which ALCA paths to use
1230  alcaList = sequence.split("+")
1231  maxLevel=0
1232  from Configuration.AlCa.autoAlca import autoAlca
1233  # support @X from autoAlca.py, and recursion support: i.e T0:@Mu+@EG+...
1234  self.expandMapping(alcaList,autoAlca)
1235 
1236  for name in alcaConfig.__dict__:
1237  alcastream = getattr(alcaConfig,name)
1238  shortName = name.replace('ALCARECOStream','')
1239  if shortName in alcaList and isinstance(alcastream,cms.FilteredStream):
1240  output = self.addExtraStream(name,alcastream, workflow = workflow)
1241  if 'DQM' in alcaList:
1242  if not self._options.inlineEventContent and hasattr(self.process,name):
1243  self.executeAndRemember('process.' + name + '.outputCommands.append("keep *_MEtoEDMConverter_*_*")')
1244  else:
1245  output.outputCommands.append("keep *_MEtoEDMConverter_*_*")
1246 
1247  #rename the HLT process name in the alca modules
1248  if self._options.hltProcess or 'HLT' in self.stepMap:
1249  if isinstance(alcastream.paths,tuple):
1250  for path in alcastream.paths:
1251  self.renameHLTprocessInSequence(path.label())
1252  else:
1253  self.renameHLTprocessInSequence(alcastream.paths.label())
1254 
1255  for i in range(alcaList.count(shortName)):
1256  alcaList.remove(shortName)
1257 
1258  # DQM needs a special handling
1259  elif name == 'pathALCARECODQM' and 'DQM' in alcaList:
1260  path = getattr(alcaConfig,name)
1261  self.schedule.append(path)
1262  alcaList.remove('DQM')
1263 
1264  if isinstance(alcastream,cms.Path):
1265  #black list the alca path so that they do not appear in the cfg
1266  self.blacklist_paths.append(alcastream)
1267 
1268 
1269  if len(alcaList) != 0:
1270  available=[]
1271  for name in alcaConfig.__dict__:
1272  alcastream = getattr(alcaConfig,name)
1273  if isinstance(alcastream,cms.FilteredStream):
1274  available.append(name.replace('ALCARECOStream',''))
1275  print "The following alcas could not be found "+str(alcaList)
1276  print "available ",available
1277  #print "verify your configuration, ignoring for now"
1278  raise Exception("The following alcas could not be found "+str(alcaList))
1279 
1280  def prepare_LHE(self, sequence = None):
1281  #load the fragment
1282  ##make it loadable
1283  loadFragment = self._options.evt_type.replace('.py','',).replace('.','_').replace('python/','').replace('/','.')
1284  print "Loading lhe fragment from",loadFragment
1285  __import__(loadFragment)
1286  self.process.load(loadFragment)
1287  ##inline the modules
1288  self._options.inlineObjets+=','+sequence
1289 
1290  getattr(self.process,sequence).nEvents = int(self._options.number)
1291 
1292  #schedule it
1293  self.process.lhe_step = cms.Path( getattr( self.process,sequence) )
1294  self.excludedPaths.append("lhe_step")
1295  self.schedule.append( self.process.lhe_step )
1296 
1297  def prepare_GEN(self, sequence = None):
1298  """ load the fragment of generator configuration """
1299  loadFailure=False
1300  #remove trailing .py
1301  #support old style .cfi by changing into something.cfi into something_cfi
1302  #remove python/ from the name
1303  loadFragment = self._options.evt_type.replace('.py','',).replace('.','_').replace('python/','')
1304  #standard location of fragments
1305  if not '/' in loadFragment:
1306  loadFragment='Configuration.Generator.'+loadFragment
1307  else:
1308  loadFragment=loadFragment.replace('/','.')
1309  try:
1310  print "Loading generator fragment from",loadFragment
1311  __import__(loadFragment)
1312  except:
1313  loadFailure=True
1314  #if self.process.source and self.process.source.type_()=='EmptySource':
1315  if not (self._options.filein or self._options.dasquery):
1316  raise Exception("Neither gen fragment of input files provided: this is an inconsistent GEN step configuration")
1317 
1318  if not loadFailure:
1319  generatorModule=sys.modules[loadFragment]
1320  genModules=generatorModule.__dict__
1321  #remove lhe producer module since this should have been
1322  #imported instead in the LHE step
1323  if self.LHEDefaultSeq in genModules:
1324  del genModules[self.LHEDefaultSeq]
1325 
1326  if self._options.hideGen:
1327  self.loadAndRemember(loadFragment)
1328  else:
1329  self.process.load(loadFragment)
1330  # expose the objects from that fragment to the configuration
1331  import FWCore.ParameterSet.Modules as cmstypes
1332  for name in genModules:
1333  theObject = getattr(generatorModule,name)
1334  if isinstance(theObject, cmstypes._Module):
1335  self._options.inlineObjets=name+','+self._options.inlineObjets
1336  elif isinstance(theObject, cms.Sequence) or isinstance(theObject, cmstypes.ESProducer):
1337  self._options.inlineObjets+=','+name
1338 
1339  if sequence == self.GENDefaultSeq or sequence == 'pgen_genonly' or ( sequence == 'pgen_himix' or sequence == 'pgen_hi'):
1340  if 'ProductionFilterSequence' in genModules and ('generator' in genModules or 'hiSignal' in genModules):
1341  self.productionFilterSequence = 'ProductionFilterSequence'
1342  elif 'generator' in genModules:
1343  self.productionFilterSequence = 'generator'
1344 
1345  """ Enrich the schedule with the rest of the generation step """
1346  self.loadDefaultOrSpecifiedCFF(sequence,self.GENDefaultCFF)
1347  genSeqName=sequence.split('.')[-1]
1348 
1349  if True:
1350  try:
1351  from Configuration.StandardSequences.VtxSmeared import VtxSmeared
1352  cffToBeLoaded=VtxSmeared[self._options.beamspot]
1353  self.loadAndRemember(cffToBeLoaded)
1354  except ImportError:
1355  raise Exception("VertexSmearing type or beamspot "+self._options.beamspot+" unknown.")
1356 
1357  if self._options.scenario == 'HeavyIons' and self._options.himix:
1358  self.loadAndRemember("SimGeneral/MixingModule/himixGEN_cff")
1359 
1360  self.process.generation_step = cms.Path( getattr(self.process,genSeqName) )
1361  self.schedule.append(self.process.generation_step)
1362 
1363  #register to the genstepfilter the name of the path (static right now, but might evolve)
1364  self.executeAndRemember('process.genstepfilter.triggerConditions=cms.vstring("generation_step")')
1365 
1366  if 'reGEN' in self.stepMap:
1367  #stop here
1368  return
1369 
1370  """ Enrich the schedule with the summary of the filter step """
1371  #the gen filter in the endpath
1372  self.loadAndRemember("GeneratorInterface/Core/genFilterSummary_cff")
1373  self.scheduleSequenceAtEnd('genFilterSummary','genfiltersummary_step')
1374  return
1375 
1376  def prepare_SIM(self, sequence = None):
1377  """ Enrich the schedule with the simulation step"""
1378  self.loadDefaultOrSpecifiedCFF(sequence,self.SIMDefaultCFF)
1379  if not self._options.fast:
1380  if self._options.gflash==True:
1381  self.loadAndRemember("Configuration/StandardSequences/GFlashSIM_cff")
1382 
1383  if self._options.magField=='0T':
1384  self.executeAndRemember("process.g4SimHits.UseMagneticField = cms.bool(False)")
1385 
1386  if self._options.himix==True:
1387  if self._options.geometry in defaultOptions.geometryExtendedOptions:
1388  self.loadAndRemember("SimGeneral/MixingModule/himixSIMExtended_cff")
1389  else:
1390  self.loadAndRemember("SimGeneral/MixingModule/himixSIMIdeal_cff")
1391  else:
1392  if self._options.magField=='0T':
1393  self.executeAndRemember("process.famosSimHits.UseMagneticField = cms.bool(False)")
1394 
1395  self.scheduleSequence(sequence.split('.')[-1],'simulation_step')
1396  return
1397 
1398  def prepare_DIGI(self, sequence = None):
1399  """ Enrich the schedule with the digitisation step"""
1400  self.loadDefaultOrSpecifiedCFF(sequence,self.DIGIDefaultCFF)
1401 
1402  if self._options.gflash==True:
1403  self.loadAndRemember("Configuration/StandardSequences/GFlashDIGI_cff")
1404 
1405  if self._options.himix==True:
1406  self.loadAndRemember("SimGeneral/MixingModule/himixDIGI_cff")
1407 
1408  if sequence == 'pdigi_valid':
1409  self.executeAndRemember("process.mix.digitizers = cms.PSet(process.theDigitizersValid)")
1410 
1411  self.scheduleSequence(sequence.split('.')[-1],'digitisation_step')
1412  return
1413 
1414  def prepare_DIGIPREMIX(self, sequence = None):
1415  """ Enrich the schedule with the digitisation step"""
1416  self.loadDefaultOrSpecifiedCFF(sequence,self.DIGIDefaultCFF)
1417 
1418  self.loadAndRemember("SimGeneral/MixingModule/digi_noNoise_cfi")
1419  self.executeAndRemember("process.mix.digitizers = cms.PSet(process.theDigitizersNoNoise)")
1420 
1421  self.scheduleSequence(sequence.split('.')[-1],'digitisation_step')
1422  return
1423 
1424  def prepare_DIGIPREMIX_S2(self, sequence = None):
1425  """ Enrich the schedule with the digitisation step"""
1426  self.loadDefaultOrSpecifiedCFF(sequence,self.DIGIDefaultCFF)
1427 
1428  self.loadAndRemember("SimGeneral/MixingModule/digi_MixPreMix_cfi")
1429 
1430 
1431  if sequence == 'pdigi_valid':
1432  self.executeAndRemember("process.mix.digitizers = cms.PSet(process.theDigitizersMixPreMixValid)")
1433  else:
1434  self.executeAndRemember("process.mix.digitizers = cms.PSet(process.theDigitizersMixPreMix)")
1435 
1436  self.scheduleSequence(sequence.split('.')[-1],'digitisation_step')
1437  return
1438 
1439  def prepare_CFWRITER(self, sequence = None):
1440  """ Enrich the schedule with the crossing frame writer step"""
1441  self.loadAndRemember(self.CFWRITERDefaultCFF)
1442  self.scheduleSequence('pcfw','cfwriter_step')
1443  return
1444 
1445  def prepare_DATAMIX(self, sequence = None):
1446  """ Enrich the schedule with the digitisation step"""
1447  self.loadAndRemember(self.DATAMIXDefaultCFF)
1448  self.scheduleSequence('pdatamix','datamixing_step')
1449 
1450  if self._options.pileup_input:
1451  theFiles=''
1452  if self._options.pileup_input.startswith('dbs:') or self._options.pileup_input.startswith('das:'):
1453  theFiles=filesFromDASQuery('file dataset = %s'%(self._options.pileup_input[4:],))[0]
1454  elif self._options.pileup_input.startswith("filelist:"):
1455  theFiles= (filesFromList(self._options.pileup_input[9:]))[0]
1456  else:
1457  theFiles=self._options.pileup_input.split(',')
1458  #print theFiles
1459  self.executeAndRemember( "process.mixData.input.fileNames = cms.untracked.vstring(%s)"%( theFiles ) )
1460 
1461  return
1462 
1463  def prepare_DIGI2RAW(self, sequence = None):
1464  self.loadDefaultOrSpecifiedCFF(sequence,self.DIGI2RAWDefaultCFF)
1465  self.scheduleSequence(sequence.split('.')[-1],'digi2raw_step')
1466  if "DIGIPREMIX" in self.stepMap.keys():
1467  self.executeAndRemember("process.esDigiToRaw.Label = cms.string('mix')") ##terrible hack - bypass zero suppression
1468  self.executeAndRemember("process.SiStripDigiToRaw.FedReadoutMode = cms.string('PREMIX_RAW')") ##special readout mode for StripTracker
1469 
1470  return
1471 
1472  def prepare_REPACK(self, sequence = None):
1473  self.loadDefaultOrSpecifiedCFF(sequence,self.REPACKDefaultCFF)
1474  self.scheduleSequence(sequence.split('.')[-1],'digi2repack_step')
1475  return
1476 
1477  def prepare_L1(self, sequence = None):
1478  """ Enrich the schedule with the L1 simulation step"""
1479  if not sequence:
1480  self.loadAndRemember(self.L1EMDefaultCFF)
1481  else:
1482  # let the L1 package decide for the scenarios available
1483  from L1Trigger.Configuration.ConfigBuilder import getConfigsForScenario
1484  listOfImports = getConfigsForScenario(sequence)
1485  for file in listOfImports:
1486  self.loadAndRemember(file)
1487  self.scheduleSequence('SimL1Emulator','L1simulation_step')
1488  return
1489 
1490  def prepare_L1REPACK(self, sequence = None):
1491  """ Enrich the schedule with the L1 simulation step, running the L1 emulator on data unpacked from the RAW collection, and repacking the result in a new RAW collection"""
1492  if sequence is not 'GT':
1493  print 'Running the full L1 emulator is not supported yet'
1494  raise Exception('unsupported feature')
1495  if sequence is 'GT':
1496  self.loadAndRemember('Configuration/StandardSequences/SimL1EmulatorRepack_GT_cff')
1497  if self._options.scenario == 'HeavyIons':
1498  self.renameInputTagsInSequence("SimL1Emulator","rawDataCollector","rawDataRepacker")
1499  self.scheduleSequence('SimL1Emulator','L1simulation_step')
1500 
1501 
1502  def prepare_HLT(self, sequence = None):
1503  """ Enrich the schedule with the HLT simulation step"""
1504  if not sequence:
1505  print "no specification of the hlt menu has been given, should never happen"
1506  raise Exception('no HLT sequence provided')
1507 
1508  if '@' in sequence:
1509  # case where HLT:@something was provided
1510  from Configuration.HLT.autoHLT import autoHLT
1511  key = sequence[1:]
1512  if key in autoHLT:
1513  sequence = autoHLT[key]
1514  else:
1515  raise ValueError('no HLT mapping key "%s" found in autoHLT' % key)
1516 
1517  if ',' in sequence:
1518  #case where HLT:something:something was provided
1519  self.executeAndRemember('import HLTrigger.Configuration.Utilities')
1520  optionsForHLT = {}
1521  if self._options.scenario == 'HeavyIons':
1522  optionsForHLT['type'] = 'HIon'
1523  else:
1524  optionsForHLT['type'] = 'GRun'
1525  optionsForHLTConfig = ', '.join('%s=%s' % (key, repr(val)) for (key, val) in optionsForHLT.iteritems())
1526  if sequence == 'run,fromSource':
1527  if hasattr(self.process.source,'firstRun'):
1528  self.executeAndRemember('process.loadHltConfiguration("run:%%d"%%(process.source.firstRun.value()),%s)'%(optionsForHLTConfig))
1529  elif hasattr(self.process.source,'setRunNumber'):
1530  self.executeAndRemember('process.loadHltConfiguration("run:%%d"%%(process.source.setRunNumber.value()),%s)'%(optionsForHLTConfig))
1531  else:
1532  raise Exception('Cannot replace menu to load %s'%(sequence))
1533  else:
1534  self.executeAndRemember('process.loadHltConfiguration("%s",%s)'%(sequence.replace(',',':'),optionsForHLTConfig))
1535  else:
1536  if self._options.fast:
1537  self.loadAndRemember('HLTrigger/Configuration/HLT_%s_Famos_cff' % sequence)
1538  else:
1539  self.loadAndRemember('HLTrigger/Configuration/HLT_%s_cff' % sequence)
1540 
1541  if self._options.isMC:
1542  self._options.customisation_file.append("HLTrigger/Configuration/customizeHLTforMC.customizeHLTforMC")
1543 
1544  if self._options.name != 'HLT':
1545  self.additionalCommands.append('from HLTrigger.Configuration.CustomConfigs import ProcessName')
1546  self.additionalCommands.append('process = ProcessName(process)')
1547  self.additionalCommands.append('')
1548  from HLTrigger.Configuration.CustomConfigs import ProcessName
1549  self.process = ProcessName(self.process)
1550 
1551  self.schedule.append(self.process.HLTSchedule)
1552  [self.blacklist_paths.append(path) for path in self.process.HLTSchedule if isinstance(path,(cms.Path,cms.EndPath))]
1553  if (self._options.fast and 'HLT' in self.stepMap and 'FASTSIM' in self.stepMap):
1554  self.finalizeFastSimHLT()
1555 
1556  #this is a fake, to be removed with fastim migration and HLT menu dump
1557  if self._options.fast and not 'FASTSIM' in self.stepMap:
1558  if not hasattr(self.process,'HLTEndSequence'):
1559  self.executeAndRemember("process.HLTEndSequence = cms.Sequence( process.dummyModule )")
1560  if not hasattr(self.process,'simulation'):
1561  self.executeAndRemember("process.simulation = cms.Sequence( process.dummyModule )")
1562 
1563 
1564  def prepare_RAW2RECO(self, sequence = None):
1565  if ','in sequence:
1566  seqReco=sequence.split(',')[1]
1567  seqDigi=sequence.split(',')[0]
1568  else:
1569  print "RAW2RECO requires two specifications",sequence,"insufficient"
1570 
1571  self.prepare_RAW2DIGI(seqDigi)
1572  self.prepare_RECO(seqReco)
1573  return
1574 
1575  def prepare_RAW2DIGI(self, sequence = "RawToDigi"):
1576  self.loadDefaultOrSpecifiedCFF(sequence,self.RAW2DIGIDefaultCFF)
1577  self.scheduleSequence(sequence,'raw2digi_step')
1578  # if self._options.isRepacked:
1579  #self.renameInputTagsInSequence(sequence)
1580  return
1581 
1582  def prepare_L1HwVal(self, sequence = 'L1HwVal'):
1583  ''' Enrich the schedule with L1 HW validation '''
1584  self.loadDefaultOrSpecifiedCFF(sequence,self.L1HwValDefaultCFF)
1585  #self.scheduleSequence(sequence.split('.')[-1],'l1hwval_step')
1586  print '\n\n\n DEPRECATED this has no action \n\n\n'
1587  return
1588 
1589  def prepare_L1Reco(self, sequence = "L1Reco"):
1590  ''' Enrich the schedule with L1 reconstruction '''
1591  self.loadDefaultOrSpecifiedCFF(sequence,self.L1RecoDefaultCFF)
1592  self.scheduleSequence(sequence.split('.')[-1],'L1Reco_step')
1593  return
1594 
1595  def prepare_L1TrackTrigger(self, sequence = "L1TrackTrigger"):
1596  ''' Enrich the schedule with L1 reconstruction '''
1598  self.scheduleSequence(sequence.split('.')[-1],'L1TrackTrigger_step')
1599  return
1600 
1601  def prepare_FILTER(self, sequence = None):
1602  ''' Enrich the schedule with a user defined filter sequence '''
1603  ## load the relevant part
1604  filterConfig=self.load(sequence.split('.')[0])
1605  filterSeq=sequence.split('.')[-1]
1606  ## print it in the configuration
1607  class PrintAllModules(object):
1608  def __init__(self):
1609  self.inliner=''
1610  pass
1611  def enter(self,visitee):
1612  try:
1613  label=visitee.label()
1614  ##needs to be in reverse order
1615  self.inliner=label+','+self.inliner
1616  except:
1617  pass
1618  def leave(self,v): pass
1619 
1620  expander=PrintAllModules()
1621  getattr(self.process,filterSeq).visit( expander )
1622  self._options.inlineObjets+=','+expander.inliner
1623  self._options.inlineObjets+=','+filterSeq
1624 
1625  ## put the filtering path in the schedule
1626  self.scheduleSequence(filterSeq,'filtering_step')
1627  self.nextScheduleIsConditional=True
1628  ## put it before all the other paths
1629  self.productionFilterSequence = filterSeq
1630 
1631  return
1632 
1633  def prepare_RECO(self, sequence = "reconstruction"):
1634  ''' Enrich the schedule with reconstruction '''
1635  self.loadDefaultOrSpecifiedCFF(sequence,self.RECODefaultCFF)
1636  self.scheduleSequence(sequence.split('.')[-1],'reconstruction_step')
1637  return
1638 
1639  def prepare_PAT(self, sequence = "miniAOD"):
1640  ''' Enrich the schedule with PAT '''
1641  self.loadDefaultOrSpecifiedCFF(sequence,self.PATDefaultCFF,1) #this is unscheduled
1642  if not self._options.runUnscheduled:
1643  raise Exception("MiniAOD production can only run in unscheduled mode, please run cmsDriver with --runUnscheduled")
1644  if self._options.isData:
1645  self._options.customisation_file_unsch.append("PhysicsTools/PatAlgos/slimming/miniAOD_tools.miniAOD_customizeAllData")
1646  else:
1647  self._options.customisation_file_unsch.append("PhysicsTools/PatAlgos/slimming/miniAOD_tools.miniAOD_customizeAllMC")
1648  if self._options.fast:
1649  self._options.customisation_file_unsch.append("PhysicsTools/PatAlgos/slimming/metFilterPaths_cff.miniAOD_customizeMETFiltersFastSim")
1650  return
1651 
1652  def prepare_EI(self, sequence = None):
1653  ''' Enrich the schedule with event interpretation '''
1654  from Configuration.StandardSequences.EventInterpretation import EventInterpretation
1655  if sequence in EventInterpretation:
1656  self.EIDefaultCFF = EventInterpretation[sequence]
1657  sequence = 'EIsequence'
1658  else:
1659  raise Exception('Cannot set %s event interpretation'%( sequence) )
1660  self.loadDefaultOrSpecifiedCFF(sequence,self.EIDefaultCFF)
1661  self.scheduleSequence(sequence.split('.')[-1],'eventinterpretaion_step')
1662  return
1663 
1664  def prepare_SKIM(self, sequence = "all"):
1665  ''' Enrich the schedule with skimming fragments'''
1666  skimConfig = self.loadDefaultOrSpecifiedCFF(sequence,self.SKIMDefaultCFF)
1667  sequence = sequence.split('.')[-1]
1668 
1669  skimlist=sequence.split('+')
1670  ## support @Mu+DiJet+@Electron configuration via autoSkim.py
1671  from Configuration.Skimming.autoSkim import autoSkim
1672  self.expandMapping(skimlist,autoSkim)
1673 
1674  #print "dictionnary for skims:",skimConfig.__dict__
1675  for skim in skimConfig.__dict__:
1676  skimstream = getattr(skimConfig,skim)
1677  if isinstance(skimstream,cms.Path):
1678  #black list the alca path so that they do not appear in the cfg
1679  self.blacklist_paths.append(skimstream)
1680  if (not isinstance(skimstream,cms.FilteredStream)):
1681  continue
1682  shortname = skim.replace('SKIMStream','')
1683  if (sequence=="all"):
1684  self.addExtraStream(skim,skimstream)
1685  elif (shortname in skimlist):
1686  self.addExtraStream(skim,skimstream)
1687  #add a DQM eventcontent for this guy
1688  if self._options.datatier=='DQM':
1689  self.process.load(self.EVTCONTDefaultCFF)
1690  skimstreamDQM = cms.FilteredStream(
1691  responsible = skimstream.responsible,
1692  name = skimstream.name+'DQM',
1693  paths = skimstream.paths,
1694  selectEvents = skimstream.selectEvents,
1695  content = self._options.datatier+'EventContent',
1696  dataTier = cms.untracked.string(self._options.datatier)
1697  )
1698  self.addExtraStream(skim+'DQM',skimstreamDQM)
1699  for i in range(skimlist.count(shortname)):
1700  skimlist.remove(shortname)
1701 
1702 
1703 
1704  if (skimlist.__len__()!=0 and sequence!="all"):
1705  print 'WARNING, possible typo with SKIM:'+'+'.join(skimlist)
1706  raise Exception('WARNING, possible typo with SKIM:'+'+'.join(skimlist))
1707 
1708  def prepare_USER(self, sequence = None):
1709  ''' Enrich the schedule with a user defined sequence '''
1710  self.loadDefaultOrSpecifiedCFF(sequence,self.USERDefaultCFF)
1711  self.scheduleSequence(sequence.split('.')[-1],'user_step')
1712  return
1713 
1714  def prepare_POSTRECO(self, sequence = None):
1715  """ Enrich the schedule with the postreco step """
1716  self.loadAndRemember(self.POSTRECODefaultCFF)
1717  self.scheduleSequence('postreco_generator','postreco_step')
1718  return
1719 
1720 
1721  def prepare_VALIDATION(self, sequence = 'validation'):
1722  print sequence,"in preparing validation"
1723  self.loadDefaultOrSpecifiedCFF(sequence,self.VALIDATIONDefaultCFF)
1724  from Validation.Configuration.autoValidation import autoValidation
1725  #in case VALIDATION:something:somethingelse -> something,somethingelse
1726  sequence=sequence.split('.')[-1]
1727  if sequence.find(',')!=-1:
1728  prevalSeqName=sequence.split(',')[0].split('+')
1729  valSeqName=sequence.split(',')[1].split('+')
1730  self.expandMapping(prevalSeqName,autoValidation,index=0)
1731  self.expandMapping(valSeqName,autoValidation,index=1)
1732  else:
1733  if '@' in sequence:
1734  prevalSeqName=sequence.split('+')
1735  valSeqName=sequence.split('+')
1736  self.expandMapping(prevalSeqName,autoValidation,index=0)
1737  self.expandMapping(valSeqName,autoValidation,index=1)
1738  else:
1739  postfix=''
1740  if sequence:
1741  postfix='_'+sequence
1742  prevalSeqName=['prevalidation'+postfix]
1743  valSeqName=['validation'+postfix]
1744  if not hasattr(self.process,valSeqName[0]):
1745  prevalSeqName=['']
1746  valSeqName=[sequence]
1747 
1748  def NFI(index):
1749  ##name from index, required to keep backward compatibility
1750  if index==0:
1751  return ''
1752  else:
1753  return '%s'%index
1754 
1755  if not 'DIGI' in self.stepMap and not self._options.fast and not any(map( lambda s : s.startswith('genvalid'), valSeqName)):
1756  if self._options.restoreRNDSeeds==False and not self._options.restoreRNDSeeds==True:
1757  self._options.restoreRNDSeeds=True
1758 
1759  #rename the HLT process in validation steps
1760  if ('HLT' in self.stepMap and not self._options.fast) or self._options.hltProcess:
1761  for s in valSeqName+prevalSeqName:
1762  if s:
1764  for (i,s) in enumerate(prevalSeqName):
1765  if s:
1766  setattr(self.process,'prevalidation_step%s'%NFI(i), cms.Path( getattr(self.process, s)) )
1767  self.schedule.append(getattr(self.process,'prevalidation_step%s'%NFI(i)))
1768 
1769  for (i,s) in enumerate(valSeqName):
1770  setattr(self.process,'validation_step%s'%NFI(i), cms.EndPath( getattr(self.process, s)))
1771  self.schedule.append(getattr(self.process,'validation_step%s'%NFI(i)))
1772 
1773  if not 'DIGI' in self.stepMap and not self._options.fast:
1774  self.executeAndRemember("process.mix.playback = True")
1775  self.executeAndRemember("process.mix.digitizers = cms.PSet()")
1776  self.executeAndRemember("for a in process.aliases: delattr(process, a)")
1777  self._options.customisation_file.append("SimGeneral/MixingModule/fullMixCustomize_cff.setCrossingFrameOn")
1778 
1779  if hasattr(self.process,"genstepfilter") and len(self.process.genstepfilter.triggerConditions):
1780  #will get in the schedule, smoothly
1781  for (i,s) in enumerate(valSeqName):
1782  getattr(self.process,'validation_step%s'%NFI(i))._seq = self.process.genstepfilter * getattr(self.process,'validation_step%s'%NFI(i))._seq
1783 
1784  return
1785 
1786 
1788  """Visitor that travels within a cms.Sequence, looks for a parameter and replace its value
1789  It will climb down within PSets, VPSets and VInputTags to find its target"""
1790  def __init__(self, paramSearch, paramReplace, verbose=False, whitelist=()):
1791  self._paramReplace = paramReplace
1792  self._paramSearch = paramSearch
1793  self._verbose = verbose
1794  self._whitelist = whitelist
1795 
1796  def doIt(self,pset,base):
1797  if isinstance(pset, cms._Parameterizable):
1798  for name in pset.parameters_().keys():
1799  # skip whitelisted parameters
1800  if name in self._whitelist:
1801  continue
1802  # if I use pset.parameters_().items() I get copies of the parameter values
1803  # so I can't modify the nested pset
1804  value = getattr(pset,name)
1805  type = value.pythonTypeName()
1806  if type in ('cms.PSet', 'cms.untracked.PSet'):
1807  self.doIt(value,base+"."+name)
1808  elif type in ('cms.VPSet', 'cms.untracked.VPSet'):
1809  for (i,ps) in enumerate(value): self.doIt(ps, "%s.%s[%d]"%(base,name,i) )
1810  elif type in ('cms.string', 'cms.untracked.string'):
1811  if value.value() == self._paramSearch:
1812  if self._verbose: print "set string process name %s.%s %s ==> %s"% (base, name, value, self._paramReplace)
1813  setattr(pset, name,self._paramReplace)
1814  elif type in ('cms.VInputTag', 'cms.untracked.VInputTag'):
1815  for (i,n) in enumerate(value):
1816  if not isinstance(n, cms.InputTag):
1817  n=cms.InputTag(n)
1818  if n.processName == self._paramSearch:
1819  # VInputTag can be declared as a list of strings, so ensure that n is formatted correctly
1820  if self._verbose:print "set process name %s.%s[%d] %s ==> %s " % (base, name, i, n, self._paramReplace)
1821  setattr(n,"processName",self._paramReplace)
1822  value[i]=n
1823  elif type in ('cms.vstring', 'cms.untracked.vstring'):
1824  for (i,n) in enumerate(value):
1825  if n==self._paramSearch:
1826  getattr(pset,name)[i]=self._paramReplace
1827  elif type in ('cms.InputTag', 'cms.untracked.InputTag'):
1828  if value.processName == self._paramSearch:
1829  if self._verbose: print "set process name %s.%s %s ==> %s " % (base, name, value, self._paramReplace)
1830  setattr(getattr(pset, name),"processName",self._paramReplace)
1831 
1832  def enter(self,visitee):
1833  label = ''
1834  try:
1835  label = visitee.label()
1836  except AttributeError:
1837  label = '<Module not in a Process>'
1838  except:
1839  label = 'other execption'
1840  self.doIt(visitee, label)
1841 
1842  def leave(self,visitee):
1843  pass
1844 
1845  #visit a sequence to repalce all input tags
1846  def renameInputTagsInSequence(self,sequence,oldT="rawDataCollector",newT="rawDataRepacker"):
1847  print "Replacing all InputTag %s => %s"%(oldT,newT)
1848  from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag
1849  massSearchReplaceAnyInputTag(getattr(self.process,sequence),oldT,newT)
1850  loadMe='from PhysicsTools.PatAlgos.tools.helpers import massSearchReplaceAnyInputTag'
1851  if not loadMe in self.additionalCommands:
1852  self.additionalCommands.append(loadMe)
1853  self.additionalCommands.append('massSearchReplaceAnyInputTag(process.%s,"%s","%s",False,True)'%(sequence,oldT,newT))
1854 
1855  #change the process name used to address HLT results in any sequence
1856  def renameHLTprocessInSequence(self,sequence,proc=None,HLTprocess='HLT'):
1857  if self._options.hltProcess:
1858  proc=self._options.hltProcess
1859  else:
1860  proc=self.process.name_()
1861  if proc==HLTprocess: return
1862  # look up all module in dqm sequence
1863  print "replacing %s process name - sequence %s will use '%s'" % (HLTprocess,sequence, proc)
1864  getattr(self.process,sequence).visit(ConfigBuilder.MassSearchReplaceProcessNameVisitor(HLTprocess,proc,whitelist = ("subSystemFolder",)))
1865  if 'from Configuration.Applications.ConfigBuilder import ConfigBuilder' not in self.additionalCommands:
1866  self.additionalCommands.append('from Configuration.Applications.ConfigBuilder import ConfigBuilder')
1867  self.additionalCommands.append('process.%s.visit(ConfigBuilder.MassSearchReplaceProcessNameVisitor("%s", "%s", whitelist = ("subSystemFolder",)))'% (sequence,HLTprocess, proc))
1868 
1869 
1870  def expandMapping(self,seqList,mapping,index=None):
1871  maxLevel=20
1872  level=0
1873  while '@' in repr(seqList) and level<maxLevel:
1874  level+=1
1875  for specifiedCommand in seqList:
1876  if specifiedCommand.startswith('@'):
1877  location=specifiedCommand[1:]
1878  if not location in mapping:
1879  raise Exception("Impossible to map "+location+" from "+repr(mapping))
1880  mappedTo=mapping[location]
1881  if index!=None:
1882  mappedTo=mappedTo[index]
1883  seqList.remove(specifiedCommand)
1884  seqList.extend(mappedTo.split('+'))
1885  break;
1886  if level==maxLevel:
1887  raise Exception("Could not fully expand "+repr(seqList)+" from "+repr(mapping))
1888 
1889  def prepare_DQM(self, sequence = 'DQMOffline'):
1890  # this one needs replacement
1891 
1892  self.loadDefaultOrSpecifiedCFF(sequence,self.DQMOFFLINEDefaultCFF)
1893  sequenceList=sequence.split('.')[-1].split('+')
1894  from DQMOffline.Configuration.autoDQM import autoDQM
1895  self.expandMapping(sequenceList,autoDQM,index=0)
1896 
1897  if len(set(sequenceList))!=len(sequenceList):
1898  sequenceList=list(set(sequenceList))
1899  print "Duplicate entries for DQM:, using",sequenceList
1900  pathName='dqmoffline_step'
1901 
1902  for (i,sequence) in enumerate(sequenceList):
1903  if (i!=0):
1904  pathName='dqmoffline_%d_step'%(i)
1905 
1906  if 'HLT' in self.stepMap.keys() or self._options.hltProcess:
1907  self.renameHLTprocessInSequence(sequence)
1908 
1909  # if both HLT and DQM are run in the same process, schedule [HLT]DQM in an EndPath
1910  if 'HLT' in self.stepMap.keys():
1911  # need to put [HLT]DQM in an EndPath, to access the HLT trigger results
1912  setattr(self.process,pathName, cms.EndPath( getattr(self.process, sequence ) ) )
1913  else:
1914  # schedule DQM as a standard Path
1915  setattr(self.process,pathName, cms.Path( getattr(self.process, sequence) ) )
1916  self.schedule.append(getattr(self.process,pathName))
1917 
1918 
1919  def prepare_HARVESTING(self, sequence = None):
1920  """ Enrich the process with harvesting step """
1921  self.EDMtoMECFF='Configuration/StandardSequences/EDMtoME'+self._options.harvesting+'_cff'
1922  self.loadAndRemember(self.EDMtoMECFF)
1923  self.scheduleSequence('EDMtoME','edmtome_step')
1924 
1925  harvestingConfig = self.loadDefaultOrSpecifiedCFF(sequence,self.HARVESTINGDefaultCFF)
1926  sequence = sequence.split('.')[-1]
1927 
1928  # decide which HARVESTING paths to use
1929  harvestingList = sequence.split("+")
1930  from DQMOffline.Configuration.autoDQM import autoDQM
1931  from Validation.Configuration.autoValidation import autoValidation
1932  import copy
1933  combined_mapping = copy.deepcopy( autoDQM )
1934  combined_mapping.update( autoValidation )
1935  self.expandMapping(harvestingList,combined_mapping,index=-1)
1936 
1937  if len(set(harvestingList))!=len(harvestingList):
1938  harvestingList=list(set(harvestingList))
1939  print "Duplicate entries for HARVESTING, using",harvestingList
1940 
1941  for name in harvestingList:
1942  if not name in harvestingConfig.__dict__:
1943  print name,"is not a possible harvesting type. Available are",harvestingConfig.__dict__.keys()
1944  continue
1945  harvestingstream = getattr(harvestingConfig,name)
1946  if isinstance(harvestingstream,cms.Path):
1947  self.schedule.append(harvestingstream)
1948  self.blacklist_paths.append(harvestingstream)
1949  if isinstance(harvestingstream,cms.Sequence):
1950  setattr(self.process,name+"_step",cms.Path(harvestingstream))
1951  self.schedule.append(getattr(self.process,name+"_step"))
1952 
1953  self.scheduleSequence('DQMSaver','dqmsave_step')
1954  return
1955 
1956  def prepare_ALCAHARVEST(self, sequence = None):
1957  """ Enrich the process with AlCaHarvesting step """
1958  harvestingConfig = self.loadAndRemember(self.ALCAHARVESTDefaultCFF)
1959  sequence=sequence.split(".")[-1]
1960 
1961  # decide which AlcaHARVESTING paths to use
1962  harvestingList = sequence.split("+")
1963  for name in harvestingConfig.__dict__:
1964  harvestingstream = getattr(harvestingConfig,name)
1965  if name in harvestingList and isinstance(harvestingstream,cms.Path):
1966  self.schedule.append(harvestingstream)
1967  self.executeAndRemember("process.PoolDBOutputService.toPut.append(process.ALCAHARVEST" + name + "_dbOutput)")
1968  self.executeAndRemember("process.pclMetadataWriter.recordsToMap.append(process.ALCAHARVEST" + name + "_metadata)")
1969  harvestingList.remove(name)
1970  # append the common part at the end of the sequence
1971  lastStep = getattr(harvestingConfig,"ALCAHARVESTDQMSaveAndMetadataWriter")
1972  self.schedule.append(lastStep)
1973 
1974  if len(harvestingList) != 0 and 'dummyHarvesting' not in harvestingList :
1975  print "The following harvesting could not be found : ", harvestingList
1976  raise Exception("The following harvesting could not be found : "+str(harvestingList))
1977 
1978 
1979 
1980  def prepare_ENDJOB(self, sequence = 'endOfProcess'):
1981  self.loadDefaultOrSpecifiedCFF(sequence,self.ENDJOBDefaultCFF)
1982  self.scheduleSequenceAtEnd(sequence.split('.')[-1],'endjob_step')
1983  return
1984 
1986  self.process.reconstruction = cms.Path(self.process.reconstructionWithFamos)
1987  self.schedule.append(self.process.reconstruction)
1988 
1989  def prepare_FASTSIM(self, sequence = "all"):
1990  """Enrich the schedule with fastsim"""
1991  self.loadAndRemember("FastSimulation/Configuration/FamosSequences_cff")
1992 
1993  if sequence in ('all','allWithHLTFiltering',''):
1994  if not 'HLT' in self.stepMap.keys():
1995  self.prepare_HLT(sequence=None)
1996 
1997  self.executeAndRemember("process.famosSimHits.SimulateCalorimetry = True")
1998  self.executeAndRemember("process.famosSimHits.SimulateTracking = True")
1999 
2000  self.executeAndRemember("process.simulation = cms.Sequence(process.simulationWithFamos)")
2001  self.executeAndRemember("process.HLTEndSequence = cms.Sequence(process.reconstructionWithFamos)")
2002 
2003  # since we have HLT here, the process should be called HLT
2004  self._options.name = "HLT"
2005 
2006  # if we don't want to filter after HLT but simulate everything regardless of what HLT tells, we have to add reconstruction explicitly
2007  if sequence == 'all' and not 'HLT' in self.stepMap.keys(): #(a)
2008  self.finalizeFastSimHLT()
2009  elif sequence == 'sim':
2010  self.executeAndRemember("process.famosSimHits.SimulateCalorimetry = True")
2011  self.executeAndRemember("process.famosSimHits.SimulateTracking = True")
2012 
2013  self.executeAndRemember("process.simulation = cms.Sequence(process.simulationWithFamos)")
2014 
2015  self.process.fastsim_step = cms.Path( getattr(self.process, "simulationWithFamos") )
2016  self.schedule.append(self.process.fastsim_step)
2017  elif sequence == 'reco':
2018  self.executeAndRemember("process.mix.playback = True")
2019  self.executeAndRemember("process.reconstruction = cms.Sequence(process.reconstructionWithFamos)")
2020 
2021  self.process.fastsim_step = cms.Path( getattr(self.process, "reconstructionWithFamos") )
2022  self.schedule.append(self.process.fastsim_step)
2023  elif sequence == 'simExtended':
2024  self.executeAndRemember("process.famosSimHits.SimulateCalorimetry = True")
2025  self.executeAndRemember("process.famosSimHits.SimulateTracking = True")
2026 
2027  self.executeAndRemember("process.simulation = cms.Sequence(process.simulationWithSomeReconstruction)")
2028 
2029  self.process.fastsim_step = cms.Path( getattr(self.process, "simulationWithSomeReconstruction") )
2030  self.schedule.append(self.process.fastsim_step)
2031  elif sequence == 'recoHighLevel':
2032  self.executeAndRemember("process.mix.playback = True")
2033  self.executeAndRemember("process.reconstruction = cms.Sequence(process.reconstructionHighLevel)")
2034 
2035  self.process.fastsim_step = cms.Path( getattr(self.process, "reconstructionHighLevel") )
2036  self.schedule.append(self.process.fastsim_step)
2037  elif sequence == 'famosWithEverything':
2038  self.process.fastsim_step = cms.Path( getattr(self.process, "famosWithEverything") )
2039  self.schedule.append(self.process.fastsim_step)
2040 
2041  # now the additional commands we need to make the config work
2042  self.executeAndRemember("process.VolumeBasedMagneticFieldESProducer.useParametrizedTrackerField = True")
2043  else:
2044  print "FastSim setting", sequence, "unknown."
2045  raise ValueError
2046 
2047  if 'Flat' in self._options.beamspot:
2048  beamspotType = 'Flat'
2049  elif 'Gauss' in self._options.beamspot:
2050  beamspotType = 'Gaussian'
2051  else:
2052  beamspotType = 'BetaFunc'
2053  self.loadAndRemember('IOMC.EventVertexGenerators.VtxSmearedParameters_cfi')
2054  beamspotName = 'process.%sVtxSmearingParameters' %(self._options.beamspot)
2055  self.executeAndRemember(beamspotName+'.type = cms.string("%s")'%(beamspotType))
2056  self.executeAndRemember('process.famosSimHits.VertexGenerator = '+beamspotName)
2057  if hasattr(self.process,'famosPileUp'):
2058  self.executeAndRemember('process.famosPileUp.VertexGenerator = '+beamspotName)
2059 
2060 
2061 
2062  def build_production_info(self, evt_type, evtnumber):
2063  """ Add useful info for the production. """
2064  self.process.configurationMetadata=cms.untracked.PSet\
2065  (version=cms.untracked.string("$Revision: 1.19 $"),
2066  name=cms.untracked.string("Applications"),
2067  annotation=cms.untracked.string(evt_type+ " nevts:"+str(evtnumber))
2068  )
2069 
2070  self.addedObjects.append(("Production Info","configurationMetadata"))
2071 
2072 
2073  def prepare(self, doChecking = False):
2074  """ Prepare the configuration string and add missing pieces."""
2075 
2076  self.loadAndRemember(self.EVTCONTDefaultCFF) #load the event contents regardless
2077  self.addMaxEvents()
2078  if self.with_input:
2079  self.addSource()
2080  self.addStandardSequences()
2081  ##adding standard sequences might change the inputEventContent option and therefore needs to be finalized after
2082  self.completeInputCommand()
2083  self.addConditions()
2084 
2085 
2086  outputModuleCfgCode=""
2087  if not 'HARVESTING' in self.stepMap.keys() and not 'SKIM' in self.stepMap.keys() and not 'ALCAHARVEST' in self.stepMap.keys() and not 'ALCAOUTPUT' in self.stepMap.keys() and self.with_output:
2088  outputModuleCfgCode=self.addOutput()
2089 
2090  self.addCommon()
2091 
2092  self.pythonCfgCode = "# Auto generated configuration file\n"
2093  self.pythonCfgCode += "# using: \n# "+__version__[1:-1]+"\n# "+__source__[1:-1]+'\n'
2094  self.pythonCfgCode += "# with command line options: "+self._options.arguments+'\n'
2095  self.pythonCfgCode += "import FWCore.ParameterSet.Config as cms\n\n"
2096  self.pythonCfgCode += "process = cms.Process('"+self.process.name_()+"')\n\n"
2097 
2098  self.pythonCfgCode += "# import of standard configurations\n"
2099  for module in self.imports:
2100  self.pythonCfgCode += ("process.load('"+module+"')\n")
2101 
2102  # production info
2103  if not hasattr(self.process,"configurationMetadata"):
2104  self.build_production_info(self._options.evt_type, self._options.number)
2105  else:
2106  #the PSet was added via a load
2107  self.addedObjects.append(("Production Info","configurationMetadata"))
2108 
2109  self.pythonCfgCode +="\n"
2110  for comment,object in self.addedObjects:
2111  if comment!="":
2112  self.pythonCfgCode += "\n# "+comment+"\n"
2113  self.pythonCfgCode += dumpPython(self.process,object)
2114 
2115  # dump the output definition
2116  self.pythonCfgCode += "\n# Output definition\n"
2117  self.pythonCfgCode += outputModuleCfgCode
2118 
2119  # dump all additional outputs (e.g. alca or skim streams)
2120  self.pythonCfgCode += "\n# Additional output definition\n"
2121  #I do not understand why the keys are not normally ordered.
2122  nl=self.additionalOutputs.keys()
2123  nl.sort()
2124  for name in nl:
2125  output = self.additionalOutputs[name]
2126  self.pythonCfgCode += "process.%s = %s" %(name, output.dumpPython())
2127  tmpOut = cms.EndPath(output)
2128  setattr(self.process,name+'OutPath',tmpOut)
2129  self.schedule.append(tmpOut)
2130 
2131  # dump all additional commands
2132  self.pythonCfgCode += "\n# Other statements\n"
2133  for command in self.additionalCommands:
2134  self.pythonCfgCode += command + "\n"
2135 
2136  #comma separated list of objects that deserve to be inlined in the configuration (typically from a modified config deep down)
2137  for object in self._options.inlineObjets.split(','):
2138  if not object:
2139  continue
2140  if not hasattr(self.process,object):
2141  print 'cannot inline -'+object+'- : not known'
2142  else:
2143  self.pythonCfgCode +='\n'
2144  self.pythonCfgCode +=dumpPython(self.process,object)
2145 
2146  # dump all paths
2147  self.pythonCfgCode += "\n# Path and EndPath definitions\n"
2148  for path in self.process.paths:
2149  if getattr(self.process,path) not in self.blacklist_paths:
2150  self.pythonCfgCode += dumpPython(self.process,path)
2151 
2152  for endpath in self.process.endpaths:
2153  if getattr(self.process,endpath) not in self.blacklist_paths:
2154  self.pythonCfgCode += dumpPython(self.process,endpath)
2155 
2156  # dump the schedule
2157  if not self._options.runUnscheduled:
2158  self.pythonCfgCode += "\n# Schedule definition\n"
2159  result = "process.schedule = cms.Schedule("
2160 
2161  # handling of the schedule
2162  self.process.schedule = cms.Schedule()
2163  for item in self.schedule:
2164  if not isinstance(item, cms.Schedule):
2165  self.process.schedule.append(item)
2166  else:
2167  self.process.schedule.extend(item)
2168 
2169  if hasattr(self.process,"HLTSchedule"):
2170  beforeHLT = self.schedule[:self.schedule.index(self.process.HLTSchedule)]
2171  afterHLT = self.schedule[self.schedule.index(self.process.HLTSchedule)+1:]
2172  pathNames = ['process.'+p.label_() for p in beforeHLT]
2173  result += ','.join(pathNames)+')\n'
2174  result += 'process.schedule.extend(process.HLTSchedule)\n'
2175  pathNames = ['process.'+p.label_() for p in afterHLT]
2176  result += 'process.schedule.extend(['+','.join(pathNames)+'])\n'
2177  else:
2178  pathNames = ['process.'+p.label_() for p in self.schedule]
2179  result ='process.schedule = cms.Schedule('+','.join(pathNames)+')\n'
2180 
2181  self.pythonCfgCode += result
2182 
2183  #repacked version
2184  if self._options.isRepacked:
2185  self.pythonCfgCode +="\n"
2186  self.pythonCfgCode +="from Configuration.Applications.ConfigBuilder import MassReplaceInputTag\n"
2187  self.pythonCfgCode +="MassReplaceInputTag(process)\n"
2188  MassReplaceInputTag(self.process)
2189 
2190  # special treatment in case of production filter sequence 2/2
2191  if self.productionFilterSequence:
2192  self.pythonCfgCode +='# filter all path with the production filter sequence\n'
2193  self.pythonCfgCode +='for path in process.paths:\n'
2194  if len(self.conditionalPaths):
2195  self.pythonCfgCode +='\tif not path in %s: continue\n'%str(self.conditionalPaths)
2196  if len(self.excludedPaths):
2197  self.pythonCfgCode +='\tif path in %s: continue\n'%str(self.excludedPaths)
2198  self.pythonCfgCode +='\tgetattr(process,path)._seq = process.%s * getattr(process,path)._seq \n'%(self.productionFilterSequence,)
2199  pfs = getattr(self.process,self.productionFilterSequence)
2200  for path in self.process.paths:
2201  if not path in self.conditionalPaths: continue
2202  if path in self.excludedPaths: continue
2203  getattr(self.process,path)._seq = pfs * getattr(self.process,path)._seq
2204 
2205 
2206  # dump customise fragment
2207  self.pythonCfgCode += self.addCustomise()
2208 
2209  if self._options.runUnscheduled:
2210  # prune and delete paths
2211  #this is not supporting the blacklist at this point since I do not understand it
2212  self.pythonCfgCode+="#do not add changes to your config after this point (unless you know what you are doing)\n"
2213  self.pythonCfgCode+="from FWCore.ParameterSet.Utilities import convertToUnscheduled\n"
2214 
2215  self.pythonCfgCode+="process=convertToUnscheduled(process)\n"
2216 
2217  #now add the unscheduled stuff
2218  for module in self.importsUnsch:
2219  self.process.load(module)
2220  self.pythonCfgCode += ("process.load('"+module+"')\n")
2221 
2222  self.pythonCfgCode += self.addCustomise(1)
2223 
2224 
2225  # make the .io file
2226 
2227  if self._options.io:
2228  #io=open(self._options.python_filename.replace('.py','.io'),'w')
2229  if not self._options.io.endswith('.io'): self._option.io+='.io'
2230  io=open(self._options.io,'w')
2231  ioJson={}
2232  if hasattr(self.process.source,"fileNames"):
2233  if len(self.process.source.fileNames.value()):
2234  ioJson['primary']=self.process.source.fileNames.value()
2235  if hasattr(self.process.source,"secondaryFileNames"):
2236  if len(self.process.source.secondaryFileNames.value()):
2237  ioJson['secondary']=self.process.source.secondaryFileNames.value()
2238  if self._options.pileup_input and (self._options.pileup_input.startswith('dbs:') or self._options.pileup_input.startswith('das:')):
2239  ioJson['pileup']=self._options.pileup_input[4:]
2240  for (o,om) in self.process.outputModules_().items():
2241  ioJson[o]=om.fileName.value()
2242  ioJson['GT']=self.process.GlobalTag.globaltag.value()
2243  if self.productionFilterSequence:
2244  ioJson['filter']=self.productionFilterSequence
2245  import json
2246  io.write(json.dumps(ioJson))
2247  return
2248 
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34
def visit
Retrieve data from a perf suite output (sub) directory, only examines TimeSize at the moment...
def prepare_RECO
put the filtering path in the schedule
tuple zip
Definition: archive.py:476
def massSearchReplaceAnyInputTag
Definition: helpers.py:262
def defineMixing
Definition: Mixing.py:167
inliner
needs to be in reverse order
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
list object
Definition: dbtoconf.py:77
double split
Definition: MVATrainer.cc:139
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run