forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PeakShapeSphericalFactory.cpp
72 lines (62 loc) · 2.65 KB
/
PeakShapeSphericalFactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidDataObjects/PeakShapeSphericalFactory.h"
#include "MantidDataObjects/PeakShapeSpherical.h"
#include "MantidJson/Json.h"
#include "MantidKernel/SpecialCoordinateSystem.h"
#include "MantidKernel/VMD.h"
#include <json/json.h>
namespace Mantid::DataObjects {
using namespace Mantid::Kernel;
/**
* @brief PeakShapeSphericalFactory::create : Creational method
* @param source : Source JSON
* @return PeakShape object
*/
Mantid::Geometry::PeakShape *PeakShapeSphericalFactory::create(const std::string &source) const {
Json::Value root;
Mantid::Geometry::PeakShape *product = nullptr;
if (Mantid::JsonHelpers::parse(source, &root)) {
const std::string shape = root["shape"].asString();
if (shape == PeakShapeSpherical::sphereShapeName()) {
const std::string algorithmName(root["algorithm_name"].asString());
const int algorithmVersion(root["algorithm_version"].asInt());
const auto frame(static_cast<SpecialCoordinateSystem>(root["frame"].asInt()));
const double radius(root["radius"].asDouble());
if (!root["background_outer_radius"].empty() && !root["background_inner_radius"].empty()) {
const double backgroundOuterRadius(root["background_outer_radius"].asDouble());
const double backgroundInnerRadius(root["background_inner_radius"].asDouble());
product = new PeakShapeSpherical(radius, backgroundInnerRadius, backgroundOuterRadius, frame, algorithmName,
algorithmVersion);
}
else {
product = new PeakShapeSpherical(radius, frame, algorithmName, algorithmVersion);
}
} else {
if (m_successor) {
product = m_successor->create(source);
} else {
throw std::invalid_argument("PeakShapeSphericalFactory:: No successor "
"factory able to process : " +
source);
}
}
} else {
throw std::invalid_argument("PeakShapeSphericalFactory:: Source JSON for "
"the peak shape is not valid: " +
source);
}
return product;
}
/**
* @brief Set successor
* @param successorFactory : successor
*/
void PeakShapeSphericalFactory::setSuccessor(PeakShapeFactory_const_sptr successorFactory) {
m_successor = successorFactory;
}
} // namespace Mantid::DataObjects