Example #1
0
/** Add a sample log (property) with value as string
 * @brief AddSampleLog::addStringLog
 * @param theRun
 * @param propName
 * @param propValue
 * @param propUnit
 */
void AddSampleLog::addStringLog(Run &theRun, const std::string &propName,
                                const std::string &propValue,
                                const std::string &propUnit) {
  theRun.addLogData(new PropertyWithValue<std::string>(propName, propValue));
  theRun.getProperty(propName)->setUnits(propUnit);
  return;
}
Example #2
0
/** Add a single value property
 * @brief AddSampleLog::addSingleValueProperty
 * @param theRun
 * @param propName
 * @param propValue
 * @param propUnit
 * @param propNumberType
 */
void AddSampleLog::addSingleValueProperty(Run &theRun,
                                          const std::string &propName,
                                          const std::string &propValue,
                                          const std::string &propUnit,
                                          const std::string &propNumberType) {
  // add a single value property, integer or double
  bool value_is_int(false);
  if (propNumberType != autoTypeOption) {
    value_is_int = (propNumberType == intTypeOption);
  } else {
    int intVal;
    if (Strings::convert(propValue, intVal)) {
      value_is_int = true;
    }
  }

  // set value
  if (value_is_int) {
    // convert to integer
    int intVal;
    int convert_to_int = Strings::convert(propValue, intVal);
    if (convert_to_int == 0) {
      // spit out error message and set to default value
      g_log.error() << "Error interpreting string '" << propValue
                    << "' as NumberType Int.";
      throw std::runtime_error("Invalie integer input");
    }
    theRun.addLogData(new PropertyWithValue<int>(propName, intVal));
  } else {
    // convert to double
    double dblVal;
    int convert_to_dbl = Strings::convert(propValue, dblVal);
    if (convert_to_dbl == 0) {
      g_log.error() << "Error interpreting string '" << propValue
                    << "' as NumberType Double.";
      throw std::runtime_error("Invalid double input.");
    }
    theRun.addLogData(new PropertyWithValue<double>(propName, dblVal));
    g_log.information() << "added property " << propName << " with value "
                        << dblVal << "\n";
  }

  // add unit
  theRun.getProperty(propName)->setUnits(propUnit);

  return;
}
Example #3
0
/**
 * Copy logs from the input workspace to the output workspace
 * and don't replace any mathcing logs in the output workspace.
 */
void CopyLogs::mergeKeepExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto prop : inputLogs) {
    // add the log only if it doesn't already exist
    if (!outputRun.hasProperty(prop->name())) {
      outputRun.addLogData(prop->clone());
    }
  }
}
Example #4
0
/**
 * Copy logs from the input workspace to the output workspace
 * and don't replace any mathcing logs in the output workspace.
 */
void CopyLogs::mergeKeepExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
    Kernel::Property *prop = *iter;
    // add the log only if it doesn't already exist
    if (!outputRun.hasProperty(prop->name())) {
      outputRun.addLogData(prop->clone());
    }
  }
}
Example #5
0
/**
 * Copy logs from the input workspace to the output workspace
 * and replace any matching logs with the ones from the input workspace.
 */
void CopyLogs::mergeReplaceExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto prop : inputLogs) {
    // if the log exists, remove and replace it
    if (outputRun.hasProperty(prop->name())) {
      outputRun.removeLogData(prop->name());
    }
    outputRun.addLogData(prop->clone());
  }
}
Example #6
0
/**
 * Copy logs from the input workspace to the output workspace
 * and replace any matching logs with the ones from the input workspace.
 */
void CopyLogs::mergeReplaceExisting(
    const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
  for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
    Kernel::Property *prop = *iter;
    // if the log exists, remove and replace it
    if (outputRun.hasProperty(prop->name())) {
      outputRun.removeLogData(prop->name());
    }
    outputRun.addLogData(prop->clone());
  }
}
Example #7
0
/**
 * Wipe any existing logs in the output workspace and replace
 * them with the logs from the input workspace.
 */
void CopyLogs::wipeExisting(const std::vector<Kernel::Property *> &inputLogs,
                            Run &outputRun) {
  auto outputLogs = outputRun.getLogData();

  // remove each of the logs from the second workspace
  for (auto iter = outputLogs.begin(); iter != outputLogs.end(); ++iter) {
    outputRun.removeLogData((*iter)->name());
  }

  // add all the logs from the new workspace
  for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
    outputRun.addLogData((*iter)->clone());
  }
}
Example #8
0
/**
 * Wipe any existing logs in the output workspace and replace
 * them with the logs from the input workspace.
 */
void CopyLogs::wipeExisting(const std::vector<Kernel::Property *> &inputLogs,
                            Run &outputRun) {
  auto outputLogs = outputRun.getLogData();

  // remove each of the logs from the second workspace
  for (auto &outputLog : outputLogs) {
    outputRun.removeLogData(outputLog->name());
  }

  // add all the logs from the new workspace
  for (auto inputLog : inputLogs) {
    outputRun.addLogData(inputLog->clone());
  }
}
Example #9
0
/** Add a sample log as a TimeSeriesProperty
 * @brief AddSampleLog::addTimeSeriesProperty
 * @param run_obj
 * @param prop_name
 * @param prop_value
 * @param prop_unit
 * @param prop_number_type
 */
void AddSampleLog::addTimeSeriesProperty(Run &run_obj,
                                         const std::string &prop_name,
                                         const std::string &prop_value,
                                         const std::string &prop_unit,
                                         const std::string &prop_number_type) {
  // set up the number type right
  bool is_int_series(false);
  if (prop_number_type == intTypeOption) {
    // integer type
    is_int_series = true;
  } else if (prop_number_type == autoTypeOption) {
    // auto type. by default
    if (prop_value.empty())
      g_log.warning("For sample log in TimeSeriesProperty and values are given "
                    "by MarixWorkspace, the default data type "
                    "is double.");
    else {
      // find out the time series data type by prop_value. integer or double
      int intVal;
      if (Strings::convert(prop_value, intVal)) {
        is_int_series = true;
      }
    }
  } else if (prop_number_type != doubleTypeOption) {
    // unsupported type: anything but double, integer or auto
    g_log.error() << "TimeSeriesProperty with data type " << prop_number_type
                  << " is not supported.\n";
    throw std::runtime_error("Unsupported TimeSeriesProperty type.");
  }

  // check using workspace or some specified start value
  std::string tsp_ws_name = getPropertyValue("TimeSeriesWorkspace");
  bool use_ws = !tsp_ws_name.empty();
  bool use_single_value = !prop_value.empty();
  if (use_ws && use_single_value) {
    throw std::runtime_error("Both TimeSeries workspace and sing value are "
                             "specified.  It is not allowed.");
  } else if (!use_ws && !use_single_value) {
    throw std::runtime_error("Neither TimeSeries workspace or sing value are "
                             "specified.  It is not allowed.");
  }

  // create workspace
  // get run start
  Types::Core::DateAndTime startTime = getRunStart(run_obj);

  // initialze the TimeSeriesProperty and add unit
  if (is_int_series) {
    auto tsp = new TimeSeriesProperty<int>(prop_name);
    if (use_single_value) {
      int intVal;
      if (Strings::convert(prop_value, intVal)) {
        tsp->addValue(startTime, intVal);
      } else {
        throw std::invalid_argument(
            "Input value cannot be converted to an integer value.");
      }
    }
    run_obj.addLogData(tsp);
  } else {
    auto tsp = new TimeSeriesProperty<double>(prop_name);
    if (use_single_value) {
      double dblVal;
      if (Strings::convert(prop_value, dblVal)) {
        tsp->addValue(startTime, dblVal);
      } else {
        throw std::invalid_argument(
            "Input value cannot be converted to a double number.");
      }
    }
    run_obj.addLogData(tsp);
  }
  // add unit
  run_obj.getProperty(prop_name)->setUnits(prop_unit);

  if (use_ws)
    setTimeSeriesData(run_obj, prop_name, is_int_series);
}