Mantid
Loading...
Searching...
No Matches
ParComponentFactory.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 +
17#include <memory>
18
19namespace Mantid::Geometry {
20
29std::shared_ptr<IDetector> ParComponentFactory::createDetector(const IDetector *base, const ParameterMap *map) {
30 // Clone may be a Detector or GridDetectorPixel instance (or nullptr)
31 auto clone = base->cloneParameterized(map);
32 return std::shared_ptr<IDetector>(clone);
33}
34
43std::shared_ptr<Instrument> ParComponentFactory::createInstrument(const std::shared_ptr<const Instrument> &base,
44 const std::shared_ptr<ParameterMap> &map) {
45 return std::make_shared<Instrument>(base, map);
46}
47
56IComponent_sptr ParComponentFactory::create(const std::shared_ptr<const IComponent> &base, const ParameterMap *map) {
57 std::shared_ptr<const IDetector> det_sptr = std::dynamic_pointer_cast<const IDetector>(base);
58 if (det_sptr) {
59 return createDetector(det_sptr.get(), map);
60 }
61
62 std::shared_ptr<const Instrument> inst_sptr = std::dynamic_pointer_cast<const Instrument>(base);
63 // @todo One of the review tasks is to take a look at the parameterized mess
64 // and
65 // short out this problem with different classes carrying different types of
66 // pointers around
67 if (inst_sptr) {
68 return createInstrument(std::const_pointer_cast<Instrument>(inst_sptr),
69 std::shared_ptr<ParameterMap>(const_cast<ParameterMap *>(map), NoDeleting()));
70 }
71
72 // Everything gets created on the fly. Note that the order matters here
73 // @todo Really could do with a better system than this. Virtual function
74 // maybe?
75 const auto *sd = dynamic_cast<const StructuredDetector *>(base.get());
76 if (sd)
77 return std::make_shared<StructuredDetector>(sd, map);
78
79 const auto *rd = dynamic_cast<const RectangularDetector *>(base.get());
80 if (rd)
81 return std::make_shared<RectangularDetector>(rd, map);
82
83 const auto *gd = dynamic_cast<const GridDetector *>(base.get());
84 if (gd)
85 return std::make_shared<GridDetector>(gd, map);
86
87 const auto *ac = dynamic_cast<const CompAssembly *>(base.get());
88 if (ac)
89 return std::make_shared<CompAssembly>(ac, map);
90 const auto *oac = dynamic_cast<const ObjCompAssembly *>(base.get());
91 if (oac)
92 return std::make_shared<ObjCompAssembly>(oac, map);
93
94 const auto *oc = dynamic_cast<const ObjComponent *>(base.get());
95 if (oc)
96 return std::make_shared<ObjComponent>(oc, map);
97 // Must be a component
98 const auto *cc = dynamic_cast<const IComponent *>(base.get());
99 if (cc)
100 return std::make_shared<Component>(cc, map);
101
102 return IComponent_sptr();
103}
104} // namespace Mantid::Geometry
Class for Assembly of geometric components.
Definition: CompAssembly.h:31
GridDetector is a type of CompAssembly, an assembly of components.
Definition: GridDetector.h:34
base class for Geometric IComponent
Definition: IComponent.h:51
Interface class for detector objects.
Definition: IDetector.h:43
virtual IDetector * cloneParameterized(const ParameterMap *map) const =0
Create a cloned instance with a parameter map applied.
Void deleter for shared pointers.
Class for Assembly of geometric components.
Object Component class, this class brings together the physical attributes of the component to the po...
Definition: ObjComponent.h:33
static std::shared_ptr< IComponent > create(const std::shared_ptr< const IComponent > &base, const ParameterMap *map)
Create a parameterized component from the given base component and ParameterMap.
static std::shared_ptr< Instrument > createInstrument(const std::shared_ptr< const Instrument > &base, const std::shared_ptr< ParameterMap > &map)
Create a parameterized instrument from the given base and ParameterMap.
static std::shared_ptr< IDetector > createDetector(const IDetector *base, const ParameterMap *map)
Create a parameterized detector from the given base component and ParameterMap and return a shared_pt...
RectangularDetector is a type of CompAssembly, an assembly of components.
StructuredDetector is a type of CompAssembly, an assembly of components.
std::shared_ptr< IComponent > IComponent_sptr
Typedef of a shared pointer to a IComponent.
Definition: IComponent.h:159