Ejemplo n.º 1
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;

    }
Ejemplo n.º 2
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;
      }
    }
Ejemplo n.º 3
0
bool ConcretePeaksPresenter::addPeakAt(double plotCoordsPointX,
                                       double plotCoordsPointY) {
  V3D plotCoordsPoint(plotCoordsPointX, plotCoordsPointY,
                      m_slicePoint.slicePoint());
  V3D hkl = m_transform->transformBack(plotCoordsPoint);

  Mantid::API::IPeaksWorkspace_sptr peaksWS =
      boost::const_pointer_cast<Mantid::API::IPeaksWorkspace>(this->m_peaksWS);

  Mantid::API::IAlgorithm_sptr alg =
      AlgorithmManager::Instance().create("AddPeakHKL");
  alg->setChild(true);
  alg->setRethrows(true);
  alg->initialize();
  alg->setProperty("Workspace", peaksWS);
  alg->setProperty("HKL", std::vector<double>(hkl));

  // Execute the algorithm
  try {
    alg->execute();
  } catch (...) {
    g_log.warning("ConcretePeaksPresenter: Could not add the peak. Make sure "
                  "that it is added within a valid workspace region");
  }

  // Reproduce the views. Proxy representations recreated for all peaks.
  this->produceViews();

  // Refind visible peaks and Set the proxy representations to be visible or
  // not.
  doFindPeaksInRegion();

  // Upstream controls need to be regenerated.
  this->informOwnerUpdate();

  return alg->isExecuted();
}
Ejemplo n.º 4
0
/**
 * Fill m_uiForm.logBox with names of the log values read from one of the input files
 */
void PlotAsymmetryByLogValueDialog::fillLogBox(const QString&)
{
  QString nexusFileName = m_uiForm.firstRunBox->text();
  QFileInfo file(nexusFileName);
  if (!file.exists())
  {
    return;
  }

  m_uiForm.logBox->clear();

  Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmFactory::Instance().create("LoadNexus",-1);
  alg->initialize();
  try
  {
    alg->setPropertyValue("Filename",nexusFileName.toStdString());
    alg->setPropertyValue("OutputWorkspace","PlotAsymmetryByLogValueDialog_tmp");
    alg->setPropertyValue("SpectrumMin","0");
    alg->setPropertyValue("SpectrumMax","0");
    alg->execute();
    if (alg->isExecuted())
    {
      std::string wsName = alg->getPropertyValue("OutputWorkspace");
      Mantid::API::Workspace_sptr ws = Mantid::API::AnalysisDataService::Instance().retrieve(wsName);
      if ( !ws )
      {
        return;
      }
      Mantid::API::MatrixWorkspace_sptr mws = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(ws);
      Mantid::API::WorkspaceGroup_sptr gws = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(ws);
      if (gws)
      {
        if (gws->getNumberOfEntries() < 2) return;
        mws = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
          Mantid::API::AnalysisDataService::Instance().retrieve(gws->getNames()[1])
        );
      }
      const std::vector< Mantid::Kernel::Property* >& props = mws->run().getLogData();
      if (gws)
      {
        std::vector<std::string> wsNames = gws->getNames();
        for(std::vector<std::string>::iterator it=wsNames.begin();it!=wsNames.end();++it)
        {
          Mantid::API::AnalysisDataService::Instance().remove(*it);
        }
      }
      else
      {
        Mantid::API::AnalysisDataService::Instance().remove("PlotAsymmetryByLogValueDialog_tmp");
      }
      for(size_t i=0;i<props.size();i++)
      {
        m_uiForm.logBox->addItem(QString::fromStdString(props[i]->name()));
      }
      // Display the appropriate value
      QString displayed("");
      if( !isForScript() )
      {
        displayed = MantidQt::API::AlgorithmInputHistory::Instance().previousInput("PlotAsymmetryByLogValue", "LogValue");
      }
      if( !displayed.isEmpty() )
      {
        int index = m_uiForm.logBox->findText(displayed);
        if( index >= 0 )
        {
          m_uiForm.logBox->setCurrentIndex(index);
        }
      }
    }
    
  }
  catch(std::exception& )
  {
  }
}