Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:51

0001 #!/usr/bin/env python3
0002 # Copyright (C) 2014 Colin Bernet
0003 # https://github.com/cbernet/heppy/blob/master/LICENSE
0004 
0005 import sys
0006 import re
0007 import os
0008 import pprint
0009 
0010 from optparse import OptionParser
0011 
0012 parser = OptionParser(usage='%prog <target_directories> [options]',
0013                       description='Check one or more chunck folders. Wildcard (*) can be used to specify multiple directories')
0014 
0015 parser.add_option("-b","--batch", dest="batch",
0016                   default=None,
0017                   help="batch command for resubmission"
0018                   )
0019 
0020 (options,args) = parser.parse_args()
0021 
0022 if len(args)==0:
0023     print('provide at least one directory in argument. Use -h to display help')
0024 
0025 dirs = sys.argv[1:]
0026 
0027 badDirs = []
0028 
0029 for dir in dirs:
0030     if not os.path.isdir(dir):
0031         continue
0032     if dir.find('_Chunk') == -1:
0033         continue
0034     logName  = '/'.join([dir, 'log.txt'])
0035     if not os.path.isfile( logName ):
0036         print(dir, ': log.txt does not exist')
0037         badDirs.append(dir)
0038         continue
0039     logFile = open(logName)
0040     nEvents = -1
0041     for line in logFile:
0042         try:
0043             nEvents = line.split('processed:')[1]
0044         except:
0045             pass
0046     if nEvents == -1:
0047         print(dir, 'cannot find number of processed events')
0048     elif nEvents == 0:
0049         print(dir, '0 events')
0050     else:
0051         continue
0052     badDirs.append(dir)
0053 
0054 print('list of bad directories:')
0055 pprint.pprint(badDirs)
0056 
0057 if options.batch is not None:
0058     for dir in badDirs:
0059         oldPwd = os.getcwd()
0060         os.chdir( dir )
0061         cmd =  [options.batch, '-J', dir, ' < batchScript.sh' ]
0062         print('resubmitting in', os.getcwd())
0063         cmds = ' '.join( cmd )
0064         print(cmds)
0065         os.system( cmds )
0066         os.chdir( oldPwd )
0067