CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Configuration/PyReleaseValidation/scripts/runTheMatrix_dev.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import os, sys, re, time
00004 
00005 import random
00006 from threading import Thread
00007         
00008 class WorkFlowRunner(Thread):
00009     def __init__(self, wf):
00010         Thread.__init__(self)
00011         self.wf = wf
00012 
00013         self.status=-1
00014         self.report=''
00015         self.nfail=0
00016         self.npass=0
00017 
00018         return
00019 
00020     def doCmd(self, cmd, dryRun=False):
00021 
00022         msg = "\n# in: " +os.getcwd()
00023         if dryRun: msg += " dryRun for '"
00024         else:      msg += " going to execute "
00025         msg += cmd.replace(';','\n')
00026         print msg
00027 
00028         cmdLog = open(self.wf.numId+'_'+self.wf.nameId+'/cmdLog','a')
00029         cmdLog.write(msg+'\n')
00030         cmdLog.close()
00031         
00032         ret = 0
00033         if not dryRun:
00034             ret = os.system(cmd)
00035             if ret != 0:
00036                 print "ERROR executing ",cmd,'ret=', ret
00037 
00038         return ret
00039     
00040     def run(self):
00041 
00042         startDir = os.getcwd()
00043 
00044         wfDir = self.wf.numId+'_'+self.wf.nameId
00045         if not os.path.exists(wfDir):
00046             os.makedirs(wfDir)
00047 
00048         preamble = ''
00049         if os.path.exists( os.path.join(os.environ["CMS_PATH"],'cmsset_default.sh') ) :
00050             preamble = 'source $CMS_PATH/cmsset_default.sh; '
00051         else:
00052             preamble = 'source $CMS_PATH/sw/cmsset_default.sh; '
00053         preamble += 'eval `scram run -sh`; '
00054         preamble += 'cd '+wfDir+'; '
00055         preamble += 'ulimit -v 4069000;' # make sure processes keep within limits ...
00056         
00057         startime='date %s' %time.asctime()
00058 
00059         # set defaults for the statuses
00060         stat1 = 'PASSED'
00061         stat2 = 'PASSED' 
00062         stat3 = 'PASSED'
00063         stat4 = 'PASSED'
00064         if not self.wf.cmdStep2: stat2 = 'NOSTEP'
00065         if not self.wf.cmdStep3: stat3 = 'NOSTEP'
00066         if not self.wf.cmdStep4: stat4 = 'NOSTEP'
00067         
00068         # run the first workflow:
00069         cmd = preamble
00070 
00071         inFile = 'file:raw.root'
00072         if self.wf.cmdStep1.startswith('DATAINPUT'):
00073             print "going to run with file input ... "
00074             if self.wf.input.run:
00075                 run      = str(self.wf.input.run)
00076             else:
00077                 run=None
00078 
00079             label    = self.wf.input.label
00080             location = self.wf.input.location.lower().strip()
00081             if 'caf' in location:
00082                 print "ignoring workflow ",self.wf.numId, self.wf.nameId, ' as this is on CAF ...'
00083                 self.npass = [0,0,0,0]
00084                 self.nfail = [0,0,0,0]
00085 
00086                 logStat = 'Step1-NOTRUN Step2-NOTRUN Step3-NOTRUN Step4-NOTRUN ' 
00087                 self.report+='%s_%s %s - time %s; exit: %s %s %s %s \n' % (self.wf.numId, self.wf.nameId, logStat, 0, 0,0,0,0)
00088                 return
00089                 
00090             files  = str(self.wf.input.files)
00091             events = '10' # ignore the give number ...    str(self.wf.input.events)
00092             if self.wf.cmdStep2 and ' -n ' not in self.wf.cmdStep2: self.wf.cmdStep2 += ' -n ' + events
00093             if self.wf.cmdStep3 and ' -n ' not in self.wf.cmdStep3: self.wf.cmdStep3 += ' -n ' + events
00094             if self.wf.cmdStep4 and ' -n ' not in self.wf.cmdStep4: self.wf.cmdStep4 += ' -n ' + events
00095 
00096             print "run, files, events, label", run, files, events, label 
00097             cmd += 'dbs search --noheader --url=https://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet '
00098             cmd += "--query='find file where dataset like "+self.wf.input.dataSet
00099             if run: cmd += " and run=" + run
00100             cmd += "' "
00101             cmd += ' > %s 2>&1; ' % ('step1_'+self.wf.nameId+'-dbsquery.log',)
00102             retStep1 = self.doCmd(cmd)
00103             if retStep1 == 0:
00104                 lf = open(wfDir+'/step1_'+self.wf.nameId+'-dbsquery.log', 'r')
00105                 lines = lf.readlines()
00106                 lf.close()
00107                 if not lines or len(lines)==0 :
00108                     inFile = "NoFileFoundInDBS"
00109                     retStep1 = -95
00110                 else:
00111                     try:
00112                         inFile = lines[0].strip()
00113                     except Exception, e:
00114                         print "ERROR determining file from DBS query: ", str(e)
00115                         inFile = "NoFileFoundInDBS"
00116                         retStep1 = -90
00117         else:
00118             cmd += self.wf.cmdStep1 + ' --fileout file:raw.root '
00119             cmd += ' > %s 2>&1; ' % ('step1_'+self.wf.nameId+'.log ',)
00120             retStep1 = self.doCmd(cmd)
00121 
00122         print " ... ret: " , retStep1
00123 
00124         # prepare and run the next workflows -- if the previous step was OK :
00125         # set some defaults
00126         retStep2 = 0
00127         retStep3 = 0
00128         retStep4 = 0
00129         if self.wf.cmdStep2 and retStep1 == 0:
00130             fullcmd = preamble
00131             fullcmd += self.wf.cmdStep2
00132             if ' -n ' not in fullcmd : fullcmd += ' -n -1 '
00133             fullcmd += ' --fileout file:reco.root '
00134             print '=====>>> ', self.wf.nameId, self.wf.numId
00135 
00136             # for HI B0 step2 use a file from a previous relval production as step1 doesn't write
00137             # any output in 1 hour. Add himix flag here as this is only needed when run on the mixed
00138             # input files (the relvals are OK)
00139             if ( '40.0' in str(self.wf.numId) ) :
00140                 fullcmd += ' --himix '
00141                 inFile = '/store/relval/CMSSW_3_8_0_pre1/RelValPyquen_ZeemumuJets_pt10_2760GeV/GEN-SIM-RAW/MC_37Y_V5-v1/0001/E0DE7C01-2C6F-DF11-B61F-0026189438F4.root'
00142             if ( '41.0' in str(self.wf.numId) ) : 
00143                 fullcmd += ' --himix '
00144                 inFile = '/store/relval/CMSSW_3_8_0_pre1/RelValPyquen_GammaJet_pt20_2760GeV/GEN-SIM-RAW/MC_37Y_V5-v1/0001/F68A53A5-2B6F-DF11-8958-003048678FE6.root'
00145 
00146             fullcmd += ' --filein '+inFile+ ' '
00147             fullcmd += ' > %s 2>&1; ' % ('step2_'+self.wf.nameId+'.log ',)
00148             # print fullcmd
00149             retStep2 = self.doCmd(fullcmd)
00150 #            if random.randint(0,100) < 20 : retStep2 = -42
00151 
00152             if self.wf.cmdStep3 and retStep2 == 0:
00153                 fullcmd = preamble
00154                 fullcmd += self.wf.cmdStep3
00155                 if ' -n ' not in fullcmd : fullcmd += ' -n -1 '
00156                 # FIXME: dirty hack for beam-spot dedicated relval
00157                 if not '134' in str(self.wf.numId):
00158                     fullcmd += ' --filein file:reco.root --fileout file:step3.root '
00159                 fullcmd += ' > %s 2>&1; ' % ('step3_'+self.wf.nameId+'.log ',)
00160                 # print fullcmd
00161                 retStep3 = self.doCmd(fullcmd)
00162 #                if random.randint(0,100) < 40 : retStep3 = -42
00163                 if self.wf.cmdStep4 and retStep3 == 0:
00164                     fullcmd = preamble
00165                     fullcmd += self.wf.cmdStep4
00166                     if ' -n ' not in fullcmd : fullcmd += ' -n -1 '
00167                     # FIXME: dirty hack for beam-spot dedicated relval
00168                     if not '134' in str(self.wf.numId):
00169                         fullcmd += ' --filein file:step3.root '
00170                     fullcmd += ' > %s 2>&1; ' % ('step4_'+self.wf.nameId+'.log ',)
00171                     # print fullcmd
00172                     retStep4 = self.doCmd(fullcmd)
00173 #                    if random.randint(0,100) < 40 : retStep4 = -42
00174 
00175         os.chdir(startDir)
00176 
00177         endtime='date %s' %time.asctime()
00178         tottime='%s-%s'%(endtime,startime)
00179 
00180         self.nfail = [0,0,0,0]
00181         self.npass = [1,1,1,1]
00182         if 'NOSTEP' in stat2: # don't say reco/alca is passed if we don't have to run them
00183             self.npass = [1,0,0,0]
00184         else: # we have a reco step, check for alca:
00185             if 'NOSTEP' in stat3 :
00186                 self.npass = [1,1,0,0]
00187                 if 'NOSTEP' in stat4 :
00188                     self.npass = [1,1,1,0]
00189         if retStep1 != 0 :
00190             stat1 = 'FAILED'
00191             stat2 = 'NOTRUN'
00192             stat3 = 'NOTRUN'
00193             stat4 = 'NOTRUN'
00194             self.npass = [0,0,0,0]
00195             self.nfail = [1,0,0,0]
00196 
00197         if retStep2 != 0 :
00198             stat2 = 'FAILED'
00199             stat3 = 'NOTRUN'
00200             stat4 = 'NOTRUN'
00201             self.npass = [1,0,0,0]
00202             self.nfail = [0,1,0,0]
00203 
00204         if retStep3 != 0 :
00205             stat3 = 'FAILED'
00206             stat4 = 'NOTRUN'
00207             self.npass = [1,1,0,0]
00208             self.nfail = [0,0,1,0]
00209 
00210         if retStep4 != 0 :
00211             stat4 = 'FAILED'
00212             self.npass = [1,1,1,0]
00213             self.nfail = [0,0,0,1]
00214 
00215         logStat = 'Step1-'+stat1+' Step2-'+stat2+' Step3-'+stat3+' '+' Step4-'+stat4+' ' 
00216         self.report+='%s_%s %s - time %s; exit: %s %s %s %s \n' % (self.wf.numId, self.wf.nameId, logStat, tottime, retStep1,retStep2,retStep3, retStep4)
00217 
00218         return
00219 
00220 
00221 # ================================================================================
00222 
00223 class WorkFlow(object):
00224 
00225     def __init__(self, num, nameID, cmd1, cmd2=None, cmd3=None, cmd4=None, inputInfo=None):
00226 
00227         self.numId  = num.strip()
00228         self.nameId = nameID
00229         self.cmdStep1 = self.check(cmd1)
00230         self.cmdStep2 = self.check(cmd2)
00231         self.cmdStep3 = self.check(cmd3)
00232         self.cmdStep4 = self.check(cmd4)
00233 
00234         # run on real data requested:
00235         self.input = inputInfo
00236         return
00237 
00238     def check(self, cmd=None):
00239         if not cmd : return None
00240 
00241         # raw data are treated differently ...
00242         if 'DATAINPUT' in cmd: return cmd
00243 
00244         # force the number of events to process to be 10
00245         reN = re.compile('\s*-n\s*\d+\s*')
00246         newCmd = reN.sub(' -n 10 ', cmd)
00247         if not reN.match(newCmd) : # -n not specified, add it:
00248             newCmd += ' -n 10 '
00249 
00250         return newCmd
00251 
00252 # ================================================================================
00253 
00254 class MatrixReader(object):
00255 
00256     def __init__(self):
00257 
00258         self.reset()
00259 
00260         return
00261 
00262     def reset(self):
00263 
00264         self.step1WorkFlows = {}
00265         self.step2WorkFlows = {}
00266         self.step3WorkFlows = {}
00267         self.step4WorkFlows = {}
00268 
00269         self.workFlows = []
00270         self.nameList  = {}
00271         
00272         self.filesPrefMap = {'relval_standard' : 'std-' ,
00273                              'relval_highstats': 'hi-'  ,
00274                              'relval_generator': 'gen-'  ,
00275                              }
00276 
00277         self.files = ['relval_standard' ,
00278                       'relval_highstats',
00279                       'relval_generator',
00280                       ]
00281 
00282         self.relvalModule = None
00283         
00284         return
00285 
00286     def makeCmd(self, step):
00287 
00288         cmd = ''
00289         cfg = None
00290         input = None
00291         #print step
00292         #print defaults
00293         for k,v in step.items():
00294             if 'no_exec' in k : continue  # we want to really run it ...
00295             if k.lower() == 'cfg':
00296                 cfg = v
00297                 continue # do not append to cmd, return separately
00298             if k.lower() == 'input':
00299                 input = v
00300                 continue # do not append to cmd, return separately
00301             #print k,v
00302             cmd += ' ' + k + ' ' + str(v)
00303         return cfg, input, cmd
00304     
00305     def readMatrix(self, fileNameIn, useInput=None):
00306         
00307         prefix = self.filesPrefMap[fileNameIn]
00308 
00309         print "processing ", fileNameIn
00310 
00311         try:
00312             _tmpMod = __import__( 'Configuration.PyReleaseValidation.'+fileNameIn )
00313             self.relvalModule = sys.modules['Configuration.PyReleaseValidation.'+fileNameIn]
00314         except Exception, e:
00315             print "ERROR importing file ", fileNameIn, str(e)
00316             return
00317 
00318         print "request for INPUT for ", useInput
00319 
00320         for num, wfInfo in self.relvalModule.workflows.items():
00321             wfName = wfInfo[0]
00322             stepList = wfInfo[1]
00323             # if no explicit name given for the workflow, use the name of step1
00324             if wfName.strip() == '': wfName = stepList[0] 
00325             stepCmds = ['','','','']
00326             stepIndex = 0
00327             name  = wfName
00328             inputInfo = None
00329             for step in stepList:
00330                 if len(name) > 0 : name += '+'
00331                 stepName = step
00332                 if stepIndex==0 and useInput and (str(num) in useInput or "all" in useInput):
00333                     # print "--> using INPUT as step1 for workflow ", num
00334                     if step+'INPUT' in self.relvalModule.step1.keys():
00335                         stepName = step+"INPUT"
00336                 name += stepName
00337                 cfg, input, opts = self.makeCmd(self.relvalModule.stepList[stepIndex][stepName])
00338                 if input and cfg :
00339                     msg = "FATAL ERROR: found both cfg and input for workflow "+str(num)+' step '+stepName
00340                     raise msg
00341 
00342                 if cfg:
00343                     cmd  = 'cmsDriver.py '+cfg+' '+opts
00344                 if stepIndex==0 and not inputInfo and input: # only if we didn't already set the input
00345                     inputInfo = input
00346                     cmd = 'DATAINPUT from '+inputInfo.dataSet
00347                     
00348                 if stepIndex > 0:
00349                     cmd  = 'cmsDriver.py step'+str(stepIndex+1)+'.py '+opts
00350                     
00351                 stepCmds[stepIndex] = cmd
00352                 stepIndex += 1
00353 
00354             self.step1WorkFlows[(float(num),prefix)] = (str(float(num)), name, stepCmds[0], stepCmds[1], stepCmds[2], stepCmds[3], inputInfo)
00355         
00356         return
00357 
00358     def showRaw(self, useInput):
00359 
00360         for matrixFile in self.files:
00361             self.reset()
00362             try:
00363                 self.readMatrix(matrixFile, useInput)
00364             except Exception, e:
00365                 print "ERROR reading file:", matrixFile, str(e)
00366                 raise
00367 
00368             if not self.step1WorkFlows: continue
00369 
00370             dataFileName = matrixFile.replace('relval_', 'cmsDriver_')+'_hlt.txt'
00371             outFile = open(dataFileName,'w')
00372 
00373             print "found ", len(self.step1WorkFlows.keys()), ' workflows for ', dataFileName
00374             ids = self.step1WorkFlows.keys()
00375             ids.sort()
00376             stepCmds = ['','','','']
00377             for key in ids:
00378                 num, name, stepCmds[0], stepCmds[1], stepCmds[2], stepCmds[3], inputInfo = self.step1WorkFlows[key]
00379                 wfName,stepNames= name.split('+',1)
00380                 otherSteps = None
00381                 if '+' in stepNames:
00382                     step1,otherSteps = stepNames.split('+',1)
00383                 line = num + ' ++ '+ wfName 
00384                 if otherSteps:
00385                     line += ' ++ ' +otherSteps.replace('+',',')
00386                 else:
00387                     line += ' ++ none' 
00388                 if inputInfo :
00389                     line += ' ++ REALDATA: '+inputInfo.dataSet
00390                     line += ', FILES: ' +str(inputInfo.files)
00391                     line += ', EVENTS: '+str(inputInfo.events)
00392                     line += ', LABEL: ' +inputInfo.label
00393                     line += ', LOCATION:'+inputInfo.location
00394                     line += ' @@@'
00395                 else:
00396                     line += ' @@@ '+stepCmds[0]
00397                 print line
00398                 outFile.write(line+'\n')
00399 
00400             outFile.write('\n'+'\n')
00401             for stepName in self.relvalModule.step2.keys():
00402                 cfg,input,cmd = self.makeCmd(self.relvalModule.step2[stepName])
00403                 line = 'STEP2 ++ ' +stepName + ' @@@ cmsDriver.py step2 ' +cmd
00404                 print line
00405                 outFile.write(line+'\n')
00406                 
00407             outFile.write('\n'+'\n')
00408             for stepName in self.relvalModule.step3.keys():
00409                 cfg,input,cmd = self.makeCmd(self.relvalModule.step3[stepName])
00410                 line ='STEP3 ++ ' +stepName + ' @@@ cmsDriver.py step3_RELVAL ' +cmd 
00411                 print line
00412                 outFile.write(line+'\n')
00413                 
00414             outFile.write('\n'+'\n')
00415             for stepName in self.relvalModule.step4.keys():
00416                 cfg,input,cmd = self.makeCmd(self.relvalModule.step4[stepName])
00417                 line = 'STEP4 ++ ' +stepName + ' @@@ cmsDriver.py step4 ' +cmd
00418                 print line
00419                 outFile.write(line+'\n')
00420                 
00421             outFile.close()
00422 
00423         
00424         return
00425 
00426     def showWorkFlows(self, selected=None):
00427 
00428         maxLen = 100 # for summary, limit width of output
00429         fmt1   = "%-6s %-35s [1]: %s ..."
00430         fmt2   = "       %35s [%d]: %s ..."
00431         print "\nfound a total of ", len(self.workFlows), ' workflows:'
00432         if selected:
00433             print "      of which the following", len(selected), 'were selected:'
00434         #-ap for now:
00435         maxLen = -1  # for individual listing, no limit on width
00436         fmt1   = "%-6s %-35s [1]: %s " 
00437         fmt2   = "       %35s [%d]: %s"
00438 
00439         n1 = 0
00440         n2 = 0
00441         n3 = 0
00442         n4 = 0
00443         for wf in self.workFlows:
00444             if selected and float(wf.numId) not in selected: continue
00445             print ''
00446             n1+=1
00447             wfName, stepNames = wf.nameId.split('+',1)
00448             print fmt1 % (wf.numId, stepNames, (wf.cmdStep1+' ')[:maxLen])
00449             if wf.cmdStep2:
00450                 n2+=1
00451                 print fmt2 % ( ' ', 2, (wf.cmdStep2+' ')[:maxLen])
00452                 if wf.cmdStep3:
00453                     n3+=1
00454                     print fmt2 % ( ' ', 3, (wf.cmdStep3+' ')[:maxLen])
00455                     if wf.cmdStep4:
00456                         n4+=1
00457                         print fmt2 % ( ' ', 4, (wf.cmdStep4+' ')[:maxLen])
00458 
00459         print n1, 'workflows for step1,'
00460         print n2, 'workflows for step1 + step2,'
00461         print n3, 'workflows for step1 + step2 + step3'
00462         print n4, 'workflows for step1 + step2 + step3 + step4'
00463 
00464         return
00465     
00466     def createWorkFlows(self, fileNameIn):
00467 
00468         prefixIn = self.filesPrefMap[fileNameIn]
00469 
00470         # get through the list of items and update the requested workflows only
00471         keyList = self.step1WorkFlows.keys()
00472         ids = []
00473         for item in keyList:
00474             id, pref = item
00475             if pref != prefixIn : continue
00476             ids.append( float(id) )
00477             
00478         ids.sort()
00479         n1 = 0
00480         n2 = 0
00481         n3 = 0
00482         n4 = 0
00483         for key in ids:
00484             val = self.step1WorkFlows[(key,prefixIn)]
00485             num, name, cmd, step2, step3, step4, inputInfo = val
00486             nameId = num+'_'+name
00487             if nameId in self.nameList.keys():
00488                 print "==> duplicate name found for ", nameId
00489                 print '    keeping  : ', self.nameList[nameId]
00490                 print '    ignoring : ', val
00491             else:
00492                 self.nameList[nameId] = val
00493 
00494             cmd2 = None
00495             cmd3 = None
00496             cmd4 = None
00497             
00498             n1 += 1
00499 
00500             if step2.lower() != '':
00501                 n2 += 1
00502                 cmd2 = step2
00503                 if step3.lower() != '':
00504                     n3 += 1
00505                     cmd3 = step3
00506                     if step4.lower() != '':
00507                         n4 += 1
00508                         cmd4 = step4
00509                     #print '\tstep3 : ', self.step3WorkFlows[step3]
00510             self.workFlows.append( WorkFlow(num, name, cmd, cmd2, cmd3, cmd4, inputInfo) )
00511 
00512         return
00513 
00514     def prepare(self, useInput=None):
00515         
00516         for matrixFile in self.files:
00517             try:
00518                 self.readMatrix(matrixFile, useInput)
00519             except Exception, e:
00520                 print "ERROR reading file:", matrixFile, str(e)
00521                 raise
00522 
00523             try:
00524                 self.createWorkFlows(matrixFile)
00525             except Exception, e:
00526                 print "ERROR creating workflows :", str(e)
00527                 raise
00528             
00529     def show(self, selected=None):    
00530         # self.showRaw()
00531         self.showWorkFlows(selected)
00532         print '\n','-'*80,'\n'
00533 
00534 
00535     def updateDB(self):
00536 
00537         import pickle
00538         pickle.dump(self.workFlows, open('theMatrix.pkl', 'w') )
00539 
00540         return
00541 
00542 # ================================================================================
00543 
00544 class MatrixRunner(object):
00545 
00546     def __init__(self, wfIn=None, nThrMax=8):
00547 
00548         self.workFlows = wfIn
00549 
00550         self.threadList = []
00551         self.maxThreads = int(nThrMax) # make sure we get a number ...
00552 
00553 
00554     def activeThreads(self):
00555 
00556         nActive = 0
00557         for t in self.threadList:
00558             if t.isAlive() : nActive += 1
00559 
00560         return nActive
00561 
00562         
00563     def runTests(self, testList=None):
00564 
00565         startDir = os.getcwd()
00566 
00567         # make sure we have a way to set the environment in the threads ...
00568         if not os.environ.has_key('CMS_PATH'):
00569             cmsPath = '/afs/cern.ch/cms'
00570             print "setting default for CMS_PATH to", cmsPath
00571             os.environ['CMS_PATH'] = cmsPath
00572 
00573         report=''       
00574         print 'Running in %s thread(s)' % self.maxThreads
00575                 
00576         for wf in self.workFlows:
00577 
00578             if testList and float(wf.numId) not in [float(x) for x in testList]: continue
00579 
00580             item = wf.nameId
00581             if os.path.islink(item) : continue # ignore symlinks
00582             
00583             # make sure we don't run more than the allowed number of threads:
00584             while self.activeThreads() >= self.maxThreads:
00585                 time.sleep(10)
00586                 continue
00587             
00588             print '\nPreparing to run %s %s' % (wf.numId, item)
00589           
00590 ##            if testList: # if we only run a selection, run only 5 events instead of 10
00591 ##                wf.cmdStep1 = wf.cmdStep1.replace('-n 10', '-n 5')
00592                 
00593             current = WorkFlowRunner(wf)
00594             self.threadList.append(current)
00595             current.start()
00596             time.sleep(random.randint(1,5)) # try to avoid race cond by sleeping random amount of time [1,5] sec 
00597 
00598         # wait until all threads are finished
00599         while self.activeThreads() > 0:
00600             time.sleep(5)
00601             
00602         # all threads are done now, check status ...
00603         nfail1 = 0
00604         nfail2 = 0
00605         nfail3 = 0
00606         nfail4 = 0
00607         npass  = 0
00608         npass1 = 0
00609         npass2 = 0
00610         npass3 = 0
00611         npass4 = 0
00612         for pingle in self.threadList:
00613             pingle.join()
00614             try:
00615                 nfail1 += pingle.nfail[0]
00616                 nfail2 += pingle.nfail[1]
00617                 nfail3 += pingle.nfail[2]
00618                 nfail4 += pingle.nfail[3]
00619                 npass1 += pingle.npass[0]
00620                 npass2 += pingle.npass[1]
00621                 npass3 += pingle.npass[2]
00622                 npass4 += pingle.npass[3]
00623                 npass  += npass1+npass2+npass3+npass4
00624                 report += pingle.report
00625                 # print pingle.report
00626             except Exception, e:
00627                 msg = "ERROR retrieving info from thread: " + str(e)
00628                 nfail1 += 1
00629                 nfail2 += 1
00630                 nfail3 += 1
00631                 nfail4 += 1
00632                 report += msg
00633                 print msg
00634                 
00635         report+='\n %s %s %s %s tests passed, %s %s %s %s failed\n' %(npass1, npass2, npass3, npass4, nfail1, nfail2, nfail3, nfail4)
00636         print report
00637         
00638         runall_report_name='runall-report-step123-.log'
00639         runall_report=open(runall_report_name,'w')
00640         runall_report.write(report)
00641         runall_report.close()
00642 
00643         os.chdir(startDir)
00644         
00645         return
00646 
00647         
00648 # ================================================================================
00649 
00650 def showRaw(useInput=None) :
00651 
00652     mrd = MatrixReader()
00653     mrd.showRaw(useInput)
00654 
00655     return 0
00656         
00657 # ================================================================================
00658 
00659 def runSelected(testList, nThreads=4, show=False, useInput=None) :
00660 
00661     stdList = ['5.2', # SingleMu10 FastSim
00662                '7',   # Cosmics+RECOCOS+ALCACOS
00663                '8',   # BeamHalo+RECOCOS+ALCABH
00664                '25',  # TTbar+RECO2+ALCATT2  STARTUP
00665                ]
00666     hiStatList = [
00667                   '121',   # TTbar_Tauola
00668                   '123.3', # TTBar FastSim
00669                    ]
00670 
00671     mrd = MatrixReader()
00672     mrd.prepare(useInput)
00673 
00674     if testList == []:
00675         testList = stdList+hiStatList
00676 
00677     ret = 0
00678     if show:
00679         mrd.show([float(x) for x in testList])
00680         print 'selected items:', testList
00681     else:
00682         mRunnerHi = MatrixRunner(mrd.workFlows, nThreads)
00683         ret = mRunnerHi.runTests(testList)
00684 
00685     return ret
00686 
00687 # ================================================================================
00688 
00689 def runData(testList, nThreads=4, show=False, useInput=None) :
00690 
00691     mrd = MatrixReader()
00692     mrd.prepare(useInput)
00693 
00694     ret = 0
00695     if show:
00696         if not testList or testList == ['all']:
00697             mrd.show()
00698         else:
00699             mrd.show([float(x) for x in testList])
00700         print 'selected items:', testList
00701     else:
00702         mRunnerHi = MatrixRunner(mrd.workFlows, nThreads)
00703         if not testList or testList == ['all']:
00704             ret = mRunnerHi.runTests()
00705         else:
00706             ret = mRunnerHi.runTests(testList)
00707 
00708     return ret
00709 
00710 # --------------------------------------------------------------------------------
00711 
00712 def runAll(testList=None, nThreads=4, show=False, useInput=None) :
00713 
00714     mrd = MatrixReader()
00715     mrd.prepare(useInput)
00716 
00717     ret = 0
00718     
00719     if show:
00720         mrd.show()
00721         print "nThreads = ",nThreads
00722     else:
00723         mRunnerHi = MatrixRunner(mrd.workFlows, nThreads)
00724         ret = mRunnerHi.runTests()
00725 
00726     return ret
00727 
00728 
00729 # --------------------------------------------------------------------------------
00730 
00731 def runOnly(only, show, nThreads=4, useInput=None):
00732 
00733     if not only: return
00734     
00735     for what in only:
00736         print "found request to run relvals only for ",what
00737         print "not implemented, nothing done"
00738 
00739 # --------------------------------------------------------------------------------
00740 
00741 def usage():
00742     print "Usage:", sys.argv[0], ' [options] '
00743     print """
00744 Where options is one of the following:
00745   -d, --data <list> comma-separated list of workflows to use from the realdata file.
00746                     <list> can be "all" to select all data workflows
00747   -l, --list <list> comma-separated list of workflows to use from the cmsDriver*.txt files
00748   -j, --nproc <n>   run <n> processes in parallel (default: 4 procs)
00749   -s, --selected    run a subset of 8 workflows (usually in the CustomIB)
00750   -n, -q, --show    show the (selected) workflows
00751   -i, --useInput <list>   will use data input (if defined) for the step1 instead of step1. <list> can be "all" for this option
00752   -r, --raw         in combination with --show will create the old style cmsDriver_*_hlt.txt file (in the working dir)
00753   
00754 <list>s should be put in single- or double-quotes to avoid confusion with/by the shell
00755 """
00756 
00757 # ================================================================================
00758 
00759 if __name__ == '__main__':
00760 
00761     import getopt
00762     
00763     try:
00764         opts, args = getopt.getopt(sys.argv[1:], "hj:sl:nqo:d:i:r", ['help',"nproc=",'selected','list=','showMatrix','only=','data=','useInput=','raw'])
00765     except getopt.GetoptError, e:
00766         print "unknown option", str(e)
00767         sys.exit(2)
00768         
00769 # check command line parameter
00770 
00771     np=4 # default: four threads
00772     sel = None
00773     input = None
00774     show = False
00775     only = None
00776     data = None
00777     raw  = False
00778     for opt, arg in opts :
00779         if opt in ('-h','--help'):
00780             usage()
00781             sys.exit(0)
00782         if opt in ('-j', "--nproc" ):
00783             np=int(arg)
00784         if opt in ('-n','-q','--showMatrix', ):
00785             show = True
00786         if opt in ('-s','--selected',) :
00787             sel = []
00788         if opt in ('-o','--only',) :
00789             only = []
00790         if opt in ('-l','--list',) :
00791             sel = arg.split(',')
00792         if opt in ('-i','--useInput',) :
00793             input = arg.split(',')
00794         if opt in ('-d','--data',) :
00795             data = arg.split(',')
00796         if opt in ('-r','--raw') :
00797             raw = True
00798             
00799     if raw and show:
00800         ret = showRaw(useInput=input)
00801         sys.exit(ret)
00802 
00803         
00804     ret = 0
00805     if sel != None: # explicit distinguish from empty list (which is also false)
00806         ret = runSelected(testList=sel, nThreads=np, show=show, useInput=input)
00807     elif only != None:
00808         ret = runOnly(only=only, show=show, nThreads=np, useInput=input)
00809     elif data != None:
00810         ret = runData(testList=data, show=show, nThreads=np, useInput=input)
00811     else:
00812         ret = runAll(show=show, nThreads=np, useInput=input)
00813 
00814     sys.exit(ret)