Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-17 07:05:55

0001 #!/usr/local/bin/python
0002 
0003 # get dawn view of detectors
0004 # W. Armstrong (ANL), original bash script
0005 # C. Peng (ANL), translate to python and add flexible run time for simulation
0006 
0007 import os
0008 import signal
0009 import subprocess
0010 import argparse
0011 import atexit
0012 import time
0013 from datetime import datetime
0014 import fcntl
0015 import psutil
0016 
0017 
0018 def readline_nonblocking(output):
0019     fd = output.fileno()
0020     fl = fcntl.fcntl(fd, fcntl.F_GETFL)
0021     fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
0022     try:
0023         return output.readline()
0024     except:
0025         return ''
0026 
0027 
0028 # arguments
0029 parser = argparse.ArgumentParser()
0030 
0031 parser.add_argument('-c', '--compact-file', type=str, dest='compact',
0032         default=os.path.join(os.environ.get('DETECTOR_PATH', '.'), 'athena.xml'),
0033         help='Top level compact file for detectors')
0034 
0035 parser.add_argument('-s', '--skip', type=int,
0036         default=0,
0037         help='Number of events number to skip in the input')
0038 
0039 parser.add_argument('-i', '--input', type=str, dest='input',
0040         default='sim_output',
0041         help='Input hepmc file')
0042 
0043 parser.add_argument('-o', '--output-dir', type=str, dest='out_dir',
0044         default='images',
0045         help='output directory')
0046 
0047 parser.add_argument('-D', '--detector-only', action='store_true', dest='detector_only',
0048         help='only generate the prim files for the detector geometry')
0049 
0050 parser.add_argument('-d', '--dawn-dir', type=str, dest='dawn_dir',
0051         default='scripts/view1',
0052         help='Directory to dawn script dir (with .DAWN files and a generate_eps script)')
0053 
0054 parser.add_argument('-t', '--tag', type=str,dest='file_tag',
0055         default='view',
0056         help='Output file tag')
0057 
0058 parser.add_argument('--timeout', type=int,
0059         default=60,
0060         help='Timeout in seconds')
0061         
0062 parser.add_argument('passthrough', nargs='*')
0063 
0064 args = parser.parse_args()
0065 
0066 macro = 'macro/dawn_picture.mac' if args.detector_only else 'macro/dawn_picture2.mac'
0067 
0068 # raise error if cannot create a temporary working dir
0069 # os.makedirs('dawn_view_tmp', exist_ok=False)
0070 os.makedirs(args.out_dir, exist_ok=True)
0071 
0072 # use absolute path so the chdir does not affect them
0073 args.input = os.path.abspath(args.input)
0074 args.out_dir = os.path.abspath(args.out_dir)
0075 args.compact = os.path.abspath(args.compact)
0076 macro = os.path.abspath(macro)
0077 
0078 prim_file = 'g4_0000.prim'
0079 dawn_env = os.environ.copy()
0080 dawn_env['DAWN_BATCH'] = 'a'
0081 # sdir = os.path.dirname(os.path.realpath(__file__))
0082 
0083 
0084 # generate DAWN images
0085 out_dir = os.path.abspath(args.out_dir)
0086 input_file = os.path.abspath(args.input)
0087 #prim_file = '{}/{}.prim'.format(input_dir,args.file_tag)
0088 #prim_file = os.path.abspath(prim_file)
0089 owd = os.getcwd()
0090 os.chdir(args.dawn_dir)
0091 subprocess.run(['pwd'])
0092 subprocess.run(['./generate_eps', '-t', args.file_tag, '-i', input_file] + args.passthrough)
0093 subprocess.run(['ls', '-lrth'])
0094 
0095 # upload the results
0096 os.system('cp *.pdf {}'.format(out_dir))
0097 os.system('cp *.png {}'.format(out_dir))
0098 os.chdir(owd)
0099