8 parser = argparse.ArgumentParser()
9 subparser = parser.add_subparsers(dest=
'command')
11 create = subparser.add_parser(
'create', help=
'Create file lists.')
12 run = subparser.add_parser(
'run', help=
'Run LEDTowerBuilder on the given file list.')
13 evtDisp = subparser.add_parser(
'evtDisp', help=
'Create event display (json) given prdf and event number.')
15 create.add_argument(
'-i',
'--run-list', type=str, nargs=
'+' , help=
'List of run numbers.')
16 create.add_argument(
'-p',
'--prdf-dir', type=str, default=
'/direct/sphenix+lustre01/sphnxpro/rawdata/commissioning/emcal/calib', help=
'Directory containing the prdf files. Default: /direct/sphenix+lustre01/sphnxpro/rawdata/commissioning/emcal/calib')
17 create.add_argument(
'-o',
'--output-dir', type=str, default=
'files', help=
'Directory to store the file lists. Default: files')
19 run.add_argument(
'-i',
'--file-list', type=str, help=
'File list containing prdfs to analyze.', required=
True)
20 run.add_argument(
'-n',
'--nevents', type=int, default = -1, help=
'Number of events to analyze. Default: -1 (analyze all)')
21 run.add_argument(
'-s',
'--skip', type=int, default = 0, help=
'Number of events to skip. Default: 0 (no skip)')
22 run.add_argument(
'-o',
'--output', type=str, default =
'data/LEDTowerBuilder.root', help=
'Output root file. Default: data/LEDTowerBuilder.root')
23 run.add_argument(
'-m',
'--max', type=int, default = 10000, help=
'Maximum number of events to analyze at once. Default: 10000')
25 evtDisp.add_argument(
'-i',
'--prdf', type=str, help=
'Prdfs to analyze.', required=
True)
26 evtDisp.add_argument(
'-r',
'--run', type=str, help=
'Run number.', required=
True)
27 evtDisp.add_argument(
'-n',
'--event', type=str, default =
'1', help=
'Event number to use. Default: 1.')
28 evtDisp.add_argument(
'-o',
'--output', type=str, help=
'Output json file.')
30 args = parser.parse_args()
33 run_list = args.run_list
34 prdf_dir = os.path.abspath(args.prdf_dir)
35 output_dir = os.path.abspath(args.output_dir)
37 print(f
'run list: {run_list}')
38 print(f
'prdf dir: {prdf_dir}')
39 print(f
'output dir: {output_dir}')
44 result = subprocess.run([
'fd', run, prdf_dir], stdout=subprocess.PIPE, text=
True)
47 with
open(f
'{output_dir}/file-list-{run}.txt',mode=
'w')
as fw:
48 fw.write(result.stdout)
51 file_list = os.path.abspath(args.file_list)
52 nevents = args.nevents
55 max_events_per_run = args.max
57 print(f
'file list: {file_list}')
58 print(f
'output: {output}')
62 with
open(file_list)
as f:
65 command = f
'dpipe -d n -s f -i {line}'
66 dpipe_process = subprocess.run(command.split(), stdout=subprocess.PIPE)
67 events = subprocess.run([
'wc',
'-l'], input=dpipe_process.stdout, stdout=subprocess.PIPE)
68 events = int(events.stdout.decode(
'utf-8'))
70 total_events += events
71 print(f
'prdf: {line}, events: {events}')
72 if(total_events > nevents+skip
and nevents >= 0):
75 nevents = total_events
if nevents == -1
else nevents
76 print(f
'total events: {total_events}')
77 if(nevents != total_events):
78 print(f
'events to analyze: {nevents}')
79 print(f
'skip: {skip}')
81 runs = int(np.ceil((nevents+skip) / max_events_per_run))
82 max_events_per_run =
min(max_events_per_run, nevents)
84 log = os.path.basename(output).split(
'.')[0]
85 output_dir = os.path.dirname(output)
86 process_events = max_events_per_run
89 print(f
'Runs: {runs}')
90 print(f
'Max events per run: {max_events_per_run}')
94 subprocess.run([
'echo', f
'Run: {i}'])
95 command = f
'./bin/Fun4All_LEDTowerBuilder {process_events} {skip} {file_list} {output_dir}/test-{i}.root &> {output_dir}/log/log-test-{i}.txt &'
97 skip += max_events_per_run
98 process_events =
min(max_events_per_run, nevents-(i+1)*max_events_per_run)
99 merge_files.append(f
'{output_dir}/test-{i}.root')
101 print(
'hadd command: ')
102 merge_files =
' '.
join(merge_files)
103 print(f
'hadd -n 50 {output} {merge_files}')
106 command = f
'./bin/Fun4All_LEDTowerBuilder {process_events} {skip} {file_list} {output} &> {output_dir}/log/log-{log}.txt &'
116 prdf_input = os.path.abspath(args.prdf)
122 output = f
'event-display/run-{run}-event-{event}.json'
124 print(f
'prdf: {prdf_input}')
126 print(f
'event: {event}')
127 print(f
'output: {output}')
128 print(f
'display only: {display_only}')
131 command = f
'eventcombiner -v -i -e {event} -n 1 -f -p data/temp/test-{run}-{event}.prdf {prdf_input}'
132 print(f
'command: {command.split()}')
133 subprocess.run(command.split())
136 with
open(
'files/test.txt',
'w')
as f:
137 f.write(f
'data/temp/test-{run}-{event}.prdf\n')
140 command = f
'bin/Fun4All_LEDTowerBuilder 1 files/test.txt data/temp test'
141 print(f
'command: {command.split()}')
142 subprocess.run(command.split())
145 command = f
'bin/event-display {run} {event} data/temp/test-CEMC.root {output} data/temp/test-HCALIN.root data/temp/test-HCALOUT.root'
146 print(f
'command: {command.split()}')
147 subprocess.run(command.split())
149 if __name__ ==
'__main__':
150 if(args.command ==
'create'):
152 if(args.command ==
'run'):
154 if(args.command ==
'evtDisp'):