Misalignment.java

  1. // @formatter:off
  2.  /*******************************************************************************
  3.  *
  4.  * This file is part of JMad.
  5.  *
  6.  * Copyright (c) 2008-2011, CERN. All rights reserved.
  7.  *
  8.  * Licensed under the Apache License, Version 2.0 (the "License");
  9.  * you may not use this file except in compliance with the License.
  10.  * You may obtain a copy of the License at
  11.  *
  12.  *     http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing, software
  15.  * distributed under the License is distributed on an "AS IS" BASIS,
  16.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.  * See the License for the specific language governing permissions and
  18.  * limitations under the License.
  19.  *
  20.  ******************************************************************************/
  21. // @formatter:on

  22. /*
  23.  * $Id: Misalignment.java,v 1.2 2009-01-20 19:43:10 kfuchsbe Exp $
  24.  *
  25.  * $Date: 2009-01-20 19:43:10 $ $Revision: 1.2 $ $Author: kfuchsbe $
  26.  *
  27.  * Copyright CERN, All Rights Reserved.
  28.  */
  29. package cern.accsoft.steering.jmad.domain.misalign;

  30. import java.util.ArrayList;
  31. import java.util.List;

  32. import cern.accsoft.steering.jmad.util.bean.NamedBean;

  33. /**
  34.  * this class defines values, which describe a misalignment of one or more elements. When communicating with MadX this
  35.  * always results in a set of <a href="http://mad.web.cern.ch/mad/error/error_align.html">EALIGN</a> commands.
  36.  *
  37.  * @author Kajetan Fuchsberger (kajetan.fuchsberger at cern.ch)
  38.  */
  39. public class Misalignment implements NamedBean {

  40.     /** the listeners */
  41.     private final List<MisalignmentListener> listeners = new ArrayList<MisalignmentListener>();

  42.     /**
  43.      * DX: The misalignment in the x-direction for the entry of the beam element (default: 0 m). DX>0 displaces the
  44.      * element in the positive x-direction
  45.      */
  46.     private Double deltaX = null;

  47.     /**
  48.      * DY: The misalignment in the y-direction for the entry of the beam element (default: 0 m). DY>0 displaces the
  49.      * element in the positive y-direction
  50.      */
  51.     private Double deltaY = null;

  52.     /**
  53.      * DS: The misalignment in the s-direction for the entry of the beam element (default: 0 m). DS>0 displaces the
  54.      * element in the positive s-direction
  55.      */
  56.     private Double deltaS = null;

  57.     /**
  58.      * DPHI: The rotation around the x-axis. A positive angle gives a greater x-coordinate for the exit than for the
  59.      * entry (default: 0 rad).
  60.      */
  61.     private Double deltaPhi = null;

  62.     /**
  63.      * DTHETA: The rotation around the y-axis according to the right hand rule (default: 0 rad).
  64.      */
  65.     private Double deltaTheta = null;

  66.     /**
  67.      * DPSI: The rotation around the s-axis according to the right hand rule (default: 0 rad).
  68.      */
  69.     private Double deltaPsi = null;

  70.     //
  71.     // the following values only apply to monitors
  72.     //

  73.     /**
  74.      * MREX: The horizontal read error for a monitor. This is ignored if the element is not a monitor If MREX>0 the
  75.      * reading for x is too high (default: 0 m).
  76.      */
  77.     private Double monitorReadErrorX = null;

  78.     /**
  79.      * MREY: The vertical read error for a monitor. This is ignored if the element is not a monitor If MREY>0, the
  80.      * reading for y is too high (default: 0 m).
  81.      */
  82.     private Double monitorReadErrorY = null;

  83.     /**
  84.      * MSCALX: The relative horizontal scaling error for a monitor. This is ignored if the element is not a monitor. If
  85.      * MSCALX>0 the reading for x is too high (default: 0). A value of 0.5 implies the actual reading is multiplied by
  86.      * 1.5.
  87.      */
  88.     private Double monitorScalingErrorX = null;

  89.     /**
  90.      * MSCALY: The relative vertical scaling error for a monitor. This is ignored if the element is not a monitor. If
  91.      * MSCALY>0 the reading for y is too high (default: 0). A value of -0.3 implies the actual reading is multiplied by
  92.      * 0.7.
  93.      */
  94.     private Double monitorScalingErrorY = null;

  95.     /**
  96.      * AREX: The misalignment in the x-direction for the entry of an aperture limit (default: 0 m). AREX>0 displaces the
  97.      * element in the positive x-direction
  98.      */
  99.     private Double apertureErrorX = null;

  100.     /**
  101.      * AREY: The misalignment in the y-direction for the entry of an aperture limit (default: 0 m). AREY>0 displaces the
  102.      * element in the positive y-direction
  103.      */
  104.     private Double apertureErrorY = null;

  105.     /**
  106.      * the name of the misalignment
  107.      */
  108.     private final String name;

  109.     /**
  110.      * the constructor-which needs a name
  111.      *
  112.      * @param name the name
  113.      */
  114.     public Misalignment(String name) {
  115.         this.name = name;
  116.     }

  117.     /*
  118.      * Getters and setters
  119.      */

  120.     /**
  121.      * @return the deltaX
  122.      */
  123.     public final Double getDeltaX() {
  124.         return deltaX;
  125.     }

  126.     /**
  127.      * @param deltaX the deltaX to set
  128.      */
  129.     public final void setDeltaX(Double deltaX) {
  130.         this.deltaX = deltaX;
  131.         fireChangedValues();
  132.     }

  133.     /**
  134.      * @return the deltaY
  135.      */
  136.     public final Double getDeltaY() {
  137.         return deltaY;
  138.     }

  139.     /**
  140.      * @param deltaY the deltaY to set
  141.      */
  142.     public final void setDeltaY(Double deltaY) {
  143.         this.deltaY = deltaY;
  144.         fireChangedValues();
  145.     }

  146.     /**
  147.      * @return the deltaS
  148.      */
  149.     public final Double getDeltaS() {
  150.         return deltaS;
  151.     }

  152.     /**
  153.      * @param deltaS the deltaS to set
  154.      */
  155.     public final void setDeltaS(Double deltaS) {
  156.         this.deltaS = deltaS;
  157.         fireChangedValues();
  158.     }

  159.     /**
  160.      * @return the deltaPhi
  161.      */
  162.     public final Double getDeltaPhi() {
  163.         return deltaPhi;
  164.     }

  165.     /**
  166.      * @param deltaPhi the deltaPhi to set
  167.      */
  168.     public final void setDeltaPhi(Double deltaPhi) {
  169.         this.deltaPhi = deltaPhi;
  170.         fireChangedValues();
  171.     }

  172.     /**
  173.      * @return the deltaTheta
  174.      */
  175.     public final Double getDeltaTheta() {
  176.         return deltaTheta;
  177.     }

  178.     /**
  179.      * @param deltaTheta the deltaTheta to set
  180.      */
  181.     public final void setDeltaTheta(Double deltaTheta) {
  182.         this.deltaTheta = deltaTheta;
  183.         fireChangedValues();
  184.     }

  185.     /**
  186.      * @return the deltaPsi
  187.      */
  188.     public final Double getDeltaPsi() {
  189.         return deltaPsi;
  190.     }

  191.     /**
  192.      * @param deltaPsi the deltaPsi to set
  193.      */
  194.     public final void setDeltaPsi(Double deltaPsi) {
  195.         this.deltaPsi = deltaPsi;
  196.         fireChangedValues();
  197.     }

  198.     /**
  199.      * @return the monitorReadErrorX
  200.      */
  201.     public final Double getMonitorReadErrorX() {
  202.         return monitorReadErrorX;
  203.     }

  204.     /**
  205.      * @param monitorReadErrorX the monitorReadErrorX to set
  206.      */
  207.     public final void setMonitorReadErrorX(Double monitorReadErrorX) {
  208.         this.monitorReadErrorX = monitorReadErrorX;
  209.         fireChangedValues();
  210.     }

  211.     /**
  212.      * @return the monitorReadErrorY
  213.      */
  214.     public final Double getMonitorReadErrorY() {
  215.         return monitorReadErrorY;
  216.     }

  217.     /**
  218.      * @param monitorReadErrorY the monitorReadErrorY to set
  219.      */
  220.     public final void setMonitorReadErrorY(Double monitorReadErrorY) {
  221.         this.monitorReadErrorY = monitorReadErrorY;
  222.         fireChangedValues();
  223.     }

  224.     /**
  225.      * @return the monitorScalingErrorX
  226.      */
  227.     public final Double getMonitorScalingErrorX() {
  228.         return monitorScalingErrorX;
  229.     }

  230.     /**
  231.      * @param monitorScalingErrorX the monitorScalingErrorX to set
  232.      */
  233.     public final void setMonitorScalingErrorX(Double monitorScalingErrorX) {
  234.         this.monitorScalingErrorX = monitorScalingErrorX;
  235.         fireChangedValues();
  236.     }

  237.     /**
  238.      * @return the monitorScalingErrorY
  239.      */
  240.     public final Double getMonitorScalingErrorY() {
  241.         return monitorScalingErrorY;
  242.     }

  243.     /**
  244.      * @param monitorScalingErrorY the monitorScalingErrorY to set
  245.      */
  246.     public final void setMonitorScalingErrorY(Double monitorScalingErrorY) {
  247.         this.monitorScalingErrorY = monitorScalingErrorY;
  248.         fireChangedValues();
  249.     }

  250.     /**
  251.      * @return the apertureErrorX
  252.      */
  253.     public final Double getApertureErrorX() {
  254.         return apertureErrorX;
  255.     }

  256.     /**
  257.      * @param apertureErrorX the apertureErrorX to set
  258.      */
  259.     public final void setApertureErrorX(Double apertureErrorX) {
  260.         this.apertureErrorX = apertureErrorX;
  261.         fireChangedValues();
  262.     }

  263.     /**
  264.      * @return the apertureErrorY
  265.      */
  266.     public final Double getApertureErrorY() {
  267.         return apertureErrorY;
  268.     }

  269.     /**
  270.      * @param apertureErrorY the apertureErrorY to set
  271.      */
  272.     public final void setApertureErrorY(Double apertureErrorY) {
  273.         this.apertureErrorY = apertureErrorY;
  274.         fireChangedValues();
  275.     }

  276.     /*
  277.      * methods concerning listeners
  278.      */

  279.     /**
  280.      * notify the listeners, that values have changed
  281.      */
  282.     private void fireChangedValues() {
  283.         for (MisalignmentListener listener : this.listeners) {
  284.             listener.changedValues(this);
  285.         }
  286.     }

  287.     /**
  288.      * @param listener the listener to add
  289.      */
  290.     public void addListener(MisalignmentListener listener) {
  291.         this.listeners.add(listener);
  292.     }

  293.     /**
  294.      * @param listener the listener to remove
  295.      */
  296.     public void removeListener(MisalignmentListener listener) {
  297.         this.listeners.remove(listener);
  298.     }

  299.     @Override
  300.     public String getName() {
  301.         return this.name;
  302.     }

  303.     @Override
  304.     public String toString() {
  305.         return "Misalignment [deltaX=" + deltaX + ", deltaY=" + deltaY + ", deltaS=" + deltaS + ", monitorReadErrorX="
  306.                 + monitorReadErrorX + ", monitorReadErrorY=" + monitorReadErrorY + ", name=" + name + "]";
  307.     }

  308. }