SetClassMisalignment.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: SetMisalignment.java,v 1.2 2009-03-16 16:35:33 kfuchsbe Exp $
  24.  *
  25.  * $Date: 2009-03-16 16:35:33 $ $Revision: 1.2 $ $Author: kfuchsbe $
  26.  *
  27.  * Copyright CERN, All Rights Reserved.
  28.  */
  29. package cern.accsoft.steering.jmad.kernel.task;

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

  32. import cern.accsoft.steering.jmad.domain.misalign.Misalignment;
  33. import cern.accsoft.steering.jmad.domain.misalign.PatternOrClassMisalignmentConfiguration;
  34. import cern.accsoft.steering.jmad.kernel.cmd.Command;
  35. import cern.accsoft.steering.jmad.kernel.cmd.EOptionCommand;
  36. import cern.accsoft.steering.jmad.kernel.cmd.GaussEalignCommand;
  37. import cern.accsoft.steering.jmad.kernel.cmd.SelectCommand;

  38. /**
  39.  * This class represents a task, which applies a certain misalignment to a class/patterns of elements with defined
  40.  * random gaussian distribution for DX and DY.
  41.  *
  42.  * @author agorzaws
  43.  */
  44. public class SetClassMisalignment extends AbstractTask {

  45.     /** the flag to use for the select command to set the misalignment */
  46.     private static final String SELECT_FLAG_ERROR = "error";

  47.     /** contains the misalignment values, which to apply to the element */
  48.     private final Misalignment misalignment;

  49.     private final String elementsClass;

  50.     private final String pattern;

  51.     private final double gaussianDistribution;

  52.     private final Double seed;

  53.     /**
  54.      * the constructor. Needs the element and the misalignment to apply.
  55.      *
  56.      * @param config the misalignment-config to apply
  57.      */
  58.     public SetClassMisalignment(PatternOrClassMisalignmentConfiguration config) {
  59.         this.elementsClass = config.getElementClass();
  60.         this.pattern = config.getElementName();
  61.         this.misalignment = config.getMisalignment();
  62.         this.gaussianDistribution = config.getGaussianDistribution();
  63.         this.seed = Double.valueOf(config.getSeed());
  64.     }

  65.     @Override
  66.     protected List<Command> getCommands() {
  67.         List<Command> commands = new ArrayList<Command>();

  68.         if ((this.elementsClass != null) && (this.misalignment != null)) {

  69.             EOptionCommand eOptionCommand = new EOptionCommand(seed, false);
  70.             commands.add(eOptionCommand);

  71.             /* first reset the select-command */
  72.             SelectCommand select = new SelectCommand();
  73.             select.setFlag(SELECT_FLAG_ERROR);
  74.             select.setClear(true);
  75.             commands.add(select);

  76.             /* set the select-command for one element */
  77.             select = new SelectCommand();
  78.             select.setFlag(SELECT_FLAG_ERROR);
  79.             if (isValueSet(elementsClass))
  80.                 select.setElementClass(this.elementsClass);
  81.             if (isValueSet(pattern)) {
  82.                 select.setPattern(this.pattern);
  83.             }
  84.             commands.add(select);

  85.             /* set the misalignment for the element class */
  86.             GaussEalignCommand ealign = new GaussEalignCommand(this.misalignment, gaussianDistribution);
  87.             commands.add(ealign);
  88.         }
  89.         return commands;
  90.     }

  91.     private boolean isValueSet(String elementToTest) {
  92.         return elementToTest != null && elementToTest != "";
  93.     }

  94. }