Skip to content

Commit d83a0b9

Browse files
Allow larcv_inject_run_number script to take a run list (different run per file)
1 parent c4f6394 commit d83a0b9

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

bin/larcv_inject_run_number.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def initialize_manager(file_path, dest, overwrite, suffix):
8181
return manager, out_path
8282

8383

84-
def main(source, source_list, dest, overwrite, run_number, offset, suffix):
84+
def main(source, source_list, dest, overwrite, run_number, run_list, offset, suffix):
8585
"""Checks the output of the SPINE process.
8686
8787
The script loops over the input files, fetch the list of keys in the file
@@ -105,6 +105,9 @@ def main(source, source_list, dest, overwrite, run_number, offset, suffix):
105105
run_number : int
106106
Run number to inject in the input file list. If it is specied as -1,
107107
each file is assigned a unique run number
108+
run_list : str
109+
Path to a text file containing a list of run numbers to assign to each
110+
input file
108111
offset : int
109112
Offset to add to the existing run number for each successive file
110113
suffix : str
@@ -116,6 +119,18 @@ def main(source, source_list, dest, overwrite, run_number, offset, suffix):
116119
with open(source_list, "r", encoding="utf-8") as f:
117120
source = f.read().splitlines()
118121

122+
# If using run list, read it in
123+
run_numbers = None
124+
if run_list is not None:
125+
with open(run_list, "r", encoding="utf-8") as f:
126+
run_numbers = f.read().splitlines()
127+
run_numbers = [int(r) for r in run_numbers]
128+
if len(run_numbers) != len(source):
129+
raise ValueError(
130+
"The number of run numbers provided does not match the number "
131+
"of input files."
132+
)
133+
119134
# Loop over the list of files in the input
120135
print("\nUpdating the run numbers of input files.")
121136
for idx, file_path in enumerate(tqdm(source)):
@@ -139,6 +154,8 @@ def main(source, source_list, dest, overwrite, run_number, offset, suffix):
139154
io.set_id(run_number, subrun, event)
140155
else:
141156
io.set_id(idx, subrun, event)
157+
elif run_numbers is not None:
158+
io.set_id(run_numbers[idx], subrun, event)
142159
else:
143160
io.set_id(run + offset, subrun, event)
144161

@@ -186,6 +203,12 @@ def main(source, source_list, dest, overwrite, run_number, offset, suffix):
186203
"assigned a unique run number",
187204
type=int,
188205
)
206+
group.add_argument(
207+
"--run-list",
208+
help="Path to a text file containing a list of run numbers to assign "
209+
"to each input file",
210+
type=str,
211+
)
189212
group.add_argument(
190213
"--offset",
191214
help="Offset to add to the existing run number for each successive file",
@@ -205,6 +228,7 @@ def main(source, source_list, dest, overwrite, run_number, offset, suffix):
205228
args.dest,
206229
args.overwrite,
207230
args.run_number,
231+
args.run_list,
208232
args.offset,
209233
args.suffix,
210234
)

0 commit comments

Comments
 (0)