CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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 
00013 
00014 def checkOptions():
00015     return
00016     
00017 def adaptOptions():
00018     return
00019 
00020 def OptionsFromCommand(command):
00021     items=command.split()
00022     if items[0] != 'cmsDriver.py':
00023         return None
00024     items.append('--evt_type')
00025     items.append(items[1])
00026     options=OptionsFromItems(items[2:])
00027     options.arguments = command
00028     return options
00029 
00030 def OptionsFromCommandLine():
00031     import sys
00032     options=OptionsFromItems(sys.argv[1:])
00033     # memorize the command line arguments 
00034     options.arguments = reduce(lambda x, y: x+' '+y, sys.argv[1:])
00035     return options
00036 
00037 def OptionsFromItems(items):
00038     import sys
00039     from Configuration.PyReleaseValidation.Options import parser
00040     (options,args) = parser.parse_args(items)
00041 
00042     if not options.conditions:
00043         raise Exception("the --conditions option is mandatory")
00044 
00045 
00046     #################################
00047     # Check parameters for validity #
00048     #################################
00049 
00050     # check in case of ALCAOUTPUT case for alca splitting
00051     if options.triggerResultsProcess == None and "ALCAOUTPUT" in options.step:
00052         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"
00053         sys.exit(1)
00054             
00055     if not options.evt_type:            
00056         options.evt_type=sys.argv[1]
00057 
00058     #now adjust the given parameters before passing it to the ConfigBuilder
00059 
00060     #trail a "/" to dirin and dirout
00061     if options.dirin!='' and (not options.dirin.endswith('/')):    options.dirin+='/'
00062     if options.dirout!='' and (not options.dirout.endswith('/')):  options.dirout+='/'
00063 
00064     # Build the IO files if necessary.
00065     # The default form of the files is:
00066     # <type>_<energy>_<step>.root
00067     prec_step = {"NONE":"",
00068                  "ALL":"",
00069                  "GEN":"",
00070                  "SIM":"GEN",
00071                  "DIGI":"SIM",
00072                  "HLT":"RAW",
00073                  "RECO":"DIGI",
00074                  "ALCA":"RECO",
00075                  "ANA":"RECO",
00076                  "SKIM":"RECO",
00077                  "DIGI2RAW":"DIGI",
00078                  "RAW2DIGI":"DIGI2RAW",
00079                  "RAW2RECO":"DIGI2RAW",
00080                  "DATAMIX":"DIGI",
00081                  "DIGI2RAW":"DATAMIX",
00082                  "HARVESTING":"RECO",
00083                  "ALCAHARVEST":"RECO"}
00084 
00085     trimmedEvtType=options.evt_type.split('/')[-1]
00086 
00087     #get the list of steps, without their options
00088     options.trimmedStep=[]
00089     for s in options.step.split(','):
00090         step=s.split(':')[0]
00091         options.trimmedStep.append(step)
00092     first_step=options.trimmedStep[0]
00093 
00094     #replace step aliases
00095     # this does not affect options.trimmedStep which still contains 'NONE'
00096     stepsAliases={
00097         'NONE':'',
00098         'ALL':'GEN,SIM,DIGI,L1,DIGI2RAW,HLT:GRun,RAW2DIGI,RECO,POSTRECO,VALIDATION,DQM',
00099         'DATA_CHAIN':'RAW2DIGI,RECO,POSTRECO,DQM'
00100         }
00101     if options.step in stepsAliases:
00102         options.step=stepsAliases[options.step]
00103 
00104     options.step = options.step.replace("SIM_CHAIN","GEN,SIM,DIGI,L1,DIGI2RAW")
00105 
00106     # add on the end of job sequence...
00107     addEndJob = True
00108     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 == "": 
00109         addEndJob = False
00110     if ("SKIM" in options.step and not "RECO" in options.step):
00111         addEndJob = False
00112     if ("ENDJOB" in options.step):
00113         addEndJob = False
00114     if ('DQMROOT' in options.datatier):
00115         addEndJob = False
00116     if addEndJob:    
00117         options.step=options.step+',ENDJOB'
00118 
00119 
00120     #determine the type of file on input
00121     if options.filetype==defaultOptions.filetype:
00122         if options.filein.lower().endswith(".lhe") or options.filein.lower().endswith(".lhef") or options.filein.startswith("lhe:"):
00123             options.filetype="LHE"
00124         elif options.filein.startswith("mcdb:"):
00125             print "This is a deprecated way of selecting lhe files from article number. Please use lhe:article argument to --filein"
00126             options.filein=options.filein.replace('mcdb:','lhe:')
00127             options.filetype="LHE"
00128         else:
00129             options.filetype="EDM"
00130 
00131     filesuffix = {"LHE": "lhe", "EDM": "root", "MCDB": "", "DQM":"root"}[options.filetype]
00132 
00133     if options.filein=="" and not (first_step in ("ALL","GEN","SIM_CHAIN")):
00134         options.dirin="file:"+options.dirin.replace('file:','')
00135         options.filein=trimmedEvtType+"_"+prec_step[first_step]+"."+filesuffix
00136 
00137 
00138     # Prepare the canonical file name for output / config file etc
00139     #   (EventType_STEP1_STEP2_..._PU)
00140     standardFileName = ""
00141     standardFileName = trimmedEvtType+"_"+"_".join(options.trimmedStep)
00142     standardFileName = standardFileName.replace(",","_").replace(".","_")
00143     if options.pileup != "NoPileUp":
00144         standardFileName += "_PU"
00145 
00146 
00147     # if no output file name given, set it to default
00148     if options.fileout=="" and not first_step in ("HARVESTING", "ALCAHARVEST"):
00149         options.fileout = standardFileName+".root"
00150 
00151     # Prepare the name of the config file
00152     if not options.python_filename:
00153         options.python_filename = standardFileName+'.py'
00154 
00155     print options.step
00156 
00157 
00158     # Setting name of process
00159     # if not set explicitly it needs some thinking
00160     if not options.name:
00161         if 'HLT' in options.trimmedStep:    
00162             options.name = 'HLT'
00163         elif 'RECO' in options.trimmedStep:
00164             options.name = 'RECO'
00165         elif options.trimmedStep == ['NONE'] and options.filetype in ('LHE', 'MCDB'):
00166             options.name = 'LHE'
00167         elif len(options.trimmedStep)==0:
00168             options.name = 'PROCESS'
00169         else:
00170             options.name = options.trimmedStep[-1]
00171 
00172     # check to be sure that people run the harvesting as a separate step
00173     isHarvesting = False
00174     isOther = False
00175 
00176     if "HARVESTING" in options.trimmedStep and len(options.trimmedStep) > 1:
00177         raise Exception("The Harvesting step must be run alone")
00178 
00179     # if not specified by user try to guess whether MC or DATA
00180     if not options.isData and not options.isMC:
00181         if 'SIM' in options.trimmedStep:
00182             options.isMC=True
00183         if 'CFWRITER' in options.trimmedStep:
00184             options.isMC=True
00185         if 'DIGI' in options.trimmedStep:
00186             options.isMC=True
00187         if (not (options.eventcontent == None)) and 'SIM' in options.eventcontent:
00188             options.isMC=True
00189         if 'SIM' in options.datatier:
00190             options.isMC=True
00191         if options.isMC:
00192             print 'We have determined that this is simulation (if not, rerun cmsDriver.py with --data)'
00193         else:
00194             print 'We have determined that this is real data (if not, rerun cmsDriver.py with --mc)'
00195 
00196     if options.profile:
00197         if options.profile and options.prefix:
00198             raise Exception("--profile and --prefix are incompatible")
00199         profilerType = 'pp'
00200         profileOpts = options.profile.split(':')
00201         if len(profileOpts):
00202             profilerType = profileOpts[0].replace("=", " ")
00203 
00204         if profilerType == "pp":
00205             options.profileTypeLabel = "performance"
00206         elif profilerType == "mp":
00207             options.profileTypeLabel = "memory"
00208         elif profilerType.startswith("fp "):
00209             options.profileTypeLabel = profilerType.replace("fp ", "")
00210         else:   
00211             raise Exception("Not a valid profiler type %s. Alternatives are pp, mp, fp=<function>."%(profilerType))
00212 
00213         options.prefix = "igprof -%s" % profilerType
00214         
00215     return options
00216