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 booleandirtyModeltrue, if some strengthes have been set since last recalc of opticsprotected static org.slf4j.LoggerLOGGERThe logger for the class
-
Constructor Summary
Constructors Constructor Description JMadModelImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(JMadModelListener listener)add a ModelListenervoidcalcOpticsIfDirty()Calculate the optics if the model became dirty.TfsSummarycalcTwissSummary()Function issues a single twiss and returns only the summary of the resulting TfsResult.voidcall(java.io.File file)calls a file from madx.voidcleanup()cleanup all the stuff and free memoryDynapResultdynap(DynapResultRequest dynapResultRequest, TrackInitialCondition trackInitialCondition)run a dynamic aperture test with the given initial condition.voidexecute(java.lang.String cmd)executes the given string directly in madx.protected voidfinalize()protected voidfireBecameDirty()notify all listeners, that some values changed, so that the actual data is no longer valid.OpticsDefinitiongetActiveOpticsDefinition()RangegetActiveRange()RangeDefinitiongetActiveRangeDefinition()AperturegetAperture()java.lang.StringgetDescription()JMadKernelgetKernel()This method retrieves theJMadKernelto which the model sends its commands.KnobManagergetKnobManager()java.util.List<MisalignmentConfiguration>getMisalignments()NOTE: due to incubation form of this method ONLY QUADRUPOLE elements are extracted!ModelModegetMode()JMadModelDefinitiongetModelDefinition()ModelFileFindergetModelFileFinder()ModelFileFinderManagergetModelFileFinderManager()java.lang.StringgetName()OpticgetOptics()JMadModelStartupConfigurationgetStartupConfiguration()StrengthVarSetgetStrengthsAndVars()StrengthVarManagergetStrengthVarManager()TwissInitialConditionsgetTwissInitialConditions()doublegetValue(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.DoublegetVariableValue(TfsResult misalignmentsRaw, java.lang.Integer elementIndex, EalignVariables variable)voidinit()inits the values.booleanisInitialized()voidloadAperture()loads all the aperture-files to the model apertureMatchResultmatch(MatchResultRequest resultRequest)Run a MadX Matching Command on the JMad ModelvoidreadAttributes(Element element)reads the properties for the given elementvoidreadAttributes(java.util.Collection<Element> elements)reads the properties for all the given elementsvoidreadTable(java.io.File file, java.lang.String tableName)instructs madx to read a table from a file.voidremoveListener(JMadModelListener listener)remove a listenervoidreset()resets the model.voidsaveBeta(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 MadXvoidset(Knob strength)voidsetActiveOpticsDefinition(OpticsDefinition newActiveOpticsDefinition)applies the values of the strengths given by the providedOpticsDefinitionto the model.voidsetActiveRangeDefinition(RangeDefinition rangeDefinition)sets the active range as the range corresponding to the given definitionvoidsetKernel(JMadKernel kernel)protected voidsetMisalignments(java.util.List<MisalignmentConfiguration> misalignmentConfigurations)sends the misalignment-commands to madxvoidsetMode(ModelMode modelMode)voidsetModelDefinition(JMadModelDefinition modelDefinition)voidsetModelFileFinderManager(ModelFileFinderManager modelFileFinderManager)voidsetStartupConfiguration(JMadModelStartupConfiguration startupConfiguration)voidsetStrengthVarManager(StrengthVarManager strengthVarManager)voidsetTitle(java.lang.String title)voidsetTwissInitialConditions(TwissInitialConditions twissInitialConditions)voidsetValue(java.lang.String name, double value)sets a value as defined by its name directly in madx.voidsetValues(java.util.Map<java.lang.String,java.lang.Double> valueNamePairs)sets a List of value - name pairs directly in madxjava.lang.StringtoString()TrackResulttrack(TrackResultRequest trackResultRequest, TrackInitialCondition trackInitialCondition)Do a tracking with the given initial condition.TfsResulttwiss(TfsResultRequest resultRequest)runs the twiss with the given given ResultRequest and the initial conditions defined in the model.TfsResulttwiss(TfsResultRequest resultRequest, TwissInitialConditions customTwissInitialConditions)runs the twiss with the given initial conditions.TfsResulttwissToFile(TfsResultRequest resultRequest, TwissInitialConditions customTwissInitialConditions, java.io.File tfsFile)run a twiss with the given initial conditions.TfsResulttwissToFile(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 JMadModelExceptionDescription copied from interface:JMadModelinits the values. Does not initialize the elements!- Specified by:
initin 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
ReadMyTableCommandis 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 JMadModelExceptionDescription copied from interface:JMadModelresets the model. Preserves the elements-state: if they are initialized, they will be reinitialized, otherwise not.- Specified by:
resetin interfaceJMadModel- Throws:
JMadModelException- if the reset fails
-
isInitialized
public boolean isInitialized()
- Specified by:
isInitializedin interfaceJMadModel- Returns:
- true if the model is initialized, false otherwise.
-
cleanup
public void cleanup() throws JMadModelExceptionDescription copied from interface:JMadModelcleanup all the stuff and free memory- Specified by:
cleanupin interfaceJMadModel- Throws:
JMadModelException- if the cleanup fails
-
getKernel
public JMadKernel getKernel()
Description copied from interface:JMadModelThis method retrieves theJMadKernelto 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 JMadModelExceptionDescription copied from interface:JMadModelreads multiple values from the model which are given by their names- Specified by:
getValuesin 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 JMadModelExceptionDescription copied from interface:JMadModelreads 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:
getValueMapin 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 JMadModelExceptionDescription copied from interface:JMadModelretrieves the value as defined by its name from madx.- Specified by:
getValuein 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:ElementAttributeReaderreads the properties for the given element- Specified by:
readAttributesin 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:ElementAttributeReaderreads the properties for all the given elements- Specified by:
readAttributesin 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:JMadModelruns the twiss with the given given ResultRequest and the initial conditions defined in the model.- Specified by:
twissin 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:JMadModelrun a twiss with the given given ResultRequest and the initial conditions defined in the model and write to file.- Specified by:
twissToFilein 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:JMadModelrun a twiss with the given initial conditions. And write to file. NOTE: This changes nothing in the state of the model- Specified by:
twissToFilein 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:JMadModelruns the twiss with the given initial conditions. NOTE: This changes nothing in the state of the model- Specified by:
twissin 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:JMadModelrun a dynamic aperture test with the given initial condition. Note : This changes nothing to the stat of the model- Specified by:
dynapin 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:JMadModelDo a tracking with the given initial condition. Note : This changes nothing in the state of the model- Specified by:
trackin interfaceJMadModel- Returns:
- The result from the tracking
- Throws:
JMadModelException- if tracking fails
-
getTwissInitialConditions
public TwissInitialConditions getTwissInitialConditions()
- Specified by:
getTwissInitialConditionsin 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 JMadModelExceptionDescription copied from interface:JMadModelsets a value as defined by its name directly in madx.- Specified by:
setValuein 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 JMadModelExceptionDescription copied from interface:JMadModelsets a List of value - name pairs directly in madx- Specified by:
setValuesin 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:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
getOptics
public Optic getOptics() throws JMadModelException
- Specified by:
getOpticsin 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 JMadModelExceptionDescription copied from interface:JMadModelCalculate the optics if the model became dirty.- Specified by:
calcOpticsIfDirtyin interfaceJMadModel- Throws:
JMadModelException- if the calculation of the optics fails
-
getKnobManager
public KnobManager getKnobManager()
- Specified by:
getKnobManagerin 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:JMadModelapplies the values of the strengths given by the providedOpticsDefinitionto 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:
setActiveOpticsDefinitionin 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:
getActiveOpticsDefinitionin interfaceJMadModel- Returns:
- the actually used
OpticsDefinition, ornullif no optic is loaded.
-
setActiveRangeDefinition
public void setActiveRangeDefinition(RangeDefinition rangeDefinition) throws JMadModelException
Description copied from interface:JMadModelsets the active range as the range corresponding to the given definition- Specified by:
setActiveRangeDefinitionin interfaceJMadModel- Parameters:
rangeDefinition- theRangeDefinitionwhich 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:
getActiveRangein interfaceJMadModel- Returns:
- the currently active
Range
-
addListener
public void addListener(JMadModelListener listener)
Description copied from interface:JMadModeladd a ModelListener- Specified by:
addListenerin interfaceJMadModel- Parameters:
listener- the listener to add
-
removeListener
public void removeListener(JMadModelListener listener)
Description copied from interface:JMadModelremove a listener- Specified by:
removeListenerin interfaceJMadModel- Parameters:
listener- the listener to remove
-
execute
public void execute(java.lang.String cmd)
Description copied from interface:JMadModelexecutes 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:JMadModelcalls 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:
getModelDefinitionin interfaceJMadModel- Returns:
- the model-definition, from which the model was created.
-
getActiveRangeDefinition
public RangeDefinition getActiveRangeDefinition()
- Specified by:
getActiveRangeDefinitionin interfaceJMadModel- Returns:
- the currently active
RangeDefinition
-
match
public MatchResult match(MatchResultRequest resultRequest) throws JMadModelException
Description copied from interface:JMadModelRun a MadX Matching Command on the JMad ModelIf no Sequence is specified in the
MatchResultRequestthe 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:
matchin interfaceJMadModel- Parameters:
resultRequest- the Matching Request containing relevant parameters- Returns:
- the
MatchResultas retrieved from MadX - Throws:
JMadModelException- if the matching fails
-
saveBeta
public void saveBeta(java.lang.String name, java.lang.String location, boolean runDummyTwiss) throws JMadModelExceptionDescription copied from interface:JMadModelExecute the MadX SaveBeta Function, which saves the Optical Functions Values for a given location with the next twiss command inside MadX- Specified by:
saveBetain 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:JMadModelFunction 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:
calcTwissSummaryin interfaceJMadModel- Returns:
- the summary part of the actually valid twiss result.
- Throws:
JMadModelException- if the twiss fails.
-
getAperture
public Aperture getAperture()
- Specified by:
getAperturein interfaceJMadModel- Returns:
- the actually loaded aperture
-
loadAperture
public void loadAperture()
Description copied from interface:JMadModelloads all the aperture-files to the model aperture- Specified by:
loadAperturein interfaceJMadModel
-
getModelFileFinder
public ModelFileFinder getModelFileFinder()
- Specified by:
getModelFileFinderin interfaceJMadModel- Returns:
- the model file finder
-
getStrengthsAndVars
public StrengthVarSet getStrengthsAndVars()
- Specified by:
getStrengthsAndVarsin interfaceJMadModel- Returns:
- the actually valid strengths and variables.
-
setKernel
public void setKernel(JMadKernel kernel)
-
getStartupConfiguration
public JMadModelStartupConfiguration getStartupConfiguration()
- Specified by:
getStartupConfigurationin 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:
setStartupConfigurationin interfaceJMadModel- Parameters:
startupConfiguration- the new startup-configuration
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getDescription
public java.lang.String getDescription()
- Specified by:
getDescriptionin 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:JMadModelNOTE: due to incubation form of this method ONLY QUADRUPOLE elements are extracted!- Specified by:
getMisalignmentsin interfaceJMadModel- Returns:
- a complete list of an actual machine imperfections accordingly to the requested definition (see:
RangeaddMisalignments(), 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:
getStrengthVarManagerin interfaceJMadModel
-
-