gov.sns.xal.smf
Class AcceleratorSeq

java.lang.Object
  |
  +--gov.sns.xal.smf.AcceleratorNode
        |
        +--gov.sns.xal.smf.AcceleratorSeq
All Implemented Interfaces:
DataListener, ElementType
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.


Field Summary
protected  java.util.List m_arrNodes
          Container of nodes in this sequence
protected  SequenceBucket m_bucSequence
          bucket for sequence parameters
protected  java.util.Map nodeTable
           
static java.lang.String s_strType
           
 
Fields inherited from class gov.sns.xal.smf.AcceleratorNode
channelSuite, m_bolIsSoft, m_bolStatus, m_bolValid, m_bucAlign, m_bucAper, m_bucTwiss, m_dblLen, m_dblPos, m_mapAttrs, m_objAccel, m_seqParent, m_strId
 
Constructor Summary
AcceleratorSeq(java.lang.String strId)
          base constructor
AcceleratorSeq(java.lang.String strId, int intReserve)
          constructor that sets aside some space for nodes to come
 
Method Summary
 void addBucket(AttributeBucket buc)
          General attribute buckets support
 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!!
 void addNodeAt(int iIndex, AcceleratorNode node)
          Add a node at a prescribed index
protected  java.util.List addSequenceChain(java.util.LinkedList orderedSequences, java.util.Map sequenceMap)
          Internal support for the oderSequences() method.
protected  boolean addSoft(AcceleratorSeq node)
          Method to add a node from to this sequence the node is also kept in its original sequence.
 boolean canPrecede(AcceleratorSeq sequence)
          Determine if this sequence can precede the one specified.
 boolean contains(AcceleratorNode node)
          returns true if this sequences contains the node
 java.lang.String dataLabel()
          support for the data adaptor - tap
static boolean formsRing(java.util.List sequences)
          Determing if the ordered list of sequences forms a closed loop.
 java.util.List getAllNodes()
          deep fetch all nodes in this sequence
 java.util.List getAllNodesOfType(java.lang.String strTypeId)
          deep fetch of nodes whose type is given by the string
 java.util.List getAllNodesWithQualifier(TypeQualifier qualifier)
          deep fetch of nodes whose type is matched through the qualifier
 java.util.List getAllSeqs()
          return a list of all sequences
 int getIndexOfNode(AcceleratorNode child)
          returns the index of a node
 java.util.Iterator getLeaves()
           
 double getLength()
          Return the total length (m) of a sequence This is the length along the closed orbit
 AcceleratorNode getNodeAt(int iIndex)
          returns the accelerator node at a prescribed index within this sequence
 int getNodeCount()
          returns the number of nodes in this sequence
 java.util.List getNodes()
          shallow fetch of nodes
 java.util.List getNodesOfType(java.lang.String strTypeId)
          shallow fetch of nodes whose type is given by the string
protected static java.util.List getNodesWithQualifier(java.util.List sourceNodes, TypeQualifier qualifier)
          fetch nodes whose type is matched through the qualifier
 java.util.List getNodesWithQualifier(TypeQualifier qualifier)
          shallow fetch of nodes whose type is matched through the qualifier
 AcceleratorNode getNodeWithId(java.lang.String label)
          Search deeply for and get the node with the specified id.
 double getPosition(AcceleratorNode node)
          get the position of a node in the sequence, including the possible offset of a local sequence containing the node
 java.lang.String[] getPredecessors()
          Return the allowed predecessor sequences of a sequence At most there can be 2 predecessors.
 AcceleratorSeq getSequence(java.lang.String strId)
          Return a sequence whose id matches the argument and which is an immediate child of this sequence.
 SequenceBucket getSequenceBuc()
          returns the bucket containing the sequence parameters - see attr.
 java.util.List getSequences()
          Return the sequences that are immediate children of this sequence
 java.lang.String getType()
          Support the node type
protected  int indexToAddNode(AcceleratorNode newNode)
          Find the index to insert the node in increasing order of position.
 boolean isLinear()
          Identify whether the sequence is within a linear section.
static java.util.List orderSequences(java.util.Collection sequences)
          Given a collection of sequences, order the sequences according to their predecessor attribute.
protected  void recurNodeSearch(java.util.LinkedList lstNodes, AcceleratorSeq seqCurr)
          Get all nodes in the specified sequence, look in all branches
protected  void recurSeqSearch(java.util.LinkedList lstSeqs, AcceleratorSeq seqCurr)
          Get all sequencess in the specified sequence, look in all branches
 void removeAllNodes()
           
 boolean removeNode(AcceleratorNode node)
          remove a node from this sequence
 void setSequence(SequenceBucket buc)
          sets the bucket containing the twiss parameters - see attr.TwissBucket
protected  void sortNodes(java.util.LinkedList lstNodes)
          method to sort nodes by position note: the position used is relative to the primary sequence
 void update(DataAdaptor adaptor)
          DataListener interface - tap
 void write(DataAdaptor adaptor)
          write the acceleratorSeq to the data adaptor
 
Methods inherited from class gov.sns.xal.smf.AcceleratorNode
channelSuite, clear, getAccelerator, getAlign, getAndConnectChannel, getAper, getBucket, getBuckets, getChannel, getHandles, getId, getParent, getPosition, getStatus, getTwiss, getValid, hasBucket, hasParent, isKindOf, isMagnet, lazilyGetAndConnect, removeFromParent, setAccelerator, setAlign, setAper, setLength, setParent, setPosition, setStatus, setTwiss, setValid, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

s_strType

public static final java.lang.String s_strType
See Also:
Constant Field Values

m_bucSequence

protected SequenceBucket m_bucSequence
bucket for sequence parameters


m_arrNodes

protected java.util.List m_arrNodes
Container of nodes in this sequence


nodeTable

protected java.util.Map nodeTable
Constructor Detail

AcceleratorSeq

public AcceleratorSeq(java.lang.String strId)
base constructor


AcceleratorSeq

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

Method Detail

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)
sets the bucket containing the twiss parameters - see attr.TwissBucket


dataLabel

public java.lang.String dataLabel()
support for the data adaptor - tap

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 java.lang.NumberFormatException
DataListener interface - tap

Specified by:
update in interface DataListener
Overrides:
update in class AcceleratorNode
Parameters:
adaptor - The adaptor from which to update the data
java.lang.NumberFormatException

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

getType

public java.lang.String getType()
Support the node type

Specified by:
getType 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)
returns true if this sequences contains the node

Parameters:
node - - the node to check

addNodeAt

public void addNodeAt(int iIndex,
                      AcceleratorNode node)
               throws java.lang.IndexOutOfBoundsException
Add a node at a prescribed index

Parameters:
iIndex - = the index to insert this node
node - - the node to insert
java.lang.IndexOutOfBoundsException

removeNode

public boolean removeNode(AcceleratorNode node)
remove a node from this sequence

Parameters:
node - the node to remove

removeAllNodes

public void removeAllNodes()

getNodeWithId

public AcceleratorNode getNodeWithId(java.lang.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.

getNodesWithQualifier

protected static java.util.List getNodesWithQualifier(java.util.List sourceNodes,
                                                      TypeQualifier qualifier)
fetch nodes whose type is matched through the qualifier


getNodesOfType

public java.util.List getNodesOfType(java.lang.String strTypeId)
shallow fetch of nodes whose type is given by the string


getNodesWithQualifier

public java.util.List getNodesWithQualifier(TypeQualifier qualifier)
shallow fetch of nodes whose type is matched through the qualifier


getAllNodesOfType

public java.util.List getAllNodesOfType(java.lang.String strTypeId)
deep fetch of nodes whose type is given by the string


getAllNodesWithQualifier

public java.util.List getAllNodesWithQualifier(TypeQualifier qualifier)
deep fetch of nodes whose type is matched through the qualifier


getLeaves

public java.util.Iterator getLeaves()

getNodes

public java.util.List getNodes()
shallow fetch of nodes


getAllNodes

public java.util.List getAllNodes()
deep fetch all nodes in this sequence


getLength

public double getLength()
Return the total length (m) of a sequence This is the length along the closed orbit

Overrides:
getLength in class AcceleratorNode

getPredecessors

public java.lang.String[] getPredecessors()
Return the allowed predecessor sequences of a sequence At most there can be 2 predecessors.


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(java.util.List sequences)
Determing 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 java.util.List orderSequences(java.util.Collection sequences)
                                     throws SequenceOrderingException
Given a collection of sequences, order the sequences according to their predecessor attribute.

SequenceOrderingException

addSequenceChain

protected java.util.List addSequenceChain(java.util.LinkedList orderedSequences,
                                          java.util.Map sequenceMap)
Internal support for the oderSequences() method. Add the 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.


getAllSeqs

public java.util.List getAllSeqs()
return a list of all sequences


getSequence

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


getSequences

public java.util.List getSequences()
Return 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

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

protected void sortNodes(java.util.LinkedList lstNodes)
method to sort nodes by position note: the position used is relative to the primary sequence


recurSeqSearch

protected void recurSeqSearch(java.util.LinkedList lstSeqs,
                              AcceleratorSeq seqCurr)
Get all sequencess in the specified sequence, look in all branches


recurNodeSearch

protected void recurNodeSearch(java.util.LinkedList lstNodes,
                               AcceleratorSeq seqCurr)
Get all nodes in the specified sequence, look in all branches