Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/8023_converttomd_validat…
Browse files Browse the repository at this point in the history
…einputs'
  • Loading branch information
AndreiSavici committed Oct 11, 2013
2 parents 4a4c3b8 + af06ec6 commit dfe7bc3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ namespace MDAlgorithms
~ConvertToMD();

/// Algorithm's name for identification
virtual const std::string name() const { return "ConvertToMD";};
virtual const std::string name() const;
/// Algorithm's version for identification
virtual int version() const { return 1;};
virtual int version() const;
/// Algorithm's category for identification
virtual const std::string category() const { return "MDAlgorithms";}
virtual const std::string category() const;


private:
void init();
std::map<std::string, std::string> validateInputs();
void exec();
/// Sets documentation strings for this algorithm
virtual void initDocs();
Expand Down
58 changes: 58 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ inline bool isNaN(T val)
volatile T buf=val;
return (val!=buf);
}

const std::string ConvertToMD::name() const
{
return "ConvertToMD";
}

int ConvertToMD::version() const
{
return 1;
}

const std::string ConvertToMD::category() const
{
return "MDAlgorithms";
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
Expand Down Expand Up @@ -352,6 +368,48 @@ ConvertToMD::init()

}

std::map<std::string, std::string> ConvertToMD::validateInputs()
{
std::map<std::string, std::string> result;

std::vector<double> minVals = this->getProperty("MinValues");
std::vector<double> maxVals = this->getProperty("MaxValues");

if (minVals.size() != maxVals.size())
{
std::stringstream msg;
msg << "Rank of MinValues != MaxValues (" << minVals.size() << "!=" << maxVals.size() << ")";
result["MinValues"] = msg.str();
result["MaxValues"] = msg.str();
}
else
{
std::stringstream msg;

size_t rank = minVals.size();
for (size_t i = 0; i < rank; ++i)
{
if (minVals[i] >= maxVals[i])
{
if (msg.str().empty())
msg << "max not bigger than min ";
else
msg << ", ";
msg << "at index=" << (i+1) << " ("
<< minVals[i] << ">=" << maxVals[i] << ")";
}
}

if (!msg.str().empty())
{
result["MinValues"] = msg.str();
result["MaxValues"] = msg.str();
}
}

return result;
}

//----------------------------------------------------------------------------------------------
/* Execute the algorithm. */
void ConvertToMD::exec()
Expand Down
6 changes: 2 additions & 4 deletions Code/Mantid/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ void testExecFailsOnNewWorkspaceNoMaxLimits(){
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("OutputWorkspace", "EnergyTransfer4DWS"));
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("MinValues", "-50.,-50.,-50,-2"));

pAlg->execute();
TSM_ASSERT("Should fail as no max limits were specified ",!pAlg->isExecuted());
TSM_ASSERT_THROWS("Should fail as no max limits were specified ",pAlg->execute(), std::runtime_error);

}
void testExecFailsLimits_MinGeMax(){
Expand All @@ -106,8 +105,7 @@ void testExecFailsLimits_MinGeMax(){
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("MinValues", "-50.,-50.,-50,-2"));
TS_ASSERT_THROWS_NOTHING(pAlg->setPropertyValue("MaxValues", " 50., 50.,-50,-2"));

pAlg->execute();
TSM_ASSERT("Should fail as wrong max limits were specified ",!pAlg->isExecuted());
TSM_ASSERT_THROWS("Should fail as wrong max limits were specified ",pAlg->execute(), std::runtime_error);

}
void testExecFine(){
Expand Down

0 comments on commit dfe7bc3

Please sign in to comment.