Skip to content

Commit ca2294b

Browse files
committed
[TASK] push orbit object and bpm data
1 parent d61b0b5 commit ca2294b

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/dt4acc/custom_epics/views/calculation_result_view.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
"""
2+
3+
Todo:
4+
improve periodic update of data e.g. orbit data
5+
* Should that be provided by an periodic publisher?
6+
* Should there be a central instance that informs
7+
periodic publishers that
8+
* calculations have been requested: i.e. update
9+
was called
10+
* that these cache data internally until it needs
11+
being republished
12+
"""
113
import itertools
214
from datetime import datetime
315
from typing import Sequence
@@ -72,6 +84,7 @@ def __init__(self, *, prefix):
7284
tmp = np.empty([2048], np.int16)
7385
tmp.fill(-2 ** 15 + 1)
7486
self.default_bpm_legacy_data = tmp
87+
self.orbit_object_data = None
7588
self.default_twiss = None
7689
self.bpm_mimicry = None
7790

@@ -80,7 +93,6 @@ def set_bpm_mimicry(self, bpm_mimicry):
8093
self.bpm_mimicry = bpm_mimicry
8194

8295
async def push_value(self, elm_update: ElementUpdate):
83-
elm_update
8496
if elm_update.property_name == "K":
8597
pass
8698
else:
@@ -127,11 +139,12 @@ async def push_bpms(self, orbit_data):
127139
bpm_legacy_data = self.bpm_mimicry.bpm_legacy_data_df_to_array(df_bpm)
128140
self.default_bpm_legacy_data = bpm_legacy_data
129141
await self.push_legacy_bpm_data(bpm_legacy_data)
130-
df_for_orbit = df_bpm.copy()
142+
orbit_object_data = df_bpm.copy()
131143
mm2nm = 1e6
132-
df_for_orbit.x = df_bpm.x * mm2nm
133-
df_for_orbit.y = df_bpm.y * mm2nm
134-
await self.push_orbit_object(df_for_orbit)
144+
orbit_object_data.x = df_bpm.x * mm2nm
145+
orbit_object_data.y = df_bpm.y * mm2nm
146+
self.orbit_object_data = orbit_object_data
147+
await self.push_orbit_object(self.orbit_object_data)
135148
except Exception as e:
136149
logger.error(f"Error processing orbit data: {e}")
137150

@@ -151,10 +164,15 @@ async def push_legacy_bpm_data(self, bpm_legacy_data: Sequence[np.int16] = None)
151164
Push BPM data to EPICS. If no data is provided, push the default data.
152165
"""
153166
if bpm_legacy_data is None:
167+
logger.info(f"Pushing legacy BPM data at {datetime.now()}")
154168
bpm_legacy_data = self.default_bpm_legacy_data
155-
logger.info(f"Pushing legacy BPM data at {datetime.now()}")
156169
await self.bpm_pvs.set_data(bpm_legacy_data)
157170

171+
if self.orbit_object_data is None:
172+
return
173+
logger.info(f"Pushing orbit object data at {datetime.now()}")
174+
await self.push_orbit_object(self.orbit_object_data)
175+
158176
async def heart_beat(self):
159177
"""
160178
Periodic heartbeat function to push default BPM data.
@@ -163,4 +181,7 @@ async def heart_beat(self):
163181
# logger.warning(f"view heartbeat {datetime.now()}")
164182
await self.push_legacy_bpm_data(self.default_bpm_legacy_data)
165183
await self.push_twiss(self.default_twiss)
166-
await self.bpm_pvs.heart_beat()
184+
# Todo: remove this duplication ...
185+
# currently
186+
#
187+
# await self.bpm_pvs.heart_beat()

0 commit comments

Comments
 (0)