Skip to content

Commit

Permalink
fix coverity 1076262-64 (dynamic_cast checks), re #11328
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Mar 12, 2015
1 parent d7efff8 commit a14f13a
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSLoad.cpp
Expand Up @@ -106,6 +106,10 @@ double getRunPropertyDbl(MatrixWorkspace_sptr inputWS,
Mantid::Kernel::Property *prop = inputWS->run().getProperty(pname);
Mantid::Kernel::PropertyWithValue<double> *dp =
dynamic_cast<Mantid::Kernel::PropertyWithValue<double> *>(prop);
if (!dp) {
throw std::runtime_error("Could not cast (interpret) the property " +
pname + " as a floating point numeric value.");
}
return *dp;
}

Expand Down Expand Up @@ -243,10 +247,11 @@ void EQSANSLoad::readSourceSlitSize(const std::string &line) {
num_str = posVec[3];
boost::regex re_size("\\w*?([0-9]+)mm");
int slit_size = 0;
boost::regex_search(num_str, posVec, re_size);
if (posVec.size() == 2) {
num_str = posVec[1];
Poco::NumberParser::tryParse(num_str, slit_size);
if (boost::regex_search(num_str, posVec, re_size)) {
if (posVec.size() == 2) {
num_str = posVec[1];
Poco::NumberParser::tryParse(num_str, slit_size);
}
}
m_slit_positions[wheel_number][slit_number] = slit_size;
}
Expand All @@ -262,17 +267,35 @@ void EQSANSLoad::getSourceSlitSize() {
return;
}

Mantid::Kernel::Property *prop = dataWS->run().getProperty("vBeamSlit");
const std::string slit1Name = "vBeamSlit";
Mantid::Kernel::Property *prop = dataWS->run().getProperty(slit1Name);
Mantid::Kernel::TimeSeriesProperty<double> *dp =
dynamic_cast<Mantid::Kernel::TimeSeriesProperty<double> *>(prop);
if (!dp) {
throw std::runtime_error("Could not cast (interpret) the property " +
slit1Name + " as a time series property with "
"floating point values.");
}
int slit1 = (int)dp->getStatistics().mean;

prop = dataWS->run().getProperty("vBeamSlit2");
const std::string slit2Name = "vBeamSlit2";
prop = dataWS->run().getProperty(slit2Name);
dp = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<double> *>(prop);
if (!dp) {
throw std::runtime_error("Could not cast (interpret) the property " +
slit2Name + " as a time series property with "
"floating point values.");
}
int slit2 = (int)dp->getStatistics().mean;

prop = dataWS->run().getProperty("vBeamSlit3");
const std::string slit3Name = "vBeamSlit3";
prop = dataWS->run().getProperty(slit3Name);
dp = dynamic_cast<Mantid::Kernel::TimeSeriesProperty<double> *>(prop);
if (!dp) {
throw std::runtime_error("Could not cast (interpret) the property " +
slit3Name + " as a time series property with "
"floating point values.");
}
int slit3 = (int)dp->getStatistics().mean;

if (slit1 < 0 && slit2 < 0 && slit3 < 0) {
Expand Down Expand Up @@ -527,9 +550,15 @@ void EQSANSLoad::exec() {
throw std::invalid_argument(
"Could not determine Z position: stopping execution");
}
Mantid::Kernel::Property *prop = dataWS->run().getProperty("detectorZ");

const std::string dzName = "detectorZ";
Mantid::Kernel::Property *prop = dataWS->run().getProperty(dzName);
Mantid::Kernel::TimeSeriesProperty<double> *dp =
dynamic_cast<Mantid::Kernel::TimeSeriesProperty<double> *>(prop);
if (!dp) {
throw std::runtime_error("Could not cast (interpret) the property " +
dzName + " as a time series property value.");
}
sdd = dp->getStatistics().mean;

// Modify SDD according to offset if given
Expand Down

0 comments on commit a14f13a

Please sign in to comment.