Package xal.smf

Class AcceleratorSeq

All Implemented Interfaces:
Comparable, ElementType, DataListener
Direct Known Subclasses:
Accelerator, AcceleratorSector, AcceleratorSeqCombo, RfCavity

public class AcceleratorSeq extends AcceleratorNode implements DataListener
The implementation of the accelerator composite node, ordered collection of accelerator elements and sequences.
Author:
Nikolay Malitsky, Christopher K. Allen
  • Field Details

  • Constructor Details

    • AcceleratorSeq

      public AcceleratorSeq(String strId)
      base constructor
    • AcceleratorSeq

      public AcceleratorSeq(String strId, int intReserve)
      constructor that sets aside some space for nodes to come
    • AcceleratorSeq

      public AcceleratorSeq(String strId, ChannelFactory channelFactory)
      constructor that sets aside some space for nodes to come
    • AcceleratorSeq

      public AcceleratorSeq(String strId, ChannelFactory channelFactory, int intReserve)
      designated constructor that sets aside some space for nodes to come
  • Method Details

    • addBucket

      public void addBucket(AttributeBucket buc)
      Description copied from class: AcceleratorNode
      General attribute buckets support
      Overrides:
      addBucket in class AcceleratorNode
    • getSequenceBuc

      public SequenceBucket getSequenceBuc()
      returns the bucket containing the sequence parameters - see attr. SequenceBucket
    • setSequence

      public void setSequence(SequenceBucket buc)
      Parameters:
      buc -
      Since:
      May 3, 2011
    • dataLabel

      public String dataLabel()
      data adaptor label
      Specified by:
      dataLabel in interface DataListener
      Overrides:
      dataLabel in class AcceleratorNode
      Returns:
      a tag that identifies the receiver's type
    • update

      public void update(DataAdaptor adaptor) throws NumberFormatException
      Update this sequence from the specified data adaptor
      Specified by:
      update in interface DataListener
      Overrides:
      update in class AcceleratorNode
      Parameters:
      adaptor - The adaptor from which to update the data
      Throws:
      NumberFormatException
    • writeDeeply

      public void writeDeeply(DataAdaptor adaptor)
      write this sequence's child accelerator nodes deeply traversing each branch. Some applications call this method since Combo sequence overrides the write method to provide only the constituents.
    • write

      public void write(DataAdaptor adaptor)
      write the acceleratorSeq to the data adaptor
      Specified by:
      write in interface DataListener
      Overrides:
      write in class AcceleratorNode
      Parameters:
      adaptor - The adaptor to which the receiver's data is written
    • writeAttributes

      protected void writeAttributes(DataAdaptor adaptor)
      Description copied from class: AcceleratorNode
      write the attributes of the Node. Subclasses can be override this method to write a different set of attributes
      Overrides:
      writeAttributes in class AcceleratorNode
    • writeStatus

      public void writeStatus(DataAdaptor adaptor)
      method to write status of the node into a separate file
      Overrides:
      writeStatus in class AcceleratorNode
    • getType

      public String getType()
      Support the node type
      Specified by:
      getType in class AcceleratorNode
    • getEntranceID

      public String getEntranceID()
      Get the ID of this sequence. Subclasses which represent combinations of sequences should override this method to return the ID of the first sequence in the combination.
      Returns:
      the ID of this sequence
    • getPrimaryAncestor

      public AcceleratorSeq getPrimaryAncestor()
      get the primary ancestor sequence that is a direct child of the accelerator
      Overrides:
      getPrimaryAncestor in class AcceleratorNode
    • getNodeCount

      public int getNodeCount()
      returns the number of nodes in this sequence
    • getIndexOfNode

      public int getIndexOfNode(AcceleratorNode child)
      returns the index of a node
      Parameters:
      child - the node for which to get the index
    • getNodeAt

      public AcceleratorNode getNodeAt(int iIndex)
      returns the accelerator node at a prescribed index within this sequence
      Parameters:
      iIndex - the index for the node of interest (indexing starts with 0)
    • indexToAddNode

      protected int indexToAddNode(AcceleratorNode newNode)
      Find the index to insert the node in increasing order of position. For efficiency, start comparing with the last node since they are likely to roughly be added in order.
    • addNode

      public boolean addNode(AcceleratorNode newNode)
      Method to move a node from one sequence to this sequence warning be careful - need to check node position when moving it about!!
    • addSoft

      protected boolean addSoft(AcceleratorSeq node)
      Method to add a node from to this sequence the node is also kept in its original sequence. This is used when concatenating nodes together into a new sequence.
    • contains

      public boolean contains(AcceleratorNode node)
      Check to see if the node is a shallow child of this sequence.
      Parameters:
      node - - the node to check
      Returns:
      true if the node is a shallow child of this sequence and false if not
    • addNodeAt

      public void addNodeAt(int iIndex, AcceleratorNode node) throws IndexOutOfBoundsException
      Add a node at a prescribed index
      Parameters:
      iIndex - = the index to insert this node
      node - - the node to insert
      Throws:
      IndexOutOfBoundsException
    • removeNode

      public boolean removeNode(AcceleratorNode node)
      remove a node from this sequence
      Parameters:
      node - the node to remove
    • removeAllNodes

      public void removeAllNodes()
      Remove all nodes from the this sequence.
    • getNodeWithId

      public AcceleratorNode getNodeWithId(String label)
      Search deeply for and get the node with the specified id.
      Parameters:
      label - The id of the node we are seeking.
      Returns:
      the node corresponding to the requested id or null if no such node is found.
    • filterNodesByClass

      public static <S extends AcceleratorNode, N extends S> List<N> filterNodesByClass(Class<N> resultClass, List<S> sourceNodes)
      Filter nodes from the source list which can be cast to the specified result class.
      Parameters:
      resultClass - filters the returned nodes to those which can be cast to this class
      sourceNodes - the list of nodes to filter
      Returns:
      the list of nodes matching the qualifier criteria
    • getNodesOfClassWithQualifier

      public static <S extends AcceleratorNode, N extends S> List<N> getNodesOfClassWithQualifier(Class<N> resultClass, List<S> sourceNodes, TypeQualifier qualifier)
      Filter nodes from the source list using the specified qualifier.
      Parameters:
      resultClass - filters the returned nodes to those which can be cast to this class (assumes AcceleratorNode if null)
      sourceNodes - the list of nodes to filter
      qualifier - the qualifier used to filter the nodes
      Returns:
      the list of nodes matching the qualifier criteria
    • appendNodesOfClassWithQualifier

      public static <S extends AcceleratorNode, N extends S> List<N> appendNodesOfClassWithQualifier(Class<N> resultClass, List<N> matchedNodes, List<S> sourceNodes, TypeQualifier qualifier)
      Filter nodes from the source list using the specified qualifier.
      Parameters:
      resultClass - filters the returned nodes to those which can be cast to this class (assumes AcceleratorNode if null)
      matchedNodes - container to append the list of matching nodes
      sourceNodes - the list of nodes to filter
      qualifier - the qualifier used to filter the nodes
      Returns:
      the list of nodes matching the qualifier criteria
    • appendNodesWithQualifier

      public static <S extends AcceleratorNode, N extends S> List<N> appendNodesWithQualifier(List<N> matchedNodes, List<S> sourceNodes, TypeQualifier qualifier)
      Filter nodes from the source list using the specified qualifier.
      Parameters:
      matchedNodes - container to append the list of matching nodes
      sourceNodes - the list of nodes to filter
      qualifier - the qualifier used to filter the nodes
      Returns:
      the list of nodes matching the qualifier criteria
    • getNodesOfClassWithQualifier

      public <S extends AcceleratorNode, N extends S> List<N> getNodesOfClassWithQualifier(Class<N> resultClass, TypeQualifier qualifier)
      Get nodes using the specified qualifier.
      Parameters:
      resultClass - filters the returned nodes to those which can be cast to this class
      qualifier - the qualifier used to filter the nodes
      Returns:
      the list of nodes matching the qualifier criteria
    • getNodesOfClassWithStatus

      public <S extends AcceleratorNode, N extends S> List<N> getNodesOfClassWithStatus(Class<N> resultClass, boolean statusFilter)
      Get nodes of the specified class with the specified status.
      Parameters:
      resultClass - filters the returned nodes to those which can be cast to this class
      statusFilter - the status for which to filter nodes
      Returns:
      the list of nodes matching the qualifier criteria
    • getNodesWithQualifier

      public static <S extends AcceleratorNode, N extends S> List<N> getNodesWithQualifier(List<S> sourceNodes, TypeQualifier qualifier)
      Filter nodes from the source list using the specified qualifier.
      Parameters:
      sourceNodes - the list of nodes to filter
      qualifier - the qualifier used to filter the nodes
      Returns:
      the list of nodes matching the qualifier criteria
    • filterNodesByStatus

      public static <T extends AcceleratorNode> List<T> filterNodesByStatus(List<T> nodes, boolean statusFilter)
      Filter nodes from the source list using the specified status filter.
      Parameters:
      nodes - the list of nodes to filter
      statusFilter - the status for which to filter nodes
      Returns:
      the list of nodes matching the status criterion
    • getNodesOfType

      public <T extends AcceleratorNode> List<T> getNodesOfType(String strTypeId)
      Shallow fetch of nodes whose type is given by the string. Only nodes that are immediate children of this sequence are filtered. A node will be considered as a match if the specified type matches either the node directly or that of one of the node's superclasses. For example, a quadrupole would match both the "Q" type and the "magnet" type.
      Parameters:
      strTypeId - type identifier of the nodes to fetch
      Returns:
      a list of this sequence's nodes which match the specified type
    • getNodesOfType

      public <T extends AcceleratorNode> List<T> getNodesOfType(String strTypeId, boolean statusFilter)
      Shallow fetch of nodes whose type is given by the string. Only nodes that are immediate children of this sequence are filtered. A node will be considered as a match if the specified type matches either the node directly or that of one of the node's superclasses. For example, a quadrupole would match both the "Q" type and the "magnet" type.
      Parameters:
      strTypeId - type identifier of the nodes to fetch
      statusFilter - the status for which to filter the nodes
      Returns:
      a list of this sequence's nodes which match the specified type
    • getNodesWithQualifier

      public <T extends AcceleratorNode> List<T> getNodesWithQualifier(TypeQualifier qualifier)
      Shallow fetch of nodes that are matched by the qualifier. Only nodes that are immediate children of this sequence are filtered.
      Parameters:
      qualifier - the qualifier used to filter nodes
      Returns:
      a list of this sequence's nodes which match the qualifier criteria
    • getAllNodesOfType

      public <T extends AcceleratorNode> List<T> getAllNodesOfType(String strTypeId)
      Fetch all nodes whose type is matched through the qualifier and are also contained in this sequence looking deeply through its nested child sequences. This sequence itself is not among the nodes that will be tested against the qualifier.
      Parameters:
      strTypeId - the type of node for which we are fetching
      Returns:
      the list of all inclusive nodes which match the qualifier criteria
    • getAllNodesWithQualifier

      public <T extends AcceleratorNode> List<T> getAllNodesWithQualifier(TypeQualifier qualifier)
      Fetch all nodes whose type is matched through the qualifier and are also contained in this sequence or one of its nested child sequences. This sequence itself is not among the nodes that will be tested against the qualifier.
      Parameters:
      qualifier - the qualifier for filtering the nodes
      Returns:
      the list of all inclusive nodes which match the qualifier criteria
    • getAllInclusiveNodes

      public List<AcceleratorNode> getAllInclusiveNodes()
      Fetch all nodes which are contained in this sequence looking deeply through its nested child sequences. This sequence itself is among the nodes included, hence the "Inclusive" nature of this method.
      Returns:
      the list of all inclusive nodes
    • getAllInclusiveNodes

      public List<AcceleratorNode> getAllInclusiveNodes(boolean statusFilter)
      Fetch all nodes which are contained in this sequence looking deeply through its nested child sequences. This sequence itself is among the nodes included, hence the "Inclusive" nature of this method.
      Parameters:
      statusFilter - the status for which to filter nodes
      Returns:
      the list of all inclusive nodes
    • getAllInclusiveNodesWithQualifier

      public <T extends AcceleratorNode> List<T> getAllInclusiveNodesWithQualifier(TypeQualifier qualifier)
      Fetch all nodes whose type is matched through the qualifier and are also contained in this sequence looking deeply through its nested child sequences. This sequence itself is among the nodes that will be tested against the qualifier, hence the "Inclusive" nature of this method.
      Parameters:
      qualifier - the qualifier for filtering the nodes
      Returns:
      the list of all inclusive nodes which match the qualifier criteria
    • getLeaves

      public Iterator<AcceleratorNode> getLeaves()
      Get an iterator of this sequence's immediate child nodes.
      Returns:
      an iterator of this sequence's immediate child nodes.
    • getNodes

      public List<AcceleratorNode> getNodes()
      Get a list of this sequence's immediate child nodes.
      Returns:
      a list of this sequence's immediate child nodes
    • getNodes

      public List<AcceleratorNode> getNodes(boolean statusFilter)
      Get the this sequence's immediate child nodes with the specified status.
      Parameters:
      statusFilter - the status for which to qualify nodes
    • getAllNodes

      public List<AcceleratorNode> getAllNodes()
      Fetch all nodes contained in this sequence looking deeply through its nested child sequences.
      Returns:
      a list of all nodes contained in this sequence
    • getAllNodes

      public List<AcceleratorNode> getAllNodes(boolean statusFilter)
      Get all nodes filtered for the specified status.
      Parameters:
      statusFilter - the status for which to filter the nodes
      Returns:
      the list of all nodes deeply nested with the specified status
    • getLength

      public double getLength()
      Return the total length (m) of this sequence
      Overrides:
      getLength in class AcceleratorNode
      Returns:
      the length of this sequence along the closed orbit
    • getPredecessors

      public String[] getPredecessors()
      Return the allowed predecessor sequences of a sequence At most there can be 2 predecessors.
      Returns:
      an array of allowed predecessor sequences
    • canPrecede

      public boolean canPrecede(AcceleratorSeq sequence)
      Determine if this sequence can precede the one specified.
      Parameters:
      sequence - the sequence which we are testing if this sequence can precede
      Returns:
      true if this sequence can precede the sequence specified in the argument and false if not
    • formsRing

      public static boolean formsRing(List<AcceleratorSeq> sequences)
      Determining if the ordered list of sequences forms a closed loop. The determination is based on whether each successive sequence has a predecessor (based on the getPredecessors() method) that precedes it in the list, and the last item in the list is a predecessor of the first item in the list.
      Parameters:
      sequences - an ordered list of sequences to test for forming a ring
      Returns:
      true if the sequences form a ring and false if not
    • orderSequences

      public static List<AcceleratorSeq> orderSequences(Collection<AcceleratorSeq> sequences) throws SequenceOrderingException
      Given a collection of sequences, order the sequences according to their predecessor attribute.
      Parameters:
      sequences - a collection of contiguous sequences to order from start to finish
      Returns:
      the ordered list of sequences
      Throws:
      SequenceOrderingException
    • addSequenceChain

      protected List<AcceleratorSeq> addSequenceChain(LinkedList<AcceleratorSeq> orderedSequences, Map<String,AcceleratorSeq> sequenceMap)
      Internal support for the orderSequences() method. Add this sequence to the beginning of the orderedSequences list and remove it from the sequenceMap. Recursively do the same for its predecessor if it has one in the sequenceMap.
      Parameters:
      orderedSequences - the list of ordered sequences to append the next sequence
      sequenceMap - the table of sequences from which to fetch the next sequence
    • getAllSeqs

      public List<AcceleratorSeq> getAllSeqs()
      Get a list of all of this sequence's subsequences including those deeply nested. return a list of all of this sequence's subsequences
    • getSequence

      public AcceleratorSeq getSequence(String strId)
      Return a sequence whose id matches the argument and which is an immediate child of this sequence.
    • getSequences

      public List<AcceleratorSeq> getSequences()
      Get the sequences that are immediate children of this sequence
    • getSequences

      public List<AcceleratorSeq> getSequences(boolean statusFilter)
      Get the sequences that are immediate children of this sequence
    • getPosition

      public double getPosition(AcceleratorNode node)
      Get the position of a node in the sequence, including the possible offset of a local sequence containing the node.
      Parameters:
      node - - the node for which the position is wanted
    • getDistanceBetween

      public double getDistanceBetween(AcceleratorNode reference, AcceleratorNode node)
      Get the distance of the second node from the first node.
      Parameters:
      reference - the node from which to measure the distance
      node - the node to which to measure the distance
    • getRelativePosition

      public double getRelativePosition(double position, String referenceNodeID)
      Convert the sequence position to a position relative to the specified reference node.
    • getRelativePosition

      public double getRelativePosition(double position, AcceleratorNode referenceNode)
      Convert the sequence position to a position relative to the specified reference node.
      Parameters:
      position - the position of a location relative to the sequence's start
      referenceNode - the node relative to which we wish to get the position
    • getShortestRelativePosition

      public double getShortestRelativePosition(AcceleratorNode node, AcceleratorNode referenceNode)
      Get the shortest relative postion of one node with respect to a reference node. This is really useful for ring sequences.
      Parameters:
      node - the node whose relative position is sought
      referenceNode - the reference node relative to which the node's position is calculated
      Returns:
      the distance (positive or negative) of the node with respect to the reference node whose magnitude is shortest
    • isLinear

      public boolean isLinear()
      Identify whether the sequence is within a linear section. This helps us to determine whether it is meaningful to identify one node as being downstream from another. At this time we will simply return true, but when the ring is introduced into the optics, we need to distinguish the ring from the linear sections.
    • sortNodes

      public void sortNodes(List<? extends AcceleratorNode> nodes)
      Sort nodes in place by position where the position used is relative to the this sequence.
      Parameters:
      nodes - the list of nodes to sort
    • sortNodesByProximity

      public void sortNodesByProximity(List<? extends AcceleratorNode> nodes, AcceleratorNode referenceNode)
      Sort nodes in place by proximity to a reference node. Used to get nodes ranked by nearness to the reference node.
      Parameters:
      nodes - the list of nodes to sort
      referenceNode - the reference node for the proximity test
    • sortNodesByRelativePosition

      public void sortNodesByRelativePosition(List<? extends AcceleratorNode> nodes, AcceleratorNode referenceNode)
      Sort nodes in place by position relative to the reference node (ranked negative to positive).
      Parameters:
      nodes - the list of nodes to sort
      referenceNode - the reference node for the proximity test
    • recurSeqSearch

      protected static LinkedList<AcceleratorSeq> recurSeqSearch(LinkedList<AcceleratorSeq> sequences, AcceleratorSeq branch)
      Get all sequences in the specified sequence branch, searching down all of its branches
      Parameters:
      sequences - the collection of all sequences found
      branch - the sequence branch down which to search for more sequences
      Returns:
      the collection of all sequences found; returned for convenience
    • recurNodeSearch

      protected static LinkedList<AcceleratorNode> recurNodeSearch(LinkedList<AcceleratorNode> nodes, AcceleratorSeq sequence)
      Get all nodes in the specified sequence searching deeply through this sequence's child sequences.
      Parameters:
      nodes - the collection of all nodes found
      sequence - the branch down which to search for nodes
      Returns:
      the collection of all nodes found; returned for convenience
    • getAperProfile

      public ApertureProfile getAperProfile()
      Get all nodes in the specified sequence and gets the aperture bucket values.
      Returns:
      an ApertureProfile object containing the X and Y aperture profiles
    • getAperProfile

      public ApertureProfile getAperProfile(List<AcceleratorNode> nodes)