Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/9538_rect_det_performance'
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlPalmen committed Jun 6, 2014
2 parents a4e017c + 701b453 commit 972342c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Expand Up @@ -82,7 +82,7 @@ class MANTID_GEOMETRY_DLL CompAssembly : public ICompAssembly, public Component
//! Get a pointer to the ith component in the assembly
boost::shared_ptr<IComponent> operator[](int i) const;
/// Returns a pointer to the first component of assembly encountered with the given name
boost::shared_ptr<const IComponent> getComponentByName(const std::string & cname, int nlevels = 0) const;
virtual boost::shared_ptr<const IComponent> getComponentByName(const std::string & cname, int nlevels = 0) const;


Kernel::V3D getPos() const;
Expand Down
Expand Up @@ -76,7 +76,7 @@ class MANTID_GEOMETRY_DLL ObjCompAssembly : public virtual ICompAssembly, public
//! Get all children
void getChildren(std::vector<IComponent_const_sptr> & outVector, bool recursive) const;
//! Returns a pointer to the first component of assembly encountered with the given name
boost::shared_ptr<const IComponent> getComponentByName(const std::string & cname, int nlevels = 0) const;
virtual boost::shared_ptr<const IComponent> getComponentByName(const std::string & cname, int nlevels = 0) const;
//! Get a pointer to the ith component in the assembly
boost::shared_ptr<IComponent> operator[](int i) const;
//! Print information about all children
Expand Down
Expand Up @@ -107,6 +107,7 @@ class MANTID_GEOMETRY_DLL RectangularDetector : public CompAssembly, public IObj
int minDetectorID();
/// maximum detector id
int maxDetectorID();
virtual boost::shared_ptr<const IComponent> getComponentByName(const std::string & cname, int nlevels = 0) const;

// This should inherit the getBoundingBox implementation from CompAssembly but
// the multiple inheritance seems to confuse it so we'll explicityly tell it that here
Expand Down
19 changes: 17 additions & 2 deletions Code/Mantid/Framework/Geometry/src/Instrument/CompAssembly.cpp
@@ -1,10 +1,11 @@
#include "MantidGeometry/Instrument/CompAssembly.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"
#include "MantidGeometry/Instrument/ParComponentFactory.h"
#include "MantidGeometry/IObjComponent.h"
#include "MantidGeometry/Objects/BoundingBox.h"
#include <algorithm>
#include <ostream>
#include <stdexcept>
#include <stdexcept>

namespace Mantid
{
Expand Down Expand Up @@ -339,7 +340,21 @@ boost::shared_ptr<const IComponent> CompAssembly::getComponentByName(const std::
{
// don't bother adding things to the queue that aren't assemblies
if (bool(boost::dynamic_pointer_cast<const ICompAssembly>(comp)))
nodeQueue.push_back(comp);
{
// for rectangular detectors search the depth rather than siblings as there
// is a specific naming convention to speed things along
auto rectDet = boost::dynamic_pointer_cast<const RectangularDetector>(comp);
if (bool(rectDet))
{
auto child = rectDet->getComponentByName(cname, nlevels);
if (child)
return child;
}
else
{
nodeQueue.push_back(comp);
}
}
}
}
}
Expand Down
Expand Up @@ -462,7 +462,28 @@ int RectangularDetector::maxDetectorID()
return m_maxDetId;
}

//-------------------------------------------------------------------------------------------------
/// @copydoc Mantid::Geometry::CompAssembly::getComponentByName
boost::shared_ptr<const IComponent> RectangularDetector::getComponentByName(const std::string & cname, int nlevels) const
{
// cache the detector's name as all the other names are longer
const std::string NAME = this->getName();

// if the component name is too short, just return
if (cname.length() <= NAME.length())
return boost::shared_ptr<const IComponent>();

// check that the searched for name starts with the detector's
// name as they are generated
if (cname.substr(0, NAME.length()).compare(NAME) == 0)
{
return CompAssembly::getComponentByName(cname, nlevels);
}
else
{
return boost::shared_ptr<const IComponent>();
}
}

//------------------------------------------------------------------------------------------------
/** Test the intersection of the ray with the children of the component assembly, for InstrumentRayTracer.
Expand Down

0 comments on commit 972342c

Please sign in to comment.