calibration_context

Module for the CalibrationContext class.

Contains CalibrationContext (the overarching context class that handles the CalibrationSet, InstrumentCluster and Monitoring subcontexts), as well as the AbortError exception and abort_handler signal handler that catches aborts raised in non-main threads within the main thread to allow for central handling.

Functions

abort_handler(sig, frame)

Abort Handler to be attached to SIGINT and SIGUSR1 to handle abort and keyboard interrupt events.

Classes

CalibrationContext([instrument_cluster, ...])

Global context class for module calibration.

Exceptions

AbortError

Error raised on application-wide abort.

abort_handler

module_testing.dirigent.calibration_context.abort_handler(sig, frame)

Abort Handler to be attached to SIGINT and SIGUSR1 to handle abort and keyboard interrupt events.

This handler ensures global error events can be caught on the main thread rather than getting stuck in a subthread.

CalibrationContext

class module_testing.dirigent.calibration_context.CalibrationContext(instrument_cluster=None, calibration_set=None, monitoring=None, sub_shell='xterm', firmware='', ph2_dir='', felis=False, module_info=None, ph2_ver='unknown', opto_dict=None, hw_config=None, dir_ver=None, default_map=None, **kwargs)

Bases: object

Global context class for module calibration.

CalibrationContext manages an instrument cluster, calibration set (i.e. config and output files) and monitoring subprocesses as locally attached instances. These should be externally instantiated, then passed to a CalibrationContext on instantiation. Leaving any of these as None will disable this functionality within the instantiated CalibrationContext.

__init__(instrument_cluster=None, calibration_set=None, monitoring=None, sub_shell='xterm', firmware='', ph2_dir='', felis=False, module_info=None, ph2_ver='unknown', opto_dict=None, hw_config=None, dir_ver=None, default_map=None, **kwargs)

Constructs a new CalibrationContext wrapping the passed objects.

The passed objects should be instantiated, but not yet activated/__enter__’d. When __enter__ is called on the CalibrationContext object, all attached contexts will be entered in the correct order.

Parameters:
  • instrument_cluster – InstrumentCluster object to be used by this context.

  • calibration_set – CalibrationSet object to be used by this context.

  • monitoring – Monitoring manager object to be used by this context.

Returns:

CalibrationContext object.

abort()

Process-wide abort handle.

Raises abort as SIGUSR1 signal to ensure main thread receives abort request and can handle it.

property active
Returns:

whether context is activated/__enter__’d.

calibration(calibration, *flags)

Return a new context manager for a Ph2ACF instance that can be activated to start the requested calibration.

Calling this does not block the main thread.

Parameters:
  • calibration – calibration name to be passed to -c flag of Ph2ACF (e.g. pixelalive).

  • flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

Returns:

Ph2ACFInstance for requested calibration.

property calibration_set
Returns:

attached calibration set.

ddr_reset(*flags)

Return a new context manager for a Ph2ACF instance that resets the FC7 DDR memory.

Calling this does not block the main thread.

Parameters:

flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

Returns:

Ph2ACFInstance for DDR reset.

property felis
property instruments
Returns:

current instrument cluster.

property last_run
Returns:

last run number in calibration set.

load_firmware(firmware, *flags)

Return a new context manager for a Ph2ACF instance that loads a firmware.

This should not block the main thread

Will also afterwards start a reset command (always required when loading a firmware)

Parameters:
  • firmware – string with the name of the firmware on the SD card. Usually it is a custom name that has to be known by the user.

  • flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

Returns:

Ph2ACFInstance for DDR reset.

property module_names
property monitoring
Returns:

attached monitoring manager.

program_system(*flags)

Return a new context manager for a Ph2ACF instance that just programs the system components.

Calling this does not block the main thread.

Parameters:

flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

Returns:

Ph2ACFInstance for programming system components.

run_calibration(calibration, *flags)

Creates and opens a new context for a Ph2ACF instance that performs the requested calibration.

Calling this blocks the main thread until calibration is complete!

Parameters:
  • calibration – calibration name to be passed to -c flag of Ph2ACF (e.g. pixelalive).

  • flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

run_ddr_reset(*flags)

Creates and opens a new context for a Ph2ACF instance that performs the FC7 DDR reset.

Calling this blocks the main thread until DDR reset is complete!

Parameters:

flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

run_load_firmware(firmware, *flags)

Creates and opens a new context for a Ph2ACF instance that loads a firmware.

Calling this blocks the main thread until the firmware is loaded.

Parameters:
  • firmware – string with the name of the firmware on the SD card. Usually it is a custom name that has to be known by the user.

  • flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

run_program_system(*flags)

Creates and opens a new context for a Ph2ACF instance that just programs the system.

Calling this blocks the main thread.

Parameters:

flags – dictionary of keyword arguments (flags) to be passed to Ph2ACFInstance constructor.

run_sequence(calibrations, title, tuning_step_args=None, required_instruments=None)

Creates and opens a new context for a CalibrationSequence instance that performs the requested sequence of calibrations.

Calling this blocks the main thread until calibration is complete!

Parameters:
  • calibrations – A list of calibrations to be passed to CalibrationSequence

  • title – A string to be passed to the database handler Felis as the name of the sequence in the Panthera database.

  • tuning_step_args – A list of strings to pass to tuning calibrations. These can be a string or JSON-formatted string dictionaries, depending on the calibration.

  • required_instruments – A dictionary containing instruments that are absolutely required to perform the sequence e.g. {“lv”, “hv”}.

sequence(calibrations, title, tuning_step_args=None, required_instruments=None)

Return a new context manager for a CalibrationSequence.

Calling this does not block the main thread.

Parameters:
  • calibrations – A list of calibrations to be passed to CalibrationSequence.

  • title – A string to be passed to the database handler Felis as the name of the sequence in the Panthera database.

  • tuning_step_args – A list of strings to pass to tuning calibrations. These can be a string or JSON-formatted string dictionaries, depending on the calibration.

  • required_instruments – A dictionary containing instruments that are absolutely required to perform the sequence e.g. {“lv”, “hv”}.

Returns:

CalibrationSequence

stop()
property subdetectors
submit_process(process_args, **kwargs)

Start a new subprocess and add to local process list.

Parameters:
  • process_args – arguments (including execution binary) to pass to popen(…).

  • kwargs – keyword arguments to pass to popen(…).

submit_task(task, *args, **kwargs)

Submit a new task to local executor.

Parameters:
  • task – function to be executed in new thread.

  • args – arguments to pass to function.

  • kwargs – keyword arguments to pass to function.

Returns:

thread handle.

property types

AbortError

module_testing.dirigent.calibration_context.AbortError()

Error raised on application-wide abort.

This should only be raised when the interlock trips, or when a SIGINT is caught. Generally raised via signal handler for SIGINT, SIGUSR1.