CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/Configuration/PyReleaseValidation/scripts/runTheMatrix.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 
00005 from Configuration.PyReleaseValidation.MatrixReader import MatrixReader
00006 from Configuration.PyReleaseValidation.MatrixRunner import MatrixRunner
00007 from Configuration.PyReleaseValidation.MatrixInjector import MatrixInjector,performInjectionOptionTest
00008         
00009 # ================================================================================
00010 
00011 def showRaw(opt):
00012 
00013     mrd = MatrixReader(opt)
00014     mrd.showRaw(opt.useInput, opt.refRel, opt.fromScratch, opt.raw, opt.step1Only, selected=opt.testList)
00015 
00016     return 0
00017         
00018 # ================================================================================
00019 
00020 def runSelected(opt):
00021 
00022     mrd = MatrixReader(opt)
00023     mrd.prepare(opt.useInput, opt.refRel, opt.fromScratch)
00024 
00025     ret = 0
00026     if opt.show:
00027         mrd.show(opt.testList,opt.extended)
00028         if opt.testList : print 'testListected items:', opt.testList
00029     else:
00030         mRunnerHi = MatrixRunner(mrd.workFlows, opt.nThreads)
00031         ret = mRunnerHi.runTests(opt)
00032 
00033     if opt.wmcontrol:
00034         if ret!=0:
00035             print 'Cannot go on with wmagent injection with failing workflows'
00036         else:
00037             wfInjector = MatrixInjector(opt,mode=opt.wmcontrol)
00038             ret= wfInjector.prepare(mrd,
00039                                     mRunnerHi.runDirs)
00040             if ret==0:
00041                 wfInjector.upload()
00042                 wfInjector.submit()
00043     return ret
00044 
00045 # ================================================================================
00046 
00047 if __name__ == '__main__':
00048 
00049     #this can get out of here
00050     predefinedSet={
00051         'limited' : [5.1, #FastSim ttbar
00052                      8, #BH/Cosmic MC
00053                      25, #MC ttbar
00054                      4.22, #cosmic data
00055                      4.291, #hlt data
00056                      1000, #data+prompt
00057                      1001, #data+express
00058                      4.53, #HI data
00059                      40, #HI MC
00060                      ],
00061         'jetmc': [5.1, 13, 15, 25, 38, 39], #MC
00062         'metmc' : [5.1, 15, 25, 37, 38, 39], #MC
00063         'muonmc' : [5.1, 124.4, 124.5, 20, 21, 22, 23, 25, 30], #MC
00064         }
00065         
00066 
00067     import optparse
00068     usage = 'usage: runTheMatrix.py --show -s '
00069 
00070     parser = optparse.OptionParser(usage)
00071 
00072     parser.add_option('-j','--nproc',
00073                       help='number of threads. 0 Will use 4 threads, not execute anything but create the wfs',
00074                       dest='nThreads',
00075                       default=4
00076                      )
00077     parser.add_option('-n','--showMatrix',
00078                       help='Only show the worflows. Use --ext to show more',
00079                       dest='show',
00080                       default=False,
00081                       action='store_true'
00082                       )
00083     parser.add_option('-e','--extended',
00084                       help='Show details of workflows, used with --show',
00085                       dest='extended',
00086                       default=False,
00087                       action='store_true'
00088                       )
00089     parser.add_option('-s','--selected',
00090                       help='Run a pre-defined selected matrix of wf. Deprecated, please use -l limited',
00091                       dest='restricted',
00092                       default=False,
00093                       action='store_true'
00094                       )
00095     parser.add_option('-l','--list',
00096                      help='Coma separated list of workflow to be shown or ran. Possible keys are also '+str(predefinedSet.keys())+'. and wild card like muon, or mc',
00097                      dest='testList',
00098                      default=None
00099                      )
00100     parser.add_option('-r','--raw',
00101                       help='Temporary dump the .txt needed for prodAgent interface. To be discontinued soon. Argument must be the name of the set (standard, pileup,...)',
00102                       dest='raw'
00103                       )
00104     parser.add_option('-i','--useInput',
00105                       help='Use recyling where available. Either all, or a coma separated list of wf number.',
00106                       dest='useInput',
00107                       default=None
00108                       )
00109     parser.add_option('-w','--what',
00110                       help='Specify the set to be used. Argument must be the name of the set (standard, pileup,...)',
00111                       dest='what',
00112                       default='all'
00113                       )
00114     parser.add_option('--step1',
00115                       help='Used with --raw. Limit the production to step1',
00116                       dest='step1Only',
00117                       default=False
00118                       )
00119     parser.add_option('--fromScratch',
00120                       help='Coma separated list of wf to be run without recycling. all is not supported as default.',
00121                       dest='fromScratch',
00122                       default=None
00123                        )
00124     parser.add_option('--refRelease',
00125                       help='Allow to modify the recycling dataset version',
00126                       dest='refRel',
00127                       default=None
00128                       )
00129     parser.add_option('--wmcontrol',
00130                       help='Create the workflows for injection to WMAgent. In the WORKING. -wmcontrol init will create the the workflows, -wmcontrol test will dryRun a test, -wmcontrol submit will submit to wmagent',
00131                       choices=['init','test','submit','force'],
00132                       dest='wmcontrol',
00133                       default=None,
00134                       )
00135     parser.add_option('--keep',
00136                       help='allow to specify for which coma separated steps the output is needed',
00137                       default=None)
00138     parser.add_option('--label',
00139                       help='allow to give a special label to the output dataset name',
00140                       default='')
00141     parser.add_option('--command',
00142                       help='provide a way to add additional command to all of the cmsDriver commands in the matrix',
00143                       dest='command',
00144                       default=None
00145                       )
00146     parser.add_option('--apply',
00147                       help='allow to use the --command only for 1 coma separeated',
00148                       dest='apply',
00149                       default=None)
00150     parser.add_option('--workflow',
00151                       help='define a workflow to be created or altered from the matrix',
00152                       action='append',
00153                       dest='workflow',
00154                       default=None
00155                       )
00156     parser.add_option('--dryRun',
00157                       help='do not run the wf at all',
00158                       action='store_true',
00159                       dest='dryRun',
00160                       default=False
00161                       )
00162     parser.add_option('--noCafVeto',
00163                       help='Run from any source, ignoring the CAF label',
00164                       dest='cafVeto',
00165                       default=True,
00166                       action='store_false'
00167                       )
00168     parser.add_option('--overWrite',
00169                       help='Change the content of a step for another. List of pairs.',
00170                       dest='overWrite',
00171                       default=None
00172                       )
00173     parser.add_option('--noRun',
00174                       help='Remove all run list selection from wfs',
00175                       dest='noRun',
00176                       default=False,
00177                       action='store_true')
00178 
00179 
00180     
00181     opt,args = parser.parse_args()
00182     if opt.restricted:
00183         print 'Deprecated, please use -l limited'
00184         if opt.testList:            opt.testList+=',limited'
00185         else:            opt.testList='limited'
00186 
00187     def stepOrIndex(s):
00188         if s.isdigit():
00189             return int(s)
00190         else:
00191             return s
00192     if opt.apply:
00193         opt.apply=map(stepOrIndex,opt.apply.split(','))
00194     if opt.keep:
00195         opt.keep=map(stepOrIndex,opt.keep.split(','))
00196         
00197                 
00198                 
00199     if opt.testList:
00200         testList=[]
00201         for entry in opt.testList.split(','):
00202             if not entry: continue
00203             mapped=False
00204             for k in predefinedSet:
00205                 if k.lower().startswith(entry.lower()) or k.lower().endswith(entry.lower()):
00206                     testList.extend(predefinedSet[k])
00207                     mapped=True
00208                     break
00209             if not mapped:
00210                 try:
00211                     testList.append(float(entry))
00212                 except:
00213                     print entry,'is not a possible selected entry'
00214             
00215         opt.testList = list(set(testList))
00216 
00217 
00218     if opt.useInput: opt.useInput = opt.useInput.split(',')
00219     if opt.fromScratch: opt.fromScratch = opt.fromScratch.split(',')
00220     if opt.nThreads: opt.nThreads=int(opt.nThreads)
00221 
00222     if opt.wmcontrol:
00223         performInjectionOptionTest(opt)
00224     if opt.overWrite:
00225         opt.overWrite=eval(opt.overWrite)
00226 
00227     if opt.raw and opt.show: ###prodAgent to be discontinued
00228         ret = showRaw(opt)
00229     else:
00230         ret = runSelected(opt)
00231 
00232 
00233     sys.exit(ret)