Skip to content

Commit

Permalink
what-is-ioc functionality to get the IOC name for a PV
Browse files Browse the repository at this point in the history
  • Loading branch information
mrakitin committed May 31, 2024
1 parent 712f9dc commit aa47ba9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions nslsii/epics_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import argparse
import socket
from socket import gaierror, herror

from caproto.threading.client import Context


def get_ioc_hostname(pvname):
"""A helper function to get the IOC hostname based on the provided PV."""

ctx = Context()
(pv,) = ctx.get_pvs(pvname)
pv.wait_for_connection()
s = pv.circuit_manager.socket

epics_addr = s.getpeername()[0]
sci_addr = epics_addr.split(".")
sci_addr[2] = str(int(sci_addr[2]) - 3)
sci_addr = ".".join(sci_addr)

try:
hostname = socket.gethostbyaddr(sci_addr)[0]
except (gaierror, herror):
hostname = socket.gethostbyaddr(epics_addr)[0]

return hostname


def main():
# Used by the `sync-experiment` command

parser = argparse.ArgumentParser(description="Start or switch beamline experiment and record it in Redis")
parser.add_argument("-p", "--pv", dest="pvname", type=str, help="PV to query information about", required=True)

args = parser.parse_args()
hostname = get_ioc_hostname(args.pvname)
print(f"IOC hostname for {args.pvname} is {hostname}")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
install_requires=requirements,
entry_points={
"console_scripts": [
# 'command = some.module:some_function',
"sync-experiment = nslsii.sync_experiment:main",
"what-is-ioc = nslsii.epics_utils:main",
],
},
)

0 comments on commit aa47ba9

Please sign in to comment.