instructions_factory module
Define methods to easily create Command or Element.
Todo
Instantiate this in BeamCalculator. It could be initialized with the
load_electromagnetic_files flag (False for TraceWin), the list of
implemented elements/commands (ex Envelope3D, not everything is set).
Todo
maybe ElementFactory and CommandFactory should be instantiated from this? Or from another class, but they do have a lot in common
- class InstructionsFactory(freq_bunch_mhz, default_field_map_folder, load_field, field_maps_in_3d, load_cython_field_maps, elements_to_dump=(), **factory_kw)[source]
Bases:
objectDefine a factory class to easily create commands and elements.
- Parameters:
- __init__(freq_bunch_mhz, default_field_map_folder, load_field, field_maps_in_3d, load_cython_field_maps, elements_to_dump=(), **factory_kw)[source]
Instantiate the command and element factories.
- Parameters:
freq_bunch_mhz (
float) – Beam bunch frequency in \(\mathrm{MHz}\).default_field_map_folder (
Path) – Where to look for field maps when noFIELD_MAP_PATHis precised. This is also the folder where theDATis.load_field (
bool) – WhetherFieldshould be created. This is not supported yet forCyEnvelope1DandEnvelope3D, but it is mandatory forEnvelope1D.field_maps_in_3d (
bool) – Whether 3D field maps should be loaded. This is useful only withEnvelope3D… Except that this is not supported yet, so it is never useful.load_cython_field_maps (
bool) – To load or not the field maps for Cython (useful only withEnvelope1DandEnvelope3Dused with Cython).elements_to_dump (
ABCMeta|tuple[ABCMeta,...], default:()) – Class of Elements that you want to remove. If you want to skip an Element because it is not implemented, prefer assigning it to aDummyElement.factory_kw (
Any) – Other parameters passed to theCommandFactoryandElementFactory.
- Return type:
None
- run(dat_filecontent)[source]
Create all the elements and commands.
Todo
Check if the return value from
apply_commandsis necessary.- Parameters:
dat_filecontent (
Collection[DatLine]) – List containing all the lines ofdat_filepath.- Return type:
- _call_proper_factory(dat_line, dat_idx=None, **instruction_kw)[source]
Create proper
Instruction, orDummy.We go across every word of
line, and create the first instruction that we find. If we do not recognize it, we return a dummy instruction instead.- Parameters:
line – A single line of the
DATfile.dat_idx (
int|None, default:None) – Line number of the line (starts at 0). If not provided, taken fromline.command_fac – A factory to create
Command.element_fac – A factory to create
Element.instruction_kw (
str) – Keywords given to therunmethod of the proper factory.dat_line (
DatLine)
- Return type:
- Returns:
- _handle_lattice_and_section(elts)[source]
Ensure that every element has proper lattice, section indexes.
- _check_every_elt_has_lattice_and_section(elts)[source]
Check that every element has a lattice and section index.