Skip to content
Snippets Groups Projects
Commit 78e81e8d authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Refs #5321. Adding methods for setting/getting mask bit.

parent 09db11d1
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,9 @@ namespace DataObjects ...@@ -22,6 +22,9 @@ namespace DataObjects
~MaskWorkspace(); ~MaskWorkspace();
bool isMasked(const detid_t detectorID) const; bool isMasked(const detid_t detectorID) const;
bool isMasked(const std::set<detid_t> &detectorIDs) const;
void setMasked(const detid_t detectorID, const bool mask=true);
void setMasked(const std::set<detid_t> &detectorIDs, const bool mask=true);
std::size_t getNumberMasked() const; std::size_t getNumberMasked() const;
virtual const std::string id() const; virtual const std::string id() const;
......
...@@ -10,6 +10,20 @@ namespace DataObjects ...@@ -10,6 +10,20 @@ namespace DataObjects
//Register the workspace //Register the workspace
DECLARE_WORKSPACE(MaskWorkspace) DECLARE_WORKSPACE(MaskWorkspace)
namespace { // keep these constants only within this file.
/// The only value allowed for a pixel to be kept.
const double LIVE_VALUE = 0.;
/**
* The default value for marking a pixel to be masked. For checks
* anything that isn't live is dead.
*/
const double DEAD_VALUE = 1.;
/// The value for uncertainty.
const double ERROR_VALUE = 0.;
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
...@@ -74,13 +88,16 @@ namespace DataObjects ...@@ -74,13 +88,16 @@ namespace DataObjects
return numMasked; return numMasked;
} }
/**
* @return True if the data should be deleted.
*/
bool MaskWorkspace::isMasked(const detid_t detectorID) const bool MaskWorkspace::isMasked(const detid_t detectorID) const
{ {
if (!m_hasInstrument) if (!m_hasInstrument)
throw std::runtime_error("There is no instrument associated with the workspace"); throw std::runtime_error("There is no instrument associated with the workspace");
// return true if the value isn't zero // return true if the value isn't zero
if (this->getValue(detectorID, 0.) != 0.) if (this->getValue(detectorID, 0.) != LIVE_VALUE)
{ {
return true; return true;
} }
...@@ -89,6 +106,55 @@ namespace DataObjects ...@@ -89,6 +106,55 @@ namespace DataObjects
return this->getInstrument()->isDetectorMasked(detectorID); return this->getInstrument()->isDetectorMasked(detectorID);
} }
/**
* @return True if the data should be deleted.
*/
bool MaskWorkspace::isMasked(const std::set<detid_t> &detectorIDs) const
{
if (detectorIDs.empty())
{
return false;
}
bool masked(true);
for (std::set<detid_t>::const_iterator it = detectorIDs.begin(); it != detectorIDs.end(); ++it)
{
if (!this->isMasked(*it))
{
masked = false;
break; // allows space for a debug print statement
}
}
return masked;
}
/**
* Mask an individual pixel.
*
* @param detectorID to mask.
* @param mask True means to delete the data.
*/
void MaskWorkspace::setMasked(const detid_t detectorID, const bool mask)
{
double value(LIVE_VALUE);
if (mask)
value = DEAD_VALUE;
this->setValue(detectorID, value, ERROR_VALUE);
}
/**
* Mask a set of pixels. This is a convenience function to
* call @link MaskWorkspace::setMasked(const detid_t, const bool).
*/
void MaskWorkspace::setMasked(const std::set<detid_t> &detectorIDs, const bool mask)
{
for (auto detId = detectorIDs.begin(); detId != detectorIDs.end(); ++detId)
{
this->setMasked(*detId, mask);
}
}
/** /**
* Gets the name of the workspace type. * Gets the name of the workspace type.
* @return Standard string name * @return Standard string name
......
...@@ -44,6 +44,28 @@ public: ...@@ -44,6 +44,28 @@ public:
TS_ASSERT(maskWS->isMasked(0)); TS_ASSERT(maskWS->isMasked(0));
} }
void test_mask_accessors()
{
int pixels = 10;
int maskpixels = 25;
Mantid::Geometry::Instrument_sptr inst =
ComponentCreationHelper::createTestInstrumentRectangular2(1,pixels);
inst->setName("MaskWorkspaceTest_Accessors");
Mantid::DataObjects::MaskWorkspace* maskWS =
new Mantid::DataObjects::MaskWorkspace(inst, false);
for (int i = 0; i < maskpixels; i++)
maskWS->setMasked(i); // mask the pixel
TS_ASSERT_EQUALS(maskWS->getNumberHistograms(), pixels*pixels);
TS_ASSERT_EQUALS(maskWS->getNumberMasked(), maskpixels);
TS_ASSERT(maskWS->isMasked(0));
TS_ASSERT_EQUALS(maskWS->isMasked(maskpixels), false); // one past the masked ones
maskWS->setMasked(0, false);
TS_ASSERT_EQUALS(maskWS->isMasked(0), false);
}
}; };
#endif // MANTID_DATAOBJECTS_MASKWORKSPACETEST_H #endif // MANTID_DATAOBJECTS_MASKWORKSPACETEST_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment