PtcGlobalVariable.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.  *
  24.  */
  25. package cern.accsoft.steering.jmad.domain.var.enums;

  26. import java.util.Set;

  27. import cern.accsoft.steering.jmad.domain.var.GlobalVariable;
  28. import cern.accsoft.steering.jmad.domain.var.VariableUtil;
  29. import cern.accsoft.steering.jmad.util.MadxVarType;

  30. /**
  31.  * This enum represents madx global variables, which appear in general in the sum-table of the twiss. TODO define units
  32.  *
  33.  * @author Kajetan Fuchsberger (kajetan.fuchsberger at cern.ch)
  34.  */
  35. public enum PtcGlobalVariable implements GlobalVariable {

  36.     NAME(MadxVarType.STRING), //
  37.     TYPE(MadxVarType.STRING), //
  38.     SEQUENCE(MadxVarType.STRING), //

  39.     /*
  40.      * beam parameters
  41.      */
  42.     PARTICLE(MadxVarType.STRING), //
  43.     MASS, CHARGE, ENERGY, PC, GAMMA, KBUNCH, BCURRENT, //
  44.     SIGE, SIGT, NPART, EX, EY, ET, //

  45.     /*
  46.      * elements of sum-table
  47.      */
  48.     LENGTH, DELTAP, //
  49.     ALPHA_C, ALPHA_C_P, ALPHA_C_P2, ALPHA_C_P3, ETA_C, GAMMA_TR, //
  50.     Q1, Q2, DQ1, DQ2, QS, //
  51.     BETA_X_MIN, BETA_X_MAX, BETA_Y_MIN, BETA_Y_MAX, //
  52.     ORBIT_X, ORBIT_PX, ORBIT_Y, ORBIT_PY, ORBIT_PT, //
  53.     ORBIT_CT("ORBIT_-CT", MadxVarType.DOUBLE), //
  54.     XCORMS, PXCORMS, YCORMS, PYCORMS, //
  55.     XCOMAX, PXCOMAX, YCOMAX, PYCOMAX, //

  56.     /*
  57.      * others
  58.      */
  59.     TITLE(MadxVarType.STRING), //
  60.     ORIGIN(MadxVarType.STRING), //
  61.     DATE(MadxVarType.STRING), //
  62.     TIME(MadxVarType.STRING),

  63.     /* if something wrong: */
  64.     UNKNOWN("jmad_unknown", MadxVarType.UNKNOWN);

  65.     private String madxName;
  66.     private String unit = null;
  67.     private MadxVarType type = MadxVarType.DOUBLE;

  68.     /*
  69.      * constructors
  70.      */

  71.     private PtcGlobalVariable() {
  72.         /*
  73.          * we use the lowercae expression as madx name.
  74.          */
  75.         this.madxName = this.name().toLowerCase();
  76.     }

  77.     private PtcGlobalVariable(String unit) {
  78.         this();
  79.         this.unit = unit;
  80.     }

  81.     private PtcGlobalVariable(String madxName, MadxVarType varType) {
  82.         this(varType);
  83.         this.madxName = madxName;
  84.     }

  85.     private PtcGlobalVariable(MadxVarType type) {
  86.         this();
  87.         this.type = type;
  88.     }

  89.     public static final PtcGlobalVariable fromMadxName(String madxName) {
  90.         return VariableUtil.findFromMadxName(PtcGlobalVariable.class, madxName, PtcGlobalVariable.UNKNOWN);
  91.     }

  92.     public static final Set<PtcGlobalVariable> allOfType(MadxVarType varType) {
  93.         return VariableUtil.findFromVarType(PtcGlobalVariable.class, varType);
  94.     }

  95.     //
  96.     // methods of interface Variable
  97.     //

  98.     @Override
  99.     public String getMadxName() {
  100.         return this.madxName;
  101.     }

  102.     @Override
  103.     public String getUnit() {
  104.         return this.unit;
  105.     }

  106.     @Override
  107.     public MadxVarType getVarType() {
  108.         return this.type;
  109.     }

  110.     @Override
  111.     public String getName() {
  112.         return getMadxName();
  113.     }

  114.     @Override
  115.     public String toString() {
  116.         return VariableUtil.toString(this);
  117.     }

  118.     @Override
  119.     public Class<?> getValueClass() {
  120.         return getVarType().getValueClass();
  121.     }

  122. }