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