Skip to content

Commit a6076cc

Browse files
committed
[TASK] added name to different async tasks, added pv's for periodic tune
1 parent 73af63f commit a6076cc

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/dt4acc/core/bl/delay_execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def request_execution(self):
3939
self.pending_task.cancel()
4040

4141
# Schedule a new execution task after the delay
42-
self.pending_task = asyncio.create_task(self._delayed_execution())
42+
self.pending_task = asyncio.create_task(self._delayed_execution(), name="delayed-execution")
4343

4444
async def _delayed_execution(self):
4545
"""

src/dt4acc/custom_epics/ioc/pv_setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
LatticeElementPropertyID,
44
DevicePropertyID,
55
)
6-
from p4p.asLib.yacc import start
76

87
from .handlers import handle_device_update, update_manager
98
from ..data.constants import config, special_pvs, cavity_names
@@ -116,7 +115,7 @@ def add_pc_pvs(builder, pc_name, prefix):
116115
rdbk = builder.aOut(f"{pc_name}:rdbk", initial_value=start_val, PREC=2)
117116

118117
async def handle_pc_update(device_id: str, property_id: str, value: float):
119-
logger.debug("%s:%s updating setpoint val=%s", device_id, property_id, value)
118+
logger.warning("%s:%s updating setpoint val=%s", device_id, property_id, value)
120119
r = await handle_device_update(
121120
device_id=device_id, property_id=property_id, value=value
122121
)
@@ -148,6 +147,12 @@ def initialize_orbit_pvs(builder):
148147
builder.aOut(f"beam:orbit:found", initial_value=0)
149148

150149

150+
def initialize_tune_pvs(builder):
151+
for axis in ["x", "y"]:
152+
builder.aOut(f"TUNECC:{axis}", initial_value=0.0, PREC=9)
153+
builder.longOut(f"TUNECC:count", initial_value=0)
154+
155+
151156
def initialize_twiss_pvs(builder):
152157
"""
153158
Initializes PVs for Twiss parameters, which describe beam optics.

src/dt4acc/custom_epics/ioc/server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from softioc import softioc, builder, asyncio_dispatcher
66

7+
from ...core.utils.logger import get_logger
78
from .tasks import monitor_heartbeat
89
from .pv_setup import (
910
initialize_power_converter_pvs,
@@ -13,9 +14,12 @@
1314
initialize_bpm_pvs,
1415
initialize_orbit_object_pvs,
1516
initialize_twiss_pvs,
17+
initialize_tune_pvs,
1618
initialize_other_pvs,
1719
)
1820

21+
logger = get_logger()
22+
1923
# Create an asyncio dispatcher to handle asynchronous PV updates
2024
dispatcher = asyncio_dispatcher.AsyncioDispatcher()
2125

@@ -39,14 +43,16 @@ def startup():
3943
initialize_bpm_pvs(builder) # Initialize Beam Position Monitor PVs
4044
initialize_orbit_object_pvs(builder) # Initialize PV's of the new orbit object ... collection of bpms
4145
initialize_twiss_pvs(builder) # Initialize Twiss parameter PVs
46+
initialize_tune_pvs(builder)
47+
logger.warning("All pvs set up")
4248

4349
# Load the database of PVs defined above into the SoftIOC server
4450
builder.LoadDatabase()
4551
# Start the SoftIOC server to handle PV interactions
4652
softioc.iocInit(dispatcher)
4753

4854
# Start monitoring the heartbeat to ensure the server is running correctly
49-
asyncio.create_task(monitor_heartbeat())
55+
asyncio.create_task(monitor_heartbeat(), name="server-heartbeat-loop")
5056

5157

5258
def main():

src/dt4acc/custom_epics/ioc/tasks.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import getpass
3+
from datetime import datetime
34

45
from p4p.client.asyncio import Context
56

@@ -25,7 +26,7 @@ async def monitor_heartbeat():
2526
await ctx.put(f'{getpass.getuser()}:VS3P2T5R:set', 1e-3)
2627
await ctx.put(f'{getpass.getuser()}:VS3P2T5R:set', 0e-3)
2728
logger.warning("Heartbeat loop initial start or it was terminated unexpectedly. Restarting...")
28-
heartbeat_task = asyncio.create_task(heartbeat_loop())
29+
heartbeat_task = asyncio.create_task(heartbeat_loop(), name="heart-beat-loop")
2930
await asyncio.sleep(1)
3031

3132

@@ -36,12 +37,14 @@ async def heartbeat_loop():
3637
Runs indefinitely and logs any errors encountered.
3738
"""
3839
while True:
40+
logger.info(f"Heart beat loop executing at {datetime.now()}")
3941
try:
4042
await asyncio.sleep(1) # Run every second
41-
# logger.warning("Heartbeat loop was running ...")
43+
logger.debug(f"Heart beat loop executed at {datetime.now()}")
4244
await view.heart_beat()
4345
except asyncio.CancelledError:
4446
logger.warning("Heartbeat loop was cancelled.")
4547
break # Exit cleanly on cancellation
4648
except Exception as exc:
4749
logger.error(f"Heartbeat encountered an error: {exc}")
50+
raise exc

0 commit comments

Comments
 (0)