Package cern.accsoft.steering.jmad.model
Class JMadModelImpl
- java.lang.Object
-
- cern.accsoft.steering.jmad.model.JMadModelImpl
-
- All Implemented Interfaces:
ElementAttributeReader
,JMadModel
public class JMadModelImpl extends java.lang.Object implements JMadModel, ElementAttributeReader
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
dirtyModel
true, if some strengthes have been set since last recalc of opticsprotected static org.slf4j.Logger
LOGGER
The logger for the class
-
Constructor Summary
Constructors Constructor Description JMadModelImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(JMadModelListener listener)
add a ModelListenervoid
calcOpticsIfDirty()
Calculate the optics if the model became dirty.TfsSummary
calcTwissSummary()
Function issues a single twiss and returns only the summary of the resulting TfsResult.void
call(java.io.File file)
calls a file from madx.void
cleanup()
cleanup all the stuff and free memoryDynapResult
dynap(DynapResultRequest dynapResultRequest, TrackInitialCondition trackInitialCondition)
run a dynamic aperture test with the given initial condition.void
execute(java.lang.String cmd)
executes the given string directly in madx.protected void
finalize()
protected void
fireBecameDirty()
notify all listeners, that some values changed, so that the actual data is no longer valid.OpticsDefinition
getActiveOpticsDefinition()
Range
getActiveRange()
RangeDefinition
getActiveRangeDefinition()
Aperture
getAperture()
java.lang.String
getDescription()
JMadKernel
getKernel()
This method retrieves theJMadKernel
to which the model sends its commands.KnobManager
getKnobManager()
java.util.List<MisalignmentConfiguration>
getMisalignments()
NOTE: due to incubation form of this method ONLY QUADRUPOLE elements are extracted!ModelMode
getMode()
JMadModelDefinition
getModelDefinition()
ModelFileFinder
getModelFileFinder()
ModelFileFinderManager
getModelFileFinderManager()
java.lang.String
getName()
Optic
getOptics()
JMadModelStartupConfiguration
getStartupConfiguration()
StrengthVarSet
getStrengthsAndVars()
StrengthVarManager
getStrengthVarManager()
TwissInitialConditions
getTwissInitialConditions()
double
getValue(java.lang.String valueName)
retrieves the value as defined by its name from madx.java.util.Map<java.lang.String,java.lang.Double>
getValueMap(java.util.Collection<java.lang.String> valueNames)
reads multiple values from the model given by their names to a map.java.util.List<java.lang.Double>
getValues(java.util.List<java.lang.String> valueNames)
reads multiple values from the model which are given by their namesprotected java.lang.Double
getVariableValue(TfsResult misalignmentsRaw, java.lang.Integer elementIndex, EalignVariables variable)
void
init()
inits the values.boolean
isInitialized()
void
loadAperture()
loads all the aperture-files to the model apertureMatchResult
match(MatchResultRequest resultRequest)
Run a MadX Matching Command on the JMad Modelvoid
readAttributes(Element element)
reads the properties for the given elementvoid
readAttributes(java.util.Collection<Element> elements)
reads the properties for all the given elementsvoid
readTable(java.io.File file, java.lang.String tableName)
instructs madx to read a table from a file.void
removeListener(JMadModelListener listener)
remove a listenervoid
reset()
resets the model.void
saveBeta(java.lang.String name, java.lang.String location, boolean runDummyTwiss)
Execute the MadX SaveBeta Function, which saves the Optical Functions Values for a given location with the next twiss command inside MadXvoid
set(Knob strength)
void
setActiveOpticsDefinition(OpticsDefinition newActiveOpticsDefinition)
applies the values of the strengths given by the providedOpticsDefinition
to the model.void
setActiveRangeDefinition(RangeDefinition rangeDefinition)
sets the active range as the range corresponding to the given definitionvoid
setKernel(JMadKernel kernel)
protected void
setMisalignments(java.util.List<MisalignmentConfiguration> misalignmentConfigurations)
sends the misalignment-commands to madxvoid
setMode(ModelMode modelMode)
void
setModelDefinition(JMadModelDefinition modelDefinition)
void
setModelFileFinderManager(ModelFileFinderManager modelFileFinderManager)
void
setStartupConfiguration(JMadModelStartupConfiguration startupConfiguration)
void
setStrengthVarManager(StrengthVarManager strengthVarManager)
void
setTitle(java.lang.String title)
void
setTwissInitialConditions(TwissInitialConditions twissInitialConditions)
void
setValue(java.lang.String name, double value)
sets a value as defined by its name directly in madx.void
setValues(java.util.Map<java.lang.String,java.lang.Double> valueNamePairs)
sets a List of value - name pairs directly in madxjava.lang.String
toString()
TrackResult
track(TrackResultRequest trackResultRequest, TrackInitialCondition trackInitialCondition)
Do a tracking with the given initial condition.TfsResult
twiss(TfsResultRequest resultRequest)
runs the twiss with the given given ResultRequest and the initial conditions defined in the model.TfsResult
twiss(TfsResultRequest resultRequest, TwissInitialConditions customTwissInitialConditions)
runs the twiss with the given initial conditions.TfsResult
twissToFile(TfsResultRequest resultRequest, TwissInitialConditions customTwissInitialConditions, java.io.File tfsFile)
run a twiss with the given initial conditions.TfsResult
twissToFile(TfsResultRequest resultRequest, java.io.File tfsFile)
run a twiss with the given given ResultRequest and the initial conditions defined in the model and write to file.
-
-
-
Method Detail
-
setModelDefinition
public void setModelDefinition(JMadModelDefinition modelDefinition)
-
init
public void init() throws JMadModelException
Description copied from interface:JMadModel
inits the values. Does not initialize the elements!- Specified by:
init
in interfaceJMadModel
- Throws:
JMadModelException
- if the initialization fails
-
readTable
public void readTable(java.io.File file, java.lang.String tableName)
instructs madx to read a table from a file.If a tableName is given, then the
ReadMyTableCommand
is used and the table is stored in the given table name. If the name isnull
, then the tablename must be given in the file.- Parameters:
file
- the file from which to load the tabletableName
- the name of the table (lowercase!)
-
reset
public void reset() throws JMadModelException
Description copied from interface:JMadModel
resets the model. Preserves the elements-state: if they are initialized, they will be reinitialized, otherwise not.- Specified by:
reset
in interfaceJMadModel
- Throws:
JMadModelException
- if the reset fails
-
isInitialized
public boolean isInitialized()
- Specified by:
isInitialized
in interfaceJMadModel
- Returns:
- true if the model is initialized, false otherwise.
-
cleanup
public void cleanup() throws JMadModelException
Description copied from interface:JMadModel
cleanup all the stuff and free memory- Specified by:
cleanup
in interfaceJMadModel
- Throws:
JMadModelException
- if the cleanup fails
-
getKernel
public JMadKernel getKernel()
Description copied from interface:JMadModel
This method retrieves theJMadKernel
to which the model sends its commands. Use with care!
-
getValues
public java.util.List<java.lang.Double> getValues(java.util.List<java.lang.String> valueNames) throws JMadModelException
Description copied from interface:JMadModel
reads multiple values from the model which are given by their names- Specified by:
getValues
in interfaceJMadModel
- Parameters:
valueNames
- the names of the values to read- Returns:
- the values
- Throws:
JMadModelException
- if the retrieval of the values fails
-
getValueMap
public java.util.Map<java.lang.String,java.lang.Double> getValueMap(java.util.Collection<java.lang.String> valueNames) throws JMadModelException
Description copied from interface:JMadModel
reads multiple values from the model given by their names to a map. The non-null map contains the mappings between valueName and read value, if the read operation was successful.- Specified by:
getValueMap
in interfaceJMadModel
- Parameters:
valueNames
- the names of the values to read- Returns:
- a guaranteed non-null map, containing the mappings of the read values
- Throws:
JMadModelException
-
getValue
public double getValue(java.lang.String valueName) throws JMadModelException
Description copied from interface:JMadModel
retrieves the value as defined by its name from madx.- Specified by:
getValue
in interfaceJMadModel
- Parameters:
valueName
- the name of the value- Returns:
- the actual value
- Throws:
JMadModelException
- if the retrieval of the values fails
-
readAttributes
public void readAttributes(Element element) throws JMadModelException
Description copied from interface:ElementAttributeReader
reads the properties for the given element- Specified by:
readAttributes
in interfaceElementAttributeReader
- Parameters:
element
- the element for which to read the properties- Throws:
JMadModelException
- if the reading of the attributes fails
-
readAttributes
public void readAttributes(java.util.Collection<Element> elements) throws JMadModelException
Description copied from interface:ElementAttributeReader
reads the properties for all the given elements- Specified by:
readAttributes
in interfaceElementAttributeReader
- Parameters:
elements
- the elements for which to read the attributes- Throws:
JMadModelException
- if the reading of the attributes failed
-
setMisalignments
protected void setMisalignments(java.util.List<MisalignmentConfiguration> misalignmentConfigurations)
sends the misalignment-commands to madx- Parameters:
misalignmentConfigurations
- the misalignment-configurations from which to create the commands
-
twiss
public TfsResult twiss(TfsResultRequest resultRequest) throws JMadModelException
Description copied from interface:JMadModel
runs the twiss with the given given ResultRequest and the initial conditions defined in the model.- Specified by:
twiss
in interfaceJMadModel
- Parameters:
resultRequest
- the requested result- Returns:
- the result of the twiss
- Throws:
JMadModelException
- if the twiss calculations fail
-
twissToFile
public TfsResult twissToFile(TfsResultRequest resultRequest, java.io.File tfsFile) throws JMadModelException
Description copied from interface:JMadModel
run a twiss with the given given ResultRequest and the initial conditions defined in the model and write to file.- Specified by:
twissToFile
in interfaceJMadModel
- Parameters:
resultRequest
- the requested resulttfsFile
- the file to write the twiss to- Returns:
- The tfsresult from the twiss
- Throws:
JMadModelException
- if the twiss calculations fail
-
twissToFile
public TfsResult twissToFile(TfsResultRequest resultRequest, TwissInitialConditions customTwissInitialConditions, java.io.File tfsFile) throws JMadModelException
Description copied from interface:JMadModel
run a twiss with the given initial conditions. And write to file. NOTE: This changes nothing in the state of the model- Specified by:
twissToFile
in interfaceJMadModel
- Parameters:
resultRequest
- the requested resultcustomTwissInitialConditions
- the initial conditions to usetfsFile
- the file to write the twiss to- Returns:
- The tfs result, which is also written to the file
- Throws:
JMadModelException
- if the twiss calculations fail
-
twiss
public TfsResult twiss(TfsResultRequest resultRequest, TwissInitialConditions customTwissInitialConditions) throws JMadModelException
Description copied from interface:JMadModel
runs the twiss with the given initial conditions. NOTE: This changes nothing in the state of the model- Specified by:
twiss
in interfaceJMadModel
- Parameters:
resultRequest
- the requested resultcustomTwissInitialConditions
- the initial conditions to use- Returns:
- the result of the twiss
- Throws:
JMadModelException
- if the twiss calculations fail
-
dynap
public DynapResult dynap(DynapResultRequest dynapResultRequest, TrackInitialCondition trackInitialCondition) throws JMadModelException
Description copied from interface:JMadModel
run a dynamic aperture test with the given initial condition. Note : This changes nothing to the stat of the model- Specified by:
dynap
in interfaceJMadModel
- Returns:
- The result from the dynap command
- Throws:
JMadModelException
- if the command fails
-
track
public TrackResult track(TrackResultRequest trackResultRequest, TrackInitialCondition trackInitialCondition) throws JMadModelException
Description copied from interface:JMadModel
Do a tracking with the given initial condition. Note : This changes nothing in the state of the model- Specified by:
track
in interfaceJMadModel
- Returns:
- The result from the tracking
- Throws:
JMadModelException
- if tracking fails
-
getTwissInitialConditions
public TwissInitialConditions getTwissInitialConditions()
- Specified by:
getTwissInitialConditions
in interfaceJMadModel
- Returns:
- the actual twiss
-
set
public void set(Knob strength) throws JMadModelException
- Throws:
JMadModelException
-
setValue
public void setValue(java.lang.String name, double value) throws JMadModelException
Description copied from interface:JMadModel
sets a value as defined by its name directly in madx.- Specified by:
setValue
in interfaceJMadModel
- Parameters:
name
- the name of the value to setvalue
- the value to set- Throws:
JMadModelException
- if setting the value to MadX fails
-
setValues
public void setValues(java.util.Map<java.lang.String,java.lang.Double> valueNamePairs) throws JMadModelException
Description copied from interface:JMadModel
sets a List of value - name pairs directly in madx- Specified by:
setValues
in interfaceJMadModel
- Parameters:
valueNamePairs
- the Map containing madx parameter names and values to assign- Throws:
JMadModelException
- if setting the values to MadX fails
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
getOptics
public Optic getOptics() throws JMadModelException
- Specified by:
getOptics
in interfaceJMadModel
- Returns:
- the actual optics values for all elements in the active range.
- Throws:
JMadModelException
- if the calculation of the optics fails
-
calcOpticsIfDirty
public void calcOpticsIfDirty() throws JMadModelException
Description copied from interface:JMadModel
Calculate the optics if the model became dirty.- Specified by:
calcOpticsIfDirty
in interfaceJMadModel
- Throws:
JMadModelException
- if the calculation of the optics fails
-
getKnobManager
public KnobManager getKnobManager()
- Specified by:
getKnobManager
in interfaceJMadModel
- Returns:
- the manager, which contains all the model specific knobs.
-
getName
public java.lang.String getName()
-
setActiveOpticsDefinition
public void setActiveOpticsDefinition(OpticsDefinition newActiveOpticsDefinition) throws JMadModelException
Description copied from interface:JMadModel
applies the values of the strengths given by the providedOpticsDefinition
to the model. after loading of the optic it reloads the activeRangeDefinition
. This behavior is necessary, as some of the optics require re-matching of both beams combined. That can result in a different Range being active after the loading of the optics.- Specified by:
setActiveOpticsDefinition
in interfaceJMadModel
- Parameters:
newActiveOpticsDefinition
- the optics definition to set as the active one- Throws:
JMadModelException
- in case setting the active range fails
-
getActiveOpticsDefinition
public OpticsDefinition getActiveOpticsDefinition()
- Specified by:
getActiveOpticsDefinition
in interfaceJMadModel
- Returns:
- the actually used
OpticsDefinition
, ornull
if no optic is loaded.
-
setActiveRangeDefinition
public void setActiveRangeDefinition(RangeDefinition rangeDefinition) throws JMadModelException
Description copied from interface:JMadModel
sets the active range as the range corresponding to the given definition- Specified by:
setActiveRangeDefinition
in interfaceJMadModel
- Parameters:
rangeDefinition
- theRangeDefinition
which shall be used to set the newly active range- Throws:
JMadModelException
- if the change of the range fails
-
setTwissInitialConditions
public void setTwissInitialConditions(TwissInitialConditions twissInitialConditions)
-
getActiveRange
public Range getActiveRange()
- Specified by:
getActiveRange
in interfaceJMadModel
- Returns:
- the currently active
Range
-
addListener
public void addListener(JMadModelListener listener)
Description copied from interface:JMadModel
add a ModelListener- Specified by:
addListener
in interfaceJMadModel
- Parameters:
listener
- the listener to add
-
removeListener
public void removeListener(JMadModelListener listener)
Description copied from interface:JMadModel
remove a listener- Specified by:
removeListener
in interfaceJMadModel
- Parameters:
listener
- the listener to remove
-
execute
public void execute(java.lang.String cmd)
Description copied from interface:JMadModel
executes the given string directly in madx. (must also contain ";" at the end!) Use with care!
-
call
public void call(java.io.File file)
Description copied from interface:JMadModel
calls a file from madx.
-
fireBecameDirty
protected void fireBecameDirty()
notify all listeners, that some values changed, so that the actual data is no longer valid.
-
getModelDefinition
public JMadModelDefinition getModelDefinition()
- Specified by:
getModelDefinition
in interfaceJMadModel
- Returns:
- the model-definition, from which the model was created.
-
getActiveRangeDefinition
public RangeDefinition getActiveRangeDefinition()
- Specified by:
getActiveRangeDefinition
in interfaceJMadModel
- Returns:
- the currently active
RangeDefinition
-
match
public MatchResult match(MatchResultRequest resultRequest) throws JMadModelException
Description copied from interface:JMadModel
Run a MadX Matching Command on the JMad ModelIf no Sequence is specified in the
MatchResultRequest
the actual Sequence will be used for matching as enabled with the last setActiveRange command.After the Matching changes to the model are updated accordingly
- Specified by:
match
in interfaceJMadModel
- Parameters:
resultRequest
- the Matching Request containing relevant parameters- Returns:
- the
MatchResult
as retrieved from MadX - Throws:
JMadModelException
- if the matching fails
-
saveBeta
public void saveBeta(java.lang.String name, java.lang.String location, boolean runDummyTwiss) throws JMadModelException
Description copied from interface:JMadModel
Execute the MadX SaveBeta Function, which saves the Optical Functions Values for a given location with the next twiss command inside MadX- Specified by:
saveBeta
in interfaceJMadModel
- Parameters:
name
- the MadX internal Name for the SaveBetalocation
- the location in the sequence where to save the Optical Functions ValuesrunDummyTwiss
- if true a 'twiss;' command is send directly after the saveBeta- Throws:
JMadModelException
-
calcTwissSummary
public TfsSummary calcTwissSummary() throws JMadModelException
Description copied from interface:JMadModel
Function issues a single twiss and returns only the summary of the resulting TfsResult. This is nothing else than a shortcut totwiss(TfsResultRequest.createSummaryOnlyRequest()).getSummary()
- Specified by:
calcTwissSummary
in interfaceJMadModel
- Returns:
- the summary part of the actually valid twiss result.
- Throws:
JMadModelException
- if the twiss fails.
-
getAperture
public Aperture getAperture()
- Specified by:
getAperture
in interfaceJMadModel
- Returns:
- the actually loaded aperture
-
loadAperture
public void loadAperture()
Description copied from interface:JMadModel
loads all the aperture-files to the model aperture- Specified by:
loadAperture
in interfaceJMadModel
-
getModelFileFinder
public ModelFileFinder getModelFileFinder()
- Specified by:
getModelFileFinder
in interfaceJMadModel
- Returns:
- the model file finder
-
getStrengthsAndVars
public StrengthVarSet getStrengthsAndVars()
- Specified by:
getStrengthsAndVars
in interfaceJMadModel
- Returns:
- the actually valid strengths and variables.
-
setKernel
public void setKernel(JMadKernel kernel)
-
getStartupConfiguration
public JMadModelStartupConfiguration getStartupConfiguration()
- Specified by:
getStartupConfiguration
in interfaceJMadModel
- Returns:
- the startup configuration which will be used when initializing and resetting the model
-
setModelFileFinderManager
public void setModelFileFinderManager(ModelFileFinderManager modelFileFinderManager)
-
getModelFileFinderManager
public ModelFileFinderManager getModelFileFinderManager()
-
setStartupConfiguration
public void setStartupConfiguration(JMadModelStartupConfiguration startupConfiguration)
- Specified by:
setStartupConfiguration
in interfaceJMadModel
- Parameters:
startupConfiguration
- the new startup-configuration
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getDescription
public java.lang.String getDescription()
- Specified by:
getDescription
in interfaceJMadModel
- Returns:
- the current description of the Model containing
- ModelDefinition Name
- current Sequence Name
- current Range Name
- current Optic Name
-
getMode
public ModelMode getMode()
-
setMode
public void setMode(ModelMode modelMode)
-
setTitle
public void setTitle(java.lang.String title)
-
getMisalignments
public java.util.List<MisalignmentConfiguration> getMisalignments()
Description copied from interface:JMadModel
NOTE: due to incubation form of this method ONLY QUADRUPOLE elements are extracted!- Specified by:
getMisalignments
in interfaceJMadModel
- Returns:
- a complete list of an actual machine imperfections accordingly to the requested definition (see:
Range
addMisalignments(), addMisalignment())
-
getVariableValue
protected java.lang.Double getVariableValue(TfsResult misalignmentsRaw, java.lang.Integer elementIndex, EalignVariables variable)
- Parameters:
misalignmentsRaw
-elementIndex
-variable
-- Returns:
-
setStrengthVarManager
public void setStrengthVarManager(StrengthVarManager strengthVarManager)
-
getStrengthVarManager
public StrengthVarManager getStrengthVarManager()
- Specified by:
getStrengthVarManager
in interfaceJMadModel
-
-