Skip to content

Commit

Permalink
Re add saving to generic reductions
Browse files Browse the repository at this point in the history
Refs #10855
  • Loading branch information
DanNixon committed Jan 13, 2015
1 parent bbe37ec commit ca008d2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
Expand Up @@ -54,6 +54,7 @@ public slots:
std::string reflection = "");

void runGenericReduction(QString instName, QString mode);
void saveGenericReductions();
void runOSIRISdiffonlyReduction();

private:
Expand Down
Expand Up @@ -52,12 +52,14 @@ IndirectDiffractionReduction::IndirectDiffractionReduction(QWidget *parent) :
connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(plotResults(bool)));
}


///Destructor
IndirectDiffractionReduction::~IndirectDiffractionReduction()
{
saveSettings();
}


/**
* Runs a diffraction reduction when the user clieks Run.
*/
Expand Down Expand Up @@ -88,6 +90,7 @@ void IndirectDiffractionReduction::demonRun()
}
}


/**
* Handles plotting result spectra from algorithm chains.
*
Expand All @@ -112,6 +115,8 @@ void IndirectDiffractionReduction::plotResults(bool error)

diffResultsGroup->removeAll();
AnalysisDataService::Instance().remove("IndirectDiffraction_Workspaces");

saveGenericReductions();
}

QString instName = m_uiForm.cbInst->currentText();
Expand All @@ -136,6 +141,66 @@ void IndirectDiffractionReduction::plotResults(bool error)
runPythonCode(pyInput);
}


/**
* Handles saving the reductions from the generic algorithm.
*/
void IndirectDiffractionReduction::saveGenericReductions()
{
for(auto it = m_plotWorkspaces.begin(); it != m_plotWorkspaces.end(); ++it)
{
std::string wsName = *it;

if(m_uiForm.ckGSS->isChecked())
{
std::string tofWsName = wsName + "_tof";

// Convert to TOF for GSS
IAlgorithm_sptr convertUnits = AlgorithmManager::Instance().create("ConvertUnits");
convertUnits->initialize();
convertUnits->setProperty("InputWorkspace", wsName);
convertUnits->setProperty("OutputWorkspace", tofWsName);
convertUnits->setProperty("Target", "TOF");
m_batchAlgoRunner->addAlgorithm(convertUnits);

BatchAlgorithmRunner::AlgorithmRuntimeProps inputFromConvUnitsProps;
inputFromConvUnitsProps["InputWorkspace"] = tofWsName;

// Save GSS
std::string gssFilename = wsName + ".gss";
IAlgorithm_sptr saveGSS = AlgorithmManager::Instance().create("SaveGSS");
saveGSS->initialize();
saveGSS->setProperty("Filename", gssFilename);
m_batchAlgoRunner->addAlgorithm(saveGSS, inputFromConvUnitsProps);
}

if(m_uiForm.ckNexus->isChecked())
{
// Save NEXus using SaveNexusProcessed
std::string nexusFilename = wsName + ".nxs";
IAlgorithm_sptr saveNexus = AlgorithmManager::Instance().create("SaveNexusProcessed");
saveNexus->initialize();
saveNexus->setProperty("InputWorkspace", wsName);
saveNexus->setProperty("Filename", nexusFilename);
m_batchAlgoRunner->addAlgorithm(saveNexus);
}

if(m_uiForm.ckAscii->isChecked())
{
// Save ASCII using SaveAscii version 1
std::string asciiFilename = wsName + ".dat";
IAlgorithm_sptr saveASCII = AlgorithmManager::Instance().create("SaveAscii", 1);
saveASCII->initialize();
saveASCII->setProperty("InputWorkspace", wsName);
saveASCII->setProperty("Filename", asciiFilename);
m_batchAlgoRunner->addAlgorithm(saveASCII);
}
}

m_batchAlgoRunner->executeBatchAsync();
}


/**
* Runs a diffraction reduction for any instrument in any mode.
*
Expand Down Expand Up @@ -183,11 +248,10 @@ void IndirectDiffractionReduction::runGenericReduction(QString instName, QString

m_batchAlgoRunner->addAlgorithm(msgDiffReduction);

//TODO: saving

m_batchAlgoRunner->executeBatchAsync();
}


/**
* Runs a diffraction reduction for OSIRIS operating in diffonly mode using the OSIRISDiffractionReduction algorithm.
*/
Expand Down Expand Up @@ -268,6 +332,7 @@ void IndirectDiffractionReduction::runOSIRISdiffonlyReduction()
m_batchAlgoRunner->executeBatchAsync();
}


/**
* Loads an empty instrument and returns a pointer to the workspace.
*
Expand Down Expand Up @@ -307,6 +372,7 @@ MatrixWorkspace_sptr IndirectDiffractionReduction::loadInstrument(std::string in
return instWorkspace;
}


/**
* Handles loading an instrument and reflections when an instruiment is selected form the drop down.
*/
Expand Down Expand Up @@ -336,6 +402,7 @@ void IndirectDiffractionReduction::instrumentSelected(int)
m_uiForm.cbReflection->blockSignals(false);
}


/**
* Handles setting default spectra range when a reflection is slected from the drop down.
*/
Expand Down Expand Up @@ -390,6 +457,7 @@ void IndirectDiffractionReduction::reflectionSelected(int)
}
}


/**
* Handles opening the directory manager window.
*/
Expand All @@ -400,6 +468,7 @@ void IndirectDiffractionReduction::openDirectoryDialog()
ad->setFocus();
}


/**
* Handles the user clicking the help button.
*/
Expand All @@ -409,6 +478,7 @@ void IndirectDiffractionReduction::help()
QDesktopServices::openUrl(QUrl(url));
}


/**
* Sets up UI components and Qt signal/slot connections.
*/
Expand Down Expand Up @@ -447,11 +517,13 @@ void IndirectDiffractionReduction::initLayout()
validateRebin();
}


void IndirectDiffractionReduction::initLocalPython()
{
instrumentSelected(0);
}


void IndirectDiffractionReduction::loadSettings()
{
QSettings settings;
Expand All @@ -466,6 +538,7 @@ void IndirectDiffractionReduction::loadSettings()
settings.endGroup();
}


void IndirectDiffractionReduction::saveSettings()
{
QSettings settings;
Expand All @@ -476,6 +549,7 @@ void IndirectDiffractionReduction::saveSettings()
settings.endGroup();
}


/**
* Validates the rebinning fields and updates invalid markers.
*
Expand Down Expand Up @@ -525,6 +599,7 @@ bool IndirectDiffractionReduction::validateRebin()
return rebinValid;
}


/**
* Checks to see if the vanadium and cal file fields are valid.
*
Expand All @@ -541,6 +616,7 @@ bool IndirectDiffractionReduction::validateVanCal()
return true;
}


/**
* Disables and shows message on run button indicating that run files have benn changed.
*/
Expand All @@ -550,6 +626,7 @@ void IndirectDiffractionReduction::runFilesChanged()
m_uiForm.pbRun->setText("Editing...");
}


/**
* Disables and shows message on run button to indicate searching for data files.
*/
Expand All @@ -559,6 +636,7 @@ void IndirectDiffractionReduction::runFilesFinding()
m_uiForm.pbRun->setText("Finding files...");
}


/**
* Updates run button with result of file search.
*/
Expand All @@ -578,6 +656,7 @@ void IndirectDiffractionReduction::runFilesFound()
m_uiForm.dem_ckSumFiles->setChecked(false);
}


/**
* Handles the user toggling the individual grouping check box.
*
Expand Down

0 comments on commit ca008d2

Please sign in to comment.