Skip to content

Commit

Permalink
Check if the longterm file exists before launching again all the jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
marialainez committed Feb 22, 2024
1 parent bdb4c87 commit 8b49ab1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
13 changes: 10 additions & 3 deletions src/osa/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,25 @@ def is_job_completed(job_id: str):
return False


def create_longterm_symlink(cherenkov_job_id: str):
def create_longterm_symlink(cherenkov_job_id: str = None):
"""If the created longterm DL1 datacheck file corresponds to the latest
version available, make symlink to it in the "all" common directory."""
if is_job_completed(cherenkov_job_id):
if not cherenkov_job_id or is_job_completed(cherenkov_job_id):
nightdir = utils.date_to_dir(options.date)
longterm_dir = Path(cfg.get("LST1", "LONGTERM_DIR"))
linked_longterm_file = longterm_dir / f"night_wise/all/DL1_datacheck_{nightdir}.h5"
all_longterm_files = longterm_dir.rglob(f"v*/{nightdir}/DL1_datacheck_{nightdir}.h5")
latest_version_file = get_latest_version_file(all_longterm_files)

log.info("Symlink the latest version longterm DL1 datacheck file in the common directory.")
linked_longterm_file.unlink(missing_ok=True)
linked_longterm_file.symlink_to(latest_version_file)
else:
log.warning(f"Job {cherenkov_job_id} (lstchain_cherenkov_transparency) did not finish successfully.")

def dl1_datacheck_longterm_file_exits(): -> bool
"""Return true if the longterm DL1 datacheck file was already produced."""
nightdir = utils.date_to_dir(options.date)
longterm_dir = Path(cfg.get("LST1", "LONGTERM_DIR"))
longterm_file = longterm_dir / options.prod_id / nightdir / f"DL1_datacheck_{nightdir}.h5"
return longterm_file.exists()

49 changes: 29 additions & 20 deletions src/osa/scripts/closer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
)
from osa.nightsummary.extract import extract_runs, extract_sequences
from osa.nightsummary.nightsummary import run_summary_table
from osa.paths import destination_dir, create_longterm_symlink
from osa.paths import (
destination_dir,
create_longterm_symlink,
dl1_datacheck_longterm_file_exits
)
from osa.raw import is_raw_data_available
from osa.report import start
from osa.utils.cliopts import closercliparsing
Expand Down Expand Up @@ -155,32 +159,37 @@ def post_process(seq_tuple):
"""Set of last instructions."""
seq_list = seq_tuple[1]

# Close the sequences
post_process_files(seq_list)
if dl1_datacheck_longterm_file_exits():
create_longterm_symlink()

# Merge DL1 datacheck files and produce PDFs. It also produces
# the daily datacheck report using the longterm script, and updates
# the longterm DL1 datacheck file with the cherenkov_transparency script.
if cfg.getboolean("lstchain", "merge_dl1_datacheck"):
list_job_id = merge_dl1_datacheck(seq_list)
longterm_job_id = daily_datacheck(daily_longterm_cmd(list_job_id))
cherenkov_job_id = cherenkov_transparency(cherenkov_transparency_cmd(longterm_job_id))
create_longterm_symlink(cherenkov_job_id)
else:
# Close the sequences
post_process_files(seq_list)

# Extract the provenance info
extract_provenance(seq_list)
# Merge DL1 datacheck files and produce PDFs. It also produces
# the daily datacheck report using the longterm script, and updates
# the longterm DL1 datacheck file with the cherenkov_transparency script.
if cfg.getboolean("lstchain", "merge_dl1_datacheck"):
list_job_id = merge_dl1_datacheck(seq_list)
longterm_job_id = daily_datacheck(daily_longterm_cmd(list_job_id))
cherenkov_job_id = cherenkov_transparency(cherenkov_transparency_cmd(longterm_job_id))
create_longterm_symlink(cherenkov_job_id)

# Merge DL1b files run-wise
merge_files(seq_list, data_level="DL1AB")
# Extract the provenance info
extract_provenance(seq_list)

merge_muon_files(seq_list)
# Merge DL1b files run-wise
merge_files(seq_list, data_level="DL1AB")

# Merge DL2 files run-wise
if not options.no_dl2:
merge_files(seq_list, data_level="DL2")
merge_muon_files(seq_list)

# Merge DL2 files run-wise
if not options.no_dl2:
merge_files(seq_list, data_level="DL2")


time.sleep(600)

time.sleep(600)

# Check if all jobs launched by autocloser finished correctly
# before creating the NightFinished.txt file
Expand Down

0 comments on commit 8b49ab1

Please sign in to comment.