Mantid
Loading...
Searching...
No Matches
MDFrameFactory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
12
13#include <boost/regex.hpp>
14namespace Mantid::Geometry {
15
17 using namespace Mantid::Kernel;
18
19 // Try to generate a proper md unit, don't just assume a label unit.
20 auto unitFactoryChain = Kernel::makeMDUnitFactoryChain();
21 auto mdUnit = unitFactoryChain->create(argument.unitString);
22
23 return new GeneralFrame(argument.frameString, MDUnit_uptr(mdUnit->clone()));
24}
25
28 auto canInterpret = true;
30 canInterpret = false;
31 }
32 return canInterpret;
33}
34
35QLab *QLabFrameFactory::createRaw(const MDFrameArgument & /*argument*/) const { return new QLab; }
36
38 // We only need to check the frame QLab only makes sense in inverse Angstroms
39 return argument.frameString == QLab::QLabName;
40}
41
42QSample *QSampleFrameFactory::createRaw(const MDFrameArgument & /*argument*/) const { return new QSample; }
43
45 // We only need to check the frame QSample only makes sense in inverse
46 // Angstroms
47 return argument.frameString == QSample::QSampleName;
48}
49
51 using namespace Mantid::Kernel;
52 auto unitFactoryChain = Kernel::makeMDUnitFactoryChain();
53 auto productMDUnit = unitFactoryChain->create(argument.unitString);
54 return new HKL(productMDUnit);
55}
56
58 using namespace Mantid::Kernel;
59 auto unitFactoryChain = Kernel::makeMDUnitFactoryChain();
60 auto mdUnit = unitFactoryChain->create(argument.unitString);
61 // We expect units to be RLU or A^-1
62 auto isInverseAngstrom = mdUnit->getUnitLabel() == Units::Symbol::InverseAngstrom;
63 auto isRLU = mdUnit->getUnitLabel() == Units::Symbol::RLU;
64 boost::regex pattern("in.*A.*\\^-1");
65 auto isHoraceStyle = boost::regex_match(mdUnit->getUnitLabel().ascii(), pattern);
66 const bool compatibleUnit = isInverseAngstrom || isRLU || isHoraceStyle;
67 // Check both the frame name and the unit name
68 return argument.frameString == HKL::HKLName && compatibleUnit;
69}
70
72 using namespace Mantid::Kernel;
73
74 // Try to generate a proper md unit, don't just assume a label unit.
75 auto unitFactoryChain = Kernel::makeMDUnitFactoryChain();
76 auto mdUnit = unitFactoryChain->create(argument.unitString);
77
78 return new UnknownFrame(MDUnit_uptr(mdUnit->clone()));
79}
80
82bool UnknownFrameFactory::canInterpret(const MDFrameArgument & /*unitString*/) const {
83 return true; // This can interpret everything
84}
85
87 MDFrameFactory_uptr first = std::make_unique<QLabFrameFactory>();
88 first->setSuccessor(std::make_unique<QSampleFrameFactory>())
89 .setSuccessor(std::make_unique<HKLFrameFactory>())
90 // Make sure that GeneralFrameFactory is the last in the chain to give a
91 // fall-through option
92 .setSuccessor(std::make_unique<GeneralFrameFactory>())
93 .setSuccessor(std::make_unique<UnknownFrameFactory>());
94 return first;
95}
96
97} // namespace Mantid::Geometry
GeneralFrame * createRaw(const MDFrameArgument &argument) const override
Create the product.
bool canInterpret(const MDFrameArgument &) const override
Indicate an ability to intepret the string.
GeneralFrame : Any MDFrame that isn't related to momemtum transfer.
Definition: GeneralFrame.h:21
HKL * createRaw(const MDFrameArgument &argument) const override
Create the product.
bool canInterpret(const MDFrameArgument &argument) const override
Indicate an ability to intepret the string.
HKL : HKL MDFrame.
Definition: HKL.h:21
static const std::string HKLName
Definition: HKL.h:27
Input argument type for MDFrameFactory chainable factory.
bool canInterpret(const MDFrameArgument &argument) const override
Indicate an ability to intepret the string.
QLab * createRaw(const MDFrameArgument &argument) const override
Create the product.
QLab : Q in the lab frame MDFrame.
Definition: QLab.h:21
static const std::string QLabName
Definition: QLab.h:35
QSample * createRaw(const MDFrameArgument &argument) const override
Create the product.
bool canInterpret(const MDFrameArgument &argument) const override
Indicate an ability to intepret the string.
QSample : Q in the sample frame.
Definition: QSample.h:21
static const std::string QSampleName
Definition: QSample.h:23
UnknownFrame * createRaw(const MDFrameArgument &argument) const override
Create the product.
bool canInterpret(const MDFrameArgument &argument) const override
Indicate an ability to intepret the string.
UnknownFrame : Unknown MDFrame.
Definition: UnknownFrame.h:21
static const std::string UnknownFrameName
Definition: UnknownFrame.h:35
static const UnitLabel InverseAngstrom
InverseAngstrom.
static const UnitLabel RLU
Reciprocal lattice units.
std::unique_ptr< MDFrameFactory > MDFrameFactory_uptr
Helper typedef.
MDFrameFactory_uptr MANTID_GEOMETRY_DLL makeMDFrameFactoryChain()
Make a complete factory chain.
MDUnitFactory_uptr MANTID_KERNEL_DLL makeMDUnitFactoryChain()
Convience method. Pre-constructed builder chain.
std::unique_ptr< MDUnit > MDUnit_uptr
Definition: MDUnit.h:70