Пример #1
0
 /** Make a (optionally) file backed MDEventWorkspace with nEvents fake data points
  * the points are randomly distributed within the box (nEvents>0) or homoheneously and regularly spread through the box (nEvents<0)
  *
  * @param wsName :: name of the workspace in ADS
  * @param fileBacked :: true for file-backed
  * @param numEvents :: number of events in the target workspace distributed randomly if numEvents>0 or regularly & homogeneously if numEvents<0
  * @return MDEW sptr
  */
 MDEventWorkspace3Lean::sptr makeFileBackedMDEW(std::string wsName, bool fileBacked,long numEvents)
 {
   // ---------- Make a file-backed MDEventWorkspace -----------------------
   std::string snEvents = boost::lexical_cast<std::string>(numEvents);
   MDEventWorkspace3Lean::sptr ws1 = MDEventsTestHelper::makeMDEW<3>(10, 0.0, 10.0, 0);
   ws1->getBoxController()->setSplitThreshold(100);
   Mantid::API::AnalysisDataService::Instance().addOrReplace(wsName,
       boost::dynamic_pointer_cast< Mantid::API::IMDEventWorkspace>(ws1));
   FrameworkManager::Instance().exec("FakeMDEventData", 6,
       "InputWorkspace", wsName.c_str(),
       "UniformParams", snEvents.c_str(), "RandomizeSignal", "1");
   if (fileBacked)
   {
     std::string filename = wsName + ".nxs";
     Mantid::API::IAlgorithm_sptr saver = FrameworkManager::Instance().exec("SaveMD", 4,
         "InputWorkspace", wsName.c_str(),
         "Filename", filename.c_str());
     FrameworkManager::Instance().exec("LoadMD", 8,
         "OutputWorkspace", wsName.c_str(),
         "Filename", saver->getPropertyValue("Filename").c_str(),
         "FileBackEnd", "1", "Memory", "0");
   }
   return boost::dynamic_pointer_cast<MDEventWorkspace3Lean>(  Mantid::API::AnalysisDataService::Instance().retrieve(wsName) );
 }
Пример #2
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& )
  {
  }
}