From 701b45327eb317608f8f15b57f22fbde1b07ca6d Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Fri, 30 May 2014 12:59:34 -0400 Subject: [PATCH] Re #9538. Added code for specialized getComponentByName for RectDet --- .../MantidGeometry/Instrument/CompAssembly.h | 2 +- .../Instrument/ObjCompAssembly.h | 2 +- .../Instrument/RectangularDetector.h | 1 + .../Geometry/src/Instrument/CompAssembly.cpp | 19 +++++++++++++++-- .../src/Instrument/RectangularDetector.cpp | 21 +++++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/CompAssembly.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/CompAssembly.h index df4f624a2e8c..531f4036a611 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/CompAssembly.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/CompAssembly.h @@ -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 operator[](int i) const; /// Returns a pointer to the first component of assembly encountered with the given name - boost::shared_ptr getComponentByName(const std::string & cname, int nlevels = 0) const; + virtual boost::shared_ptr getComponentByName(const std::string & cname, int nlevels = 0) const; Kernel::V3D getPos() const; diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ObjCompAssembly.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ObjCompAssembly.h index 11596c4fae94..c57dfcdd91ba 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ObjCompAssembly.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/ObjCompAssembly.h @@ -76,7 +76,7 @@ class MANTID_GEOMETRY_DLL ObjCompAssembly : public virtual ICompAssembly, public //! Get all children void getChildren(std::vector & outVector, bool recursive) const; //! Returns a pointer to the first component of assembly encountered with the given name - boost::shared_ptr getComponentByName(const std::string & cname, int nlevels = 0) const; + virtual boost::shared_ptr getComponentByName(const std::string & cname, int nlevels = 0) const; //! Get a pointer to the ith component in the assembly boost::shared_ptr operator[](int i) const; //! Print information about all children diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/RectangularDetector.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/RectangularDetector.h index ecade9ad74ea..48132d1da669 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/RectangularDetector.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Instrument/RectangularDetector.h @@ -107,6 +107,7 @@ class MANTID_GEOMETRY_DLL RectangularDetector : public CompAssembly, public IObj int minDetectorID(); /// maximum detector id int maxDetectorID(); + virtual boost::shared_ptr 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 diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/CompAssembly.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/CompAssembly.cpp index d2930924dbca..998d85f624d2 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/CompAssembly.cpp +++ b/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 #include -#include +#include namespace Mantid { @@ -339,7 +340,21 @@ boost::shared_ptr CompAssembly::getComponentByName(const std:: { // don't bother adding things to the queue that aren't assemblies if (bool(boost::dynamic_pointer_cast(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(comp); + if (bool(rectDet)) + { + auto child = rectDet->getComponentByName(cname, nlevels); + if (child) + return child; + } + else + { + nodeQueue.push_back(comp); + } + } } } } diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/RectangularDetector.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/RectangularDetector.cpp index 290690bc8004..8dfdbc9f571f 100644 --- a/Code/Mantid/Framework/Geometry/src/Instrument/RectangularDetector.cpp +++ b/Code/Mantid/Framework/Geometry/src/Instrument/RectangularDetector.cpp @@ -462,7 +462,28 @@ int RectangularDetector::maxDetectorID() return m_maxDetId; } +//------------------------------------------------------------------------------------------------- +/// @copydoc Mantid::Geometry::CompAssembly::getComponentByName +boost::shared_ptr 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(); + // 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(); + } +} //------------------------------------------------------------------------------------------------ /** Test the intersection of the ray with the children of the component assembly, for InstrumentRayTracer.