CMS 3D CMS Logo

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