Skip to content

Commit

Permalink
Refs #5453, #5623, #5655 and #5678. Major changes.
Browse files Browse the repository at this point in the history
I had to a lot of major changes to stop workspaces from getting stomped on.
I had to turn off reliance on the ADS and pass workspace pointers around by
hand to keep things separated.
  • Loading branch information
Michael Reuter committed Aug 3, 2012
1 parent 8d7c34a commit 346d66e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 117 deletions.
120 changes: 51 additions & 69 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/DgsDiagnose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ hand off to the DetectorDiagnostic algorithm.
#include "MantidWorkflowAlgorithms/DgsDiagnose.h"
#include "MantidAPI/PropertyManagerDataService.h"

#include <boost/pointer_cast.hpp>

using namespace Mantid::Kernel;
using namespace Mantid::API;

Expand Down Expand Up @@ -117,39 +119,37 @@ namespace WorkflowAlgorithms
const double samLo = 0.0;
const double bleedRate = reductionManager->getProperty("MaxFramerate");
const int bleedPixels = reductionManager->getProperty("IgnoredPixels");
//reductionManager->getProperty();
//reductionManager->getProperty();

// Make some internal names for workspaces
const std::string dvInternal = "__det_van";
const std::string dvCompInternal = "__det_van_comp";
const std::string sampleInternal = "__sample";
const std::string bkgInternal = "__background_int";
const std::string countsInternal = "__total_counts";
const std::string dvInternal = "_det_van";
const std::string dvCompInternal = "_det_van_comp";
const std::string sampleInternal = "_sample";
const std::string bkgInternal = "_background_int";
const std::string countsInternal = "_total_counts";

// Clone the incoming workspace
IAlgorithm_sptr cloneWs = this->createSubAlgorithm("CloneWorkspace");
cloneWs->setProperty("InputWorkspace", detVanWS);
cloneWs->executeAsSubAlg();
// CloneWorkspace returns Workspace_sptr
Workspace_sptr tmp = cloneWs->getProperty("OutputWorkspace");
MatrixWorkspace_sptr dvWS = boost::static_pointer_cast<MatrixWorkspace>(tmp);
dvWS->setName(dvInternal);

// Process the detector vanadium
IAlgorithm_sptr detVan = this->createSubAlgorithm("DgsProcessDetectorVanadium");
detVan->setAlwaysStoreInADS(true);
detVan->setProperty("InputWorkspace", detVanWS);
detVan->setProperty("OutputWorkspace", dvInternal);
detVan->setProperty("InputWorkspace", dvWS);
detVan->setProperty("ReductionProperties", reductionManagerName);
detVan->executeAsSubAlg();
dvWS = detVan->getProperty("OutputWorkspace");

// Process the comparison detector vanadium workspace if present
MatrixWorkspace_sptr dvCompWS;
if (detVanCompWS)
{
detVan->setProperty("InputWorkspace", detVanCompWS);
detVan->setProperty("OutputWorkspace", dvCompInternal);
detVan->executeAsSubAlg();
}

AnalysisDataServiceImpl & dataStore = AnalysisDataService::Instance();
// Get the processed workspaces for possible later use.
MatrixWorkspace_sptr dvWS = dataStore.retrieveWS<MatrixWorkspace>(dvInternal);
MatrixWorkspace_sptr dvCompWS;
if (dataStore.doesExist(dvCompInternal))
{
dvCompWS = dataStore.retrieveWS<MatrixWorkspace>(dvCompInternal);
dvCompWS = detVan->getProperty("OutputWorkspace");
}
else
{
Expand All @@ -161,40 +161,37 @@ namespace WorkflowAlgorithms
{
sampleWS = this->getProperty("SampleWorkspace");

IAlgorithm_sptr cloneWs = this->createSubAlgorithm("CloneWorkspace");
cloneWs->setProperty("InputWorkspace", sampleWS);
cloneWs->executeAsSubAlg();
Workspace_sptr tmp = cloneWs->getProperty("OutputWorkspace");
sampleWS = boost::static_pointer_cast<MatrixWorkspace>(tmp);
sampleWS->setName(sampleInternal);

IAlgorithm_sptr norm = this->createSubAlgorithm("DgsPreprocessData");
norm->setAlwaysStoreInADS(true);
norm->setProperty("InputWorkspace", sampleWS);
norm->setProperty("OutputWorkspace", sampleInternal);
norm->setProperty("ReductionProperties", reductionManagerName);
norm->executeAsSubAlg();
}

// Handle case where one of the other tests (checkBkg or rejectZeroBkg)
// are requested, but not createPsdBleed.
if (createPsdBleed)
{
sampleWS = dataStore.retrieveWS<MatrixWorkspace>(sampleInternal);
}
else
{
sampleWS = boost::shared_ptr<MatrixWorkspace>();
tmp = cloneWs->getProperty("OutputWorkspace");
sampleWS = boost::static_pointer_cast<MatrixWorkspace>(tmp);
//sampleWS->setName(sampleInternal);
}

// Create the total counts workspace if necessary
MatrixWorkspace_sptr totalCountsWS;
if (rejectZeroBkg)
{
IAlgorithm_sptr integrate = this->createSubAlgorithm("Integration");
integrate->setAlwaysStoreInADS(true);
integrate->setProperty("InputWorkspace", sampleInternal);
integrate->setProperty("OutputWorkspace", countsInternal);
integrate->setProperty("InputWorkspace", sampleWS);
integrate->setPropertyValue("OutputWorkspace", countsInternal);
integrate->setProperty("IncludePartialBins", true);
integrate->executeAsSubAlg();

g_log.warning() << "Total Counts being used" << std::endl;
totalCountsWS = integrate->getProperty("OutputWorkspace");
}
else
{
g_log.warning() << "Total Counts NOT being used" << std::endl;
totalCountsWS = boost::shared_ptr<MatrixWorkspace>();
}

Expand All @@ -206,40 +203,24 @@ namespace WorkflowAlgorithms
const double rangeEnd = reductionManager->getProperty("BackgroundTofEnd");

IAlgorithm_sptr integrate = this->createSubAlgorithm("Integration");
integrate->setAlwaysStoreInADS(true);
integrate->setProperty("InputWorkspace", sampleInternal);
integrate->setProperty("OutputWorkspace", bkgInternal);
integrate->setProperty("InputWorkspace", sampleWS);
integrate->setPropertyValue("OutputWorkspace", bkgInternal);
integrate->setProperty("RangeLower", rangeStart);
integrate->setProperty("RangeUpper", rangeEnd);
integrate->setProperty("IncludePartialBins", true);
integrate->executeAsSubAlg();
backgroundIntWS = integrate->getProperty("OutputWorkspace");

IAlgorithm_sptr cvu = this->createSubAlgorithm("ConvertUnits");
cvu->setAlwaysStoreInADS(true);
cvu->setProperty("InputWorkspace", bkgInternal);
cvu->setProperty("OutputWorkspace", bkgInternal);
cvu->setProperty("InputWorkspace", backgroundIntWS);
cvu->setProperty("OutputWorkspace", backgroundIntWS);
cvu->setProperty("Target", "Energy");
cvu->executeAsSubAlg();
backgroundIntWS = cvu->getProperty("OutputWorkspace");

backgroundIntWS = dataStore.retrieveWS<MatrixWorkspace>(bkgInternal);
// What is this magic value !?!?!?!?
backgroundIntWS *= 1.7016e8;
/*
const std::string scaleFactor = "__sample_bkg_sf";
IAlgorithm_sptr svw = this->createSubAlgorithm("CreateSingleValuedWorkspace");
svw->setAlwaysStoreInADS(true);
svw->setProperty("OutputWorkspace", scaleFactor);
// What is this magic value !?!?!?!?
svw->setProperty("DataValue", 1.7016e8);
svw->executeAsSubAlg();
IAlgorithm_sptr mult = this->createSubAlgorithm("Multiply");
mult->setAlwaysStoreInADS(true);
mult->setProperty("LHSWorkspace", bkgInternal);
mult->setProperty("RHSWorkspace", scaleFactor);
mult->setProperty("OutputWorkspace", bkgInternal);
mult->executeAsSubAlg();
*/

// Normalise the background integral workspace
if (dvCompWS)
{
Expand All @@ -258,9 +239,15 @@ namespace WorkflowAlgorithms
backgroundIntWS = boost::shared_ptr<MatrixWorkspace>();
}

// Handle case where one of the other tests (checkBkg or rejectZeroBkg)
// are requested, but not createPsdBleed.
if (!createPsdBleed)
{
sampleWS = boost::shared_ptr<MatrixWorkspace>();
}

IAlgorithm_sptr diag = this->createSubAlgorithm("DetectorDiagnostic");
diag->setAlwaysStoreInADS(true);
diag->setProperty("InputWorkspace", dvInternal);
diag->setProperty("InputWorkspace", dvWS);
diag->setProperty("WhiteBeamCompare", dvCompWS);
diag->setProperty("SampleWorkspace", sampleWS);
diag->setProperty("SampleTotalCountsWorkspace", totalCountsWS);
Expand All @@ -276,18 +263,13 @@ namespace WorkflowAlgorithms
diag->setProperty("MaxTubeFramerate", bleedRate);
diag->setProperty("NIgnoredCentralPixels", bleedPixels);
diag->setProperty("OutputWorkspace", maskName);
//diag->setProperty("");
diag->executeAsSubAlg();

// Cleanup
dataStore.remove(dvInternal);
dataStore.remove(dvCompInternal);
dataStore.remove(sampleInternal);
dataStore.remove(countsInternal);
dataStore.remove(bkgInternal);
MatrixWorkspace_sptr maskWS = diag->getProperty("OutputWorkspace");

int numMasked = diag->getProperty("NumberOfFailures");
g_log.information() << "Number of masked pixels = " << numMasked << std::endl;
this->setProperty("OutputWorkspace", maskWS);
}

} // namespace WorkflowAlgorithms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ namespace WorkflowAlgorithms
*/
void DgsPreprocessData::init()
{
this->declareProperty(new WorkspaceProperty<>("InputWorkspace", "",
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "",
Direction::Input), "An input workspace.");
this->declareProperty(new WorkspaceProperty<>("OutputWorkspace", "",
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace", "",
Direction::Output, PropertyMode::Optional), "An output workspace.");
this->declareProperty("ReductionProperties", "__dgs_reduction_properties",
Direction::Input);
Expand Down Expand Up @@ -104,6 +104,7 @@ namespace WorkflowAlgorithms
MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
// Make output workspace name the same as input workspace
const std::string outWsName = inputWS->getName();
MatrixWorkspace_sptr outputWS;// = this->getProperty("OutputWorkspace");

std::string incidentBeamNorm = reductionManager->getProperty("IncidentBeamNormalisation");
g_log.notice() << "Incident beam norm method = " << incidentBeamNorm << std::endl;
Expand All @@ -121,9 +122,9 @@ namespace WorkflowAlgorithms
}
const std::string normAlg = "Normalise" + incidentBeamNorm;
IAlgorithm_sptr norm = this->createSubAlgorithm(normAlg);
norm->setAlwaysStoreInADS(true);
norm->setProperty("InputWorkspace", outWsName);
norm->setProperty("OutputWorkspace", outWsName);
//norm->setAlwaysStoreInADS(true);
norm->setProperty("InputWorkspace", inputWS);
norm->setPropertyValue("OutputWorkspace", outWsName);
if ("ToMonitor" == incidentBeamNorm)
{
// Perform extra setup for monitor normalisation
Expand Down Expand Up @@ -163,8 +164,10 @@ namespace WorkflowAlgorithms
}
norm->executeAsSubAlg();

outputWS = norm->getProperty("OutputWorkspace");

IAlgorithm_sptr addLog = this->createSubAlgorithm("AddSampleLog");
addLog->setProperty("Workspace", outWsName);
addLog->setProperty("Workspace", outputWS);
addLog->setProperty("LogName", doneLog);
addLog->setProperty("LogText", normAlg);
addLog->executeAsSubAlg();
Expand All @@ -177,7 +180,6 @@ namespace WorkflowAlgorithms
}
}

MatrixWorkspace_sptr outputWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWsName);
this->setProperty("OutputWorkspace", outputWS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ namespace WorkflowAlgorithms
{
auto wsValidator = boost::make_shared<CompositeValidator>();
wsValidator->add<WorkspaceUnitValidator>("TOF");
this->declareProperty(new WorkspaceProperty<>("InputWorkspace", "", Direction::Input, wsValidator),
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "", Direction::Input, wsValidator),
"An input workspace containing the detector vanadium data in TOF units.");
this->declareProperty(new WorkspaceProperty<>("OutputWorkspace", "", Direction::Output),
this->declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace", "", Direction::Output),
"The workspace containing the processed results.");
this->declareProperty("ReductionProperties", "__dgs_reduction_properties",
Direction::Output);
Expand All @@ -93,25 +93,24 @@ namespace WorkflowAlgorithms

this->enableHistoryRecordingForChild(true);

MatrixWorkspace_const_sptr inputWS = this->getProperty("InputWorkspace");
const std::string inWsName = inputWS->getName();
const std::string outWsName = inWsName + "_idetvan";
MatrixWorkspace_sptr inputWS = this->getProperty("InputWorkspace");
const std::string outWsName = inputWS->getName() + "_idetvan";
MatrixWorkspace_sptr outputWS;

// Normalise result workspace to incident beam parameter
IAlgorithm_sptr norm = this->createSubAlgorithm("DgsPreprocessData");
norm->setAlwaysStoreInADS(true);
norm->setProperty("InputWorkspace", inWsName);
norm->setProperty("OutputWorkspace", outWsName);
norm->execute();
norm->setProperty("InputWorkspace", inputWS);
norm->executeAsSubAlg();
outputWS = norm->getProperty("OutputWorkspace");

const std::string hardMaskWsName = reductionManager->getProperty("HardMaskWorkspace");
if (!hardMaskWsName.empty())
{
IAlgorithm_sptr mask = this->createSubAlgorithm("MaskDetectors");
mask->setAlwaysStoreInADS(true);
mask->setProperty("Workspace", outWsName);
mask->setProperty("MaskedWorkspace", hardMaskWsName);
mask->execute();
mask->setProperty("Workspace", outputWS);
mask->setPropertyValue("MaskedWorkspace", hardMaskWsName);
mask->executeAsSubAlg();
outputWS = mask->getProperty("Workspace");
}

double detVanIntRangeLow = reductionManager->getProperty("DetVanIntRangeLow");
Expand All @@ -130,12 +129,12 @@ namespace WorkflowAlgorithms
{
// Convert the data to the appropriate units
IAlgorithm_sptr cnvun = this->createSubAlgorithm("ConvertUnits");
cnvun->setAlwaysStoreInADS(true);
cnvun->setProperty("InputWorkspace", outWsName);
cnvun->setProperty("OutputWorkspace", outWsName);
cnvun->setProperty("InputWorkspace", outputWS);
cnvun->setProperty("OutputWorkspace", outputWS);
cnvun->setProperty("Target", detVanIntRangeUnits);
cnvun->setProperty("EMode", "Elastic");
cnvun->execute();
cnvun->executeAsSubAlg();
outputWS = cnvun->getProperty("OutputWorkspace");
}

// Rebin the data (not Integration !?!?!?)
Expand All @@ -145,33 +144,20 @@ namespace WorkflowAlgorithms
binning.push_back(detVanIntRangeHigh);

IAlgorithm_sptr rebin = this->createSubAlgorithm("Rebin");
rebin->setAlwaysStoreInADS(true);
rebin->setProperty("InputWorkspace", outWsName);
rebin->setProperty("OutputWorkspace", outWsName);
rebin->setProperty("InputWorkspace", outputWS);
rebin->setProperty("OutputWorkspace", outputWS);
rebin->setProperty("Params", binning);
rebin->execute();
rebin->executeAsSubAlg();
outputWS = rebin->getProperty("OutputWorkspace");

const std::string facility = ConfigService::Instance().getFacility().name();
if ("ISIS" == facility)
{
// Scale results by a constant
double wbScaleFactor = inputWS->getInstrument()->getNumberParameter("wb-scale-factor")[0];
const std::string scaleFactorName = "WbScaleFactor";
IAlgorithm_sptr csvw = this->createSubAlgorithm("CreateSingleValuedWorkspace");
csvw->setAlwaysStoreInADS(true);
csvw->setProperty("OutputWorkspace", scaleFactorName);
csvw->setProperty("DataValue", wbScaleFactor);
csvw->execute();

IAlgorithm_sptr mult = this->createSubAlgorithm("Multiply");
mult->setAlwaysStoreInADS(true);
mult->setProperty("LHSWorkspace", outWsName);
mult->setProperty("RHSWorkspace", scaleFactorName);
mult->setProperty("OutputWorkspace", outWsName);
mult->execute();
outputWS *= wbScaleFactor;
}

MatrixWorkspace_sptr outputWS = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outWsName);
this->setProperty("OutputWorkspace", outputWS);
}

Expand Down
16 changes: 10 additions & 6 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/DgsReduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,16 @@ namespace WorkflowAlgorithms
Workspace_sptr idetVanWS;
if (detVanWS)
{
IAlgorithm_sptr diag = this->createSubAlgorithm("DgsDiagnose");
diag->setProperty("DetVanWorkspace", detVanWS);
diag->setProperty("SampleWorkspace", sampleWS);
diag->setProperty("ReductionProperties", reductionManagerName);
diag->executeAsSubAlg();

const bool runDiag = this->getProperty("FindBadDetectors");
if (runDiag)
{
IAlgorithm_sptr diag = this->createSubAlgorithm("DgsDiagnose");
diag->setProperty("DetVanWorkspace", detVanWS);
diag->setProperty("SampleWorkspace", sampleWS);
diag->setProperty("OutputWorkspace", "samDetVanProcMask");
diag->setProperty("ReductionProperties", reductionManagerName);
diag->executeAsSubAlg();
}
detVan = this->createSubAlgorithm("DgsProcessDetectorVanadium");
detVan->setProperty("InputWorkspace", detVanWS);
detVan->setProperty("ReductionProperties", reductionManagerName);
Expand Down

0 comments on commit 346d66e

Please sign in to comment.