Skip to content

Commit

Permalink
Refs #10438. Adjusted validateInputs in algorithms.
Browse files Browse the repository at this point in the history
This was done with an eye towards providing some level
of validation when possible.
  • Loading branch information
peterfpeterson committed Nov 7, 2014
1 parent f584272 commit 37efdbf
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
16 changes: 15 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/EditInstrumentGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,28 @@ namespace Algorithms

// everything depends on being parallel to the workspace # histo
size_t numHist(0);
bool hasWorkspacePtr(false);
{
MatrixWorkspace_const_sptr workspace = getProperty("Workspace");
numHist = workspace->getNumberHistograms();
// this is to guard against WorkspaceGroups
// fallthrough is to skip workspace check and make sure
if (bool(workspace)) {
hasWorkspacePtr = true;
numHist = workspace->getNumberHistograms();
}
}

std::string error;

const std::vector<int32_t> specids = this->getProperty("SpectrumIDs");
if (!hasWorkspacePtr) {
// use the number of spectra for the number of histograms
numHist = specids.size();
// give up if it is empty
if (numHist == 0) {
return result;
}
}
error = checkValues(specids, numHist);
if (!error.empty())
result["SpectrumIDs"] = error;
Expand Down
7 changes: 6 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/FilterByLogValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ std::map<std::string, std::string> FilterByLogValue::validateInputs()
{
std::map<std::string, std::string> errors;

// Check that the log exists for the given input workspace
// check for null pointers - this is to protect against workspace groups
EventWorkspace_const_sptr inputWS = this->getProperty("InputWorkspace");
if (!inputWS) {
return errors;
}

// Check that the log exists for the given input workspace
std::string logname = getPropertyValue("LogName");
try {
ITimeSeriesProperty * log = dynamic_cast<ITimeSeriesProperty*>( inputWS->run().getLogData(logname) );
Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/PDFFourierTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ namespace Mantid
if (Qmax <= Qmin)
result["Qmax"] = "Must be greater than Qmin";

// check for null pointers - this is to protect against workspace groups
API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace");
if (!inputWS) {
return result;
}

if (inputWS->getNumberHistograms() != 1)
{
result["InputWorkspace"] = "Input workspace must have only one spectrum";
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/SumEventsByLogValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ namespace Algorithms
{
std::map<std::string, std::string> errors;

// check for null pointers - this is to protect against workspace groups
m_inputWorkspace = getProperty("InputWorkspace");
if (!m_inputWorkspace) {
return errors;
}

// This only works for unweighted events
// TODO: Either turn this check into a proper validator or amend the algorithm to work for weighted events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ namespace DataHandling

// get the input paramters
string filename = getPropertyValue(PARAM_IN_FILE);
MatrixWorkspace_sptr inWS = getProperty(PARAM_IN_WKSP);
string inWSname = getPropertyValue(PARAM_IN_WKSP);
string instName = getPropertyValue(PARAM_INST_NAME);
string instFilename = getPropertyValue(PARAM_INST_FILE);

// count how many ways the input instrument was specified
int numInst = 0;
if (!filename.empty()) numInst++;
if (inWS) numInst++;
if (!inWSname.empty()) numInst++;
if (!instName.empty()) numInst++;
if (!instFilename.empty()) numInst++;

Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/DataHandling/src/SavePDFGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ namespace DataHandling
std::map<std::string, std::string> SavePDFGui::validateInputs(){
std::map<std::string, std::string> result;

// check for null pointers - this is to protect against workspace groups
API::MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace");
if (!inputWS){
return result;
}

const int nHist = static_cast<int> (inputWS->getNumberHistograms());
if (nHist != 1)
{
Expand Down

0 comments on commit 37efdbf

Please sign in to comment.