Skip to content

SNS_LinacLatticeFactory fails to construct lattice from non-neighboring sections declared in XML #116

Description

@woodtp

@kruisard found that initializing a lattice from non-contiguous XML sections results in the following error:

ORBIT message: The LinacLatticeFactory method getLinacAccLattice(names): sequence names array is wrong!
existing names=['MEBT1', 'MEBT2', 'STUB']
sequence names=['MEBT1', 'STUB']
  File "<PROJECT_ROOT>/track.py", line 73, in <module>
    accelerator.init_lattice(
  File "<PROJECT_ROOT>/btfpo3/model.py", line 249, in init_lattice
    self.lattice = lattice_factory.getLinacAccLattice(sequences, xml_filename)
  File "<PYTHON_ENV>/site-packages/orbit/py_linac/linac_parsers/sns_linac_lattice_factory.py", line 73, in getLinacAccLattice
    return self.getLinacAccLatticeFromDA(names, acc_da)
  File "<PYTHON_ENV>/site-packages/orbit/py_linac/linac_parsers/sns_linac_lattice_factory.py", line 88, in getLinacAccLatticeFromDA
    accSeq_da_arr = self.filterSequences_and_OptionalCheck(accSeq_da_arr, names)
  File "<PYTHON_ENV>/site-packages/orbit/py_linac/linac_parsers/sns_linac_lattice_factory.py", line 472, in filterSequences_and_OptionalCheck
    orbitFinalize(msg)
  File "<PYTHON_ENV>/site-packages/orbit/utils/orbitFinalize.py", line 11, in orbitFinalize
    traceback.print_stack()
STOP

Steps to Reproduce

For the BTF, the XML specifies three sections:

<BTF_Lattice>
  <MEBT1 ...>
    ...
  </MEBT1>
  <MEBT2 ...>
    ...
  </MEBT2>
  <STUB ...>
    ...
  </STUB>
</BTF_Lattice>

Combining MEBT1 with MEBT2 is fine, but trying to run MEBT1 with STUB emits the error.
e.g.,

lattice_factory = SNS_LinacLatticeFactory()
bend_mode_2 = lattice_factory.getLinacAccLattice(['MEBT1', 'MEBT2'], <xml>) # works OK
bend_mode_1 = lattice_factory.getLinacAccLattice(['MEBT1', 'STUB'], <xml>) # Errors

The issue stems from the following check:

for name in names:
ind = seqencesLocalNames.index(name)
if ind < 0 or (count > 0 and ind != (ind_old + 1)):
msg = "The LinacLatticeFactory method getLinacAccLattice(names): sequence names array is wrong!"
msg = msg + os.linesep
msg = msg + "existing names=" + str(seqencesLocalNames)
msg = msg + os.linesep
msg = msg + "sequence names=" + str(names)
orbitFinalize(msg)

which will fail if you try to initialize a lattice from sections which are not declared sequentially in XML.

We probably want to rework this so that the function will still check whether the requested section(s) actually exists, but not be sensitive to the explicit ordering in the XML, which may be arbitrary.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions