Skip to content

Commit c6a5034

Browse files
authored
Merge pull request #1398 from cta-observatory/check_duplicated_runs
Prevent using more than one datacheck file per run
2 parents acd210d + 51447e9 commit c6a5034

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lstchain/scripts/lstchain_cherenkov_transparency.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def main():
9494
picture_thresh = []
9595
boundary_thresh = []
9696

97+
# Prevent more than one datacheck file per run ID
98+
# Dict with key: run_id and value: file
99+
run_info = {}
100+
97101
for file in tqdm(files):
98102
a = tables.open_file(file)
99103

@@ -167,10 +171,22 @@ def main():
167171
corrected_elapsed_time.append(newtime)
168172

169173
subrun_index.append(a.root.dl1datacheck.cosmics.col('subrun_index'))
170-
run.append(int(file[file.find('.Run') + 4:file.find('.Run') + 9]))
174+
runnumber = int(file[file.find('.Run') + 4:file.find('.Run') + 9])
175+
run.append(runnumber)
171176

172177
num_subruns = len(a.root.dl1datacheck.cosmics.col('subrun_index'))
173178

179+
# check if the run is duplicated
180+
prev_file = run_info.get(runnumber)
181+
if prev_file is None:
182+
run_info[runnumber] = file
183+
else:
184+
a.close()
185+
raise RuntimeError(
186+
f"The datacheck for run {runnumber} has been loaded twice: "
187+
f"from path {prev_file} and path {file}"
188+
)
189+
174190
if 'pedestals' in a.root.dl1datacheck:
175191
if len(a.root.dl1datacheck.pedestals.col(
176192
'subrun_index')) == num_subruns: # all subruns present

lstchain/scripts/lstchain_longterm_dl1_check.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ class pixwise_info(tables.IsDescription):
245245

246246
dicts = [cosmics, pedestals, flatfield]
247247

248+
# Prevent more than one datacheck file per run ID
249+
# Dict with key: run_id and value: file
250+
run_info = {}
251+
248252
# files are of the type datacheck_dl1_LST-1.RunXXXXX.h5
249253
for file in files:
250254

@@ -257,6 +261,17 @@ class pixwise_info(tables.IsDescription):
257261
runnumber = int(file.name[file.name.find('.Run') + 4:
258262
file.name.find('.Run') + 9])
259263

264+
# check if the run is duplicated
265+
prev_file = run_info.get(runnumber)
266+
if prev_file is None:
267+
run_info[runnumber] = file
268+
else:
269+
a.close()
270+
raise RuntimeError(
271+
f"The datacheck for run {runnumber} has been loaded twice: "
272+
f"from path {prev_file} and path {file}"
273+
)
274+
260275
# Lists to keep the datacheck tables for cosmics, pedestals and
261276
# flatfield. The "_no_stars" list will have nans for pixels which
262277
# were close to stars during a given subrun

0 commit comments

Comments
 (0)