CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Configuration/PyReleaseValidation/python/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 re
00009 import Configuration.PyReleaseValidation
00010 from Configuration.PyReleaseValidation.ConfigBuilder import ConfigBuilder, defaultOptions
00011 import traceback
00012 # Prepare a parser to read the options
00013 usage=\
00014 """%prog <TYPE> [options].
00015 Example:
00016 
00017 %prog reco -s RAW2DIGI,RECO --conditions STARTUP_V4::All --eventcontent RECOSIM
00018 """
00019 parser = optparse.OptionParser(usage)
00020 
00021 expertSettings = optparse.OptionGroup(parser, '===============\n  Expert Options', 'Caution: please use only if you know what you are doing.')
00022 famosSettings = optparse.OptionGroup(parser, '===============\n  FastSimulation options', '')
00023 parser.add_option_group(expertSettings)
00024 
00025 parser.add_option("-s", "--step",
00026                    help="The desired step. The possible values are: "+\
00027                         "GEN,SIM,DIGI,L1,DIGI2RAW,HLT,RAW2DIGI,RECO,POSTRECO,DQM,ALCA,VALIDATION,HARVESTING, NONE or ALL.",
00028                    default="ALL",
00029                    dest="step")
00030 
00031 parser.add_option("--conditions",
00032                   help="What conditions to use. Default are frontier conditions 'STARTUP_V4::All' ",
00033                   default=None,
00034                   dest="conditions")
00035 
00036 parser.add_option("--eventcontent",
00037                   help="What event content to write out. Default=FEVTDEBUG, or FEVT (for cosmics)",
00038                   default='RECOSIM',
00039                   dest="eventcontent")
00040 
00041 parser.add_option("--filein",
00042                    help="The infile name.",
00043                    default="",#to be changed in the default form later
00044                    dest="filein")
00045 
00046 parser.add_option("--fileout",
00047                    help="The outfile name. If absent a default value is assigned",
00048                    default="", #to be changed in the default form later
00049                    dest="fileout")
00050 
00051 parser.add_option("--filetype",
00052                    help="The type of the infile (EDM, LHE).",
00053                    default="",#to be changed in the default form later
00054                    dest="filetype")
00055 
00056 parser.add_option("-n", "--number",
00057                   help="The number of events. The default is 1.",
00058                   default="1",
00059                   dest="number")
00060 
00061 parser.add_option("--mc",
00062                   help="Specify that simulation is to be processed (default = guess based on options",
00063                   action="store_true",
00064                   default=False,
00065                   dest="isMC")
00066 
00067 parser.add_option("--data",
00068                   help="Specify that data is to be processed (default = guess based on options",
00069                   action="store_true",
00070                   default=False,
00071                   dest="isData")
00072 
00073 parser.add_option("--cust_function",
00074                   help="Specify the customise function to be called from the customise fragment.",
00075                   default='',
00076                   dest='cust_function')
00077 
00078 parser.add_option("--no_exec",
00079                   help="Do not exec cmsRun. Just prepare the python config file.",
00080                   action="store_true",
00081                   default=False,
00082                   dest="no_exec_flag")   
00083 
00084 # expert settings
00085 expertSettings.add_option("--beamspot",
00086                           help="What beam spot to use (from Configuration/StandardSequences). Default depends on scenario",
00087                           default=defaultOptions.beamspot,
00088                           dest="beamspot")
00089 
00090 expertSettings.add_option("--customise",
00091                           help="Specify the file where the code to modify the process object is stored.",
00092                           default="",
00093                           dest="customisation_file")
00094 
00095 expertSettings.add_option("--datatier",
00096                           help="What data tier to use.",
00097                           default='',
00098                           dest="datatier")
00099 
00100 expertSettings.add_option( "--dirin",
00101                           help="The infile directory.",
00102                           default="",
00103                           dest="dirin")                    
00104 
00105 expertSettings.add_option( "--dirout",
00106                           help="The outfile directory.",
00107                           default="",
00108                           dest="dirout")                
00109 
00110 expertSettings.add_option("--filtername",
00111                           help="What filter name to specify in output module",
00112                           default="",
00113                           dest="filtername")
00114 
00115 expertSettings.add_option("--geometry",
00116                           help="What geometry to use (from Configuration/StandardSequences). Default=Ideal",
00117                           default=defaultOptions.geometry,
00118                           dest="geometry")
00119 
00120 expertSettings.add_option("--magField",
00121                           help="What magnetic field to use (from Configuration/StandardSequences).",
00122                           default=defaultOptions.magField,
00123                           dest="magField")
00124 
00125 expertSettings.add_option("--no_output",
00126                           help="Do not write anything to disk. This is for "+\
00127                           "benchmarking purposes.",
00128                           action="store_true",
00129                           default=False,
00130                           dest="no_output_flag")
00131 
00132 expertSettings.add_option("--oneoutput",
00133                           help="use only one output module",
00134                           action="store_true",
00135                           default="False",
00136                           dest="oneoutput")
00137 
00138 expertSettings.add_option("--prefix",
00139                           help="Specify a prefix to the cmsRun command.",
00140                           default="",
00141                           dest="prefix")  
00142 
00143 expertSettings.add_option("--relval",
00144                           help="Set total number of events and events per job.", #this does not get used but get parsed in the command by DatOps
00145                           default="",
00146                           dest="relval")
00147 
00148 expertSettings.add_option("--dump_python",
00149                   help="Dump the config file in python "+\
00150                   "and do a full expansion of imports.",
00151                   action="store_true",
00152                   default=False,                  
00153                   dest="dump_python")
00154 
00155 expertSettings.add_option("--dump_DSetName",
00156                           help="Dump the primary datasetname.",
00157                           action="store_true",
00158                           default=False,
00159                           dest="dump_dsetname_flag")
00160 
00161 expertSettings.add_option("--pileup",
00162                   help="What pileup config to use. Default=NoPileUp.",
00163                   default=defaultOptions.pileup,
00164                   dest="pileup")
00165 
00166 expertSettings.add_option("--datamix",
00167                   help="What datamix config to use. Default=DataOnSim.",
00168                   default=defaultOptions.datamix,
00169                   dest="datamix")
00170 
00171 expertSettings.add_option("--gflash",
00172                   help="Run the FULL SIM using the GFlash parameterization.",
00173                   action="store_true",
00174                   default=defaultOptions.gflash,
00175                   dest="gflash")
00176 
00177 expertSettings.add_option("--himix",
00178                  help="Run the Heavy Ions signal mixing.",
00179                  action="store_true",
00180                  default=defaultOptions.himix,
00181                  dest="himix")
00182                                                     
00183 expertSettings.add_option("--python_filename",
00184                           help="Change the name of the created config file ",
00185                           default='',
00186                           dest="python_filename")
00187 
00188 expertSettings.add_option("--secondfilein",
00189                           help="The secondary infile name."+\
00190                                 "for the two-file solution. Default is no file",
00191                           default="",#to be changed in the default form later
00192                           dest="secondfilein")
00193 
00194 expertSettings.add_option("--writeraw",
00195                           help="In addition to the nominal output, write a file with just raw",
00196                           action="store_true",
00197                           default=False,
00198                           dest="writeraw")
00199 
00200 expertSettings.add_option("--processName",
00201                           help="set process name explicitly",
00202                           default = None,
00203                           dest="name" 
00204                           )
00205 
00206 expertSettings.add_option("--triggerResultsProcess",
00207                           help="for splitting jobs specify from which process to take edm::TriggerResults",
00208                           default = None,
00209                           dest="triggerResultsProcess"
00210                           )
00211 
00212 expertSettings.add_option("--hltProcess",
00213                           help="modify the DQM sequence to look for HLT trigger results with the specified process name", 
00214                           default = None,
00215                           dest="hltProcess"
00216                           )
00217 
00218 expertSettings.add_option("--scenario",
00219                           help="Select scenario overriding standard settings (available:"+str(defaultOptions.scenarioOptions)+")",
00220                           default='pp',
00221                           dest="scenario")
00222 
00223 expertSettings.add_option("--harvesting",
00224                           help="What harvesting to use (from Configuration/StandardSequences). Default=AtRunEnd",
00225                           default=defaultOptions.harvesting,
00226                           dest="harvesting")
00227 
00228 expertSettings.add_option("--particle_table",
00229                           help="Which particle properties table is loaded. Default=pythia",
00230                           default=defaultOptions.particleTable,
00231                           dest="particleTable")
00232 
00233 expertSettings.add_option("--dbsquery",
00234                           help="Allow to define the source.fileNames from the dbs search command",
00235                           default='',
00236                           dest="dbsquery")
00237 
00238 expertSettings.add_option("--lazy_download",
00239                   help="Enable lazy downloading of input files",
00240                   action="store_true",
00241                   default=False,
00242                   dest="lazy_download")   
00243 
00244 expertSettings.add_option("--repacked",
00245                           help="When the input file is a file with repacked raw data with label rawDataRepacker",
00246                           action="store_true",
00247                           default=False,
00248                           dest="isRepacked"
00249                           )
00250 
00251 expertSettings.add_option("--custom_conditions",
00252                           help="Allow to give a few overriding tags for the GT",
00253                           default='',
00254                           dest='custom_conditions')
00255 
00256 expertSettings.add_option("--inline_eventcontent",
00257                           help="expand event content definitions",
00258                           action="store_true",
00259                           default=False,
00260                           dest="inlineEventContent")
00261 
00262 
00263 expertSettings.add_option("--inline_object",
00264                           help="expand explicitely the definition of a list of objects",
00265                           default='',
00266                           dest="inlineObjets")
00267 
00268 expertSettings.add_option("--hideGen",
00269                           help="do not inline the generator information, just load it",
00270                           default=False,
00271                           action="store_true")
00272 expertSettings.add_option("--output",
00273                           help="specify the list of output modules using dict",
00274                           default='',
00275                           dest="outputDefinition")
00276 
00277 expertSettings.add_option("--inputCommands",
00278                           help="specify the input commands; i.e dropping products",
00279                           default=None,
00280                           dest="inputCommands")
00281                           
00282 (options,args) = parser.parse_args() # by default the arg is sys.argv[1:]
00283 
00284 
00285 #################################
00286 # Check parameters for validity #
00287 #################################
00288 # A simple check on the consistency of the arguments
00289 if len(sys.argv)==1:
00290     raise "Event Type: ", "No event type specified!"
00291 
00292 # check in case of ALCAOUTPUT case for alca splitting
00293 if options.triggerResultsProcess == None and "ALCAOUTPUT" in options.step:
00294     print "ERROR: If ALCA splitting is requested, the name of the process in which the alca producers ran needs to be specified. E.g. via --triggerResultsProcess RECO"
00295     sys.exit(1)
00296             
00297             
00298 options.evt_type=sys.argv[1]
00299 
00300 # memorize the command line arguments 
00301 options.arguments = reduce(lambda x, y: x+' '+y, sys.argv[1:])
00302 
00303 # now adjust the given parameters before passing it to the ConfigBuilder
00304 
00305 
00306 
00307 # Build the IO files if necessary.
00308 # The default form of the files is:
00309 # <type>_<energy>_<step>.root
00310 prec_step = {"NONE":"",
00311              "ALL":"",
00312              "GEN":"",
00313              "SIM":"GEN",
00314              "DIGI":"SIM",
00315              "HLT":"RAW",
00316              "RECO":"DIGI",
00317              "ALCA":"RECO",
00318              "ANA":"RECO",
00319              "SKIM":"RECO",
00320              "DIGI2RAW":"DIGI",
00321              "RAW2DIGI":"DIGI2RAW",
00322              "RAW2RECO":"DIGI2RAW",
00323              "DATAMIX":"DIGI",
00324              "DIGI2RAW":"DATAMIX",
00325              "HARVESTING":"RECO",
00326              "ALCAHARVEST":"RECO"}
00327 
00328 trimmedEvtType=options.evt_type.split('/')[-1]
00329 
00330 trimmedStep=''
00331 isFirst=0
00332 step_list=options.step.split(',')
00333 for s in step_list:
00334     stepSP=s.split(':')
00335     step=stepSP[0]
00336     if ( isFirst==0 ):
00337         trimmedStep=step
00338         isFirst=1
00339     else:
00340         trimmedStep=trimmedStep+','+step
00341 
00342 
00343 if options.filetype=="":
00344     if options.filein.lower().endswith(".lhe") or options.filein.lower().endswith(".lhef") or options.filein.startswith("lhe:"):
00345         options.filetype="LHE"
00346     elif options.filein.startswith("mcdb:"):
00347         print "This is a deprecated way of selecting lhe files from article number. Please use lhe:article argument to --filein"
00348         options.filein=options.filein.replace('mcdb:','lhe:')
00349         options.filetype="LHE"
00350     else:
00351         options.filetype="EDM"
00352 
00353 filesuffix = {"LHE": "lhe", "EDM": "root", "MCDB": ""}[options.filetype]
00354 
00355 first_step=trimmedStep.split(',')[0]             
00356 if options.filein=="" and not (first_step in ("ALL","GEN","SIM_CHAIN") and options.dirin == ""):
00357     if options.dirin=="":
00358         options.dirin="file:"
00359     options.filein=trimmedEvtType+"_"+prec_step[first_step]+"."+filesuffix
00360 
00361 
00362 # Prepare the canonical file name for output / config file etc
00363 #   (EventType_STEP1_STEP2_..._PU)
00364 standardFileName = ""
00365 standardFileName = trimmedEvtType+"_"+trimmedStep
00366 standardFileName = standardFileName.replace(",","_").replace(".","_")
00367 if options.pileup != "NoPileUp":
00368     standardFileName += "_PU"
00369 
00370 
00371 # if no output file name given, set it to default
00372 if options.fileout=="" and not first_step in ("HARVESTING", "ALCAHARVEST"):
00373     options.fileout = standardFileName+".root"
00374 
00375 # Prepare the name of the config file
00376 # (in addition list conditions in name)
00377 python_config_filename = standardFileName
00378 
00379 # now treat the conditions...
00380 conditionsSP = options.conditions.split(',')
00381 if len(conditionsSP) > 1:
00382     # for conditions like STARTUP_V1, IDEAL_V1 we want only the STARTUP or IDEAL part
00383     conditionsType = conditionsSP[1].split("_")[0]
00384     python_config_filename += "_"+str(conditionsType)
00385 
00386 python_config_filename+=".py"
00387 
00388 
00389 #if desired, just add _rawonly to the end of the output file name
00390 fileraw=''
00391 if options.writeraw:
00392     fileraw=options.dirout
00393     wrSP=options.fileout.split('.')
00394     wrSPLen=len(wrSP)
00395     counter=0
00396     for w in wrSP:
00397         counter=counter+1
00398         if ( counter < wrSPLen ):
00399             if ( counter == 1):
00400                 fileraw=fileraw+w
00401             else:    
00402                 fileraw=fileraw+'.'+w
00403         else:
00404             fileraw=fileraw+'_rawonly.'+w
00405 
00406 
00407 
00408 secondfilestr=''
00409 if options.secondfilein!='':
00410     secondfilestr=options.dirin+options.secondfilein
00411 
00412 
00413 # replace step aliases by right list
00414 if options.step=='NONE': 
00415         options.step=''
00416 elif options.step=='ALL':
00417         options.step='GEN,SIM,DIGI,L1,DIGI2RAW,RAW2DIGI,RECO,POSTRECO,VALIDATION,DQM'
00418 elif options.step=='DATA_CHAIN':
00419         options.step='RAW2DIGI,RECO,POSTRECO,DQM'
00420 options.step = options.step.replace("SIM_CHAIN","GEN,SIM,DIGI,L1,DIGI2RAW")
00421 
00422 # add on the end of job sequence...
00423 # if not fastsim or harvesting...
00424 
00425 addEndJob = True
00426 if ("FASTSIM" in options.step and not "VALIDATION" in options.step) or "HARVESTING" in options.step or "ALCAHARVEST" in options.step or "ALCAOUTPUT" in options.step or options.step == "": 
00427     addEndJob = False
00428 if ("SKIM" in options.step and not "RECO" in options.step):
00429     addEndJob = False
00430 if ("ENDJOB" in options.step):
00431     addEndJob = False
00432 if addEndJob:    
00433     options.step=options.step+',ENDJOB'
00434 print options.step
00435 
00436 
00437 # Setting name of process
00438 # if not set explicitly it needs some thinking
00439 if not options.name:
00440     if 'HLT' in trimmedStep:    
00441         options.name = 'HLT'
00442     elif 'RECO' in trimmedStep:
00443         options.name = 'RECO'
00444     elif trimmedStep == 'NONE' and options.filetype in ('LHE', 'MCDB'):
00445         options.name = 'LHE'
00446     else:
00447         options.name = trimmedStep.split(',')[-1]
00448 
00449 # check to be sure that people run the harvesting as a separate step
00450 isHarvesting = False
00451 isOther = False
00452 
00453 s_list=options.step.split(',')
00454 if "HARVESTING" in options.step and len(s_list) > 1:
00455     print "The Harvesting step must be run alone"
00456     sys.exit(1)
00457 
00458 # if not specified by user try to guess whether MC or DATA
00459 if not options.isData and not options.isMC:
00460     if 'SIM' in trimmedStep:
00461         options.isMC=True
00462     if 'CFWRITER' in trimmedStep:
00463         options.isMC=True
00464     if 'DIGI' in trimmedStep:
00465         options.isMC=True
00466     if (not (options.eventcontent == None)) and 'SIM' in options.eventcontent:
00467         options.isMC=True
00468     if 'SIM' in options.datatier:
00469         options.isMC=True
00470     if options.isMC:
00471         print 'We have determined that this is simulation (if not, rerun cmsDriver.py with --data)'
00472     else:
00473         print 'We have determined that this is real data (if not, rerun cmsDriver.py with --mc)'
00474     
00475