/**
 * Looks at each of the parameters, to see if they are default, and if they are,
 * over-writes them
 * with the values set in the instrument parameters (if they exist).
 * @param instrument : Instrument on input workspace.
 * @param ndims : Number of dimensions in output workspace.
 */
void BoxControllerSettingsAlgorithm::takeDefaultsFromInstrument(
    Mantid::Geometry::Instrument_const_sptr instrument, const size_t ndims) {
  const std::string splitThresholdName = "SplitThreshold";
  const std::string splitIntoName = "SplitInto";
  const std::string maxRecursionDepthName = "MaxRecursionDepth";
  Property *p = getProperty(splitThresholdName);
  if (p->isDefault()) {
    std::vector<double> instrumentSplitThresholds =
        instrument->getNumberParameter(splitThresholdName, true);
    if (!instrumentSplitThresholds.empty()) {
      setProperty(splitThresholdName,
                  static_cast<int>(instrumentSplitThresholds.front()));
    }
  }
  p = getProperty(splitIntoName);
  if (p->isDefault()) {
    std::vector<double> instrumentSplitInto =
        instrument->getNumberParameter(splitIntoName, true);
    if (!instrumentSplitInto.empty()) {
      const int splitInto = static_cast<int>(instrumentSplitInto.front());
      std::vector<int> newSplitInto(ndims, splitInto);
      setProperty(splitIntoName, newSplitInto);
    }
  }
  p = getProperty(maxRecursionDepthName);
  if (p->isDefault()) {
    std::vector<double> instrumentMaxRecursionDepth =
        instrument->getNumberParameter(maxRecursionDepthName, true);
    if (!instrumentMaxRecursionDepth.empty()) {
      setProperty(maxRecursionDepthName,
                  static_cast<int>(instrumentMaxRecursionDepth.front()));
    }
  }
}
double ReflectometryReductionOneAuto::checkForDefault(
    std::string propName, Mantid::Geometry::Instrument_const_sptr instrument,
    std::string idf_name) const {
    auto algProperty = this->getPointerToProperty(propName);
    if (algProperty->isDefault()) {
        auto defaults = instrument->getNumberParameter(idf_name);
        if (defaults.size() == 0) {
            throw std::runtime_error("No data could be retrieved from the parameters "
                                     "and argument wasn't provided: " +
                                     propName);
        }
        return defaults[0];
    } else {
        return boost::lexical_cast<double, std::string>(algProperty->value());
    }
}
Ejemplo n.º 3
0
/**
 * Gets the eFixed value from the workspace using the instrument parameters.
 *
 * @param ws Pointer to the workspace
 * @return eFixed value
 */
double IndirectTab::getEFixed(Mantid::API::MatrixWorkspace_sptr ws) {
  Mantid::Geometry::Instrument_const_sptr inst = ws->getInstrument();
  if (!inst)
    throw std::runtime_error("No instrument on workspace");

  // Try to get the parameter form the base instrument
  if (inst->hasParameter("Efixed"))
    return inst->getNumberParameter("Efixed")[0];

  // Try to get it form the analyser component
  if (inst->hasParameter("analyser")) {
    std::string analyserName = inst->getStringParameter("analyser")[0];
    auto analyserComp = inst->getComponentByName(analyserName);

    if (analyserComp && analyserComp->hasParameter("Efixed"))
      return analyserComp->getNumberParameter("Efixed")[0];
  }

  throw std::runtime_error("Instrument has no efixed parameter");
}