예제 #1
0
/**
 * Execute the given algorithm asynchronously.
 * @param algorithm :: The algorithm to execute.
 */
void CatalogHelper::executeAsynchronously(
    const Mantid::API::IAlgorithm_sptr &algorithm) {
  Poco::ActiveResult<bool> result(algorithm->executeAsync());
  while (!result.available()) {
    QCoreApplication::processEvents();
  }
}
예제 #2
0
    /** This method executes the ListInstruments algorithm
     * and fills the instrument box with instrument lists returned by ICat API
     * @return shared pointer to workspace which contains instrument names
     */
    std::vector<std::string> ICatUtils::executeListInstruments()
    {
      QString algName("CatalogListInstruments");
      const int version=-1;
      Mantid::API::IAlgorithm_sptr alg;
      try
      {
        alg = Mantid::API::AlgorithmManager::Instance().create(algName.toStdString(),version);
      }
      catch(...)
      {
        throw std::runtime_error("Error when Populating the instrument list box");

      }

      Poco::ActiveResult<bool> result(alg->executeAsync());
      while( !result.available() )
      {
        QCoreApplication::processEvents();
      }
      if(!alg->isExecuted())
      {
        //if the algorithm failed check the session id passed is valid
        if(!isSessionValid(alg))
        {
          //at this point session is invalid, popup loginbox to login
          if(login())
          {
            //now populate instrument box
            std::vector<std::string> instruments =executeListInstruments();
            return instruments;
          }
          else
          {
            throw std::runtime_error("Please Login to the information catalog using the login menu provided to do the investigation search.");
          }
        }
        else
        {
          return std::vector<std::string>();
        }
      }
      std::vector<std::string>instrlist;
      try
      {

        instrlist= alg->getProperty("InstrumentList");
      }
      catch (Mantid::Kernel::Exception::NotFoundError&)
      {
        throw;
      }
      return instrlist;

    }
예제 #3
0
    /// execute getdatafIles algorithm
    ITableWorkspace_sptr ICatInvestigation::executeGetdataFiles()
    {
      QString algName("CatalogGetDataFiles");
      const int version=1;
      Mantid::API::ITableWorkspace_sptr  ws_sptr;
      Mantid::API::IAlgorithm_sptr alg;
      try
      {
        alg = Mantid::API::AlgorithmManager::Instance().create(algName.toStdString(),version);
      }
      catch(...)
      {
        throw std::runtime_error("Error when loading the data files associated to the selected investigation ");
      }
      try
      {
        alg->setProperty("InvestigationId",m_invstId);
        alg->setProperty("FilterLogFiles",isDataFilesChecked());
        alg->setPropertyValue("OutputWorkspace","datafiles");
      }
      catch(std::invalid_argument& e)
      {
        emit error(e.what());
        return ws_sptr;
      }
      catch (Mantid::Kernel::Exception::NotFoundError& e)
      {
        emit error(e.what());
        return ws_sptr;
      }

      try
      {
        Poco::ActiveResult<bool> result(alg->executeAsync());
        while( !result.available() )
        {
          QCoreApplication::processEvents();
        }
      }
      catch(...)
      {
        return ws_sptr;
      }
      if(AnalysisDataService::Instance().doesExist("datafiles"))
      {
        ws_sptr = boost::dynamic_pointer_cast<Mantid::API::ITableWorkspace>
        (AnalysisDataService::Instance().retrieve("datafiles"));
      }
      return ws_sptr;

    }
예제 #4
0
    bool ICatUtils::login()
    {
      QString algName("CatalogLogin");
      const int version =-1;
      Mantid::API::IAlgorithm_sptr alg;
      try
      {
        alg = Mantid::API::AlgorithmManager::Instance().create(algName.toStdString(),version);
      }
      catch(...)
      {
        throw std::runtime_error("Error when Populating the instrument list box");
      }
      if(!m_applicationWindow)
      {return false;}

      MantidQt::API::InterfaceManager interfaceManager;
      MantidQt::API::AlgorithmDialog *dlg = interfaceManager.createDialog(alg.get(), m_applicationWindow);
      if(!dlg) return false;
      if(dlg->exec()==QDialog::Accepted)
      {
        delete dlg;
        Poco::ActiveResult<bool> result(alg->executeAsync());
        while( !result.available() )
        {
          QCoreApplication::processEvents();
        }

        if(!alg->isExecuted())
        {
          return false;
        }
        return true;
      }
      else
      {
        return false;
      }
    }
예제 #5
0
/**
 * Execute the underlying algorithm
 */
void AlgorithmDialog::executeAlgorithmAsync() {
  Mantid::API::IAlgorithm_sptr algToExec = m_algorithm;
  // Clear any previous trackers so we know what state we are in
  this->stopObserving(algToExec);

  try {
    // Add any custom AlgorithmObservers to the algorithm
    for (auto it = m_observers.begin(); it != m_observers.end(); ++it) {
      (*it)->observeAll(algToExec);
    }

    // Only need to observe finish events if we are staying open
    if (m_keepOpenCheckBox && m_keepOpenCheckBox->isChecked()) {
      this->observeFinish(algToExec);
      this->observeError(algToExec);
      m_statusTracked = true;
      // Disable close button for a short period. If it is clicked to soon then
      // Mantid crashes - https://github.com/mantidproject/mantid/issues/13836
      if (m_exitButton) {
        m_exitButton->setEnabled(false);
        m_btnTimer.setInterval(1000);
        connect(&m_btnTimer, SIGNAL(timeout()), this, SLOT(enableExitButton()));
      } else {
        m_statusTracked = false;
      }
    }
    algToExec->executeAsync();
    m_btnTimer.start();

    if (m_okButton) {
      m_okButton->setEnabled(false);
    }
  } catch (Poco::NoThreadAvailableException &) {
    g_log.error() << "No thread was available to run the " << algToExec->name()
                  << " algorithm in the background.\n";
  }
}