Skip to content

Commit

Permalink
fix coverity 1075403 (constructor init), re #11328
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Mar 12, 2015
1 parent ecfe4ba commit 27aaf76
Showing 1 changed file with 30 additions and 35 deletions.
65 changes: 30 additions & 35 deletions Code/Mantid/Framework/DataHandling/src/LoadMask.cpp
Expand Up @@ -47,13 +47,8 @@ DECLARE_ALGORITHM(LoadMask)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
LoadMask::LoadMask() {
// mMaskWS = NULL;
// mInstrumentName = "";
pDoc = NULL;
pRootElem = NULL;

return;
LoadMask::LoadMask(): m_MaskWS(), m_instrumentPropValue(""), m_pDoc(NULL),
m_pRootElem(NULL), m_DefaultToUse(true) {
}

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -92,9 +87,9 @@ void LoadMask::exec() {
m_instrumentPropValue = instrumentname;

this->intializeMaskWorkspace();
setProperty("OutputWorkspace", mMaskWS);
setProperty("OutputWorkspace", m_MaskWS);

mDefaultToUse = true;
m_DefaultToUse = true;

// 2. Parse Mask File
std::string filename = getProperty("InputFile");
Expand All @@ -107,7 +102,7 @@ void LoadMask::exec() {
boost::ends_with(filename, "K")) {
// 2.2 ISIS Masking file
loadISISMaskFile(filename);
mDefaultToUse = true;
m_DefaultToUse = true;
} else {
g_log.error() << "File " << filename << " is not in supported format. "
<< std::endl;
Expand Down Expand Up @@ -151,10 +146,10 @@ void LoadMask::exec() {

void LoadMask::initDetectors() {

if (!mDefaultToUse) { // Default is to use all detectors
size_t numHist = mMaskWS->getNumberHistograms();
if (!m_DefaultToUse) { // Default is to use all detectors
size_t numHist = m_MaskWS->getNumberHistograms();
for (size_t wkspIndex = 0; wkspIndex < numHist; wkspIndex++) {
mMaskWS->setMaskedIndex(wkspIndex);
m_MaskWS->setMaskedIndex(wkspIndex);
}
}

Expand All @@ -174,7 +169,7 @@ void LoadMask::processMaskOnDetectors(bool tomask,
std::vector<int32_t> pairdetids_up) {
// 1. Get index map
const detid2index_map indexmap =
mMaskWS->getDetectorIDToWorkspaceIndexMap(true);
m_MaskWS->getDetectorIDToWorkspaceIndexMap(true);

// 2. Mask
g_log.debug() << "Mask = " << tomask
Expand All @@ -188,9 +183,9 @@ void LoadMask::processMaskOnDetectors(bool tomask,
if (it != indexmap.end()) {
size_t index = it->second;
if (tomask)
mMaskWS->dataY(index)[0] = 1;
m_MaskWS->dataY(index)[0] = 1;
else
mMaskWS->dataY(index)[0] = 0;
m_MaskWS->dataY(index)[0] = 0;
} else {
g_log.error() << "Pixel w/ ID = " << detid << " Cannot Be Located"
<< std::endl;
Expand All @@ -212,7 +207,7 @@ void LoadMask::processMaskOnDetectors(bool tomask,
*/
void LoadMask::componentToDetectors(std::vector<std::string> componentnames,
std::vector<int32_t> &detectors) {
Geometry::Instrument_const_sptr minstrument = mMaskWS->getInstrument();
Geometry::Instrument_const_sptr minstrument = m_MaskWS->getInstrument();

for (size_t i = 0; i < componentnames.size(); i++) {
g_log.debug() << "Component name = " << componentnames[i] << std::endl;
Expand Down Expand Up @@ -280,7 +275,7 @@ void LoadMask::bankToDetectors(std::vector<std::string> singlebanks,
}
g_log.debug(infoss.str());

Geometry::Instrument_const_sptr minstrument = mMaskWS->getInstrument();
Geometry::Instrument_const_sptr minstrument = m_MaskWS->getInstrument();

for (size_t ib = 0; ib < singlebanks.size(); ib++) {
std::vector<Geometry::IDetector_const_sptr> idetectors;
Expand Down Expand Up @@ -336,7 +331,7 @@ void LoadMask::processMaskOnWorkspaceIndex(bool mask,
}

// 2. Get Map
const spec2index_map s2imap = mMaskWS->getSpectrumToWorkspaceIndexMap();
const spec2index_map s2imap = m_MaskWS->getSpectrumToWorkspaceIndexMap();
spec2index_map::const_iterator s2iter;

// 3. Set mask
Expand All @@ -356,19 +351,19 @@ void LoadMask::processMaskOnWorkspaceIndex(bool mask,
throw std::runtime_error("Logic error");
} else {
size_t wsindex = s2iter->second;
if (wsindex >= mMaskWS->getNumberHistograms()) {
if (wsindex >= m_MaskWS->getNumberHistograms()) {
// workspace index is out of range. bad branch
g_log.error() << "Group workspace's spec2index map is set wrong: "
<< " Found workspace index = " << wsindex
<< " for spectrum ID " << specid
<< " with workspace size = "
<< mMaskWS->getNumberHistograms() << std::endl;
<< m_MaskWS->getNumberHistograms() << std::endl;
} else {
// Finally set the group workspace. only good branch
if (mask)
mMaskWS->dataY(wsindex)[0] = 1.0;
m_MaskWS->dataY(wsindex)[0] = 1.0;
else
mMaskWS->dataY(wsindex)[0] = 0.0;
m_MaskWS->dataY(wsindex)[0] = 0.0;
} // IF-ELSE: ws index out of range
} // IF-ELSE: spectrum ID has an entry
} // FOR EACH SpecID
Expand Down Expand Up @@ -427,16 +422,16 @@ void LoadMask::initializeXMLParser(const std::string &filename) {
// Set up the DOM parser and parse xml file
DOMParser pParser;
try {
pDoc = pParser.parseString(xmlText);
m_pDoc = pParser.parseString(xmlText);
} catch (Poco::Exception &exc) {
throw Kernel::Exception::FileError(
exc.displayText() + ". Unable to parse File:", filename);
} catch (...) {
throw Kernel::Exception::FileError("Unable to parse File:", filename);
}
// Get pointer to root element
pRootElem = pDoc->documentElement();
if (!pRootElem->hasChildNodes()) {
m_pRootElem = m_pDoc->documentElement();
if (!m_pRootElem->hasChildNodes()) {
g_log.error("XML file: " + filename + "contains no root element.");
throw Kernel::Exception::InstrumentDefinitionError(
"No root element in XML instrument file", filename);
Expand All @@ -448,14 +443,14 @@ void LoadMask::initializeXMLParser(const std::string &filename) {
*/
void LoadMask::parseXML() {
// 0. Check
if (!pDoc)
if (!m_pDoc)
throw std::runtime_error("Call LoadMask::initialize() before parseXML.");

// 1. Parse and create a structure
Poco::AutoPtr<NodeList> pNL_type = pRootElem->getElementsByTagName("type");
Poco::AutoPtr<NodeList> pNL_type = m_pRootElem->getElementsByTagName("type");
g_log.information() << "Node Size = " << pNL_type->length() << std::endl;

Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::NodeIterator it(m_pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node *pNode = it.nextNode();

bool tomask = true;
Expand Down Expand Up @@ -515,17 +510,17 @@ void LoadMask::parseXML() {

} else if (pNode->nodeName().compare("detector-masking") == 0) {
// Node "detector-masking". Check default value
mDefaultToUse = true;
m_DefaultToUse = true;
/*
Poco::XML::NamedNodeMap* att = pNode->attributes();
if (att->length() > 0){
Poco::XML::Node* cNode = att->item(0);
mDefaultToUse = true;
m_DefaultToUse = true;
if (cNode->localName().compare("default") == 0){
if (cNode->getNodeValue().compare("use") == 0){
mDefaultToUse = true;
m_DefaultToUse = true;
} else {
mDefaultToUse = false;
m_DefaultToUse = false;
}
} // if - att-length
*/
Expand Down Expand Up @@ -861,9 +856,9 @@ void LoadMask::intializeMaskWorkspace() {
"Incorrect instrument name or invalid IDF given.");
}

mMaskWS = DataObjects::MaskWorkspace_sptr(
m_MaskWS = DataObjects::MaskWorkspace_sptr(
new DataObjects::MaskWorkspace(tempWs->getInstrument()));
mMaskWS->setTitle("Mask");
m_MaskWS->setTitle("Mask");
}

} // namespace Mantid
Expand Down

0 comments on commit 27aaf76

Please sign in to comment.