LightController
While the BeamPath
object provides basic control functionality, the
LightController
is what organizes of all of LCLS’s
devices. The facility is represented by an Directed Graph, starting at the
source and ending at the beamline hutches. After placing each device in the
facility graph, each beamline is constructed as a BeamPath
object.
This includes not only devices on the upstream beamline but all of the
beamlines before it. For example, the MEC beampath will include devices in both
the FEE and the XRT. The MEC beampath will also contain devices that appear in
XPP’s and XCS’s beampath. In some cases there are multiple possible paths beam
may take to reach a given endstation. In the case of multiple possible paths,
the LightController.active_path()
will return the path with the latest
impediment. (equivalently, the path that lets the beam through farthest)
The LightController
handles this logic as well as a basic overview of
where the beam is
- class lightpath.LightController(client: Client, endstations: list[str] | None = None, cfg: dict[str, Any] = {})[source]
Controller for the LCLS Lightpath
Handles grouping devices into beamlines and joining paths together. Also provides an overview of the state of the entire beamline
- Parameters:
client (happi.Client) – Happi Client
endstations (List[str], optional) – List of experimental endstations to load BeamPath objects for. If left as None, all endstations will be loaded
- active_path(dest: str) BeamPath [source]
Return the most active path to the requested endstation
Looks for the path with the latest impediment (highest z)
- Parameters:
dest (str) – endstation to look for paths towards
- Returns:
path – the active path
- Return type:
BeamPath
- property destinations: list[Device]
Current device destinations for the LCLS photon beam
- Returns:
a list of beam destinations
- Return type:
List[Device]
- property devices: list[Device]
All of the devices loaded in the facility
- Returns:
list of devices loaded in the facility
- Return type:
List[Device]
- get_device(device_name: str) Device [source]
Return device in the facility. Creates the device if it has not been already.
- Parameters:
device (NodeName) – name of device
- Returns:
requested device, or a mock version of the device
- Return type:
Device
- get_paths(endstation: str) list[BeamPath] [source]
Returns the BeamPaths for a specified endstation. Create and fill the BeamPaths if they have not been already
- Parameters:
endstation (str) – name of endstation to return paths for
- Returns:
a list of BeamPath’s to the requested endstation
- Return type:
List[BeamPath]
- static imped_z(path: BeamPath) float [source]
Get z position of impediment or inf.
- Parameters:
path (
BeamPath
) – BeamPath to find impediment position in- Returns:
z position of impediment
- Return type:
float
- property incident_devices: list[Device]
List of all devices in contact with photons along the beamline
- Returns:
list of all incident devices in facility
- Return type:
List[Device]
- static is_source_name(name: str) bool [source]
Checks if the node name provided is a valid source name
- Parameters:
name (str) – name to check
- Returns:
if name is a valid source name
- Return type:
bool
- load_beamline(endstation: str)[source]
Load a beamline given the facility graph. Finds all possible paths from facility sources to the endstation’s branch. Branches are mapped to endstations in the config. Each branch can be optionally mapped to a final z to consider part of the path.
Loads valid beampaths into the LightController.beamlines attribute for later access.
- Parameters:
endstation (str) – Name of endstation to load
- load_facility()[source]
Load the facility from the provided happi client.
The facility is represented by a directed graph, with devices as nodes. Edge weights are initialized as 0, and labeled with their branch.
The facility graph is created by combining subgraphs that each contain all the devices on a given branch.
- static make_graph(branch_devs: list[SearchResult], branch_name: str, sources: list[str] = []) DiGraph [source]
Create a graph with devices from
branch_devs
as nodes, arranged in z-order.It is assumed that all devices lie on branch:
branch_name
If
sources
is provided, will prepend a source node at the beginning of the branch ifbranch_name == sources
- Parameters:
branch_devs (List[happi.SearchResult]) – a list of devices to generate graph with
branch_name (str) – branch name, used to label edges
sources (List[NodeName], optional) – source node Names, by default []
- Returns:
The branch comprised of nodes holding devices from branch_devs
- Return type:
nx.DiGraph
- path_to(device: Device) BeamPath [source]
Returns the path with latest blocking device (highest blocking z-position) to the requested device
To get all possible paths, see
LightController.paths_to
- Parameters:
device (Device) – A device somewhere in the facility
- Returns:
path to the specified device
- Return type:
- paths_to(device: Device) list[BeamPath] [source]
Create all BeamPaths from the facility source to the requested device
- Parameters:
device (Device) – A device somewhere in LCLS
- Raises:
PathError – If a single, valid path cannot be determined
- Returns:
paths – Paths to and including given device
- Return type:
List[
BeamPath
]
- walk_facility() dict[str, list[str]] [source]
Return the paths from each source to its destination by walking the graph.
Starting from a source node, steps iteratively through a node’s successors (nearest neighbors). If there is one and only one valid successor, step to that device and repeat. Once there are no more connections, we have reached the end of the line.
Successors are considered invalid if a node’s output branch does not match the successor’s input.
- Returns:
A mapping from source node names to path of nodes
- Return type:
Dict[NodeName, List[NodeName]]
- Raises:
PathError – If a single, valid path cannot be determined