Skip to content

Commit

Permalink
Merge pull request #230 from cta-observatory/add_gainsel
Browse files Browse the repository at this point in the history
Add gain selection to OSA workflow
  • Loading branch information
morcuended authored Mar 12, 2024
2 parents b8767ae + e4e6d3d commit e589deb
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 87 deletions.
2 changes: 2 additions & 0 deletions src/osa/configs/sequencer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ HIGH_LEVEL_DIR: %(OSA_DIR)s/HighLevel
LONGTERM_DIR: %(OSA_DIR)s/DL1DataCheck_LongTerm
MERGED_SUMMARY: %(OSA_DIR)s/Catalog/merged_RunSummary.ecsv
SEQUENCER_WEB_DIR: %(OSA_DIR)s/SequencerWeb
GAIN_SELECTION_FLAG_DIR: %(OSA_DIR)s/GainSel

# To be set by the user. Using PROD-ID will overcome the automatic
# fetching of lstchain version. Otherwise leave it empty (and without the colon symbol).
Expand Down Expand Up @@ -138,6 +139,7 @@ WORKFLOWPREFIX: Workflow
GRAPHSUFFIX: .dot
SVGSUFFIX: .svg
end_of_activity: NightFinished.txt
gain_selection_check: GainSelFinished.txt

[OUTPUT]
# REPORTWIDTH is the width in characters of the heading frame for the output
Expand Down
25 changes: 22 additions & 3 deletions src/osa/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ def monitoring_dir(base_test_dir):
return monitoring_dir


@pytest.fixture(scope="session")
def osa_dir(base_test_dir):
osa_dir = base_test_dir / "OSA"
osa_dir.mkdir(parents=True, exist_ok=True)
return osa_dir


@pytest.fixture(scope="session")
def run_summary_dir(monitoring_dir):
summary_dir = monitoring_dir / "RunSummary"
Expand Down Expand Up @@ -436,6 +443,8 @@ def sequence_file_list(
drs4_time_calibration_files,
systematic_correction_files,
r0_data,
gain_selection_flag_file,
merged_run_summary,
):
for r0_file in r0_data:
assert r0_file.exists()
Expand All @@ -448,6 +457,8 @@ def sequence_file_list(

assert run_summary_file.exists()
assert run_catalog.exists()
assert gain_selection_flag_file.exists()
assert merged_run_summary.exists()

run_program("sequencer", "-d", "2020-01-17", "--no-submit", "-t", "LST1")
# First sequence in the list corresponds to the calibration run 1809
Expand Down Expand Up @@ -548,11 +559,9 @@ def run_catalog(run_catalog_dir):


@pytest.fixture(scope="session")
def database(base_test_dir):
def database(osa_dir):
import sqlite3

osa_dir = base_test_dir / "OSA"
osa_dir.mkdir(parents=True, exist_ok=True)
db_file = osa_dir / "osa.db"
with sqlite3.connect(db_file) as connection:
cursor = connection.cursor()
Expand All @@ -562,3 +571,13 @@ def database(base_test_dir):
)
cursor.connection.commit()
yield cursor


@pytest.fixture(scope="session")
def gain_selection_flag_file(osa_dir):

GainSel_dir = osa_dir / "GainSel" / "20200117"
GainSel_dir.mkdir(parents=True, exist_ok=True)
file = GainSel_dir / "GainSelFinished.txt"
file.touch()
return file
10 changes: 7 additions & 3 deletions src/osa/scripts/autocloser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
config_file: Path,
ignore_cronlock: bool = False,
test: bool = False,
no_gainsel: bool = False,
):
"""
Parameters
Expand Down Expand Up @@ -82,7 +83,7 @@ def __init__(
if not self.lock_automatic_sequencer() and not ignore_cronlock:
log.warning(f"{self.telescope} already locked! Ignoring {self.telescope}")
return
if not self.simulate_sequencer(date, config_file, test):
if not self.simulate_sequencer(date, config_file, test, no_gainsel):
log.warning(
f"Simulation of the sequencer failed "
f"for {self.telescope}! Ignoring {self.telescope}"
Expand Down Expand Up @@ -121,7 +122,7 @@ def lock_automatic_sequencer(self):
self.locked = True
return True

def simulate_sequencer(self, date: str, config_file: Path, test: bool):
def simulate_sequencer(self, date: str, config_file: Path, test: bool, no_gainsel: bool):
"""Launch the sequencer in simulation mode."""
if test:
self.read_file()
Expand All @@ -135,6 +136,9 @@ def simulate_sequencer(self, date: str, config_file: Path, test: bool):
date,
self.telescope,
]
if no_gainsel:
sequencer_cmd.insert(1, "--no-gainsel")

log.debug(f"Executing {' '.join(sequencer_cmd)}")
sequencer = subprocess.Popen(
sequencer_cmd,
Expand Down Expand Up @@ -445,7 +449,7 @@ def main():
# create telescope and sequence objects
log.info("Simulating sequencer...")

telescope = Telescope(args.tel_id, date, args.config)
telescope = Telescope(args.tel_id, date, args.config, no_gainsel=args.no_gainsel)

log.info(f"Processing {args.tel_id}...")

Expand Down
Loading

0 comments on commit e589deb

Please sign in to comment.