Skip to content

Commit

Permalink
Refs #6473. Pass loading algorithm to the dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Dec 13, 2013
1 parent b28b209 commit 78debd2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
Expand Up @@ -45,7 +45,7 @@ namespace MantidWidgets
Q_OBJECT

public:
MuonSequentialFitDialog(MuonFitPropertyBrowser* fitPropBrowser);
MuonSequentialFitDialog(MuonFitPropertyBrowser* fitPropBrowser, Algorithm_sptr loadAlg);
virtual ~MuonSequentialFitDialog();

enum DialogState
Expand Down Expand Up @@ -88,6 +88,9 @@ namespace MantidWidgets
/// Whether user requested fitting to be stopped
bool m_stopRequested;

/// Algorithm the dialog should use for loading
Algorithm_sptr m_loadAlg;

// -- STATIC MEMBERS ------------------------------------------------------

/// Checks if specified name is valid as a name for label.
Expand Down
53 changes: 23 additions & 30 deletions Code/Mantid/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp
Expand Up @@ -2,6 +2,7 @@
#include "MantidQtMantidWidgets/MuonFitPropertyBrowser.h"

#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmProxy.h"

namespace MantidQt
{
Expand All @@ -12,11 +13,11 @@ namespace MantidWidgets

Logger& MuonSequentialFitDialog::g_log(Logger::get("MuonSequentialFitDialog"));
/**
* Constructor
*/
MuonSequentialFitDialog::MuonSequentialFitDialog(MuonFitPropertyBrowser* fitPropBrowser) :
QDialog(fitPropBrowser), m_fitPropBrowser(fitPropBrowser)
MuonSequentialFitDialog::MuonSequentialFitDialog(MuonFitPropertyBrowser* fitPropBrowser,
Algorithm_sptr loadAlg) :
QDialog(fitPropBrowser), m_fitPropBrowser(fitPropBrowser), m_loadAlg(loadAlg)
{
m_ui.setupUi(this);

Expand Down Expand Up @@ -292,20 +293,26 @@ namespace MantidWidgets
if ( m_stopRequested )
break;

Workspace_sptr loadedWS;
MatrixWorkspace_sptr ws;

auto load = boost::dynamic_pointer_cast<AlgorithmProxy>( AlgorithmManager::Instance().create("MuonLoad") );
load->setChild(true);
load->setRethrows(true);
load->copyPropertiesFrom(*m_loadAlg);

try
{
// TODO: should be MuonLoad here
IAlgorithm_sptr loadAlg = AlgorithmManager::Instance().createUnmanaged("LoadMuonNexus");
loadAlg->setChild(true);
loadAlg->setRethrows(true);
loadAlg->initialize();
loadAlg->setPropertyValue( "Filename", fileIt->toStdString() );
loadAlg->setPropertyValue( "OutputWorkspace", "__YouDontSeeMeIAmNinja" ); // Is not used
loadAlg->execute();

loadedWS = loadAlg->getProperty("OutputWorkspace");
load->initialize();

load->setPropertyValue( "Filename", fileIt->toStdString() );
load->setPropertyValue( "OutputWorkspace", "__YouDontSeeMeIAmNinja" ); // Is not used

if ( m_fitPropBrowser->rawData() ) // TODO: or vice verca?
load->setPropertyValue( "RebinParams", "" );

load->execute();

ws = load->getProperty("OutputWorkspace");
}
catch(std::exception& e)
{
Expand All @@ -314,22 +321,9 @@ namespace MantidWidgets
break;
}

MatrixWorkspace_sptr ws;

if ( auto single = boost::dynamic_pointer_cast<MatrixWorkspace>(loadedWS) )
{
ws = single;
}
else if ( auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(loadedWS) )
{
auto first = boost::dynamic_pointer_cast<MatrixWorkspace>( group->getItem(0) );
ws = first;
}

const std::string runTitle = getRunTitle(ws);
const std::string wsBaseName = labelGroupName + "_" + runTitle;


IFunction_sptr functionToFit;

if ( useInitFitFunction )
Expand All @@ -339,12 +333,11 @@ namespace MantidWidgets
// Use the same function over and over, so that previous fitted params are used for the next fit
functionToFit = fitFunction;

IAlgorithm_sptr fit = AlgorithmManager::Instance().createUnmanaged("Fit");
IAlgorithm_sptr fit = AlgorithmManager::Instance().create("Fit");
fit->setRethrows(true);

try
{
fit->initialize();
fit->setRethrows(true);

// Set function. Gets updated when fit is done.
fit->setProperty("Function", functionToFit);
Expand Down

0 comments on commit 78debd2

Please sign in to comment.