pyaml.yellow_pages#

Dynamic discovery service for accelerator objects.

Fully dynamic YellowPages service attached to Accelerator.

Key points:
  • Auto-discovery only: arrays, tools and diagnostics are discovered at runtime by scanning all modes.

  • No caching: every call reflects current runtime state.

  • Simple query syntax for identifiers:
    • wildcard / fnmatch:

      yp[“OH4*”]

    • regular expression:

      yp[“re:^SH1A-C0[12]-H$”]

Accelerator interface#

  • controls() -> dict[str, ElementHolder]

  • simulators() -> dict[str, ElementHolder]

  • modes() -> dict[str, ElementHolder]

Classes

YellowPages(accelerator)

Dynamic discovery service for accelerator objects.

YellowPagesCategory(*values)

Kind of object a YellowPages entry refers to.

Exceptions

YellowPagesError(message)

YellowPages-specific error with clear user-facing messages.

YellowPagesQueryError(message)

Raised when a YellowPages query string cannot be evaluated.

exception pyaml.yellow_pages.YellowPagesError(message)#

Bases: PyAMLException

YellowPages-specific error with clear user-facing messages.

exception pyaml.yellow_pages.YellowPagesQueryError(message)#

Bases: YellowPagesError

Raised when a YellowPages query string cannot be evaluated.

class pyaml.yellow_pages.YellowPages(accelerator)#

Bases: object

Dynamic discovery service for accelerator objects.

YellowPages provides a unified access layer to arrays, tuning tools and diagnostics available in an Accelerator.

Entries are discovered dynamically by scanning all ElementHolder instances associated with the Accelerator control and simulation modes.

Parameters:

accelerator ('Accelerator') – Accelerator whose modes are scanned on every query.

Methods

has()

Check whether a YellowPages key exists.

categories()

Return the list of available categories.

keys()

Return available YellowPages keys.

availability()

Return the set of modes where a key is available.

get()

Search identifiers using a wildcard or regular expression.

Notes

The Accelerator must provide:

  • controls() -> dict[str, ElementHolder]

  • simulators() -> dict[str, ElementHolder]

  • modes() -> dict[str, ElementHolder]

Examples

Print the global overview:

>>> print(sr.yellow_pages)

Resolve an entry across all modes:

>>> sr.yellow_pages.get("BPM")

Resolve in a specific mode:

>>> sr.yellow_pages.get("BPM", mode="live")

Search identifiers using wildcards:

>>> sr.yellow_pages["OH4*"]

Search identifiers using a regular expression:

>>> sr.yellow_pages["re:^SH1A-C0[12]-H$"]
availability(key)#

Return the set of modes where a key is available.

Parameters:

key (str) – Entry name.

Returns:

set[str]

Return type:

set[str]

Examples

>>> sr.yellow_pages.availability("BPM")
>>> sr.yellow_pages.availability("DEFAULT_ORBIT_CORRECTION")
categories()#

Return the list of available categories.

Only categories that contain entries are returned.

Returns:

list[str]

Return type:

list[str]

Examples

>>> sr.yellow_pages.categories()
['Arrays', 'Tools', 'Diagnostics']
get(query, mode=None)#

Search identifiers using a wildcard or regular expression.

Parameters:
  • query (str) – Search expression.

  • mode (str, optional) – Restrict the search to a specific Accelerator mode.

Returns:

list[str]

Return type:

list[str]

Examples

>>> sr.yellow_pages.get("OH4*")

>>> sr.yellow_pages.get("OH4*", mode="live")

>>> sr.yellow_pages.get("re:^SH1A-C0[12]-H$")
has(key)#

Check whether a YellowPages key exists.

Parameters:

key (str) – Entry name.

Returns:

bool – True if the key exists.

Return type:

bool

Examples

>>> sr.yellow_pages.has("BPM")
True
>>> sr.yellow_pages.has("UNKNOWN")
False
keys(category=None)#

Return available YellowPages keys.

Parameters:

category (str or YellowPagesCategory, optional) – Restrict the result to a specific category.

Returns:

list[str]

Return type:

list[str]

Examples

All entries:

>>> sr.yellow_pages.keys()

Only arrays:

>>> sr.yellow_pages.keys("Arrays")

Using enum:

>>> sr.yellow_pages.keys(YellowPagesCategory.ARRAYS)
class pyaml.yellow_pages.YellowPagesCategory(*values)#

Bases: str, Enum

Kind of object a YellowPages entry refers to.

Attributes

ARRAYS

Named element families declared in the arrays configuration section.

TOOLS

Tuning and measurement tools attached to a mode.

DIAGNOSTICS

Monitors such as betatron tune and chromaticity monitors.