MDHistoWorkspace_sptr doTest(std::string algoName, std::string inName, std::string outName,
      bool succeeds, std::string otherProp, std::string otherPropValue)
  {
    MDHistoWorkspace_sptr histo = MDEventsTestHelper::makeFakeMDHistoWorkspace(2.0, 2, 5, 10.0, 2.0);
    IMDEventWorkspace_sptr event = MDEventsTestHelper::makeMDEW<2>(3, 0.0, 10.0, 1);
    WorkspaceSingleValue_sptr scalar = WorkspaceCreationHelper::CreateWorkspaceSingleValue(2.5);
    AnalysisDataService::Instance().addOrReplace("histo", histo);
    AnalysisDataService::Instance().addOrReplace("event", event);
    AnalysisDataService::Instance().addOrReplace("scalar", scalar);

    IAlgorithm* alg = FrameworkManager::Instance().createAlgorithm(algoName);
    alg->initialize();
    alg->setPropertyValue("InputWorkspace", inName );
    alg->setPropertyValue("OutputWorkspace", outName );
    if (!otherProp.empty())
      alg->setPropertyValue(otherProp, otherPropValue);
    alg->execute();
    if (succeeds)
    {
      if (!alg->isExecuted())
        throw std::runtime_error("Algorithm " + algoName + " did not succeed.");
      IMDWorkspace_sptr out = boost::dynamic_pointer_cast<IMDWorkspace>( AnalysisDataService::Instance().retrieve(outName));
      if (!out)
        throw std::runtime_error("Algorithm " + algoName + " did not create the output workspace.");
      return boost::dynamic_pointer_cast<MDHistoWorkspace>(out);
    }
    else
    {
      if (alg->isExecuted())
        throw std::runtime_error("Algorithm " + algoName + " did not fail as expected.");
      return (MDHistoWorkspace_sptr());
    }
  }
  /// Run a binary algorithm.
  MDHistoWorkspace_sptr doTest(std::string algoName, std::string lhs, std::string rhs, std::string outName,
      bool succeeds, std::string otherProp, std::string otherPropValue)
  {
    setUpBinaryOperationMDTestHelper();

    IAlgorithm* alg = FrameworkManager::Instance().createAlgorithm(algoName);
    alg->initialize();
    alg->setPropertyValue("LHSWorkspace", lhs );
    alg->setPropertyValue("RHSWorkspace", rhs );
    alg->setPropertyValue("OutputWorkspace", outName );
    if (!otherProp.empty())
      alg->setPropertyValue(otherProp, otherPropValue);
    alg->execute();
    if (succeeds)
    {
      if (!alg->isExecuted())
        throw std::runtime_error("Algorithm " + algoName + " did not succeed.");
      IMDWorkspace_sptr out = boost::dynamic_pointer_cast<IMDWorkspace>( AnalysisDataService::Instance().retrieve(outName));
      if (!out)
        throw std::runtime_error("Algorithm " + algoName + " did not create the output workspace.");
      return boost::dynamic_pointer_cast<MDHistoWorkspace>(out);
    }
    else
    {
      if (alg->isExecuted())
        throw std::runtime_error("Algorithm " + algoName + " did not fail as expected.");
      return (MDHistoWorkspace_sptr());
    }
  }
/** Creates an instance of an algorithm, sets the properties provided and
 *       then executes it.
 * 
 *  @param algName :: The name of the algorithm required
 *  @param propertiesArray :: A single string containing properties in the 
 *                         form "Property1=Value1;Property2=Value2;..."
 *  @param version :: The version of the algorithm
 *  @return A pointer to the executed algorithm
 *          WARNING! DO NOT DELETE THIS POINTER, because it is owned
 *          by a shared pointer in the AlgorithmManager.
 * 
 *  @throw NotFoundError Thrown if algorithm requested is not registered
 *  @throw std::invalid_argument Thrown if properties string is ill-formed
 *  @throw runtime_error Thrown if algorithm cannot be executed
 */ 
IAlgorithm* FrameworkManagerImpl::exec(const std::string& algName, const std::string& propertiesArray, const int& version)
{
  // Make use of the previous method for algorithm creation and property setting
  IAlgorithm *alg = createAlgorithm(algName, propertiesArray,version);
  
  // Now execute the algorithm
  alg->execute();
  
  return alg;
}
Example #4
0
/**
  * Execute an algorithm
  * @param nlhs :: The number of parameters on the left-hand side of the equals
  * @param plhs :: The data on the left-hand side of the equals
  * @param nrhs :: The number of parameters in the Matlab function call
  * @param prhs :: The data from the Matlab function call
 * @returns An integer indicating success/failure
   */
int RunAlgorithm(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  try {
    char buffer[256];

    uint64_t *data = (uint64_t *)mxGetData(prhs[0]);
    IAlgorithm *alg = (IAlgorithm *)data[0];
    mxGetString(prhs[1], buffer, sizeof(buffer));
    alg->setProperties(buffer);
    alg->execute();
    plhs[0] = mxCreateString("");
    return 0;
  } catch (std::exception &e) {
    mexErrMsgTxt(e.what());
    return 1;
  }
}
Example #5
0
/**
  * Execute an algorithm with a property list
  * @param nlhs :: The number of parameters on the left-hand side of the equals
  * @param plhs :: The data on the left-hand side of the equals
  * @param nrhs :: The number of parameters in the Matlab function call
  * @param prhs :: The data from the Matlab function call
  * @returns An integer indicating success/failure
  */
int RunAlgorithmPV(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
  try {
    mxArray *marray;
    char buffer[256];
    std::string property_name;

    uint64_t *data = (uint64_t *)mxGetData(prhs[0]);
    IAlgorithm *alg = (IAlgorithm *)data[0];
    int i = 1;
    while (i < nrhs) {
      if (mxGetClassID(prhs[i]) != mxCHAR_CLASS) {
        mexErrMsgTxt("Algorithm property name must be a string");
      }
      mxGetString(prhs[i], buffer, sizeof(buffer));
      property_name = buffer;
      i++;
      strcpy(buffer, mxGetClassName(prhs[i]));
      if (!strcmp(buffer, "char")) {
        mxGetString(prhs[i], buffer, sizeof(buffer));
        alg->setPropertyValue(property_name, buffer);
      } else if (!strcmp(buffer, "MantidWorkspace")) {
        marray = mxGetField(prhs[i], 0, "name");
        mxGetString(marray, buffer, sizeof(buffer));
        alg->setPropertyValue(property_name, buffer);
      } else {
        mexErrMsgTxt("Algorithm property value must be a string");
      }
      i++;
    }
    alg->execute();
    plhs[0] = mxCreateString("");
    return 0;
  } catch (std::exception &e) {
    mexErrMsgTxt(e.what());
    return 1;
  }
}