Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:30

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