Commit 909cc84f authored by Anders Markvardsen's avatar Anders Markvardsen
Browse files

Store sample component not as IObjComponent but IComponent. re #9133

parent 2fdde41d
......@@ -65,6 +65,7 @@ using namespace Mantid::API;
using namespace Mantid::Kernel;
using Mantid::Geometry::CompAssembly;
using Mantid::Geometry::IObjComponent_const_sptr;
using Mantid::Geometry::IComponent_const_sptr;
namespace Mantid
{
......@@ -260,7 +261,7 @@ namespace Mantid
//------------------"clone" orig instruments pmap -------------------
cLone( pmap, instSave, pmapSv );
IObjComponent_const_sptr sample = instChange->getSample();
IComponent_const_sptr sample = instChange->getSample();
V3D sampPos = sample->getRelativePos();
V3D sampOffsets( getParameter( "SampleXOffset" ), getParameter( "SampleYOffset" ), getParameter( "SampleZOffset" ) );
......
......@@ -1645,7 +1645,7 @@ namespace Mantid
IObjComponent_const_sptr source = NewInstrument->getSource();
updateSourceParams(source, pmap, pmapOld);
IObjComponent_const_sptr sample = NewInstrument->getSample();
IComponent_const_sptr sample = NewInstrument->getSample();
V3D SamplePos = sample->getPos();
if( SamplePos != newSampPos)
{
......@@ -1804,7 +1804,7 @@ namespace Mantid
IObjComponent_const_sptr source = instrument->getSource();
oss3 << "<component-link name=\"" << source->getName() << "\">" << endl;
IObjComponent_const_sptr sample = instrument->getSample();
IComponent_const_sptr sample = instrument->getSample();
V3D sourceRelPos = source->getRelativePos();
writeXmlParameter(oss3, "x", sourceRelPos.X());
......
......@@ -341,7 +341,7 @@ namespace Crystal
double mu = (9.614 * lambda) + 0.266; // mu for GS20 glass
double depth = 0.2;
double eff_center = 1.0 - std::exp(-mu * depth); // efficiency at center of detector
IObjComponent_const_sptr sample = ws->getInstrument()->getSample();
IComponent_const_sptr sample = ws->getInstrument()->getSample();
double cosA = ws->getInstrument()->getComponentByName(p.getBankName())->getDistance(*sample) / p.getL2();
double pathlength = depth / cosA;
double eff_R = 1.0 - exp(-mu * pathlength); // efficiency at point R
......
......@@ -239,7 +239,7 @@ public:
Kernel::V3D SampPos(.0003, -.00025, .00015);
boost::shared_ptr<Geometry::ParameterMap> pmap = Inst->getParameterMap();//check if parameterized.
Geometry::IObjComponent_const_sptr sample = Inst->getSample();
Geometry::IComponent_const_sptr sample = Inst->getSample();
Kernel::V3D oldSampPos = sample->getPos();// Should reset Inst
pmap->addPositionCoordinate(sample.get(), "x", SampPos.X());
......
......@@ -174,7 +174,7 @@ void IkedaCarpenterPV::calWavelengthAtEachDataPoint(const double* xValues, const
{
API::MatrixWorkspace_const_sptr mws = getMatrixWorkspace();
Instrument_const_sptr instrument = mws->getInstrument();
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
Geometry::IComponent_const_sptr sample = instrument->getSample();
if (sample != NULL)
{
convertValue(m_waveLength, wavelength, mws, m_workspaceIndex);
......
......@@ -192,7 +192,7 @@ namespace DataHandling
Geometry::Instrument_const_sptr instrument = ws->getInstrument();
// Get the sample (needed to calculate distances)
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
Geometry::IComponent_const_sptr sample = instrument->getSample();
// Get the source (moderator)
Geometry::IObjComponent_const_sptr source = instrument->getSource();
......
......@@ -514,7 +514,7 @@ FindDetectorsPar::populate_values_from_file(const API::MatrixWorkspace_sptr & in
else
{
Geometry::IObjComponent_const_sptr sample =inputWS->getInstrument()->getSample();
Geometry::IComponent_const_sptr sample =inputWS->getInstrument()->getSample();
secondaryFlightpath.resize(nHist);
// Loop over the spectra
for (size_t i = 0; i < nHist; i++){
......
......@@ -363,7 +363,7 @@ namespace Mantid
// Cache base instrument
m_baseInstrument = m_workspace->getInstrument()->baseInstrument();
Geometry::IObjComponent_const_sptr sample = m_workspace->getInstrument()->getSample();
Geometry::IComponent_const_sptr sample = m_workspace->getInstrument()->getSample();
if( sample ) m_samplePos = sample->getPos();
// cache values of instrument level parameters so we only change then if they are different
......
......@@ -99,7 +99,7 @@ double LoadHelper::calculateTOF(double distance,double wavelength) {
double LoadHelper::getL1(const API::MatrixWorkspace_sptr& workspace) {
Geometry::Instrument_const_sptr instrument =
workspace->getInstrument();
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
Geometry::IComponent_const_sptr sample = instrument->getSample();
double l1 = instrument->getSource()->getDistance(*sample);
return l1;
}
......@@ -109,7 +109,7 @@ double LoadHelper::getL2(const API::MatrixWorkspace_sptr& workspace, int detId)
Geometry::Instrument_const_sptr instrument =
workspace->getInstrument();
// Get the distance between the source and the sample (assume in metres)
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
Geometry::IComponent_const_sptr sample = instrument->getSample();
// Get the sample-detector distance for this detector (in metres)
double l2 = workspace->getDetector(detId)->getPos().distance(
sample->getPos());
......
......@@ -334,7 +334,7 @@ void SaveFocusedXYE::getFocusedPos(Mantid::API::MatrixWorkspace_const_sptr wksp,
return;
}
Geometry::IObjComponent_const_sptr source = instrument->getSource();
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
Geometry::IComponent_const_sptr sample = instrument->getSample();
if (source == NULL || sample == NULL)
{
l1 = 0.;
......
......@@ -94,7 +94,7 @@ namespace Mantid
return;
}
Geometry::IObjComponent_const_sptr source = instrument->getSource();
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
Geometry::IComponent_const_sptr sample = instrument->getSample();
if (source == NULL || sample == NULL)
{
l1 = 0.;
......@@ -144,7 +144,7 @@ namespace Mantid
double l1, l2, tth;
Geometry::Instrument_const_sptr instrument = inputWS->getInstrument();
Geometry::IObjComponent_const_sptr source;
Geometry::IObjComponent_const_sptr sample;
Geometry::IComponent_const_sptr sample;
if (instrument != NULL)
{
source = instrument->getSource();
......
......@@ -126,7 +126,7 @@ namespace Mantid
this->nBins = inputWS->blocksize();
// Get a pointer to the sample
Geometry::IObjComponent_const_sptr sample =
Geometry::IComponent_const_sptr sample =
inputWS->getInstrument()->getSample();
// Retrieve the filename from the properties
......
......@@ -76,7 +76,7 @@ void SavePAR::exec() {
const std::string filename = getProperty("Filename");
// Get a pointer to the sample
IObjComponent_const_sptr sample =
IComponent_const_sptr sample =
inputWorkspace->getInstrument()->getSample();
std::ofstream outPAR_file(filename.c_str());
......
......@@ -76,7 +76,7 @@ void SavePHX::exec() {
const std::string filename = getProperty("Filename");
// Get a pointer to the sample
IObjComponent_const_sptr sample =
IComponent_const_sptr sample =
inputWorkspace->getInstrument()->getSample();
std::ofstream outPHX_file(filename.c_str());
......
......@@ -182,7 +182,7 @@ public:
TS_ASSERT_EQUALS( source->getName(), "undulator");
TS_ASSERT_DELTA( source->getPos().Z(), -17.0,0.01);
boost::shared_ptr<const IObjComponent> samplepos = i->getSample();
boost::shared_ptr<const IComponent> samplepos = i->getSample();
TS_ASSERT_EQUALS( samplepos->getName(), "nickel-holder");
TS_ASSERT_DELTA( samplepos->getPos().Y(), 0.0,0.01);
......@@ -296,7 +296,7 @@ public:
TS_ASSERT_EQUALS( source->getName(), "undulator");
TS_ASSERT_DELTA( source->getPos().Z(), -11.016,0.01);
boost::shared_ptr<const IObjComponent> samplepos = i->getSample();
boost::shared_ptr<const IObjComponent> samplepos = boost::dynamic_pointer_cast<const IObjComponent>(i->getSample());
TS_ASSERT_EQUALS( samplepos->getName(), "nickel-holder");
TS_ASSERT_DELTA( samplepos->getPos().Y(), 0.0,0.01);
......
......@@ -322,7 +322,7 @@ namespace DataObjects
const Geometry::IObjComponent_const_sptr sourceObj = m_inst->getSource();
if (sourceObj == NULL)
throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed to get source component from instrument");
const Geometry::IObjComponent_const_sptr sampleObj = m_inst->getSample();
const Geometry::IComponent_const_sptr sampleObj = m_inst->getSample();
if (sampleObj == NULL)
throw Exception::InstrumentDefinitionError("Peak::setInstrument(): Failed to get sample component from instrument");
......
......@@ -78,7 +78,7 @@ namespace Mantid
IObjComponent_const_sptr getSource() const;
IObjComponent_const_sptr getChopperPoint(const size_t index = 0) const;
size_t getNumberOfChopperPoints() const;
IObjComponent_const_sptr getSample() const;
IComponent_const_sptr getSample() const;
Kernel::V3D getBeamDirection() const;
IDetector_const_sptr getDetector(const detid_t &detector_id) const;
......@@ -99,7 +99,7 @@ namespace Mantid
/// mark a Component which has already been added to the Instrument (as a child comp.)
/// to be 'the' samplePos Component. For now it is assumed that we have
/// at most one of these.
void markAsSamplePos(const ObjComponent*);
void markAsSamplePos(const IComponent*);
/// Marks a Component which already exists in the instrument to the chopper cache
void markAsChopperPoint(const ObjComponent *comp);
......@@ -252,7 +252,7 @@ namespace Mantid
std::vector<const ObjComponent*> * m_chopperPoints;
/// Purpose to hold copy of samplePos component. For now assumed to be just one component
const ObjComponent* m_sampleCache;
const IComponent* m_sampleCache;
/// To store info about the parameters defined in IDF. Indexed according to logfile-IDs, which equals logfile filename minus the run number and file extension
InstrumentParameterCache m_logfileCache;
......
......@@ -374,20 +374,32 @@ namespace Mantid
/** Gets a pointer to the Sample Position
* @returns a pointer to the Sample Position
*/
IObjComponent_const_sptr Instrument::getSample() const
IComponent_const_sptr Instrument::getSample() const
{
if ( !m_sampleCache )
{
g_log.warning("In Instrument::getSamplePos(). No SamplePos has been set.");
return IObjComponent_const_sptr(m_sampleCache,NoDeleting());
return IComponent_const_sptr(m_sampleCache,NoDeleting());
}
else if (m_isParametrized)
{
return IObjComponent_const_sptr(new ObjComponent(static_cast<const Instrument*>(m_base)->m_sampleCache,m_map));
auto sampleCache = static_cast<const Instrument*>(m_base)->m_sampleCache;
if ( dynamic_cast<const ObjComponent*>(sampleCache) )
return IComponent_const_sptr(new ObjComponent(sampleCache,m_map));
else if ( dynamic_cast<const CompAssembly*>(sampleCache) )
return IComponent_const_sptr(new CompAssembly(sampleCache,m_map));
else if ( dynamic_cast<const Component*>(sampleCache) )
return IComponent_const_sptr(new Component(sampleCache,m_map));
else
{
g_log.error("In Instrument::getSamplePos(). SamplePos is not a recognised component type.");
g_log.error("Try to assume it is a Component.");
return IComponent_const_sptr(new ObjComponent(sampleCache,m_map));
}
}
else
{
return IObjComponent_const_sptr(m_sampleCache,NoDeleting());
return IComponent_const_sptr(m_sampleCache,NoDeleting());
}
}
......@@ -664,7 +676,7 @@ namespace Mantid
*
* @param comp :: Component to be marked (stored for later retrieval) as a "SamplePos" Component
*/
void Instrument::markAsSamplePos(const ObjComponent* comp)
void Instrument::markAsSamplePos(const IComponent* comp)
{
if (m_isParametrized)
throw std::runtime_error("Instrument::markAsSamplePos() called on a parametrized Instrument object.");
......@@ -1021,7 +1033,7 @@ namespace Mantid
beamline_norm=2.0*beamline.norm();
// Get the distance between the source and the sample (assume in metres)
IObjComponent_const_sptr sample = this->getSample();
IComponent_const_sptr sample = this->getSample();
try
{
l1 = this->getSource()->getDistance(*sample);
......@@ -1138,7 +1150,7 @@ namespace Mantid
std::vector<IDetector_const_sptr> detectors;
detectors = getDetectors( detIDs );
Geometry::IObjComponent_const_sptr sample = getSample();
Geometry::IComponent_const_sptr sample = getSample();
Kernel::V3D sample_pos;
if(sample) sample_pos = sample->getPos();
......
......@@ -170,7 +170,7 @@ public:
TS_ASSERT_EQUALS( source->getName(), "undulator");
TS_ASSERT_DELTA( source->getPos().Z(), -17.0,0.01);
boost::shared_ptr<const IObjComponent> samplepos = i->getSample();
boost::shared_ptr<const IObjComponent> samplepos = boost::dynamic_pointer_cast<const IObjComponent>(i->getSample());
TS_ASSERT_EQUALS( samplepos->getName(), "nickel-holder");
TS_ASSERT_DELTA( samplepos->getPos().Y(), 0.0,0.01);
......
......@@ -254,7 +254,7 @@ namespace Mantid
//this->pBaseInstr = instrument->baseInstrument();
//
Geometry::IObjComponent_const_sptr source = instrument->getSource();
Geometry::IObjComponent_const_sptr sample = instrument->getSample();
Geometry::IComponent_const_sptr sample = instrument->getSample();
if ((!source) || (!sample))
{
g_log.error()<<" Instrument is not fully defined. Can not identify source or sample\n";
......
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