#! /usr/bin/env python # ______________________________________________________________________ # # Filename: events_read # # Created: 26-AUG-2001, Harry Melanson # # ______________________________________________________________________ """Summarizes the status of framework jobs that have been run in this directory. USAGE: events_read [-h] OPTIONS: -h, --help -- Print help text and exit. This script gives a summary of the status of framework jobs that have been submitted from the current directory. You should execute the script in the directory where you submitted the jobs. The script then searchs each sub-directory for the file 'events.read', and uses that file to figure out how many events have been processed. This script can be used in conjunction with the runxxx commands supported with d0tools. """ # ______________________________________________________________________ # import sys, os, glob, string # ______________________________________________________________________ # __author__ = 'Harry Melanson, melanson@fnal.gov' __version__ = '01.00.00' __filename__ = 'events_read.py' __doc__ = __doc__ % vars() # ______________________________________________________________________ # class Result: def __init__(self, job, events, status): self.job = job self.events = events self.status = status def sortResults(a, b): if a.job < b.job: return -1 elif b.job < a.job: return 1 else: return 0 # ______________________________________________________________________ # def process_command(): """Process the command.""" from scriptutil import getOptions optlist, args = getOptions('', [], __doc__) results = [] maxlen = 0 # Get a list of all available events.read file eventsfile = 'events.read' list = glob.glob('*/' + eventsfile) if len(list) == 0: print '\n', 'ERROR: No evidence of any directories containing framework jobs.' print 'Could not find any sub-directories that contain "events.read" files.' print 'If you just submitted a job, please wait for it to start.' print "Also, make sure you are in a directory where you've run some jobs." sys.exit() # Look at each one for file in list: job = string.split(file, '/')[0] events = '?' status = 'UNKNOWN' file = open(file,'r') for line in file.readlines(): if string.find(line, 'Total events: ') != -1: events = line[14:-1] if string.find(line, 'Status: ') != -1: if line[8:-1] == 'open': status = 'Running' else: status = 'Done' result = os.popen('grep -i controller ' + job + '/*.out').readlines() if status != 'Running' and len(result) == 0: status = 'UNKNOWN' if len(glob.glob(job + '/core')) != 0: status = 'Crashed' file.close() results.append(Result(job, events, status)) if len(job) > maxlen: maxlen = len(job) # Print summary format = '%-' + ('%i' % maxlen) + 's %6s %-7s' print '\n', (format) % ('Job', 'Events', 'Status') print (format) % ('---', '------', '------') results.sort(sortResults) for result in results: print (format) % (result.job, result.events, result.status) # Self-test if __name__ == '__main__': process_command() sys.exit(0)