Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-07 22:32:55

0001 #! /usr/bin/env python3
0002 
0003 # A Pyrelval Wrapper
0004 
0005 from __future__ import print_function
0006 def run():
0007         import sys
0008         import os
0009         import Configuration.Applications
0010         from Configuration.Applications.ConfigBuilder import ConfigBuilder
0011         from Configuration.Applications.cmsDriverOptions import OptionsFromCommandLine
0012         options = OptionsFromCommandLine()
0013         
0014         # after cleanup of all config parameters pass it to the ConfigBuilder
0015         configBuilder = ConfigBuilder(options, with_output = True, with_input = True)
0016 
0017         # Switch on any eras that have been specified. This is not required to create
0018         # the file, it is only relevant if dump_python is set. It does have to be done
0019         # before the prepare() call though. If not, then the config files will be loaded
0020         # without applying the era changes. This doesn't affect the config file written,
0021         # but when the dump_python branch uses execfile to read it back in it doesn't
0022         # reload the modules - it picks up a reference to the already loaded ones. 
0023         if hasattr( options, "era" ) and options.era is not None :
0024             from Configuration.StandardSequences.Eras import eras
0025             for eraName in options.era.split(',') :
0026                 getattr( eras, eraName )._setChosen()
0027         
0028         configBuilder.prepare()
0029         # fetch the results and write it to file
0030         config = open(options.python_filename,"w")
0031         config.write(configBuilder.pythonCfgCode)
0032         config.close()
0033 
0034         # handle different dump options
0035         if options.dump_python:
0036             result = {}
0037             exec(open(options.python_filename).read(), result)
0038             process = result["process"]
0039             expanded = process.dumpPython()
0040             expandedFile = open(options.python_filename,"w")
0041             expandedFile.write(expanded)
0042             expandedFile.close()
0043             print("Expanded config file", options.python_filename, "created")
0044             sys.exit(0)           
0045   
0046         if options.no_exec_flag:
0047             print("Config file "+options.python_filename+ " created")
0048             sys.exit(0)
0049         else:
0050             commandString = options.prefix+" cmsRun "+options.suffix
0051             print("Starting "+commandString+' '+options.python_filename)
0052             commands = commandString.lstrip().split()
0053             os.execvpe(commands[0],commands+[options.python_filename],os.environ)
0054             sys.exit()
0055 
0056 run()
0057 
0058 
0059