CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
MatrixRunner.MatrixRunner Class Reference
Inheritance diagram for MatrixRunner.MatrixRunner:

Public Member Functions

def __init__
 
def activeThreads
 
def runTests
 

Public Attributes

 maxThreads
 
 nThreads
 
 runDirs
 
 threadList
 
 workFlows
 

Detailed Description

Definition at line 9 of file MatrixRunner.py.

Constructor & Destructor Documentation

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

Definition at line 11 of file MatrixRunner.py.

11 
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={}

Member Function Documentation

def MatrixRunner.MatrixRunner.activeThreads (   self)

Definition at line 22 of file MatrixRunner.py.

References MatrixRunner.MatrixRunner.threadList.

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

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

Definition at line 31 of file MatrixRunner.py.

References MatrixRunner.MatrixRunner.activeThreads(), submitPVResolutionJobs.count, join(), MatrixRunner.MatrixRunner.maxThreads, MatrixRunner.MatrixRunner.nThreads, print(), sistrip::SpyUtilities.range(), MatrixRunner.MatrixRunner.runDirs, str, MatrixRunner.MatrixRunner.threadList, MatrixRunner.MatrixRunner.workFlows, and MatrixReader.MatrixReader.workFlows.

31 
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  self.maxThreads=4
45  print('resetting to default number of process threads = %s' % self.maxThreads)
46 
47  print('Running %s %s %s, each with %s thread%s per process' % ('up to' if self.maxThreads > 1 else '', self.maxThreads, 'concurrent jobs' if self.maxThreads > 1 else 'job', self.nThreads, 's' if self.nThreads > 1 else ''))
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(1)
60 
61  print('\nPreparing to run %s %s' % (wf.numId, item))
62  sys.stdout.flush()
63  current = WorkFlowRunner(wf,noRun,dryRun,cafVeto, opt.dasOptions, opt.jobReports, opt.nThreads, opt.nStreams, opt.maxSteps)
64  self.threadList.append(current)
65  current.start()
66  if not dryRun:
67  time.sleep(0.5) # try to avoid race cond by sleeping 0.5 sec
68 
69  # wait until all threads are finished
70  while self.activeThreads() > 0:
71  time.sleep(0.5)
72 
73 
74  #wrap up !
75  totpassed=[]
76  totfailed=[]
77  def count(collect,result):
78  #pad with zeros
79  for i in range(len(collect),len(result)):
80  collect.append(0)
81  for i,c in enumerate(result):
82  collect[i]+=c
83 
84  for pingle in self.threadList:
85  pingle.join()
86  try:
87  count(totpassed,pingle.npass)
88  count(totfailed,pingle.nfail)
89  report+=pingle.report
90  self.runDirs[pingle.wf.numId]=pingle.wfDir
91  except Exception as e:
92  msg = "ERROR retrieving info from thread: " + str(e)
93  report += msg
94 
95  report+=' '.join(map(str,totpassed))+' tests passed, '+' '.join(map(str,totfailed))+' failed\n'
96  print(report)
97  sys.stdout.flush()
98 
99  runall_report_name='runall-report-step123-.log'
100  runall_report=open(runall_report_name,'w')
101  runall_report.write(report)
102  runall_report.close()
103  os.chdir(startDir)
104 
105  anyFail=sum(totfailed)
106 
107  return anyFail
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
#define str(s)

Member Data Documentation

MatrixRunner.MatrixRunner.maxThreads

Definition at line 16 of file MatrixRunner.py.

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

MatrixRunner.MatrixRunner.nThreads

Definition at line 17 of file MatrixRunner.py.

Referenced by MatrixRunner.MatrixRunner.runTests().

MatrixRunner.MatrixRunner.runDirs

Definition at line 20 of file MatrixRunner.py.

Referenced by MatrixRunner.MatrixRunner.runTests().

MatrixRunner.MatrixRunner.threadList

Definition at line 15 of file MatrixRunner.py.

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

MatrixRunner.MatrixRunner.workFlows

Definition at line 13 of file MatrixRunner.py.

Referenced by MatrixRunner.MatrixRunner.runTests().