Skip to content

Commit

Permalink
Refs #4814. Faster isMonitor implementation.
Browse files Browse the repository at this point in the history
Much like isDetectorMasked, isMonitor removes the need to make temporary
copies of objects.
  • Loading branch information
peterfpeterson committed Feb 21, 2012
1 parent d902b39 commit fc17b2b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
30 changes: 12 additions & 18 deletions Code/Mantid/Framework/Algorithms/src/FindDetectorsOutsideLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ namespace Mantid
const int diagLength = static_cast<int>(countsWS->getNumberHistograms());
const int progStep = static_cast<int>(std::ceil(diagLength / 100.0));

bool checkForMask = false;
Geometry::Instrument_const_sptr instrument = inputWS->getInstrument();
if (instrument != NULL)
{
checkForMask = ((instrument->getSource() != NULL) && (instrument->getSample() != NULL));
}

int numFailed(0);
PARALLEL_FOR2(countsWS, outputWS)
for (int i = 0; i < diagLength; ++i)
Expand All @@ -136,29 +143,16 @@ namespace Mantid
progress(static_cast<double>(i)/diagLength);
interruption_point();
}
IDetector_const_sptr det;
try
{
det = countsWS->getDetector(i);
}
catch(Exception::NotFoundError&)

if (instrument->isMonitor(i))
{
continue; // do include or exclude from mask
}
// Mark no detector spectra as failed
if( !det )

if (instrument->isDetectorMasked(i))
{
keepData = false;
}
else
{
if( det->isMasked() )
keepData = false;
if( det->isMonitor() )
{
// Don't include but don't mask either
continue;
}
}

const double & yValue = countsWS->readY(i)[0];
// Mask out NaN and infinite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace Mantid
Kernel::V3D getBeamDirection() const;

IDetector_const_sptr getDetector(const detid_t &detector_id) const;
bool isMonitor(const detid_t &detector_id) const;
bool isDetectorMasked(const detid_t &detector_id) const;
bool isDetectorMasked(const std::set<detid_t> &detector_ids) const;

Expand Down
13 changes: 13 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,19 @@ namespace Mantid
}
}

bool Instrument::isMonitor(const detid_t &detector_id) const
{
// Find the (base) detector object in the map.
detid2det_map::const_iterator it = m_instr->m_detectorCache.find(detector_id);
if ( it == m_instr->m_detectorCache.end() )
return false;
// This is the detector
const Detector * det = dynamic_cast<const Detector*>(it->second.get());
if (det == NULL)
return false;
return det->isMonitor();
}

//--------------------------------------------------------------------------
/** Is the detector with the given ID masked?
*
Expand Down

0 comments on commit fc17b2b

Please sign in to comment.