factory module

This module holds a factory to create the BeamCalculator.

BEAM_CALCULATORS = ('Envelope1D', 'TraceWin', 'Envelope3D')
_get_beam_calculator(tool, flag_cython, **kwargs)[source]

Get the proper BeamCalculator constructor.

Parameters:
  • tool (Literal['Envelope1D', 'TraceWin', 'Envelope3D'])

  • flag_cython (bool)

Return type:

type

class BeamCalculatorsFactory(files, beam, **kwargs)[source]

Bases: object

A class to create BeamCalculator objects.

Respects singleton pattern, so that only one factory can be created.

Parameters:
Return type:

Self

_instance: Self | None = None
classmethod reset()[source]

Allow creation of a new factory.

Use this when the files or the beam TOML configuration dicts were updated.

Return type:

None

__init__(files, beam, **kwargs)[source]

Set up factory with arguments common to all BeamCalculator.

Note

This object was designed to work with constant files and beam. If those dictionaries happen to change during the execution of the script, execute BeamCalculatorsFactory.reset().

Note

This object was designed to work with constant files and beam. If those dictionaries happen to change during the execution of the script, execute BeamCalculatorsFactory.reset().

Parameters:
  • files (dict[str, Any]) – Configuration entries for the input/output paths.

  • beam (BeamKwargs) – Configuration dictionary holding the initial beam parameters.

  • kwargs (dict) – Other keyword arguments, not used for the moment.

Return type:

None

_patch_to_remove_misunderstood_key(beam_calculator_kw)[source]

Patch to remove a key not understood by TraceWin. Declare id list.

Todo

fixme

Parameters:

beam_calculator_kw (dict[str, Any])

Return type:

None

run(reference_phase_policy, tool, export_phase, flag_cython=False, force_new=False, **beam_calculator_kw)[source]

Create a single BeamCalculator.

If a BeamCalculator was already created with this factory and with the same arguments, we return it instead of instantiating a new one. Unless force_new is set to True.

If a BeamCalculator was already created with this factory and with the same arguments, we return it instead of instantiating a new one. Unless force_new is set to True.

Parameters:
  • reference_phase_policy (Literal['phi_0_abs', 'phi_0_rel', 'phi_s'] | Literal['as_in_original_dat']) – How reference phase of CavitySettings will be initialized.

  • tool (Literal['Envelope1D', 'TraceWin', 'Envelope3D']) – The name of the beam calculator to construct.

  • export_phase (Literal['phi_0_abs', 'phi_0_rel', 'phi_s'] | Literal['as_in_original_dat'] | Literal['as_in_settings']) – The type of phase you want to export for your FIELD_MAP.

  • flag_cython (bool, default: False) – If the beam calculator involves loading cython field maps.

  • force_new (bool, default: False) – To force creation of a new BeamCalculator.

Return type:

BeamCalculator

Returns:

An instance of the proper beam calculator.

_make_cache_key(reference_phase_policy, tool, export_phase, flag_cython=False, **beam_calculator_kw)[source]

Create unique cache key to avoid re-creating BeamCalculators.

Parameters:
  • reference_phase_policy (Literal['phi_0_abs', 'phi_0_rel', 'phi_s'] | Literal['as_in_original_dat'])

  • tool (Literal['Envelope1D', 'TraceWin', 'Envelope3D'])

  • export_phase (Literal['phi_0_abs', 'phi_0_rel', 'phi_s'] | Literal['as_in_original_dat'] | Literal['as_in_settings'])

  • flag_cython (bool, default: False)

Return type:

int

run_all(beam_calculators_kw, force_new=False)[source]

Create all the beam calculators.

Parameters:
Return type:

tuple[BeamCalculator, ...]

_make_hashable(value)[source]

Recursively convert unhashable types to hashable equivalents.

Parameters:

value (Any)

Return type:

Any