Commit 001407bf authored by Russell Taylor's avatar Russell Taylor
Browse files

Add a copy constructor to Instrument. Oh, and go on a const-correctness hunt...

Add a copy constructor to Instrument. Oh, and go on a const-correctness hunt that led this commit to touch slightly more than just the one class. Re #1944.
parent 170d60d3
......@@ -89,9 +89,9 @@ namespace Mantid
/**@name Instrument queries */
//@{
Geometry::IDetector_sptr getDetector(const size_t workspaceIndex) const;
Geometry::IDetector_sptr getDetector(const int workspaceIndex) const;
Geometry::IDetector_sptr getDetector(const int64_t workspaceIndex) const;
Geometry::IDetector_const_sptr getDetector(const size_t workspaceIndex) const;
Geometry::IDetector_const_sptr getDetector(const int workspaceIndex) const;
Geometry::IDetector_const_sptr getDetector(const int64_t workspaceIndex) const;
double detectorTwoTheta(Geometry::IDetector_const_sptr det) const;
double gravitationalDrop(Geometry::IDetector_const_sptr det, const double waveLength) const;
//@}
......
......@@ -262,11 +262,11 @@ void IFunctionMW::setMatrixWorkspace(boost::shared_ptr<const API::MatrixWorkspac
const Geometry::ParameterMap& paramMap = m_workspace->instrumentParameters();
Geometry::IDetector_sptr det = m_workspace->getDetector(wi);
Geometry::IDetector_const_sptr det = m_workspace->getDetector(wi);
// if det is a detector groupworkspace then take as the detector
// the detector returned by det->getID()
if ( boost::dynamic_pointer_cast<Geometry::DetectorGroup>(det) )
if ( boost::dynamic_pointer_cast<const Geometry::DetectorGroup>(det) )
{
Instrument_const_sptr inst = m_workspace->getInstrument();
det = inst->getDetector(det->getID());
......
......@@ -702,7 +702,7 @@ namespace Mantid
* @throw Kernel::Exception::NotFoundError if the SpectraDetectorMap or the Instrument
do not contain the requested spectrum number of detector ID
*/
Geometry::IDetector_sptr MatrixWorkspace::getDetector(const size_t workspaceIndex) const
Geometry::IDetector_const_sptr MatrixWorkspace::getDetector(const size_t workspaceIndex) const
{
const ISpectrum * spec = this->getSpectrum(workspaceIndex);
if (!spec)
......@@ -729,16 +729,16 @@ namespace Mantid
throw Kernel::Exception::NotFoundError("MatrixWorkspace::getDetector(): No detectors for this workspace index.", "");
}
// Else need to construct a DetectorGroup and return that
std::vector<Geometry::IDetector_sptr> dets_ptr = localInstrument->getDetectors(dets);
return Geometry::IDetector_sptr( new Geometry::DetectorGroup(dets_ptr, false) );
std::vector<Geometry::IDetector_const_sptr> dets_ptr = localInstrument->getDetectors(dets);
return Geometry::IDetector_const_sptr( new Geometry::DetectorGroup(dets_ptr, false) );
}
Geometry::IDetector_sptr MatrixWorkspace::getDetector(const int workspaceIndex) const
Geometry::IDetector_const_sptr MatrixWorkspace::getDetector(const int workspaceIndex) const
{
return this->getDetector(static_cast<size_t>(workspaceIndex));
}
Geometry::IDetector_sptr MatrixWorkspace::getDetector(const int64_t workspaceIndex) const
Geometry::IDetector_const_sptr MatrixWorkspace::getDetector(const int64_t workspaceIndex) const
{
return this->getDetector(static_cast<size_t>(workspaceIndex));
}
......@@ -1090,7 +1090,7 @@ namespace Mantid
{
try
{
if ( Geometry::Detector* det = dynamic_cast<Geometry::Detector*>(sptr_instrument->getDetector(*iter).get()) )
if ( const Geometry::Detector* det = dynamic_cast<const Geometry::Detector*>(sptr_instrument->getDetector(*iter).get()) )
{
m_parmap->addBool(det,"masked",true); // Thread-safe method
}
......@@ -1350,7 +1350,7 @@ namespace Mantid
verts[3] = Coordinate::createCoordinate2D(this->dataX(histogram)[bin+1], histogram_d+1.);
}
IDetector_sptr detector;
IDetector_const_sptr detector;
const ISpectrum * spec = this->getSpectrum(histogram);
if(spec->getDetectorIDs().size() > 0)
{
......
......@@ -208,7 +208,7 @@ public:
// Initially un masked
for( int i = 0; i < numHist; ++i )
{
IDetector_sptr det;
IDetector_const_sptr det;
TS_ASSERT_THROWS_NOTHING(det = workspace->getDetector(i));
if( det )
{
......@@ -224,14 +224,14 @@ public:
ISpectrum * spec = workspace->getSpectrum(0);
spec->addDetectorID(1);
spec->addDetectorID(2);
IDetector_sptr det;
IDetector_const_sptr det;
TS_ASSERT_THROWS_NOTHING(det = workspace->getDetector(0));
TS_ASSERT(det);
// Now an empty (no detector) pixel
spec = workspace->getSpectrum(1);
spec->clearDetectorIDs();
IDetector_sptr det2;
IDetector_const_sptr det2;
TS_ASSERT_THROWS_ANYTHING(det2 = workspace->getDetector(1));
TS_ASSERT(!det2);
}
......@@ -250,7 +250,7 @@ public:
TS_ASSERT_EQUALS(workspace->readY(i)[0], 1.0);
TS_ASSERT_EQUALS(workspace->readE(i)[0], 1.0);
IDetector_sptr det;
IDetector_const_sptr det;
TS_ASSERT_THROWS_NOTHING(det = workspace->getDetector(i));
if( det )
{
......@@ -282,7 +282,7 @@ public:
TS_ASSERT_EQUALS(workspace->readY(i)[0], expectedValue);
TS_ASSERT_EQUALS(workspace->readE(i)[0], expectedValue);
IDetector_sptr det;
IDetector_const_sptr det;
TS_ASSERT_THROWS_NOTHING(det = workspace->getDetector(i));
if( det )
{
......
......@@ -70,7 +70,7 @@ private:
///Execution code
void exec();
///Getting Efixed
double getEfixed(Geometry::IDetector_sptr detector, API::MatrixWorkspace_const_sptr inputWS, int emode) const;
double getEfixed(Geometry::IDetector_const_sptr detector, API::MatrixWorkspace_const_sptr inputWS, int emode) const;
};
} // namespace Algorithms
......
......@@ -103,7 +103,7 @@ class DLLExport DetectorEfficiencyCor : public API::Algorithm
/// Calculate one over the wave vector for 2 bin bounds
double calculateOneOverK(double loBinBound, double uppBinBound) const;
/// Sets the detector geometry cache if necessary
void getDetectorGeometry(boost::shared_ptr<Geometry::IDetector> det, double & detRadius, Kernel::V3D & detAxis);
void getDetectorGeometry(boost::shared_ptr<const Geometry::IDetector> det, double & detRadius, Kernel::V3D & detAxis);
/// Computes the distance to the given shape from a starting point
double distToSurface(const Kernel::V3D start, const Geometry::Object *shape) const;
/// Computes the detector efficiency for a given paramater
......
......@@ -75,7 +75,7 @@ private:
/// Correct the given spectra index for efficiency
void correctForEfficiency(std::size_t spectraIndex);
/// Sets the detector geometry cache if necessary
void getDetectorGeometry(boost::shared_ptr<Geometry::IDetector> det,
void getDetectorGeometry(boost::shared_ptr<const Geometry::IDetector> det,
double & detRadius, Kernel::V3D & detAxis);
/// Computes the distance to the given shape from a starting point
double distToSurface(const Kernel::V3D start,
......@@ -87,11 +87,11 @@ private:
void logErrors() const;
/// Retrieve the detector parameters from workspace or detector properties
double getParameter(std::string wsPropName, std::size_t currentIndex,
std::string detPropName, boost::shared_ptr<Geometry::IDetector> idet);
std::string detPropName, boost::shared_ptr<const Geometry::IDetector> idet);
/// Helper for event handling
template<class T> void eventHelper(std::vector<T>& events, double expval);
/// Function to calculate exponential contribution
double calculateExponential(std::size_t spectraIndex, boost::shared_ptr<Geometry::IDetector> idet);
double calculateExponential(std::size_t spectraIndex, boost::shared_ptr<const Geometry::IDetector> idet);
/// The user selected (input) workspace
API::MatrixWorkspace_const_sptr inputWS;
......
......@@ -117,10 +117,10 @@ namespace Mantid
double lowerLeft, lowerRight, upperRight, upperLeft;
};
/// Calculate the corner Q values
QValues calculateQValues(Geometry::IDetector_sptr det,
QValues calculateQValues(Geometry::IDetector_const_sptr det,
const double dEMin, const double dEMax) const;
/// Calculate the Kf vectors
std::pair<Kernel::V3D, Kernel::V3D> calculateScatterDir(Geometry::IDetector_sptr det) const;
std::pair<Kernel::V3D, Kernel::V3D> calculateScatterDir(Geometry::IDetector_const_sptr det) const;
/// Calculate a single Q value
double calculateQ(const Kernel::V3D scatterDir, const double energy) const;
/// E Mode
......
......@@ -77,12 +77,12 @@ private:
/// sort by distance
void sortByDistance(std::map<specid_t, double> & nearest, const size_t & noNeighbours);
/// create expanded bounding box for our purposes
void createBox(boost::shared_ptr<Mantid::Geometry::IDetector> det, Mantid::Geometry::BoundingBox & bndbox);
void createBox(boost::shared_ptr<const Geometry::IDetector> det, Geometry::BoundingBox & bndbox);
/// grow dimensions of our bounding box to the factor
void growBox(double & min, double & max, const double & factor);
/// map of detectors in the instrument
std::map<specid_t, boost::shared_ptr<Mantid::Geometry::IDetector> > m_detectors;
std::map<specid_t, boost::shared_ptr<const Geometry::IDetector> > m_detectors;
/// flag which detectors are included in a group already
std::set<specid_t> m_included;
/// first and last values for each group
......
......@@ -134,7 +134,7 @@ void AbsorptionCorrection::exec()
correctionFactors->dataX(i) = X;
// Get detector position
IDetector_sptr det;
IDetector_const_sptr det;
try
{
det = m_inputWS->getDetector(i);
......
......@@ -79,7 +79,7 @@ std::map<detid_t, double> * AlignDetectors::calcTofToD_ConversionMap(Mantid::API
for (it = allDetectors.begin(); it != allDetectors.end(); it++)
{
detid_t detectorID = it->first;
Geometry::IDetector_sptr det = it->second;
Geometry::IDetector_const_sptr det = it->second;
//Find the offset, if any
double offset = offsetsWS->getValue(detectorID, 0.0);
......
......@@ -339,7 +339,7 @@ namespace Mantid
const int64_t index, API::MatrixWorkspace_sptr out)
{
bool continueOp(true);
IDetector_sptr det_lhs, det_rhs;
IDetector_const_sptr det_lhs, det_rhs;
try
{
det_lhs = lhs->getDetector(index);
......@@ -766,7 +766,7 @@ namespace Mantid
try
{
IDetector_sptr det_out = out->getDetector(m_indicesToMask[i]);
IDetector_const_sptr det_out = out->getDetector(m_indicesToMask[i]);
PARALLEL_CRITICAL(BinaryOperation_masking)
{
pmap.addBool(det_out.get(), "masked", true);
......
......@@ -111,7 +111,7 @@ namespace Algorithms
std::vector<double> xval;
xval.push_back(inputWS->readX(i).front());
xval.push_back(inputWS->readX(i).back());
IDetector_sptr detector = inputWS->getDetector(i);
IDetector_const_sptr detector = inputWS->getDetector(i);
double twoTheta, l1val, l2;
if ( ! detector->isMonitor() )
{
......@@ -181,7 +181,7 @@ namespace Algorithms
}
double ConvertSpectrumAxis::getEfixed(IDetector_sptr detector, MatrixWorkspace_const_sptr inputWS, int emode) const
double ConvertSpectrumAxis::getEfixed(IDetector_const_sptr detector, MatrixWorkspace_const_sptr inputWS, int emode) const
{
double efixed(0);
double efixedProp = getProperty("Efixed");
......@@ -212,7 +212,7 @@ namespace Algorithms
if ( efixedVec.empty() )
{
int detid = detector->getID();
IDetector_sptr detectorSingle = inputWS->getInstrument()->getDetector(detid);
IDetector_const_sptr detectorSingle = inputWS->getInstrument()->getDetector(detid);
efixedVec = detectorSingle->getNumberParameter("Efixed");
}
if (! efixedVec.empty() )
......
......@@ -419,7 +419,7 @@ void ConvertUnits::convertViaTOF(Kernel::Unit_const_sptr fromUnit, API::MatrixWo
try
{
// Now get the detector object for this histogram
IDetector_sptr det = outputWS->getDetector(i);
IDetector_const_sptr det = outputWS->getDetector(i);
// Get the sample-detector distance for this detector (in metres)
double l2, twoTheta;
if ( ! det->isMonitor() )
......
......@@ -129,7 +129,7 @@ void CorrectKiKf::exec()
if ( efixedProp != EMPTY_DBL()) Efi = efixedProp;
else try
{
IDetector_sptr det = inputWS->getDetector(i);
IDetector_const_sptr det = inputWS->getDetector(i);
if (!det->isMonitor())
{
std::vector< double > wsProp=det->getNumberParameter("Efixed");
......@@ -267,7 +267,7 @@ void CorrectKiKf::execEvent()
if ( efixedProp != EMPTY_DBL()) Efi = efixedProp;
else try
{
IDetector_sptr det = inputWS->getDetector(i);
IDetector_const_sptr det = inputWS->getDetector(i);
if (!det->isMonitor())
{
std::vector< double > wsProp=det->getNumberParameter("Efixed");
......
......@@ -74,7 +74,7 @@ namespace Mantid
/// Execute the algorithm
void CreatePSDBleedMask::exec()
{
using Geometry::IDetector_sptr;
using Geometry::IDetector_const_sptr;
MatrixWorkspace_const_sptr inputWorkspace = getProperty("InputWorkspace");
// We require the number of good frames. Check that we have this
......@@ -110,7 +110,7 @@ namespace Mantid
// order
for( int i = 0; i < numSpectra; ++i )
{
IDetector_sptr det;
IDetector_const_sptr det;
try
{
det = inputWorkspace->getDetector(i);
......@@ -121,8 +121,8 @@ namespace Mantid
}
if( det->isMonitor() ) continue;
boost::shared_ptr<Geometry::DetectorGroup> group =
boost::dynamic_pointer_cast<Geometry::DetectorGroup>(det);
boost::shared_ptr<const Geometry::DetectorGroup> group =
boost::dynamic_pointer_cast<const Geometry::DetectorGroup>(det);
if( group )
{
......
......@@ -18,7 +18,7 @@ namespace Mantid
using API::MatrixWorkspace_sptr;
using API::IAlgorithm_sptr;
using Geometry::IDetector_sptr;
using Geometry::IDetector_const_sptr;
using namespace Mantid::DataObjects;
using namespace Mantid::API;
......@@ -111,7 +111,7 @@ namespace Mantid
{
PARALLEL_START_INTERUPT_REGION
IDetector_sptr det;
IDetector_const_sptr det;
try
{
det = input->getDetector(i);
......
......@@ -193,7 +193,7 @@ Gets the detector information and uses this to calculate its efficiency
*/
void DetectorEfficiencyCor::correctForEfficiency(int64_t spectraIn)
{
IDetector_sptr det = m_inputWS->getDetector(spectraIn);
IDetector_const_sptr det = m_inputWS->getDetector(spectraIn);
if( det->isMonitor() || det->isMasked() )
{
return;
......@@ -220,7 +220,7 @@ void DetectorEfficiencyCor::correctForEfficiency(int64_t spectraIn)
std::vector<double> oneOverWaveVectors(yValues.size());
for( ; it != iend ; ++it )
{
IDetector_sptr det_member = m_inputWS->getInstrument()->getDetector(*it);
IDetector_const_sptr det_member = m_inputWS->getInstrument()->getDetector(*it);
Parameter_sptr par = m_paraMap->get(det_member.get(),"3He(atm)");
if ( !par )
......@@ -294,7 +294,7 @@ double DetectorEfficiencyCor::calculateOneOverK(double loBinBound, double uppBin
* @param detRadius :: An output paramater that contains the detector radius
* @param detAxis :: An output parameter that contains the detector axis vector
*/
void DetectorEfficiencyCor::getDetectorGeometry(boost::shared_ptr<Geometry::IDetector> det, double & detRadius, V3D & detAxis)
void DetectorEfficiencyCor::getDetectorGeometry(Geometry::IDetector_const_sptr det, double & detRadius, V3D & detAxis)
{
boost::shared_ptr<const Object> shape_sptr = det->shape();
std::map<const Geometry::Object *, std::pair<double, Kernel::V3D> >::const_iterator it =
......
......@@ -30,7 +30,7 @@ namespace Mantid
using Kernel::Direction;
using Geometry::IDetector_sptr;
using Geometry::IDetector_const_sptr;
using namespace API;
//--------------------------------------------------------------------------
......@@ -77,37 +77,37 @@ namespace Mantid
const ISpectrum * inSpec = inputWS->getSpectrum(i);
// Copy X, spectrum number and detector IDs
outSpec->setX(xValues);
outSpec->copyInfoFrom(*inSpec);
outSpec->setX(xValues);
outSpec->copyInfoFrom(*inSpec);
IDetector_sptr inputDet;
bool inputIsMasked(false);
try
{
inputDet = inputWS->getDetector(i);
if( inputDet->isMasked() )
{
inputIsMasked = true;
}
}
catch(Kernel::Exception::NotFoundError &)
{
inputIsMasked = false;
}
IDetector_const_sptr inputDet;
bool inputIsMasked(false);
try
{
inputDet = inputWS->getDetector(i);
if( inputDet->isMasked() )
{
inputIsMasked = true;
}
}
catch(Kernel::Exception::NotFoundError &)
{
inputIsMasked = false;
}
if( inputIsMasked )
{
outSpec->dataY()[0] = 0.0;
outSpec->dataE()[0] = 0.0;
}
else
{
outSpec->dataY()[0] = 1.0;
outSpec->dataE()[0] = 1.0;
}
prog.report();
if( inputIsMasked )
{
outSpec->dataY()[0] = 0.0;
outSpec->dataE()[0] = 0.0;
}
else
{
outSpec->dataY()[0] = 1.0;
outSpec->dataE()[0] = 1.0;
}
prog.report();
PARALLEL_END_INTERUPT_REGION
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
......
......@@ -132,7 +132,7 @@ void GetEi::exec()
*/
void GetEi::getGeometry(API::MatrixWorkspace_const_sptr WS, specid_t mon0Spec, specid_t mon1Spec, double &monitor0Dist, double &monitor1Dist) const
{
const IObjComponent_sptr source = WS->getInstrument()->getSource();
const IObjComponent_const_sptr source = WS->getInstrument()->getSource();
// retrieve a pointer to the first detector and get its distance
size_t monWI = 0;
......@@ -154,7 +154,7 @@ void GetEi::getGeometry(API::MatrixWorkspace_const_sptr WS, specid_t mon0Spec, s
g_log.error() << "Error retrieving data for the first monitor" << std::endl;
throw std::bad_cast();
}
IDetector_sptr det = WS->getInstrument()->getDetector(*dets.begin());
IDetector_const_sptr det = WS->getInstrument()->getDetector(*dets.begin());
monitor0Dist = det->getDistance(*(source.get()));
// repeat for the second detector
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment