Mantid
Loading...
Searching...
No Matches
PeakShapeDetectorBinFactory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2024 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include "MantidJson/Json.h"
11
12#include <json/json.h>
13#include <stdexcept>
14
15using namespace Mantid::Kernel;
16
17namespace Mantid::DataObjects {
18
25 Json::Value root;
26 Mantid::Geometry::PeakShape *peakShape = nullptr;
27 if (!Mantid::JsonHelpers::parse(source, &root)) {
28 throw std::invalid_argument("PeakShapeDetectorBinFactory:: Source JSON for "
29 "the peak shape is not valid: " +
30 source);
31 }
32
33 const std::string shape = root["shape"].asString();
35 const std::string algorithmName(root["algorithm_name"].asString());
36 const int algorithmVersion(root["algorithm_version"].asInt());
37 const auto frame(static_cast<SpecialCoordinateSystem>(root["frame"].asInt()));
38
39 std::vector<std::tuple<int32_t, double, double>> detectorBinList;
40 const Json::Value detectorList = root["detectors"];
41 for (uint32_t index = 0; index < detectorList.size(); index++) {
42 const Json::Value detBinVal = detectorList[index];
43 detectorBinList.emplace_back(detBinVal["detId"].asInt(), detBinVal["startX"].asDouble(),
44 detBinVal["endX"].asDouble());
45 }
46 peakShape = new PeakShapeDetectorBin(detectorBinList, frame, algorithmName, algorithmVersion);
47 } else {
48 if (m_successor) {
49 peakShape = m_successor->create(source);
50 } else {
51 throw std::invalid_argument("PeakShapeDetectorBinFactory:: No successor "
52 "factory able to process : " +
53 source);
54 }
55 }
56 return peakShape;
57}
58
63void PeakShapeDetectorBinFactory::setSuccessor(std::shared_ptr<const PeakShapeFactory> successorFactory) {
64 this->m_successor = successorFactory;
65}
66
67} // namespace Mantid::DataObjects
std::map< DeltaEMode::Type, std::string > index
IntArray detectorList
PeakShapeFactory_const_sptr m_successor
Successor factory.
Mantid::Geometry::PeakShape * create(const std::string &source) const override
Make product.
void setSuccessor(PeakShapeFactory_const_sptr successorFactory) override
Set a successor should this factory be unsuitable.
PeakShapeDetectorBin : PeakShape representing detector ids and integration limits of a peak.
PeakShape : Abstract type to describes the shape of a peak.
Definition PeakShape.h:20
SpecialCoordinateSystem
Special coordinate systems for Q3D.