CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cmsswPreprocessor.py
Go to the documentation of this file.
1 import os
2 import re
3 import imp
6  def __init__(self,configFile,command="cmsRun") :
7  self.configFile=configFile
8  self.command=command
9 
10  def run(self,component,wd,firstEvent,nEvents):
11  print wd,firstEvent,nEvents
12  if nEvents is None:
13  nEvents = -1
14  cmsswConfig = imp.load_source("cmsRunProcess",self.configFile)
15  inputfiles= []
16  for fn in component.files :
17  if not re.match("file:.*",fn) and not re.match("root:.*",fn) :
18  fn="file:"+fn
19  inputfiles.append(fn)
20  cmsswConfig.process.source.fileNames = inputfiles
21  cmsswConfig.process.maxEvents.input=nEvents
22  #fixme: implement skipEvent / firstevent
23 
24  outfilename=wd+"/cmsswPreProcessing.root"
25  for outName in cmsswConfig.process.endpath.moduleNames() :
26  out = getattr(cmsswConfig.process,outName)
27  out.fileName = outfilename
28  if not hasattr(component,"options"):
29  component.options = CFG(name="postCmsrunOptions")
30  #use original as primary and new as secondary
31  #component.options.inputFiles= component.files
32  #component.options.secondaryInputFiles=[outfilename]
33 
34  #use new as primary and original as secondary
35  component.options.secondaryInputFiles= component.files
36  component.options.inputFiles=[outfilename]
37  component.files=[outfilename]
38 
39  configfile=wd+"/cmsRun_config.py"
40  f = open(configfile, 'w')
41  f.write(cmsswConfig.process.dumpPython())
42  f.close()
43  runstring="%s %s >& %s/cmsRun.log" % (self.command,configfile,wd)
44  print "Running pre-processor: %s " %runstring
45  os.system(runstring)
46  return component