Example #1
0
/**
 * If an output workspace was created then extract it from the given dictionary
 * @param locals A dictionary possibly containing an 'output' reference
 * @return A pointer to the output workspace if created, otherwise an empty
 * pointer
 */
boost::shared_ptr<API::Workspace> RunPythonScript::extractOutputWorkspace(
    const boost::python::dict &locals) const {
  using namespace API;
  using namespace boost::python;

  // Might be None, string or a workspace object
  auto pyoutput = locals.get("output");
  if (isNone(pyoutput))
    return Workspace_sptr();

  auto ptrExtract = ExtractWorkspace(pyoutput);
  if (ptrExtract.check()) {
    return ptrExtract();
  } else {
    extract<std::string> extractString(pyoutput);
    if (extractString.check()) {
      // Will raise an error if the workspace does not exist as the user
      // requested
      // an output workspace
      // but didn't create one.
      return AnalysisDataService::Instance().retrieve(extractString());
    } else {
      throw std::runtime_error(
          "Invalid type assigned to 'output' variable. Must "
          "be a string or a Workspace object");
    }
  }
}