Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make link of the updated longterm datacheck file in a common directory #273

Merged
merged 19 commits into from
Feb 14, 2024
Merged
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion src/osa/scripts/closer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import subprocess
import sys
import glob
from datetime import datetime, timedelta
from pathlib import Path
from typing import Tuple, Iterable, List
Expand All @@ -18,7 +19,7 @@
from osa.job import are_all_jobs_correctly_finished, save_job_information
from osa.nightsummary.extract import extract_runs, extract_sequences
from osa.nightsummary.nightsummary import run_summary_table
from osa.paths import destination_dir
from osa.paths import destination_dir, get_major_version
from osa.raw import is_raw_data_available
from osa.report import start
from osa.utils.cliopts import closercliparsing
Expand All @@ -32,6 +33,7 @@
create_lock,
gettag,
date_to_iso,
get_lstchain_version,
)

__all__ = [
Expand Down Expand Up @@ -158,6 +160,7 @@ def post_process(seq_tuple):
list_job_id = merge_dl1_datacheck(seq_list)
longterm_job_id = daily_datacheck(daily_longterm_cmd(list_job_id))
cherenkov_transparency(cherenkov_transparency_cmd(longterm_job_id))
create_longterm_symlink()

# Extract the provenance info
extract_provenance(seq_list)
Expand Down Expand Up @@ -526,5 +529,44 @@ def cherenkov_transparency(cmd: List[str]):
log.debug("Simulate launching scripts")


def get_latest_version(longterm_files: List[str]) -> str:
morcuended marked this conversation as resolved.
Show resolved Hide resolved
"""Get the latest version of the produced longterm DL1 datacheck files."""
morcuended marked this conversation as resolved.
Show resolved Hide resolved
nightdir = date_to_dir(options.date)
latest_version = 0
for file in longterm_files:
idx1 = file.find("/v0.")
idx2 = file.find(f"/{nightdir}")
version = file[idx1+1:idx2]
if int(version[3:])>latest_version:
latest_version = int(version[3:])

return "v0."+str(latest_version)
morcuended marked this conversation as resolved.
Show resolved Hide resolved


def create_longterm_symlink():
morcuended marked this conversation as resolved.
Show resolved Hide resolved
"""If the created longterm DL1 datacheck file corresponds to the latest
version available, make symlink to it in the "all" common directory."""
nightdir = date_to_dir(options.date)
longterm_dir = Path(cfg.get("LST1", "LONGTERM_DIR"))
longterm_datacheck_file = longterm_dir / options.prod_id / nightdir / f"DL1_datacheck_{nightdir}.h5"
linked_longterm_file = longterm_dir / f"night_wise/all/DL1_datacheck_{nightdir}.h5"
morcuended marked this conversation as resolved.
Show resolved Hide resolved
all_longterm_files = glob.glob(longterm_dir + f"/v*/{nightdir}/DL1_datacheck_{nightdir}.h5")
morcuended marked this conversation as resolved.
Show resolved Hide resolved
morcuended marked this conversation as resolved.
Show resolved Hide resolved

if len(all_longterm_files) > 1:
latest_version = get_latest_version(all_longterm_files)
current_version = get_major_version(get_lstchain_version())
if current_version == latest_version:
log.info("Make symlink of the longterm DL1 datacheck file in the common directory.")
linked_longterm_file.unlink()
linked_longterm_file.symlink_to(longterm_datacheck_file)
else:
log.info("The created longterm DL1 datacheck file does not correspond to the \
latest available version, so no symlink is made.")
return
else:
log.info("Make symlink of the longterm DL1 datacheck file in the common directory.")
linked_longterm_file.symlink_to(longterm_datacheck_file)


if __name__ == "__main__":
main()
Loading