From 5ca34281d6232b2dc855f4cbf13da21f5131df5e Mon Sep 17 00:00:00 2001 From: Daniel Douglas Date: Tue, 3 Feb 2026 18:09:07 +0100 Subject: [PATCH 1/4] fixed stupid arg parsing bullshit --- bin/run_flow2supera.py | 90 ++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/bin/run_flow2supera.py b/bin/run_flow2supera.py index 3199847..0c31588 100755 --- a/bin/run_flow2supera.py +++ b/bin/run_flow2supera.py @@ -3,58 +3,64 @@ import sys,os from optparse import OptionParser -... -parser = OptionParser(usage='Provide option flags followed by a list of input files.') -parser.add_option("-o", "--output", dest="output_filename", metavar="FILE", - help="Output (LArCV) filename") -parser.add_option("-c", "--config", dest="config", metavar='FILE/KEYWORD', default='', - help="Configuration keyword or a file path (full or relative including the file name)") -parser.add_option("-n", "--num_events", dest="num_events", metavar="INT", default=None, - help="number of events to process") -parser.add_option("-s", "--skip", dest="skip", metavar="INT", default=0, - help="number of first events to skip") -#parser.add_option("-b", action="store_true", dest="ignore_bad_association", default=False) -parser.add_option("-l", "--log", dest="log_file", metavar="FILE", default='', - help="the name of a log file to be created. ") - -(data, args) = parser.parse_args() - -if os.path.isfile(data.output_filename): - print('Ouput file already exists:',data.output_filename) + +import argparse +parser = argparse.ArgumentParser() +parser.add_argument('input_file', + type = str, + help = "input file from which to read and simulate an event.", + ) +parser.add_argument('-o', '--output', + type = str, + help = "Output (LArCV) filename.") +parser.add_argument('-c', '--config', + type = str, + default = '', + help = "Configuration keyword or a file path (full or relative including the file name).", + required = True) +parser.add_argument('-n', '--num_events', + type = int, + default = -1, + help="number of events to process.") +parser.add_argument('-s', '--skip', + type = int, + default = 0, + help="number of first events to skip.") +parser.add_argument('-l', '--log', + type = str, + default = '', + help="the name of a log file to be created.") + +args = parser.parse_args() + +if os.path.isfile(args.output): + print('Ouput file already exists:', args.output) print('Exiting') sys.exit(1) -if not data.config in flow2supera.config.list_config() and not os.path.isfile(data.config): - print('Invalid configuration given:',data.config) +if not args.config in flow2supera.config.list_config() and not os.path.isfile(args.config): + print('Invalid configuration given:',args.config) print('The argument is not valid as a file path nor matched with any of') print('predefined config keys:',flow2supera.config.list_config()) print('Exiting') sys.exit(2) -if len(args) < 1: +if not args.input_file: print('No input files given! Exiting') sys.exit(3) -output = sys.argv[1] -input_files = sys.argv[2:] - -if os.path.isfile(sys.argv[1]): - print('Output file already exists:',output) - sys.exit(2) - -if not data.config: - print('Configuration file/keyword is required.') - sys.exit(3) +output = args.output +input_files = args.input_file -if not flow2supera.config.get_config(data.config): - print('Invalid configuration option argument:',data.config) - sys.exit(3) +if args.num_events >= 0: + num_events = args.num_events +else: + num_events = None -flow2supera.utils.run_supera(out_file=data.output_filename, - in_file=args[0], - config_key=data.config, - num_events=data.num_events if data.num_events is None else int(data.num_events), - num_skip=int(data.skip), - #ignore_bad_association=bool(data.ignore_bad_association), - save_log=data.log_file, - ) +flow2supera.utils.run_supera(out_file=args.output, + in_file=args.input, + config_key=args.config, + num_events=num_events, + num_skip=int(args.skip), + save_log=args.log_file, + ) From a3ac5ae917e7da437c22cb0cfbb2c1e8c8358400 Mon Sep 17 00:00:00 2001 From: Daniel Douglas Date: Thu, 5 Feb 2026 16:21:18 +0100 Subject: [PATCH 2/4] better arg handling (needs to be tested) --- bin/run_flow2supera.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/bin/run_flow2supera.py b/bin/run_flow2supera.py index 0c31588..c31e23e 100755 --- a/bin/run_flow2supera.py +++ b/bin/run_flow2supera.py @@ -2,8 +2,6 @@ import flow2supera import sys,os -from optparse import OptionParser - import argparse parser = argparse.ArgumentParser() parser.add_argument('input_file', @@ -17,10 +15,10 @@ type = str, default = '', help = "Configuration keyword or a file path (full or relative including the file name).", - required = True) + ) parser.add_argument('-n', '--num_events', type = int, - default = -1, + default = None, help="number of events to process.") parser.add_argument('-s', '--skip', type = int, @@ -52,15 +50,10 @@ output = args.output input_files = args.input_file -if args.num_events >= 0: - num_events = args.num_events -else: - num_events = None - flow2supera.utils.run_supera(out_file=args.output, in_file=args.input, config_key=args.config, - num_events=num_events, + num_events=args.num_events, num_skip=int(args.skip), save_log=args.log_file, ) From 98abcd10ae8c9765f38de2b0bd072a69b9a50283 Mon Sep 17 00:00:00 2001 From: Daniel Douglas Date: Thu, 5 Feb 2026 16:32:49 +0100 Subject: [PATCH 3/4] typo in input arg passing --- bin/run_flow2supera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run_flow2supera.py b/bin/run_flow2supera.py index c31e23e..1074690 100755 --- a/bin/run_flow2supera.py +++ b/bin/run_flow2supera.py @@ -51,7 +51,7 @@ input_files = args.input_file flow2supera.utils.run_supera(out_file=args.output, - in_file=args.input, + in_file=args.input_file, config_key=args.config, num_events=args.num_events, num_skip=int(args.skip), From aaad328280eeb26342115fbeba5ee5ed00849172 Mon Sep 17 00:00:00 2001 From: Daniel Douglas Date: Thu, 5 Feb 2026 16:33:31 +0100 Subject: [PATCH 4/4] typo in passing log_file arg --- bin/run_flow2supera.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/run_flow2supera.py b/bin/run_flow2supera.py index 1074690..35e53f4 100755 --- a/bin/run_flow2supera.py +++ b/bin/run_flow2supera.py @@ -24,7 +24,7 @@ type = int, default = 0, help="number of first events to skip.") -parser.add_argument('-l', '--log', +parser.add_argument('-l', '--log_file', type = str, default = '', help="the name of a log file to be created.")