From 8d49f9cd28cc12f715b633ee4b8b50549961d512 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Tue, 24 Sep 2024 08:29:08 +0000
Subject: [PATCH] Always apply latest CalTables from S3

---
 README.md                                            |  1 +
 tangostationcontrol/VERSION                          |  2 +-
 .../tangostationcontrol/devices/calibration.py       | 12 ++++++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 93d84eba0..259e6cc0b 100644
--- a/README.md
+++ b/README.md
@@ -151,6 +151,7 @@ Next change the version in the following places:
 
 # Release Notes
 
+* 0.42.9 Use latest tables from S3 to calibrate antenna fields
 * 0.42.8 Emit metrics even if attribute is polled by AttributePoller as well as Tango
 * 0.42.7 Prevent Prometheus name collision in ProtectionControl state attribute
 * 0.42.6 Fix crash caused by emitting change events for attributes polled by Tango
diff --git a/tangostationcontrol/VERSION b/tangostationcontrol/VERSION
index 959c4e573..dc2f1e7e5 100644
--- a/tangostationcontrol/VERSION
+++ b/tangostationcontrol/VERSION
@@ -1 +1 @@
-0.42.8
+0.42.9
diff --git a/tangostationcontrol/tangostationcontrol/devices/calibration.py b/tangostationcontrol/tangostationcontrol/devices/calibration.py
index fcc6edd73..349743990 100644
--- a/tangostationcontrol/tangostationcontrol/devices/calibration.py
+++ b/tangostationcontrol/tangostationcontrol/devices/calibration.py
@@ -86,6 +86,10 @@ class Calibration(LOFARDevice):
             logger.warning("Device not active. Ignore AntennaField changed event")
             return
 
+        # make sure we have the latest tables
+        logger.debug("Syncing calibration tables")
+        self._calibration_manager.sync_calibration_tables()
+
         # frequencies changed, so we need to recalibrate
         self._calibrate_antenna_field(device.name())
 
@@ -96,6 +100,10 @@ class Calibration(LOFARDevice):
             logger.warning("Device not active. Ignore clock changed event")
             return
 
+        # make sure we have the latest tables
+        logger.debug("Syncing calibration tables")
+        self._calibration_manager.sync_calibration_tables()
+
         found = False
         for k, ant in self.ant_proxies.items():
             # Recalibrate associated AntennaField
@@ -279,8 +287,8 @@ class Calibration(LOFARDevice):
             )
 
     def configure_for_on(self):
-        # Calibrate all antennafields, as we did not receive
+        # (Re)calibrate all antennafields, as we did not receive
         # any events yet.
-        self.calibrate_all()
+        self.download_calibration_tables()
 
         super().configure_for_on()
-- 
GitLab