Class ElementSeq
- All Implemented Interfaces:
Iterable<IComponent>
,IComponent
,IComposite
- Direct Known Subclasses:
ElectromagnetSeq
,IdealRfCavity
,Lattice
,LineModel
,RingModel
,Sector
Convenience abstract base class for a composite modeling element. The composite is represented as a sequence of modeling elements, perhaps other composites. Specifically we have an ordered list of child modeling elements.
Propagation of probes (objects exposing the IProbe
interface) is
done by passing it sequentially to each child. Of course if a child is also a
composite the same is done there.
- Version:
- 2.0 February, 2009
- Author:
- Christopher K. Allen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
default number of element positions to reserve in list array -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ElementSeq
(String strType) Creates a new instance ofElementSeq
without of the given soft type but without a sequence identifier.protected
ElementSeq
(String strType, String strId) Creates a new instance ofElementSeq
with the given soft type and sequence identifier.protected
ElementSeq
(String strType, String strId, int szReserve) Creates a new instance ofElementSeq
with the given soft type and sequence identifier. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(IComponent iComp) Add a component object at the tail of the sequence list and at the head of the reverse sequence list.void
backPropagate
(IProbe probe) Backward propagation of probe through sequence.void
backPropagate
(IProbe probe, double pos) Override ofIComponent.propagate(xal.model.IProbe, double)
Return anIterator
object that cycles through all the direct children of the sequence.protected void
Recompute all the dependent parameters.void
Concatenate the indicatedElementSeq
object to the tail of this sequence.double
Get the horizontal misalignmentdouble
Get the vertical misalignmentdouble
Get the longitudinal misalignmentReturns a list of all elements contained in this sequence, more specifically, all leaf elements.getChild
(int indChild) Get the child IComponent interface at location specified by index.int
Get the number of direct children in this sequence.Get any user comments regarding this sequence.Return the list ofIElement
objects contained in this sequence.protected List<IComponent>
Return the internal list of componentsReturns the string identifier of the hardware node which this element models.getId()
Get the sequence identifierdouble
Return the (center) position of this component within the global lattice structure to which it belongs.int
Get the number ofIElement
derived objects contained in this sequence.double
Return the length of the sequence.Returns the composite structure (if any) that owns this component.double
getPhiX()
double
getPhiY()
double
getPhiZ()
double
Return the center position of this component within the immediate parent composite element.protected List<IComponent>
Return the reverse component list (downstream to upstream)getType()
Get the type identifier for the composite element.Return anIterator
object that iterates over everyIComponent
object in this composite.Return anIterator
object that iterates over everyIComponent
object in this composite.void
initializeFrom
(LatticeElement latticeElement) Initialization method to be provided by the useriterator()
Returns a shallow iterator for the direct descendants of this composite modeling element.Return anIterator
object that iterates over the direct descendants only of this composite element, in reverse order.Return anIterator
object that iterates over the direct descendants only of this composite element, in order.void
print
(PrintWriter os) Dump contents to a text stream.void
Propagate probe through sequencevoid
Override ofIComponent.propagate(xal.model.IProbe, double)
boolean
remove
(IComponent iCmp) Remove an element from the entire tree.void
Set the alignment parameters all at once.void
setAlignX
(double x) Set the horizontal misalignmentvoid
setAlignY
(double y) Set the vertical misalignmentvoid
setAlignZ
(double z) Set the longitudinal misalignmentvoid
setComments
(String strComment) Sets any user comment associated with this sequence.protected void
setCompList
(List<? extends IComponent> elements) Set the comp list to the new list of elements.void
setDirty
(IComponent cmpCaller) void
setHardwareNodeId
(String strSmfId) Sets the string identifier of the hardware node which this element models.void
Set the string identifier for the element.void
setParent
(IComposite cpsParent) Sets the parent structure containing this composite structure.void
setPhiX
(double phix) void
setPhiY
(double phiy) void
setPhiZ
(double phiz) toString()
Writes out the modeling elements in this element sequence structure.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
SIZE_DEF_RESERVE
public static final int SIZE_DEF_RESERVEdefault number of element positions to reserve in list array- See Also:
-
-
Constructor Details
-
ElementSeq
Creates a new instance ofElementSeq
without of the given soft type but without a sequence identifier.- Parameters:
strType
- soft type of the sequence (defined by the child class)
-
ElementSeq
Creates a new instance ofElementSeq
with the given soft type and sequence identifier.- Parameters:
strType
- soft type of the sequence (defined by the child class)strId
- identifier of the sequence
-
ElementSeq
Creates a new instance ofElementSeq
with the given soft type and sequence identifier. Also reserves space for a the sequence elements. This saves a little CPU time if the relative size of the sequence is known a priori.- Parameters:
strType
- soft type of the sequence (defined by the child class)strId
- identifier of the sequenceszReserve
- number of Element spaces to reserve
-
-
Method Details
-
setId
Set the string identifier for the element.- Parameters:
strId
- new string identifier for element
-
setHardwareNodeId
Sets the string identifier of the hardware node which this element models. Node that this sequence probably models an accelerator sector, or logical unit. Thus, this ID is likely of the type "HEBT", "RING", "DTL", etc.- Parameters:
strSmfId
- identifier for the modeled hardware node (SMF object)- Since:
- Sep 2, 2014
-
setComments
Sets any user comment associated with this sequence.- Parameters:
strComment
- string containing user comments
-
getComments
Get any user comments regarding this sequence. Returns the null string if none.- Returns:
- string containing user comments
-
getLeafCount
public int getLeafCount()Get the number ofIElement
derived objects contained in this sequence.- Returns:
- number of
Element
object w/in sequence
-
getElementList
Return the list ofIElement
objects contained in this sequence.- Returns:
- list of elements composing this sequence
-
getAllElements
Returns a list of all elements contained in this sequence, more specifically, all leaf elements.- Returns:
- list containing all
IComponent
class elements in this sequence - Since:
- Sep 11, 2014
-
setAlign
Set the alignment parameters all at once.- Parameters:
vecAlign
- (dx,dy,dz)
-
setAlignX
public void setAlignX(double x) Set the horizontal misalignment- Parameters:
x
- misalignment (in m)- Since:
- Dec 17, 2014 by Christopher K. Allen
-
setAlignY
public void setAlignY(double y) Set the vertical misalignment- Parameters:
y
- misalignment (in m)- Since:
- Dec 17, 2014 by Christopher K. Allen
-
setAlignZ
public void setAlignZ(double z) Set the longitudinal misalignment- Parameters:
z
- misalignment (in m)- Since:
- Dec 17, 2014 by Christopher K. Allen
-
getAlignX
public double getAlignX()Get the horizontal misalignment- Returns:
- the misalignment (in meters)
- Since:
- Dec 17, 2014 by Christopher K. Allen
-
getAlignY
public double getAlignY()Get the vertical misalignment- Returns:
- the misalignment (in meters)
- Since:
- Dec 17, 2014 by Christopher K. Allen
-
getAlignZ
public double getAlignZ()Get the longitudinal misalignment- Returns:
- the misalignment (in meters)
- Since:
- Dec 17, 2014 by Christopher K. Allen
-
getPhiX
public double getPhiX() -
getPhiY
public double getPhiY() -
getPhiZ
public double getPhiZ() -
setPhiX
public void setPhiX(double phix) -
setPhiY
public void setPhiY(double phiy) -
setPhiZ
public void setPhiZ(double phiz) -
localBackIterator
Return anIterator
object that iterates over the direct descendants only of this composite element, in reverse order.- Returns:
- interface to iterator object
- Since:
- Feb 27, 2009
- See Also:
-
globalBackIterator
Return anIterator
object that iterates over everyIComponent
object in this composite. ForIComponent
which are also composite the parent is returned first, then all its children. This would be in reverse order.- Returns:
Iterator
interface to iterator object- See Also:
-
childIterator
Return anIterator
object that cycles through all the direct children of the sequence. Note that any child may have children itself.- Returns:
- iterator of
IElement
interfaces
-
concatenateEquals
Concatenate the indicatedElementSeq
object to the tail of this sequence.- Parameters:
seq
- object to append to this one
-
initializeFrom
Initialization method to be provided by the user- Specified by:
initializeFrom
in interfaceIComponent
- Parameters:
latticeElement
- the SMF node to convert
-
getType
Get the type identifier for the composite element.- Specified by:
getType
in interfaceIComponent
- Returns:
- type identifier for ElementSeq
-
getId
Get the sequence identifier- Specified by:
getId
in interfaceIComponent
- Returns:
- sequence identifier
-
getHardwareNodeId
Returns the string identifier of the hardware node which this element models. This value is likely a sector of an accelerator structure, such as "HEBT", "RING", "MEBT", etc.- Specified by:
getHardwareNodeId
in interfaceIComponent
- Returns:
- the identifier string of the hardware this element models
- Since:
- Sep 2, 2014
-
getLength
public double getLength()Return the length of the sequence. The length of the sequence is determined but summing the lengths of all the contained
IComponent
objects.- Specified by:
getLength
in interfaceIComponent
- Returns:
- total length of the sequence (in meters)
-
getPosition
public double getPosition()Description copied from interface:IComponent
Return the center position of this component within the immediate parent composite element. If there is no parent then this method should return zero.
This value is typically a "hardware property," especially if this element models a hardware node. That is, the value is specified in the description of the hardware node and, thus, carries through to the modeling element. The situation is different than the property
where the position is completely dependent upon where the modeling element lies within the overall lattice structure.IComponent.getLatticePosition()
- Specified by:
getPosition
in interfaceIComponent
- Returns:
- center position of this element within the immediate parent container (meters)
- Since:
- Dec 3, 2015, Christopher K. Allen
- See Also:
-
getLatticePosition
public double getLatticePosition()Description copied from interface:IComponent
Return the (center) position of this component within the global lattice structure to which it belongs. Note the difference between this parameter and that returned by
IComponent
which returns the position with respect to the direct parent.IComponent.getLength()
The returned value is not usually a design parameter, in particular if composites are pasted together or otherwise form a larger tree structure. It should be computed according to the current structure of the global composite structure. Thus, moving this element in the lattice should change this value.
- Specified by:
getLatticePosition
in interfaceIComponent
- Returns:
- the center position of this component within the entire lattice containing this element (not just the parent)
- Since:
- Dec 3, 2015, Christopher K. Allen
- See Also:
-
getParent
Description copied from interface:IComponent
Returns the composite structure (if any) that owns this component.- Specified by:
getParent
in interfaceIComponent
- Returns:
- returns the composite structure owning this composite structure,
or
null
if this structure is top level - Since:
- Jan 22, 2015 by Christopher K. Allen
- See Also:
-
setParent
Sets the parent structure containing this composite structure. The parent is assumed to be a composite structure built from component elements.- Specified by:
setParent
in interfaceIComponent
- Parameters:
cpsParent
- the composite structure built from this component- Since:
- Jan 22, 2015 by Christopher K. Allen
- See Also:
-
propagate
Override of
IComponent.propagate(xal.model.IProbe, double)
- Specified by:
propagate
in interfaceIComponent
- Throws:
ModelException
- Since:
- Feb 27, 2009
- See Also:
-
propagate
Propagate probe through sequence- Specified by:
propagate
in interfaceIComponent
- Specified by:
propagate
in interfaceIComposite
- Parameters:
probe
- the state of the probe will be advance using the elements dynamics- Throws:
ModelException
- an error occurred while advancing the probe state- See Also:
-
backPropagate
Override of
IComponent.propagate(xal.model.IProbe, double)
NOTES: CKA
· Support for backward propagation February, 2009.
· You must use the proper algorithm object for this method to work correctly!- Specified by:
backPropagate
in interfaceIComponent
- Parameters:
probe
- probe to be propagate - its state is advancedpos
- position within element- Throws:
ModelException
- error advancing the probe state- Since:
- Feb 27, 2009
- See Also:
-
backPropagate
Backward propagation of probe through sequence.
NOTES: CKA
· Support for backward propagation February, 2009.
· You must use the proper algorithm object for this method to work correctly!- Specified by:
backPropagate
in interfaceIComponent
- Parameters:
probe
- the state of the probe will be advance using the elements dynamics- Throws:
ModelException
- an error occurred while advancing the probe state
-
localIterator
Return anIterator
object that iterates over the direct descendants only of this composite element, in order.- Specified by:
localIterator
in interfaceIComposite
- Returns:
- interface to iterator object
- See Also:
-
globalIterator
Return anIterator
object that iterates over everyIComponent
object in this composite. ForIComponent
which are also composite the parent is returned first, then all its children. This would be in reverse order.- Specified by:
globalIterator
in interfaceIComposite
- Returns:
Iterator
interface to iterator object- See Also:
-
getChildCount
public int getChildCount()Get the number of direct children in this sequence. Note that this is not the number of leaves in the sequence.- Specified by:
getChildCount
in interfaceIComposite
- Returns:
- number of direct descendants
-
getChild
Get the child IComponent interface at location specified by index.- Specified by:
getChild
in interfaceIComposite
- Parameters:
indChild
- position index within the sequence list- Returns:
- child at position indChild
-
addChild
Add a component object at the tail of the sequence list and at the head of the reverse sequence list.
NOTES: CKA
· Added support for backward propagation February, 2009- Specified by:
addChild
in interfaceIComposite
- Parameters:
iComp
- new component object
-
remove
Remove an element from the entire tree. The element can be a single leaf node or a composite node.- Specified by:
remove
in interfaceIComposite
- Parameters:
iCmp
- IComponent object to be removed- Returns:
- return true if element was found and removed, false otherwise
-
setDirty
Description copied from interface:IComposite
Need only be called by implementing classes
Indicates internally that the composite structure has been modified and any dependent parameters must be recomputed. This is needed if these parameters must be computed upon demand due to dynamic changes in the composite. In order to avoid expensive re-iteration through large composite structures, by employing this method a state condition can be set up so that the dependent parameters are only recomputed when the composite changes.- Implementing classes should call this method whenever the composite
changes, in particular whenever
andIComposite.addChild(IComponent)
are called.IComposite.remove(IComponent)
- They respond to this call by setting a dirty flag and calls the same method on their parent object.
- If the dirty flag is set then all dependent parameters should be recomputed whenever one is requested (after which the flag can be cleared).
- Specified by:
setDirty
in interfaceIComposite
- Parameters:
cmpCaller
- theIComponent
object calling this method, ornull
if the object is not a component- Since:
- Dec 3, 2015, Christopher K. Allen
- See Also:
-
xal.model.IComposite#setDirty()
- Implementing classes should call this method whenever the composite
changes, in particular whenever
-
iterator
Returns a shallow iterator for the direct descendants of this composite modeling element. This is the same iterator returned by
. This method is needed by thelocalIterator()
Iterable
interface to satisfyforeach
language constructions.- Specified by:
iterator
in interfaceIterable<IComponent>
- Returns:
- a shallow iterator traversing the direct descendants of this container
- Since:
- Dec 2, 2015, Christopher K. Allen
-
toString
Writes out the modeling elements in this element sequence structure. -
toStringLegacy
- Since:
- Feb 3, 2015 by Christopher K. Allen
- See Also:
-
print
Dump contents to a text stream.- Parameters:
os
- output stream
-
getForwardCompList
Return the internal list of components -
getReverseCompList
Return the reverse component list (downstream to upstream)
NOTES: CKA
· Added support for backward propagation February, 2009- Returns:
List
of sequence components in reverse order- Since:
- Feb 27, 2009
-
setCompList
Set the comp list to the new list of elements.
NOTES: CKA
· Added support for backward propagation February, 2009- Parameters:
elements
- the new list of elements
-
compDependParams
protected void compDependParams()Recompute all the dependent parameters. Right now that is the sequence length and the position of this sequence within the parent sequence. The dirty flag is cleared once it's all done.- Since:
- Dec 3, 2015, Christopher K. Allen
-