CMS 3D CMS Logo

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