CMS 3D CMS Logo

heppy_check.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # Copyright (C) 2014 Colin Bernet
3 # https://github.com/cbernet/heppy/blob/master/LICENSE
4 
5 from __future__ import print_function
6 import sys
7 import re
8 import os
9 import pprint
10 
11 from optparse import OptionParser
12 
13 parser = OptionParser(usage='%prog <target_directories> [options]',
14  description='Check one or more chunck folders. Wildcard (*) can be used to specify multiple directories')
15 
16 parser.add_option("-b","--batch", dest="batch",
17  default=None,
18  help="batch command for resubmission"
19  )
20 
21 (options,args) = parser.parse_args()
22 
23 if len(args)==0:
24  print('provide at least one directory in argument. Use -h to display help')
25 
26 dirs = sys.argv[1:]
27 
28 badDirs = []
29 
30 for dir in dirs:
31  if not os.path.isdir(dir):
32  continue
33  if dir.find('_Chunk') == -1:
34  continue
35  logName = '/'.join([dir, 'log.txt'])
36  if not os.path.isfile( logName ):
37  print(dir, ': log.txt does not exist')
38  badDirs.append(dir)
39  continue
40  logFile = open(logName)
41  nEvents = -1
42  for line in logFile:
43  try:
44  nEvents = line.split('processed:')[1]
45  except:
46  pass
47  if nEvents == -1:
48  print(dir, 'cannot find number of processed events')
49  elif nEvents == 0:
50  print(dir, '0 events')
51  else:
52  continue
53  badDirs.append(dir)
54 
55 print('list of bad directories:')
56 pprint.pprint(badDirs)
57 
58 if options.batch is not None:
59  for dir in badDirs:
60  oldPwd = os.getcwd()
61  os.chdir( dir )
62  cmd = [options.batch, '-J', dir, ' < batchScript.sh' ]
63  print('resubmitting in', os.getcwd())
64  cmds = ' '.join( cmd )
65  print(cmds)
66  os.system( cmds )
67  os.chdir( oldPwd )
68 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:21