Skip to content

Commit f8ec6c8

Browse files
committed
[TASK] added an empty custom tango views
1 parent 87d27b8 commit f8ec6c8

File tree

4 files changed

+134
-2
lines changed

4 files changed

+134
-2
lines changed

src/dt4acc/core/views/shared_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def get_view_instance():
2020
server_type = os.environ.get("server", "epics").lower()
2121

2222
if server_type == "tango":
23-
from ...custom_epics.views.calculation_result_view import ResultView
24-
elif server_type == "epics":
2523
from ...custom_tango.views.calculation_result_view import ResultView
24+
elif server_type == "epics":
25+
from ...custom_epics.views.calculation_result_view import ResultView
2626
else:
2727
raise ValueError(f"Unsupported server type: {server_type}")
2828

src/dt4acc/custom_tango/__init__.py

Whitespace-only changes.

src/dt4acc/custom_tango/views/__init__.py

Whitespace-only changes.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
from datetime import datetime
2+
from typing import Sequence
3+
4+
import numpy as np
5+
from p4p.client.asyncio import Context
6+
7+
from ...core.model.element_upate import ElementUpdate
8+
from ...core.model.orbit import Orbit
9+
from ...core.model.twiss import TwissWithAggregatedKValues
10+
from ...core.utils.logger import get_logger
11+
# from ..data.constants import special_pvs
12+
# from ..views.bpm_data import BeamPositionPVs
13+
# from ..views.create_or_update_pv import update_or_create_pv
14+
15+
logger = get_logger()
16+
17+
ctx = Context("pva")
18+
19+
20+
async def update_orbit_pv(pv_name, orbit_result):
21+
pass
22+
# try:
23+
# await ctx.put(f"{pv_name}:x", orbit_result.x)
24+
# await ctx.put(f"{pv_name}:y", orbit_result.y)
25+
# await ctx.put(f"{pv_name}:names", orbit_result.names)
26+
# await ctx.put(f"{pv_name}:found", orbit_result.found)
27+
# await ctx.put(f"{pv_name}:x0", orbit_result.x0)
28+
# except Exception as e:
29+
# logger.error(f"Failed to update or create Orbit PV {pv_name}: {e}")
30+
31+
32+
async def update_twiss_pv(pv_name, twiss_result):
33+
pass
34+
# try:
35+
# await ctx.put(f"{pv_name}:x:alpha", twiss_result.x.alpha)
36+
# await ctx.put(f"{pv_name}:x:beta", twiss_result.x.beta)
37+
# await ctx.put(f"{pv_name}:x:nu", twiss_result.x.nu)
38+
# await ctx.put(f"{pv_name}:y:alpha", twiss_result.y.alpha)
39+
# await ctx.put(f"{pv_name}:y:beta", twiss_result.y.beta)
40+
# await ctx.put(f"{pv_name}:y:nu", twiss_result.y.nu)
41+
# # await ctx.put(f"{pv_name}:names", twiss_result.names)
42+
# except Exception as e:
43+
# logger.error(f"Failed to update or create twiss PV {pv_name}: {e}")
44+
# try:
45+
#
46+
# await ctx.put([k.pv_name for k in twiss_result.main_values], [k.value for k in twiss_result.main_values])
47+
# except Exception as e:
48+
# logger.error(f"Failed to update or create magnet_strength PV {pv_name}: {e}")
49+
50+
51+
class ResultView:
52+
def __init__(self, *, prefix):
53+
self.prefix = prefix
54+
# self.bpm_pvs = BeamPositionPVs(prefix=f"{self.prefix}:{special_pvs['bpm_pv']}")
55+
# tmp = np.empty([2048], np.int16)
56+
# tmp.fill(-2 ** 15 + 1)
57+
# self.default_bpm_legacy_data = tmp
58+
# self.bpm_mimicry = None
59+
60+
# dependency injection (push bpm mimicry when it is available
61+
def set_bpm_mimicry(self, bpm_mimicry):
62+
self.bpm_mimicry = bpm_mimicry
63+
64+
async def push_value(self, elm_update: ElementUpdate):
65+
pass
66+
# elm_update
67+
# if elm_update.property_name == "K":
68+
# pass
69+
# else:
70+
# property_name = 'x:set' if 'x' in elm_update.property_name else (
71+
# 'y:set' if 'dy' in elm_update.property_name else elm_update.property_name)
72+
# label = f'{self.prefix}:{elm_update.element_id}:{property_name}'
73+
# await update_or_create_pv(elm_update, label, elm_update.value, 'float', 'd')
74+
75+
async def push_orbit(self, orbit_result: Orbit):
76+
logger.warning('Orbit pushing views')
77+
pass
78+
79+
# # Define the PV name for the structured Orbit data
80+
# pv_name = f"{self.prefix}:beam:orbit"
81+
#
82+
# # Use the new function to update the structured Orbit PV
83+
# try:
84+
# await update_orbit_pv(pv_name, orbit_result)
85+
# except Exception as exc:
86+
# logger.warning('Orbit views pushing failed: %s', exc)
87+
# raise exc
88+
# else:
89+
# logger.warning('Orbit pushed views')
90+
#
91+
async def push_twiss(self, twiss_result: TwissWithAggregatedKValues):
92+
logger.warning('Twiss pushing views')
93+
pass
94+
#
95+
# # Define the PV name for the structured Twiss data
96+
# pv_name = f"{self.prefix}:beam:twiss"
97+
#
98+
# # Use the bulk update function to update the structured PV
99+
# await update_twiss_pv(pv_name, twiss_result)
100+
# logger.warning('Twiss pushed views')
101+
102+
# bessy specific way of setting bpm and pushing it
103+
async def push_bpms(self, orbit_data):
104+
pass
105+
# if not self.bpm_mimicry:
106+
# raise ValueError("BPM Mimicry not set in ResultView")
107+
# try:
108+
# logger.warning(f"pushing legacy bpm data")
109+
# bpm_legacy_data = self.bpm_mimicry.extract_bpm_legacy_data(orbit_data)
110+
# self.default_bpm_legacy_data = bpm_legacy_data
111+
# await self.push_legacy_bpm_data(bpm_legacy_data)
112+
# except Exception as e:
113+
# logger.error(f"Error processing orbit data: {e}")
114+
115+
async def push_legacy_bpm_data(self, bpm_legacy_data: Sequence[np.int16] = None):
116+
pass
117+
"""
118+
Push BPM data to EPICS. If no data is provided, push the default data.
119+
"""
120+
# if bpm_legacy_data is None:
121+
# bpm_legacy_data = self.default_bpm_legacy_data
122+
# logger.info(f"Pushing legacy BPM data at {datetime.now()}")
123+
# await self.bpm_pvs.set_data(bpm_legacy_data)
124+
125+
async def heart_beat(self):
126+
"""
127+
Periodic heartbeat function to push default BPM data.
128+
"""
129+
130+
# logger.warning(f"views heartbeat {datetime.now()}")
131+
await self.push_legacy_bpm_data(self.default_bpm_legacy_data)
132+
await self.bpm_pvs.heart_beat()

0 commit comments

Comments
 (0)