CMS 3D CMS Logo

cmsDriverOptions.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 # A Pyrelval Wrapper
00004 
00005 import optparse
00006 import sys
00007 import os
00008 import Configuration.PyReleaseValidation
00009 from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder, defaultOptions
00010 import traceback
00011 # Prepare a parser to read the options
00012 usage=\
00013 """%prog <TYPE> [options].
00014 Examples:
00015 
00016 %prog SingleMuPt10_cfi -n 100 --no_output
00017 %prog QCD_Pt_15_20_cfi -s GEN,SIM,DIGI,L1,DQM,DIGI2RAW,HLT -n 10
00018 %prog reco -s RAW2DIGI,RECO --conditions FrontierConditions_GlobalTag,STARTUP_V4::All
00019 """
00020 parser = optparse.OptionParser(usage)
00021 
00022 expertSettings = optparse.OptionGroup(parser, '===============\n  Expert Options', 'Caution: please use only if you know what you are doing.')
00023 famosSettings = optparse.OptionGroup(parser, '===============\n  FastSimulation options', '')
00024 parser.add_option_group(expertSettings)
00025 
00026 parser.add_option("-s", "--step",
00027                    help="The desired step. The possible values are: "+\
00028                         "GEN,SIM,DIGI,DIGI2RAW,HLT,RAW2DIGI,RECO,POSTRECO,DQM,ALCA,VALIDATION or ALL.",
00029                    default="ALL",
00030                    dest="step")
00031 
00032 parser.add_option("--conditions",
00033                   help="What conditions to use. Default are frontier conditions 'STARTUP_V4::All' (FrontierConditions_GlobalTag,STARTUP_V4::All)",
00034                   default=defaultOptions.conditions,
00035                   dest="conditions")
00036 
00037 parser.add_option("--eventcontent",
00038                   help="What event content to write out. Default=FEVTDEBUG, or FEVT (for cosmics)",
00039                   default=None,
00040                   dest="eventcontent")
00041 
00042 parser.add_option("--filein",
00043                    help="The infile name.",
00044                    default="",#to be changed in the default form later
00045                    dest="filein")
00046 
00047 parser.add_option("--fileout",
00048                    help="The outfile name. If absent a default value is assigned",
00049                    default="", #to be changed in the default form later
00050                    dest="fileout")
00051 
00052 parser.add_option("-n", "--number",
00053                   help="The number of events. The default is 1.",
00054                   default="1",
00055                   dest="number")
00056 
00057 parser.add_option("--mc",
00058                   help="Specify that simulation is to be processed (default = guess based on options",
00059                   action="store_true",
00060                   default=False,
00061                   dest="isMC")
00062 parser.add_option("--data",
00063                   help="Specify that data is to be processed (default = guess based on options",
00064                   action="store_true",
00065                   default=False,
00066                   dest="isData")
00067 
00068 
00069 # expert settings
00070 expertSettings.add_option("--beamspot",
00071                           help="What beam spot to use (from Configuration/StandardSequences). Default depends on scenario",
00072                           default=None,
00073                           dest="beamspot")
00074 
00075 expertSettings.add_option("--customise",
00076                           help="Specify the file where the code to modify the process object is stored.",
00077                           default="",
00078                           dest="customisation_file")
00079 
00080 expertSettings.add_option("--datatier",
00081                           help="What data tier to use.",
00082                           default='',
00083                           dest="datatier")
00084 
00085 expertSettings.add_option( "--dirin",
00086                           help="The infile directory.",
00087                           default="",
00088                           dest="dirin")                    
00089 
00090 expertSettings.add_option( "--dirout",
00091                           help="The outfile directory.",
00092                           default="",
00093                           dest="dirout")                
00094 
00095 expertSettings.add_option("--filtername",
00096                           help="What filter name to specify in output module",
00097                           default="",
00098                           dest="filtername")
00099 
00100 expertSettings.add_option("--geometry",
00101                           help="What geometry to use (from Configuration/StandardSequences). Default=Pilot2",
00102                           default=defaultOptions.geometry,
00103                           dest="geometry")
00104 
00105 expertSettings.add_option("--magField",
00106                           help="What magnetic field to use (from Configuration/StandardSequences).",
00107                           default=defaultOptions.magField,
00108                           dest="magField")
00109 
00110 expertSettings.add_option("--no_output",
00111                           help="Do not write anything to disk. This is for "+\
00112                           "benchmarking purposes.",
00113                           action="store_true",
00114                           default=False,
00115                           dest="no_output_flag")
00116 
00117 expertSettings.add_option("--oneoutput",
00118                           help="use only one output module",
00119                           action="store_true",
00120                           default="False",
00121                           dest="oneoutput")
00122 
00123 expertSettings.add_option("--prefix",
00124                           help="Specify a prefix to the cmsRun command.",
00125                           default="",
00126                           dest="prefix")  
00127 
00128 expertSettings.add_option("--relval",
00129                           help="Set total number of events and events per job.", #this does not get used but get parsed in the command by DatOps
00130                           default="",
00131                           dest="relval")
00132 
00133 expertSettings.add_option("--dump_python",
00134                   help="Dump the config file in python "+\
00135                   "and do a full expansion of imports.",
00136                   action="store_true",
00137                   default=False,                  
00138                   dest="dump_python")
00139 
00140 expertSettings.add_option("--dump_DSetName",
00141                           help="Dump the primary datasetname.",
00142                           action="store_true",
00143                           default=False,
00144                           dest="dump_dsetname_flag")
00145 
00146 expertSettings.add_option("--pileup",
00147                   help="What pileup config to use. Default=NoPileUp.",
00148                   default=defaultOptions.pileup,
00149                   dest="pileup")
00150 
00151                                                     
00152 expertSettings.add_option("--python_filename",
00153                           help="Change the name of the created config file ",
00154                           default='',
00155                           dest="python_filename")
00156 
00157 expertSettings.add_option("--secondfilein",
00158                           help="The secondary infile name."+\
00159                                 "for the two-file solution. Default is no file",
00160                           default="",#to be changed in the default form later
00161                           dest="secondfilein")
00162 
00163 expertSettings.add_option("--writeraw",
00164                           help="In addition to the nominal output, write a file with just raw",
00165                           action="store_true",
00166                           default=False,
00167                           dest="writeraw")
00168 
00169 expertSettings.add_option("--scenario",
00170                           help="Select scenario overriding standard settings (available:"+str(defaultOptions.scenarioOptions)+")",
00171                           default='pp',
00172                           dest="scenario")
00173 
00174 
00175 parser.add_option("--no_exec",
00176                   help="Do not exec cmsRun. Just prepare the python config file.",
00177                   action="store_true",
00178                   default=False,
00179                   dest="no_exec_flag")   
00180                   
00181 (options,args) = parser.parse_args() # by default the arg is sys.argv[1:]
00182 
00183 # A simple check on the consistency of the arguments
00184 if len(sys.argv)==1:
00185     raise "Event Type: ", "No event type specified!"
00186 
00187 options.evt_type=sys.argv[1]
00188 
00189 # memorize the command line arguments 
00190 options.arguments = reduce(lambda x, y: x+' '+y, sys.argv[1:])
00191 
00192 # now adjust the given parameters before passing it to the ConfigBuilder
00193 
00194 
00195 
00196 # Build the IO files if necessary.
00197 # The default form of the files is:
00198 # <type>_<energy>_<step>.root
00199 prec_step = {"ALL":"",
00200              "GEN":"",
00201              "SIM":"GEN",
00202              "DIGI":"SIM",
00203              "RECO":"DIGI",
00204              "ALCA":"RECO",
00205              "ANA":"RECO",
00206              "DIGI2RAW":"DIGI",
00207              "RAW2DIGI":"DIGI2RAW"}
00208 
00209 trimmedEvtType=options.evt_type.split('/')[-1]
00210 
00211 trimmedStep=''
00212 isFirst=0
00213 step_list=options.step.split(',')
00214 for s in step_list:
00215     stepSP=s.split(':')
00216     step=stepSP[0]
00217     if ( isFirst==0 ):
00218         trimmedStep=step
00219         isFirst=1
00220     else:
00221         trimmedStep=trimmedStep+','+step
00222 
00223         
00224 first_step=trimmedStep.split(',')[0]             
00225 if options.filein=="" and not first_step in ("ALL","GEN","SIM_CHAIN"):
00226     if options.dirin=="":
00227         options.dirin="file:"
00228     options.filein=trimmedEvtType+"_"+prec_step[first_step]+".root"
00229 
00230 
00231 # Prepare the canonical file name for output / config file etc
00232 #   (EventType_STEP1_STEP2_..._PU)
00233 standardFileName = ""
00234 standardFileName = trimmedEvtType+"_"+trimmedStep
00235 standardFileName = standardFileName.replace(",","_").replace(".","_")
00236 if options.pileup != "NoPileUp":
00237     standardFileName += "_PU"
00238 
00239 
00240 # if no output file name given, set it to default
00241 if options.fileout=="":
00242     options.fileout = standardFileName+".root"
00243 
00244 
00245 # Prepare the name of the config file
00246 # (in addition list conditions in name)
00247 python_config_filename = standardFileName
00248 conditionsSP = options.conditions.split(',')
00249 
00250 if len(conditionsSP) > 1:
00251     # for conditions like STARTUP_V1, IDEAL_V1 we want only the STARTUP or IDEAL part
00252     conditionsType = conditionsSP[1].split("_")[0]
00253     python_config_filename += "_"+str(conditionsType)
00254 
00255 python_config_filename+=".py"
00256 
00257 
00258 #if desired, just add _rawonly to the end of the output file name
00259 fileraw=''
00260 if options.writeraw:
00261     fileraw=options.dirout
00262     wrSP=options.fileout.split('.')
00263     wrSPLen=len(wrSP)
00264     counter=0
00265     for w in wrSP:
00266         counter=counter+1
00267         if ( counter < wrSPLen ):
00268             if ( counter == 1):
00269                 fileraw=fileraw+w
00270             else:    
00271                 fileraw=fileraw+'.'+w
00272         else:
00273             fileraw=fileraw+'_rawonly.'+w
00274 
00275 
00276 
00277 secondfilestr=''
00278 if options.secondfilein!='':
00279     secondfilestr=options.dirin+options.secondfilein
00280 
00281 
00282 # replace step aliases by right list
00283 if options.step=='ALL':
00284         options.step='GEN,SIM,DIGI,L1,DIGI2RAW,RAW2DIGI,RECO,POSTRECO,VALIDATION,DQM'
00285 elif options.step=='DATA_CHAIN':
00286         options.step='RAW2DIGI,RECO,POSTRECO,DQM'
00287 options.step = options.step.replace("SIM_CHAIN","GEN,SIM,DIGI,L1,DIGI2RAW")
00288 
00289 # add on the end of job sequence...
00290 # if not fastsim...
00291 if not "FASTSIM" in options.step: 
00292   options.step=options.step+',ENDJOB'
00293 print options.step
00294 
00295 # the process name is just the last step in the list of steps
00296 options.name = trimmedStep.split(',')[-1]
00297 if options.name in ('POSTRECO,ALCA,DQM') and 'RECO' in trimmedStep:
00298     options.name = 'RECO'
00299 
00300 # if we're dealing with HLT, the process name has to be 'HLT' only
00301 if 'HLT' in trimmedStep:
00302     options.name = 'HLT'
00303 
00304 # sanity check options specifying data or mc
00305 if options.isData and options.isMC:
00306     print "You may specify only --data or --mc, not both"
00307     sys.exit(1)
00308 
00309 # if not specified by user try to guess
00310 if not options.isData and not options.isMC:
00311     if 'SIM' in trimmedStep:
00312         options.isMC=True
00313     if 'DIGI' in trimmedStep:
00314         options.isMC=True
00315     if (not (options.eventcontent == None)) and 'SIM' in options.eventcontent:
00316         options.isMC=True
00317     if 'SIM' in options.datatier:
00318         options.isMC=True
00319     if options.isMC:
00320         print 'We have determined that this is simulation (if not, rerun cmsDriver.py with --data)'
00321     else:
00322         print 'We have determined that this is real data (if not, rerun cmsDriver.py with --mc)'
00323     
00324 options.outfile_name = options.dirout+options.fileout
00325 

Generated on Tue Jun 9 17:26:58 2009 for CMSSW by  doxygen 1.5.4