CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
MatrixRunner.MatrixRunner Class Reference
Inheritance diagram for MatrixRunner.MatrixRunner:

Public Member Functions

def __init__ (self, wfIn=None, nThrMax=4, nThreads=1)
 
def activeThreads (self)
 
def runTests (self, opt)
 

Public Attributes

 maxThreads
 
 nThreads
 
 runDirs
 
 threadList
 
 workFlows
 

Detailed Description

Definition at line 10 of file MatrixRunner.py.

Constructor & Destructor Documentation

def MatrixRunner.MatrixRunner.__init__ (   self,
  wfIn = None,
  nThrMax = 4,
  nThreads = 1 
)

Definition at line 12 of file MatrixRunner.py.

12  def __init__(self, wfIn=None, nThrMax=4, nThreads=1):
13 
14  self.workFlows = wfIn
15 
16  self.threadList = []
17  self.maxThreads = nThrMax
18  self.nThreads = nThreads
19 
20  #the directories in which it happened
21  self.runDirs={}
22 
def __init__(self, wfIn=None, nThrMax=4, nThreads=1)
Definition: MatrixRunner.py:12

Member Function Documentation

def MatrixRunner.MatrixRunner.activeThreads (   self)

Definition at line 23 of file MatrixRunner.py.

References MatrixRunner.MatrixRunner.threadList.

Referenced by MatrixRunner.MatrixRunner.runTests(), and addOnTests.StandardTester.runTests().

23  def activeThreads(self):
24 
25  nActive = 0
26  for t in self.threadList:
27  if t.isAlive() : nActive += 1
28 
29  return nActive
30 
31 
def MatrixRunner.MatrixRunner.runTests (   self,
  opt 
)

Definition at line 32 of file MatrixRunner.py.

References MatrixRunner.MatrixRunner.activeThreads(), KineDebug3.count(), objects.autophobj.float, join(), genParticles_cff.map, MatrixRunner.MatrixRunner.maxThreads, MatrixRunner.MatrixRunner.runDirs, harvestTrackValidationPlots.str, MatrixRunner.MatrixRunner.threadList, MatrixRunner.MatrixRunner.workFlows, and MatrixReader.MatrixReader.workFlows.

32  def runTests(self, opt):
33 
34  testList=opt.testList
35  dryRun=opt.dryRun
36  cafVeto=opt.cafVeto
37 
38  startDir = os.getcwd()
39 
40  report=''
41  noRun=(self.maxThreads==0)
42  if noRun:
43  print 'Not running the wf, only creating cfgs and logs'
44  print 'resetting to default number of threads'
45  self.maxThreads=4
46 
47  print 'Running in %s thread(s)' % self.maxThreads
48 
49 
50  for wf in self.workFlows:
51 
52  if testList and float(wf.numId) not in [float(x) for x in testList]: continue
53 
54  item = wf.nameId
55  if os.path.islink(item) : continue # ignore symlinks
56 
57  # make sure we don't run more than the allowed number of threads:
58  while self.activeThreads() >= self.maxThreads:
59  time.sleep(10)
60  continue
61 
62  print '\nPreparing to run %s %s' % (wf.numId, item)
63  sys.stdout.flush()
64  current = WorkFlowRunner(wf,noRun,dryRun,cafVeto, opt.dasOptions, opt.jobReports, opt.nThreads, opt.maxSteps)
65  self.threadList.append(current)
66  current.start()
67  if not dryRun:
68  time.sleep(random.randint(1,5)) # try to avoid race cond by sleeping random amount of time [1,5] sec
69 
70  # wait until all threads are finished
71  while self.activeThreads() > 0:
72  time.sleep(0.5)
73 
74 
75  #wrap up !
76  totpassed=[]
77  totfailed=[]
78  def count(collect,result):
79  #pad with zeros
80  for i in range(len(collect),len(result)):
81  collect.append(0)
82  for i,c in enumerate(result):
83  collect[i]+=c
84 
85  for pingle in self.threadList:
86  pingle.join()
87  try:
88  count(totpassed,pingle.npass)
89  count(totfailed,pingle.nfail)
90  report+=pingle.report
91  self.runDirs[pingle.wf.numId]=pingle.wfDir
92  except Exception as e:
93  msg = "ERROR retrieving info from thread: " + str(e)
94  report += msg
95 
96  report+=' '.join(map(str,totpassed))+' tests passed, '+' '.join(map(str,totfailed))+' failed\n'
97  print report
98  sys.stdout.flush()
99 
100  runall_report_name='runall-report-step123-.log'
101  runall_report=open(runall_report_name,'w')
102  runall_report.write(report)
103  runall_report.close()
104  os.chdir(startDir)
105 
106  anyFail=sum(totfailed)
107 
108  return anyFail
109 

Member Data Documentation

MatrixRunner.MatrixRunner.maxThreads
MatrixRunner.MatrixRunner.nThreads

Definition at line 18 of file MatrixRunner.py.

MatrixRunner.MatrixRunner.runDirs

Definition at line 21 of file MatrixRunner.py.

Referenced by MatrixRunner.MatrixRunner.runTests().

MatrixRunner.MatrixRunner.workFlows

Definition at line 14 of file MatrixRunner.py.

Referenced by MatrixRunner.MatrixRunner.runTests().