Skip to content

Commit

Permalink
refs #10904. Hook new factory into loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Feb 6, 2015
1 parent 78da658 commit 8d327c5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
17 changes: 11 additions & 6 deletions Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
Expand Up @@ -32,6 +32,7 @@
#include "MantidKernel/MultiThreaded.h"
#include "MantidDataObjects/PeakNoShapeFactory.h"
#include "MantidDataObjects/PeakShapeSphericalFactory.h"
#include "MantidDataObjects/PeakShapeEllipsoidFactory.h"
#include "MantidDataObjects/PeakShape.h"

namespace Mantid {
Expand Down Expand Up @@ -1122,26 +1123,30 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
// Read shape information
using namespace Mantid::DataObjects;

PeakShapeFactory_sptr peakFactory = boost::make_shared<PeakShapeSphericalFactory>();
peakFactory->setSuccessor(boost::make_shared<PeakNoShapeFactory>());
PeakShapeFactory_sptr peakFactoryEllipsoid = boost::make_shared<PeakShapeEllipsoidFactory>();
PeakShapeFactory_sptr peakFactorySphere = boost::make_shared<PeakShapeSphericalFactory>();
PeakShapeFactory_sptr peakFactoryNone = boost::make_shared<PeakNoShapeFactory>();

peakFactoryEllipsoid->setSuccessor(peakFactorySphere);
peakFactorySphere->setSuccessor(peakFactoryNone);

NXInfo info = nx_tw.getDataSetInfo(str.c_str());
NXChar data = nx_tw.openNXChar(str.c_str());

const int maxShapeJSONLength = info.dims[1];
data.load();
for (int r = 0; r < numberPeaks; r++) {
for (int i = 0; i < numberPeaks; ++i) {

// iR = peak row number
auto startPoint = data() + (maxShapeJSONLength * r);
auto startPoint = data() + (maxShapeJSONLength * i);
std::string shapeJSON(startPoint, startPoint + maxShapeJSONLength);
boost::trim_right(shapeJSON);

// Make the shape
PeakShape* peakShape = peakFactory->create(shapeJSON);
PeakShape* peakShape = peakFactoryEllipsoid->create(shapeJSON);

// Set the shape
peakWS->getPeak(r).setPeakShape(peakShape);
peakWS->getPeak(i).setPeakShape(peakShape);

}
}
Expand Down
Expand Up @@ -65,6 +65,8 @@ class DLLExport PeakShapeSpherical : public PeakShapeBase {
boost::optional<double> backgroundOuterRadius() const;
/// Peak inner background radius
boost::optional<double> backgroundInnerRadius() const;
/// Non-instance shape name
static const std::string sphereShapeName();

private:
/// Peak radius
Expand Down
13 changes: 11 additions & 2 deletions Code/Mantid/Framework/DataObjects/src/PeakShapeSpherical.cpp
Expand Up @@ -106,7 +106,7 @@ PeakShapeSpherical *PeakShapeSpherical::clone() const {
return new PeakShapeSpherical(*this);
}

std::string PeakShapeSpherical::shapeName() const { return "spherical"; }
std::string PeakShapeSpherical::shapeName() const { return sphereShapeName() ; }

bool PeakShapeSpherical::operator==(const PeakShapeSpherical &other) const {
return PeakShapeBase::operator==(other) && other.radius() == this->radius() &&
Expand Down Expand Up @@ -135,7 +135,16 @@ boost::optional<double> PeakShapeSpherical::backgroundOuterRadius() const {
* @return boost optional inner radius.
*/
boost::optional<double> PeakShapeSpherical::backgroundInnerRadius() const {
return m_backgroundInnerRadius;
return m_backgroundInnerRadius;
}

/**
* @brief PeakShapeSpherical::sphereShapeName
* @return Spherical shape name for this type.
*/
const std::string PeakShapeSpherical::sphereShapeName()
{
return "spherical";
}

} // namespace DataObjects
Expand Down
Expand Up @@ -30,7 +30,7 @@ PeakShape *PeakShapeSphericalFactory::create(const std::string &source) const {
PeakShape *product = NULL;
if (reader.parse(source, root)) {
const std::string shape = root["shape"].asString();
if (shape == "spherical") {
if (shape == PeakShapeSpherical::sphereShapeName()) {

const std::string algorithmName(root["algorithm_name"].asString());
const int algorithmVersion(root["algorithm_version"].asInt());
Expand Down

0 comments on commit 8d327c5

Please sign in to comment.