CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
runTheMatrix_dev.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import os, sys, re, time
4 
5 import random
6 from threading import Thread
7 
8 class WorkFlowRunner(Thread):
9  def __init__(self, wf):
10  Thread.__init__(self)
11  self.wf = wf
12 
13  self.status=-1
14  self.report=''
15  self.nfail=0
16  self.npass=0
17 
18  return
19 
20  def doCmd(self, cmd, dryRun=False):
21 
22  msg = "\n# in: " +os.getcwd()
23  if dryRun: msg += " dryRun for '"
24  else: msg += " going to execute "
25  msg += cmd.replace(';','\n')
26  print msg
27 
28  cmdLog = open(self.wf.numId+'_'+self.wf.nameId+'/cmdLog','a')
29  cmdLog.write(msg+'\n')
30  cmdLog.close()
31 
32  ret = 0
33  if not dryRun:
34  ret = os.system(cmd)
35  if ret != 0:
36  print "ERROR executing ",cmd,'ret=', ret
37 
38  return ret
39 
40  def run(self):
41 
42  startDir = os.getcwd()
43 
44  wfDir = self.wf.numId+'_'+self.wf.nameId
45  if not os.path.exists(wfDir):
46  os.makedirs(wfDir)
47 
48  preamble = ''
49  if os.path.exists( os.path.join(os.environ["CMS_PATH"],'cmsset_default.sh') ) :
50  preamble = 'source $CMS_PATH/cmsset_default.sh; '
51  else:
52  preamble = 'source $CMS_PATH/sw/cmsset_default.sh; '
53  preamble += 'eval `scram run -sh`; '
54  preamble += 'cd '+wfDir+'; '
55  preamble += 'ulimit -v 4069000;' # make sure processes keep within limits ...
56 
57  startime='date %s' %time.asctime()
58 
59  # set defaults for the statuses
60  stat1 = 'PASSED'
61  stat2 = 'PASSED'
62  stat3 = 'PASSED'
63  stat4 = 'PASSED'
64  if not self.wf.cmdStep2: stat2 = 'NOSTEP'
65  if not self.wf.cmdStep3: stat3 = 'NOSTEP'
66  if not self.wf.cmdStep4: stat4 = 'NOSTEP'
67 
68  # run the first workflow:
69  cmd = preamble
70 
71  inFile = 'file:raw.root'
72  if self.wf.cmdStep1.startswith('DATAINPUT'):
73  print "going to run with file input ... "
74  if self.wf.input.run:
75  run = str(self.wf.input.run)
76  else:
77  run=None
78 
79  label = self.wf.input.label
80  location = self.wf.input.location.lower().strip()
81  if 'caf' in location:
82  print "ignoring workflow ",self.wf.numId, self.wf.nameId, ' as this is on CAF ...'
83  self.npass = [0,0,0,0]
84  self.nfail = [0,0,0,0]
85 
86  logStat = 'Step1-NOTRUN Step2-NOTRUN Step3-NOTRUN Step4-NOTRUN '
87  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)
88  return
89 
90  files = str(self.wf.input.files)
91  events = '10' # ignore the give number ... str(self.wf.input.events)
92  if self.wf.cmdStep2 and ' -n ' not in self.wf.cmdStep2: self.wf.cmdStep2 += ' -n ' + events
93  if self.wf.cmdStep3 and ' -n ' not in self.wf.cmdStep3: self.wf.cmdStep3 += ' -n ' + events
94  if self.wf.cmdStep4 and ' -n ' not in self.wf.cmdStep4: self.wf.cmdStep4 += ' -n ' + events
95 
96  print "run, files, events, label", run, files, events, label
97  cmd += 'dbs search --noheader --url=http://cmsdbsprod.cern.ch/cms_dbs_prod_global/servlet/DBSServlet '
98  cmd += "--query='find file where dataset like "+self.wf.input.dataSet
99  if run: cmd += " and run=" + run
100  cmd += "' "
101  cmd += ' > %s 2>&1; ' % ('step1_'+self.wf.nameId+'-dbsquery.log',)
102  retStep1 = self.doCmd(cmd)
103  if retStep1 == 0:
104  lf = open(wfDir+'/step1_'+self.wf.nameId+'-dbsquery.log', 'r')
105  lines = lf.readlines()
106  lf.close()
107  if not lines or len(lines)==0 :
108  inFile = "NoFileFoundInDBS"
109  retStep1 = -95
110  else:
111  try:
112  inFile = lines[0].strip()
113  except Exception, e:
114  print "ERROR determining file from DBS query: ", str(e)
115  inFile = "NoFileFoundInDBS"
116  retStep1 = -90
117  else:
118  cmd += self.wf.cmdStep1 + ' --fileout file:raw.root '
119  cmd += ' > %s 2>&1; ' % ('step1_'+self.wf.nameId+'.log ',)
120  retStep1 = self.doCmd(cmd)
121 
122  print " ... ret: " , retStep1
123 
124  # prepare and run the next workflows -- if the previous step was OK :
125  # set some defaults
126  retStep2 = 0
127  retStep3 = 0
128  retStep4 = 0
129  if self.wf.cmdStep2 and retStep1 == 0:
130  fullcmd = preamble
131  fullcmd += self.wf.cmdStep2
132  if ' -n ' not in fullcmd : fullcmd += ' -n -1 '
133  fullcmd += ' --fileout file:reco.root '
134  print '=====>>> ', self.wf.nameId, self.wf.numId
135 
136  # for HI B0 step2 use a file from a previous relval production as step1 doesn't write
137  # any output in 1 hour. Add himix flag here as this is only needed when run on the mixed
138  # input files (the relvals are OK)
139  if ( '40.0' in str(self.wf.numId) ) :
140  fullcmd += ' --himix '
141  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'
142  if ( '41.0' in str(self.wf.numId) ) :
143  fullcmd += ' --himix '
144  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'
145 
146  fullcmd += ' --filein '+inFile+ ' '
147  fullcmd += ' > %s 2>&1; ' % ('step2_'+self.wf.nameId+'.log ',)
148  # print fullcmd
149  retStep2 = self.doCmd(fullcmd)
150 # if random.randint(0,100) < 20 : retStep2 = -42
151 
152  if self.wf.cmdStep3 and retStep2 == 0:
153  fullcmd = preamble
154  fullcmd += self.wf.cmdStep3
155  if ' -n ' not in fullcmd : fullcmd += ' -n -1 '
156  # FIXME: dirty hack for beam-spot dedicated relval
157  if not '134' in str(self.wf.numId):
158  fullcmd += ' --filein file:reco.root --fileout file:step3.root '
159  fullcmd += ' > %s 2>&1; ' % ('step3_'+self.wf.nameId+'.log ',)
160  # print fullcmd
161  retStep3 = self.doCmd(fullcmd)
162 # if random.randint(0,100) < 40 : retStep3 = -42
163  if self.wf.cmdStep4 and retStep3 == 0:
164  fullcmd = preamble
165  fullcmd += self.wf.cmdStep4
166  if ' -n ' not in fullcmd : fullcmd += ' -n -1 '
167  # FIXME: dirty hack for beam-spot dedicated relval
168  if not '134' in str(self.wf.numId):
169  fullcmd += ' --filein file:step3.root '
170  fullcmd += ' > %s 2>&1; ' % ('step4_'+self.wf.nameId+'.log ',)
171  # print fullcmd
172  retStep4 = self.doCmd(fullcmd)
173 # if random.randint(0,100) < 40 : retStep4 = -42
174 
175  os.chdir(startDir)
176 
177  endtime='date %s' %time.asctime()
178  tottime='%s-%s'%(endtime,startime)
179 
180  self.nfail = [0,0,0,0]
181  self.npass = [1,1,1,1]
182  if 'NOSTEP' in stat2: # don't say reco/alca is passed if we don't have to run them
183  self.npass = [1,0,0,0]
184  else: # we have a reco step, check for alca:
185  if 'NOSTEP' in stat3 :
186  self.npass = [1,1,0,0]
187  if 'NOSTEP' in stat4 :
188  self.npass = [1,1,1,0]
189  if retStep1 != 0 :
190  stat1 = 'FAILED'
191  stat2 = 'NOTRUN'
192  stat3 = 'NOTRUN'
193  stat4 = 'NOTRUN'
194  self.npass = [0,0,0,0]
195  self.nfail = [1,0,0,0]
196 
197  if retStep2 != 0 :
198  stat2 = 'FAILED'
199  stat3 = 'NOTRUN'
200  stat4 = 'NOTRUN'
201  self.npass = [1,0,0,0]
202  self.nfail = [0,1,0,0]
203 
204  if retStep3 != 0 :
205  stat3 = 'FAILED'
206  stat4 = 'NOTRUN'
207  self.npass = [1,1,0,0]
208  self.nfail = [0,0,1,0]
209 
210  if retStep4 != 0 :
211  stat4 = 'FAILED'
212  self.npass = [1,1,1,0]
213  self.nfail = [0,0,0,1]
214 
215  logStat = 'Step1-'+stat1+' Step2-'+stat2+' Step3-'+stat3+' '+' Step4-'+stat4+' '
216  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)
217 
218  return
219 
220 
221 # ================================================================================
222 
224 
225  def __init__(self, num, nameID, cmd1, cmd2=None, cmd3=None, cmd4=None, inputInfo=None):
226 
227  self.numId = num.strip()
228  self.nameId = nameID
229  self.cmdStep1 = self.check(cmd1)
230  self.cmdStep2 = self.check(cmd2)
231  self.cmdStep3 = self.check(cmd3)
232  self.cmdStep4 = self.check(cmd4)
233 
234  # run on real data requested:
235  self.input = inputInfo
236  return
237 
238  def check(self, cmd=None):
239  if not cmd : return None
240 
241  # raw data are treated differently ...
242  if 'DATAINPUT' in cmd: return cmd
243 
244  # force the number of events to process to be 10
245  reN = re.compile('\s*-n\s*\d+\s*')
246  newCmd = reN.sub(' -n 10 ', cmd)
247  if not reN.match(newCmd) : # -n not specified, add it:
248  newCmd += ' -n 10 '
249 
250  return newCmd
251 
252 # ================================================================================
253 
255 
256  def __init__(self):
257 
258  self.reset()
259 
260  return
261 
262  def reset(self):
263 
264  self.step1WorkFlows = {}
265  self.step2WorkFlows = {}
266  self.step3WorkFlows = {}
267  self.step4WorkFlows = {}
268 
269  self.workFlows = []
270  self.nameList = {}
271 
272  self.filesPrefMap = {'relval_standard' : 'std-' ,
273  'relval_highstats': 'hi-' ,
274  'relval_generator': 'gen-' ,
275  }
276 
277  self.files = ['relval_standard' ,
278  'relval_highstats',
279  'relval_generator',
280  ]
281 
282  self.relvalModule = None
283 
284  return
285 
286  def makeCmd(self, step):
287 
288  cmd = ''
289  cfg = None
290  input = None
291  #print step
292  #print defaults
293  for k,v in step.items():
294  if 'no_exec' in k : continue # we want to really run it ...
295  if k.lower() == 'cfg':
296  cfg = v
297  continue # do not append to cmd, return separately
298  if k.lower() == 'input':
299  input = v
300  continue # do not append to cmd, return separately
301  #print k,v
302  cmd += ' ' + k + ' ' + str(v)
303  return cfg, input, cmd
304 
305  def readMatrix(self, fileNameIn, useInput=None):
306 
307  prefix = self.filesPrefMap[fileNameIn]
308 
309  print "processing ", fileNameIn
310 
311  try:
312  _tmpMod = __import__( 'Configuration.PyReleaseValidation.'+fileNameIn )
313  self.relvalModule = sys.modules['Configuration.PyReleaseValidation.'+fileNameIn]
314  except Exception, e:
315  print "ERROR importing file ", fileNameIn, str(e)
316  return
317 
318  print "request for INPUT for ", useInput
319 
320  for num, wfInfo in self.relvalModule.workflows.items():
321  wfName = wfInfo[0]
322  stepList = wfInfo[1]
323  # if no explicit name given for the workflow, use the name of step1
324  if wfName.strip() == '': wfName = stepList[0]
325  stepCmds = ['','','','']
326  stepIndex = 0
327  name = wfName
328  inputInfo = None
329  for step in stepList:
330  if len(name) > 0 : name += '+'
331  stepName = step
332  if stepIndex==0 and useInput and (str(num) in useInput or "all" in useInput):
333  # print "--> using INPUT as step1 for workflow ", num
334  if step+'INPUT' in self.relvalModule.step1.keys():
335  stepName = step+"INPUT"
336  name += stepName
337  cfg, input, opts = self.makeCmd(self.relvalModule.stepList[stepIndex][stepName])
338  if input and cfg :
339  msg = "FATAL ERROR: found both cfg and input for workflow "+str(num)+' step '+stepName
340  raise msg
341 
342  if cfg:
343  cmd = 'cmsDriver.py '+cfg+' '+opts
344  if stepIndex==0 and not inputInfo and input: # only if we didn't already set the input
345  inputInfo = input
346  cmd = 'DATAINPUT from '+inputInfo.dataSet
347 
348  if stepIndex > 0:
349  cmd = 'cmsDriver.py step'+str(stepIndex+1)+'.py '+opts
350 
351  stepCmds[stepIndex] = cmd
352  stepIndex += 1
353 
354  self.step1WorkFlows[(float(num),prefix)] = (str(float(num)), name, stepCmds[0], stepCmds[1], stepCmds[2], stepCmds[3], inputInfo)
355 
356  return
357 
358  def showRaw(self, useInput):
359 
360  for matrixFile in self.files:
361  self.reset()
362  try:
363  self.readMatrix(matrixFile, useInput)
364  except Exception, e:
365  print "ERROR reading file:", matrixFile, str(e)
366  raise
367 
368  if not self.step1WorkFlows: continue
369 
370  dataFileName = matrixFile.replace('relval_', 'cmsDriver_')+'_hlt.txt'
371  outFile = open(dataFileName,'w')
372 
373  print "found ", len(self.step1WorkFlows.keys()), ' workflows for ', dataFileName
374  ids = self.step1WorkFlows.keys()
375  ids.sort()
376  stepCmds = ['','','','']
377  for key in ids:
378  num, name, stepCmds[0], stepCmds[1], stepCmds[2], stepCmds[3], inputInfo = self.step1WorkFlows[key]
379  wfName,stepNames= name.split('+',1)
380  otherSteps = None
381  if '+' in stepNames:
382  step1,otherSteps = stepNames.split('+',1)
383  line = num + ' ++ '+ wfName
384  if otherSteps:
385  line += ' ++ ' +otherSteps.replace('+',',')
386  else:
387  line += ' ++ none'
388  if inputInfo :
389  line += ' ++ REALDATA: '+inputInfo.dataSet
390  line += ', FILES: ' +str(inputInfo.files)
391  line += ', EVENTS: '+str(inputInfo.events)
392  line += ', LABEL: ' +inputInfo.label
393  line += ', LOCATION:'+inputInfo.location
394  line += ' @@@'
395  else:
396  line += ' @@@ '+stepCmds[0]
397  print line
398  outFile.write(line+'\n')
399 
400  outFile.write('\n'+'\n')
401  for stepName in self.relvalModule.step2.keys():
402  cfg,input,cmd = self.makeCmd(self.relvalModule.step2[stepName])
403  line = 'STEP2 ++ ' +stepName + ' @@@ cmsDriver.py step2 ' +cmd
404  print line
405  outFile.write(line+'\n')
406 
407  outFile.write('\n'+'\n')
408  for stepName in self.relvalModule.step3.keys():
409  cfg,input,cmd = self.makeCmd(self.relvalModule.step3[stepName])
410  line ='STEP3 ++ ' +stepName + ' @@@ cmsDriver.py step3_RELVAL ' +cmd
411  print line
412  outFile.write(line+'\n')
413 
414  outFile.write('\n'+'\n')
415  for stepName in self.relvalModule.step4.keys():
416  cfg,input,cmd = self.makeCmd(self.relvalModule.step4[stepName])
417  line = 'STEP4 ++ ' +stepName + ' @@@ cmsDriver.py step4 ' +cmd
418  print line
419  outFile.write(line+'\n')
420 
421  outFile.close()
422 
423 
424  return
425 
426  def showWorkFlows(self, selected=None):
427 
428  maxLen = 100 # for summary, limit width of output
429  fmt1 = "%-6s %-35s [1]: %s ..."
430  fmt2 = " %35s [%d]: %s ..."
431  print "\nfound a total of ", len(self.workFlows), ' workflows:'
432  if selected:
433  print " of which the following", len(selected), 'were selected:'
434  #-ap for now:
435  maxLen = -1 # for individual listing, no limit on width
436  fmt1 = "%-6s %-35s [1]: %s "
437  fmt2 = " %35s [%d]: %s"
438 
439  n1 = 0
440  n2 = 0
441  n3 = 0
442  n4 = 0
443  for wf in self.workFlows:
444  if selected and float(wf.numId) not in selected: continue
445  print ''
446  n1+=1
447  wfName, stepNames = wf.nameId.split('+',1)
448  print fmt1 % (wf.numId, stepNames, (wf.cmdStep1+' ')[:maxLen])
449  if wf.cmdStep2:
450  n2+=1
451  print fmt2 % ( ' ', 2, (wf.cmdStep2+' ')[:maxLen])
452  if wf.cmdStep3:
453  n3+=1
454  print fmt2 % ( ' ', 3, (wf.cmdStep3+' ')[:maxLen])
455  if wf.cmdStep4:
456  n4+=1
457  print fmt2 % ( ' ', 4, (wf.cmdStep4+' ')[:maxLen])
458 
459  print n1, 'workflows for step1,'
460  print n2, 'workflows for step1 + step2,'
461  print n3, 'workflows for step1 + step2 + step3'
462  print n4, 'workflows for step1 + step2 + step3 + step4'
463 
464  return
465 
466  def createWorkFlows(self, fileNameIn):
467 
468  prefixIn = self.filesPrefMap[fileNameIn]
469 
470  # get through the list of items and update the requested workflows only
471  keyList = self.step1WorkFlows.keys()
472  ids = []
473  for item in keyList:
474  id, pref = item
475  if pref != prefixIn : continue
476  ids.append( float(id) )
477 
478  ids.sort()
479  n1 = 0
480  n2 = 0
481  n3 = 0
482  n4 = 0
483  for key in ids:
484  val = self.step1WorkFlows[(key,prefixIn)]
485  num, name, cmd, step2, step3, step4, inputInfo = val
486  nameId = num+'_'+name
487  if nameId in self.nameList.keys():
488  print "==> duplicate name found for ", nameId
489  print ' keeping : ', self.nameList[nameId]
490  print ' ignoring : ', val
491  else:
492  self.nameList[nameId] = val
493 
494  cmd2 = None
495  cmd3 = None
496  cmd4 = None
497 
498  n1 += 1
499 
500  if step2.lower() != '':
501  n2 += 1
502  cmd2 = step2
503  if step3.lower() != '':
504  n3 += 1
505  cmd3 = step3
506  if step4.lower() != '':
507  n4 += 1
508  cmd4 = step4
509  #print '\tstep3 : ', self.step3WorkFlows[step3]
510  self.workFlows.append( WorkFlow(num, name, cmd, cmd2, cmd3, cmd4, inputInfo) )
511 
512  return
513 
514  def prepare(self, useInput=None):
515 
516  for matrixFile in self.files:
517  try:
518  self.readMatrix(matrixFile, useInput)
519  except Exception, e:
520  print "ERROR reading file:", matrixFile, str(e)
521  raise
522 
523  try:
524  self.createWorkFlows(matrixFile)
525  except Exception, e:
526  print "ERROR creating workflows :", str(e)
527  raise
528 
529  def show(self, selected=None):
530  # self.showRaw()
531  self.showWorkFlows(selected)
532  print '\n','-'*80,'\n'
533 
534 
535  def updateDB(self):
536 
537  import pickle
538  pickle.dump(self.workFlows, open('theMatrix.pkl', 'w') )
539 
540  return
541 
542 # ================================================================================
543 
545 
546  def __init__(self, wfIn=None, nThrMax=8):
547 
548  self.workFlows = wfIn
549 
550  self.threadList = []
551  self.maxThreads = int(nThrMax) # make sure we get a number ...
552 
553 
554  def activeThreads(self):
555 
556  nActive = 0
557  for t in self.threadList:
558  if t.isAlive() : nActive += 1
559 
560  return nActive
561 
562 
563  def runTests(self, testList=None):
564 
565  startDir = os.getcwd()
566 
567  # make sure we have a way to set the environment in the threads ...
568  if not os.environ.has_key('CMS_PATH'):
569  cmsPath = '/afs/cern.ch/cms'
570  print "setting default for CMS_PATH to", cmsPath
571  os.environ['CMS_PATH'] = cmsPath
572 
573  report=''
574  print 'Running in %s thread(s)' % self.maxThreads
575 
576  for wf in self.workFlows:
577 
578  if testList and float(wf.numId) not in [float(x) for x in testList]: continue
579 
580  item = wf.nameId
581  if os.path.islink(item) : continue # ignore symlinks
582 
583  # make sure we don't run more than the allowed number of threads:
584  while self.activeThreads() >= self.maxThreads:
585  time.sleep(10)
586  continue
587 
588  print '\nPreparing to run %s %s' % (wf.numId, item)
589 
590 ## if testList: # if we only run a selection, run only 5 events instead of 10
591 ## wf.cmdStep1 = wf.cmdStep1.replace('-n 10', '-n 5')
592 
593  current = WorkFlowRunner(wf)
594  self.threadList.append(current)
595  current.start()
596  time.sleep(random.randint(1,5)) # try to avoid race cond by sleeping random amount of time [1,5] sec
597 
598  # wait until all threads are finished
599  while self.activeThreads() > 0:
600  time.sleep(5)
601 
602  # all threads are done now, check status ...
603  nfail1 = 0
604  nfail2 = 0
605  nfail3 = 0
606  nfail4 = 0
607  npass = 0
608  npass1 = 0
609  npass2 = 0
610  npass3 = 0
611  npass4 = 0
612  for pingle in self.threadList:
613  pingle.join()
614  try:
615  nfail1 += pingle.nfail[0]
616  nfail2 += pingle.nfail[1]
617  nfail3 += pingle.nfail[2]
618  nfail4 += pingle.nfail[3]
619  npass1 += pingle.npass[0]
620  npass2 += pingle.npass[1]
621  npass3 += pingle.npass[2]
622  npass4 += pingle.npass[3]
623  npass += npass1+npass2+npass3+npass4
624  report += pingle.report
625  # print pingle.report
626  except Exception, e:
627  msg = "ERROR retrieving info from thread: " + str(e)
628  nfail1 += 1
629  nfail2 += 1
630  nfail3 += 1
631  nfail4 += 1
632  report += msg
633  print msg
634 
635  report+='\n %s %s %s %s tests passed, %s %s %s %s failed\n' %(npass1, npass2, npass3, npass4, nfail1, nfail2, nfail3, nfail4)
636  print report
637 
638  runall_report_name='runall-report-step123-.log'
639  runall_report=open(runall_report_name,'w')
640  runall_report.write(report)
641  runall_report.close()
642 
643  os.chdir(startDir)
644 
645  return
646 
647 
648 # ================================================================================
649 
650 def showRaw(useInput=None) :
651 
652  mrd = MatrixReader()
653  mrd.showRaw(useInput)
654 
655  return 0
656 
657 # ================================================================================
658 
659 def runSelected(testList, nThreads=4, show=False, useInput=None) :
660 
661  stdList = ['5.2', # SingleMu10 FastSim
662  '7', # Cosmics+RECOCOS+ALCACOS
663  '8', # BeamHalo+RECOCOS+ALCABH
664  '25', # TTbar+RECO2+ALCATT2 STARTUP
665  ]
666  hiStatList = [
667  '121', # TTbar_Tauola
668  '123.3', # TTBar FastSim
669  ]
670 
671  mrd = MatrixReader()
672  mrd.prepare(useInput)
673 
674  if testList == []:
675  testList = stdList+hiStatList
676 
677  ret = 0
678  if show:
679  mrd.show([float(x) for x in testList])
680  print 'selected items:', testList
681  else:
682  mRunnerHi = MatrixRunner(mrd.workFlows, nThreads)
683  ret = mRunnerHi.runTests(testList)
684 
685  return ret
686 
687 # ================================================================================
688 
689 def runData(testList, nThreads=4, show=False, useInput=None) :
690 
691  mrd = MatrixReader()
692  mrd.prepare(useInput)
693 
694  ret = 0
695  if show:
696  if not testList or testList == ['all']:
697  mrd.show()
698  else:
699  mrd.show([float(x) for x in testList])
700  print 'selected items:', testList
701  else:
702  mRunnerHi = MatrixRunner(mrd.workFlows, nThreads)
703  if not testList or testList == ['all']:
704  ret = mRunnerHi.runTests()
705  else:
706  ret = mRunnerHi.runTests(testList)
707 
708  return ret
709 
710 # --------------------------------------------------------------------------------
711 
712 def runAll(testList=None, nThreads=4, show=False, useInput=None) :
713 
714  mrd = MatrixReader()
715  mrd.prepare(useInput)
716 
717  ret = 0
718 
719  if show:
720  mrd.show()
721  print "nThreads = ",nThreads
722  else:
723  mRunnerHi = MatrixRunner(mrd.workFlows, nThreads)
724  ret = mRunnerHi.runTests()
725 
726  return ret
727 
728 
729 # --------------------------------------------------------------------------------
730 
731 def runOnly(only, show, nThreads=4, useInput=None):
732 
733  if not only: return
734 
735  for what in only:
736  print "found request to run relvals only for ",what
737  print "not implemented, nothing done"
738 
739 # --------------------------------------------------------------------------------
740 
741 def usage():
742  print "Usage:", sys.argv[0], ' [options] '
743  print """
744 Where options is one of the following:
745  -d, --data <list> comma-separated list of workflows to use from the realdata file.
746  <list> can be "all" to select all data workflows
747  -l, --list <list> comma-separated list of workflows to use from the cmsDriver*.txt files
748  -j, --nproc <n> run <n> processes in parallel (default: 4 procs)
749  -s, --selected run a subset of 8 workflows (usually in the CustomIB)
750  -n, -q, --show show the (selected) workflows
751  -i, --useInput <list> will use data input (if defined) for the step1 instead of step1. <list> can be "all" for this option
752  -r, --raw in combination with --show will create the old style cmsDriver_*_hlt.txt file (in the working dir)
753 
754 <list>s should be put in single- or double-quotes to avoid confusion with/by the shell
755 """
756 
757 # ================================================================================
758 
759 if __name__ == '__main__':
760 
761  import getopt
762 
763  try:
764  opts, args = getopt.getopt(sys.argv[1:], "hj:sl:nqo:d:i:r", ['help',"nproc=",'selected','list=','showMatrix','only=','data=','useInput=','raw'])
765  except getopt.GetoptError, e:
766  print "unknown option", str(e)
767  sys.exit(2)
768 
769 # check command line parameter
770 
771  np=4 # default: four threads
772  sel = None
773  input = None
774  show = False
775  only = None
776  data = None
777  raw = False
778  for opt, arg in opts :
779  if opt in ('-h','--help'):
780  usage()
781  sys.exit(0)
782  if opt in ('-j', "--nproc" ):
783  np=int(arg)
784  if opt in ('-n','-q','--showMatrix', ):
785  show = True
786  if opt in ('-s','--selected',) :
787  sel = []
788  if opt in ('-o','--only',) :
789  only = []
790  if opt in ('-l','--list',) :
791  sel = arg.split(',')
792  if opt in ('-i','--useInput',) :
793  input = arg.split(',')
794  if opt in ('-d','--data',) :
795  data = arg.split(',')
796  if opt in ('-r','--raw') :
797  raw = True
798 
799  if raw and show:
800  ret = showRaw(useInput=input)
801  sys.exit(ret)
802 
803 
804  ret = 0
805  if sel != None: # explicit distinguish from empty list (which is also false)
806  ret = runSelected(testList=sel, nThreads=np, show=show, useInput=input)
807  elif only != None:
808  ret = runOnly(only=only, show=show, nThreads=np, useInput=input)
809  elif data != None:
810  ret = runData(testList=data, show=show, nThreads=np, useInput=input)
811  else:
812  ret = runAll(show=show, nThreads=np, useInput=input)
813 
814  sys.exit(ret)
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
list object
Definition: dbtoconf.py:77