TrackTask.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.kernel.task.track;

  23. import java.util.ArrayList;
  24. import java.util.List;

  25. import cern.accsoft.steering.jmad.domain.result.ResultType;
  26. import cern.accsoft.steering.jmad.domain.result.track.TrackResultRequest;
  27. import cern.accsoft.steering.jmad.domain.track.RelativeParticleCoordinate;
  28. import cern.accsoft.steering.jmad.domain.track.TrackInitialCondition;
  29. import cern.accsoft.steering.jmad.kernel.cmd.Command;
  30. import cern.accsoft.steering.jmad.kernel.cmd.WriteCommand;
  31. import cern.accsoft.steering.jmad.kernel.cmd.track.TrackCommand;
  32. import cern.accsoft.steering.jmad.kernel.cmd.track.TrackEndCommand;
  33. import cern.accsoft.steering.jmad.kernel.cmd.track.TrackRunCommand;
  34. import cern.accsoft.steering.jmad.kernel.cmd.track.TrackStartCommand;
  35. import cern.accsoft.steering.jmad.kernel.task.AbstractTask;

  36. /**
  37.  * Execute a track task and if an output file is defined write the result to it.
  38.  *
  39.  * @author xbuffat
  40.  */

  41. public class TrackTask extends AbstractTask {

  42.     private final TrackInitialCondition trackInitialCondition;
  43.     private final TrackResultRequest trackResultRequest;

  44.     public TrackTask(TrackInitialCondition init, TrackResultRequest request) {
  45.         this.trackInitialCondition = init;
  46.         this.trackResultRequest = request;
  47.     }

  48.     @Override
  49.     protected List<Command> getCommands() {
  50.         List<Command> commands = new ArrayList<Command>();
  51.         commands.add(new TrackCommand(this.getTrackInitialCondition()));
  52.         for (RelativeParticleCoordinate coord : this.getTrackResultRequest().getRelativeParticleDistribution()) {
  53.             commands.add(new TrackStartCommand(coord));
  54.         }
  55.         commands.add(new TrackRunCommand(this.getTrackResultRequest()));
  56.         commands.add(new TrackEndCommand());
  57.         if (this.getOutputFile() != null) {
  58.             commands.add(new WriteCommand("trackone", this.getOutputFile().getAbsolutePath()));
  59.         }
  60.         return commands;
  61.     }

  62.     @Override
  63.     public ResultType getResultType() {
  64.         return ResultType.TRACK_RESULT;
  65.     }

  66.     public TrackInitialCondition getTrackInitialCondition() {
  67.         return trackInitialCondition;
  68.     }

  69.     public TrackResultRequest getTrackResultRequest() {
  70.         return trackResultRequest;
  71.     }

  72. }