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());
    }
  }
示例#3
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;
  }
}
示例#4
0
    /**
    * Create the dynamic widgets for the concrete loader
    */
    void LoadDialog::createDynamicLayout()
    {
      // Disable the layout so that a widget cannot be interacted with while it may be being deleted
      m_form.propertyLayout->setEnabled(false);

      using namespace Mantid::API;
      using namespace Mantid::Kernel;

      if( !m_form.fileWidget->isValid() ) return;
      // First step is the get the specific loader that is responsible
      IAlgorithm *loadAlg = getAlgorithm();
      const QString filenames = m_form.fileWidget->getUserInput().asString();
      if( filenames == m_currentFiles ) return;
      m_currentFiles = filenames;
      removeOldInputWidgets(m_form.propertyLayout); // The new file might be invalid
      try
      {
        loadAlg->setPropertyValue("Filename", filenames.toStdString());
      }
      catch(std::exception & exc)
      {
        m_form.fileWidget->setFileProblem(QString::fromStdString(exc.what()));
        m_form.propertyLayout->setEnabled(true);
        m_form.propertyLayout->activate();
        this->resize(this->width(), m_initialHeight + 15);
        
        // Reset the algorithm pointer so that the base class re-reads the properties and drops links from
        // old widgets meaning they are safe to remove
        setAlgorithm(loadAlg);
        tieStaticWidgets(false); //The ties are cleared when resetting the algorithm

        return;
      }
      // Reset the algorithm pointer so that the base class re-reads the properties and drops links from
      // old widgets meaning they are safe to remove
      setAlgorithm(loadAlg);
      tieStaticWidgets(false); //The ties are cleared when resetting the algorithm
      // Add the new ones
      const std::vector<Property*> & inputProps = loadAlg->getProperties();
      int dialogHeight = m_initialHeight;
      for( size_t i = 0; i < inputProps.size(); ++i )
      {
        const Property* prop = inputProps[i];
        const QString propName = QString::fromStdString(prop->name());
        if( propName == "OutputWorkspace" || propName == "Filename" ) continue;
        if( requiresUserInput(propName) )
        {
          dialogHeight += createWidgetsForProperty(prop, m_form.propertyLayout, m_form.scrollAreaWidgetContents);
        }
      }
      // Re-enable and recompute the size of the layout
      m_form.propertyLayout->setEnabled(true);
      m_form.propertyLayout->activate();

      const int screenHeight = QApplication::desktop()->height();
      // If the thing won't end up too big compared to the screen height,
      // resize the scroll area so we don't get a scroll bar
      if ( dialogHeight < 0.8*screenHeight ) this->resize(this->width(),dialogHeight + 20);

      // Make sure the OutputWorkspace value has been stored so that the validator is cleared appropriately
      QString wsName(m_form.workspaceEdit->text());
      if(!wsName.isEmpty()) storePropertyValue("OutputWorkspace",wsName);
      setPropertyValues(QStringList("Filename"));
    }