Exemplo n.º 1
0
  /**
   * Load the correctors of the specified type, construct the corresponding corrector agents and
   * populate the corrector agent list.
   *
   * @param correctorAgents the list to which the corrector agents should be added
   * @param nodeType the type of corrector nodes to fetch
   */
  public void loadCorrectors(final List<CorrectorAgent> correctorAgents, final String nodeType) {
    final Map<String, CorrectorSupply> supplyMap = new HashMap<String, CorrectorSupply>();
    final List<Dipole> allCorrectors = _sequence.getAllNodesOfType(nodeType);
    final List<Dipole> correctors = AcceleratorSeq.filterNodesByStatus(allCorrectors, true);

    final Iterator<Dipole> correctorIter = correctors.iterator();
    while (correctorIter.hasNext()) {
      final Dipole corrector = correctorIter.next();
      final MagnetMainSupply supply = corrector.getMainSupply();
      if (supply != null) {
        final String supplyID = supply.getId();
        if (!supplyMap.containsKey(supplyID)) {
          supplyMap.put(supplyID, new CorrectorSupply(supply));
        }
        final CorrectorSupply supplyAgent = supplyMap.get(supplyID);
        final CorrectorAgent correctorAgent = new CorrectorAgent(corrector);
        supplyAgent.addCorrector(correctorAgent);
        _correctorAgents.add(correctorAgent);
      }
    }

    _correctorSupplyMap = supplyMap;
    _correctorSupplies = new ArrayList<CorrectorSupply>(supplyMap.values());
    Collections.sort(
        _correctorSupplies, CorrectorSupply.getFirstCorrectorPositionComparator(_sequence));
  }
Exemplo n.º 2
0
  /**
   * Update the data based on the information provided by the data provider.
   *
   * @param adaptor The adaptor from which to update the data
   */
  public void update(final DataAdaptor adaptor) {
    if (_correctorSupplyMap != null) {
      final List<DataAdaptor> supplyAdaptors = adaptor.childAdaptors("supply");
      for (final DataAdaptor supplyAdaptor : supplyAdaptors) {
        final String supplyID = supplyAdaptor.stringValue("id");
        final CorrectorSupply supply = _correctorSupplyMap.get(supplyID);
        if (supply != null) {
          if (supplyAdaptor.hasAttribute("enable")) {
            final boolean enable = supplyAdaptor.booleanValue("enable");
            supply.setEnabled(enable);
          }

          if (supplyAdaptor.hasAttribute("lowerFieldLimit")) {
            supply.setLowerFieldLimit(supplyAdaptor.doubleValue("lowerFieldLimit"));
          }

          if (supplyAdaptor.hasAttribute("upperFieldLimit")) {
            supply.setUpperFieldLimit(supplyAdaptor.doubleValue("upperFieldLimit"));
          }
        }
      }
    }

    final List<DataAdaptor> bpmAdaptors = adaptor.childAdaptors("bpm");
    if (bpmAdaptors != null && bpmAdaptors.size() > 0 && _bpmAgents != null) {
      // cache all our bpms so we can access them by ID
      final Map<String, BpmAgent> bpmAgentMap = new HashMap<String, BpmAgent>(_bpmAgents.size());
      for (final BpmAgent bpmAgent : _bpmAgents) {
        bpmAgentMap.put(bpmAgent.getID(), bpmAgent);
      }

      for (final DataAdaptor bpmAdaptor : bpmAdaptors) {
        final String bpmID = bpmAdaptor.stringValue("id");
        final BpmAgent bpmAgent = bpmAgentMap.get(bpmID);
        if (bpmAgent != null) {
          if (bpmAdaptor.hasAttribute("flattenEnable")) {
            bpmAgent.setFlattenEnabled(bpmAdaptor.booleanValue("flattenEnable"));
          }
        }
      }
    }

    final DataAdaptor flattenerAdaptor = adaptor.childAdaptor(Flattener.DATA_LABEL);
    if (flattenerAdaptor != null) {
      getFlattener().update(flattenerAdaptor);
    }

    final List<DataAdaptor> orbitSourceAdaptors = adaptor.childAdaptors(OrbitSource.DATA_LABEL);
    for (DataAdaptor orbitSourceAdaptor : orbitSourceAdaptors) {
      final String type = orbitSourceAdaptor.stringValue("type");
      if (type.equals("snapshot")) {
        final SnapshotOrbitSource orbitSource =
            SnapshotOrbitSource.getInstance(orbitSourceAdaptor, _sequence, _bpmAgents);
        addOrbitSource(orbitSource);
      }
    }
  }
Exemplo n.º 3
0
 /**
  * Get the list of vertical corrector supplies.
  *
  * @return the list of vertical corrector supplies
  */
 public List<CorrectorSupply> getVerticalCorrectorSupplies() {
   final List<CorrectorSupply> verticalSupplies =
       new ArrayList<CorrectorSupply>(_correctorSupplies.size());
   for (CorrectorSupply supply : _correctorSupplies) {
     if (supply.isVertical()) {
       verticalSupplies.add(supply);
     }
   }
   return verticalSupplies;
 }
Exemplo n.º 4
0
 /**
  * Get the list of horizontal corrector supplies.
  *
  * @return the list of horizontal corrector supplies
  */
 public List<CorrectorSupply> getHorizontalCorrectorSupplies() {
   final List<CorrectorSupply> horizontalSupplies =
       new ArrayList<CorrectorSupply>(_correctorSupplies.size());
   for (CorrectorSupply supply : _correctorSupplies) {
     if (supply.isHorizontal()) {
       horizontalSupplies.add(supply);
     }
   }
   return horizontalSupplies;
 }
Exemplo n.º 5
0
  /**
   * Write data to the data adaptor for storage.
   *
   * @param adaptor The adaptor to which the receiver's data is written
   */
  public void write(final DataAdaptor adaptor) {
    if (_correctorSupplyMap != null) {
      for (final CorrectorSupply supply : _correctorSupplyMap.values()) {
        final DataAdaptor supplyAdaptor = adaptor.createChild("supply");
        supplyAdaptor.setValue("id", supply.getID());
        supplyAdaptor.setValue("enable", supply.isEnabled());

        if (supply.isLowerFieldLimitCustom()) {
          supplyAdaptor.setValue("lowerFieldLimit", supply.getLowerFieldLimit());
        }

        if (supply.isUpperFieldLimitCustom()) {
          supplyAdaptor.setValue("upperFieldLimit", supply.getUpperFieldLimit());
        }
      }
    }

    if (_bpmAgents != null) {
      for (final BpmAgent bpmAgent : _bpmAgents) {
        final boolean flattenEnable = bpmAgent.getFlattenEnabled();
        if (!flattenEnable) { // only need to store the exceptions
          final DataAdaptor bpmAdaptor = adaptor.createChild("bpm");
          bpmAdaptor.setValue("id", bpmAgent.getID());
          bpmAdaptor.setValue("flattenEnable", flattenEnable);
        }
      }
    }

    if (_flattener != null) {
      adaptor.writeNode(_flattener);
    }

    for (OrbitSource orbitSource : _orbitSources) {
      if (orbitSource instanceof SnapshotOrbitSource || orbitSource instanceof LiveOrbitSource) {
        adaptor.writeNode(orbitSource);
      }
    }
  }