MadxTwissVariable.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. package cern.accsoft.steering.jmad.domain.var.enums;

  23. import java.util.Set;

  24. import cern.accsoft.steering.jmad.domain.var.TwissVariable;
  25. import cern.accsoft.steering.jmad.domain.var.VariableUtil;
  26. import cern.accsoft.steering.jmad.util.MadxVarType;

  27. public enum MadxTwissVariable implements TwissVariable {

  28.     // generic stuff
  29.     NAME("name", MadxVarType.STRING), //
  30.     KEYWORD("keyword", MadxVarType.STRING), //
  31.     PARENT("parent", MadxVarType.STRING),

  32.     // canonical variables
  33.     X("x", "m"), PX("px", "rad"), Y("y", "m"), PY("py", "rad"), T("t"), PT("pt"), DELTAP("deltap"),

  34.     // independent variable
  35.     S("s", "m"), L("l", "m"),

  36.     // normalized variables and other derived quantities
  37.     XN("xn"), PXN("pxn"), WX("wx"), PHIX("phix"), YN("yn"), PYN("pyn"), WY("wy"), PHIY("phiy"), TN("tn"), PTN("ptn"), WT(
  38.             "wt"), PHIT("phit"),

  39.     // linear lattice functions
  40.     BETX("betx", "m"), ALFX("alfx"), MUX("mux", "2pi"), DX("dx", "m"), DPX("dpx"), BETY("bety", "m"), ALFY("alfy"), MUY(
  41.             "muy", "2pi"), DY("dy", "m"), DPY("dpy"),

  42.     // additional for twiss table:
  43.     GAMX("gamx"), GAMY("gamy"), SIGX("sigx"), SIGY("sigy"),

  44.     // chromatic functions
  45.     DMUX("dmux"), DDX("ddx"), DDPX("ddpx"), DMUY("dmuy"), DDY("ddy"), DDPY("ddpy"), DBX("dbx"), DBY("dby"),

  46.     // k-values
  47.     K0L("k0l"), // dipole
  48.     K1L("k1l"), // quad
  49.     K2L("k2l"), // sextupole
  50.     K3L("k3l"), // ocupole
  51.     K4L("k4l"), // decapole
  52.     K5L("k5l"), // dodecapole
  53.     // skew k-values
  54.     K0SL("k0sl"), // dipole
  55.     K1SL("k1sl"), // quad
  56.     K2SL("k2sl"), // sextupole
  57.     K3SL("k3sl"), // ocupole
  58.     K4SL("k4sl"), // decapole
  59.    
  60.     ANGLE("angle"), //the angle = K0L

  61.     HKICK("hkick"), VKICK("vkick"), // kickers...
  62.     POLARITY("polarity"), // and the assigned polarity

  63.     // 2x2 coupling matrix coefficients
  64.     R11("r11"), R12("r12"), R21("r21"), R22("r22"),

  65.     // if something wrong:
  66.     UNKNOWN("jmad_unknown", MadxVarType.UNKNOWN);

  67.     private String name;
  68.     private String unit = null;
  69.     private MadxVarType type;

  70.     private MadxTwissVariable(String tag, MadxVarType type) {
  71.         this.name = tag;
  72.         this.type = type;
  73.     }

  74.     private MadxTwissVariable(String tag) {
  75.         this(tag, MadxVarType.DOUBLE);
  76.     }

  77.     private MadxTwissVariable(String tag, String unit) {
  78.         this(tag, MadxVarType.DOUBLE);
  79.         this.unit = unit;
  80.     }

  81.     @Override
  82.     public String getMadxName() {
  83.         return name;
  84.     }

  85.     @Override
  86.     public MadxVarType getVarType() {
  87.         return type;
  88.     }

  89.     /**
  90.      * Determine the correct Value of Variable for a given tag.
  91.      *
  92.      * @param madxName the tag for which to get the VarType - Value.
  93.      * @return The VarType corresponding to the given tag.
  94.      */
  95.     public static final MadxTwissVariable fromMadxName(String madxName) {
  96.         return VariableUtil.findFromMadxName(MadxTwissVariable.class, madxName, MadxTwissVariable.UNKNOWN);
  97.     }

  98.     /**
  99.      * returns a set of variables of a given type.
  100.      *
  101.      * @param type which variables to retrieve
  102.      * @return the variables.
  103.      */
  104.     public static final Set<MadxTwissVariable> allOfType(MadxVarType type) {
  105.         return VariableUtil.findFromVarType(MadxTwissVariable.class, type);
  106.     }

  107.     @Override
  108.     public boolean isApertureVariable() {
  109.         return false;
  110.     }

  111.     @Override
  112.     public String getUnit() {
  113.         return this.unit;
  114.     }

  115.     @Override
  116.     public String getName() {
  117.         return getMadxName();
  118.     }

  119.     @Override
  120.     public String toString() {
  121.         return VariableUtil.toString(this);
  122.     }

  123.     @Override
  124.     public Class<?> getValueClass() {
  125.         return getVarType().getValueClass();
  126.     }

  127. }