Mantid
Loading...
Searching...
No Matches
ComponentInfo.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2017 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 +
7#pragma once
8
9#include "MantidBeamline/ComponentType.h"
10#include "MantidBeamline/PixelGridComponent.h"
11#include "MantidBeamline/StructuredGridComponent.h"
12#include "MantidGeometry/DllConfig.h"
18#include "MantidTypes/Core/DateAndTime.h"
19#include <limits>
20#include <memory>
21#include <set>
22#include <tuple>
23#include <unordered_map>
24#include <vector>
25
26namespace Mantid {
27
28namespace Kernel {
29class Quat;
30class V2D;
31class V3D;
32} // namespace Kernel
33
34namespace Geometry {
35class IComponent;
36class IObject;
37class ReferenceFrame;
38} // namespace Geometry
39
40namespace Beamline {
41class ComponentInfo;
42}
43
44namespace Geometry {
45class Instrument;
46
50class MANTID_GEOMETRY_DLL ComponentInfo {
51public:
53 static constexpr size_t invalidIndex = std::numeric_limits<size_t>::max();
54
55private:
57 std::unique_ptr<Beamline::ComponentInfo> m_componentInfo;
59 std::shared_ptr<const std::vector<Geometry::IComponent *>> m_componentIds;
61 std::shared_ptr<const std::unordered_map<Geometry::IComponent const *, size_t>> m_compIDToIndex;
62
64 std::shared_ptr<std::vector<std::shared_ptr<const Geometry::IObject>>> m_shapes;
65
67 std::shared_ptr<ParameterInfo> m_parameterInfo;
68
70 std::shared_ptr<const ReferenceFrame> m_referenceFrame;
71
73 std::shared_ptr<Parameter> findParameter(size_t componentIndex, std::string const &name, bool recursive) const;
74
75 template <class T> std::vector<T> getParameter(size_t componentIndex, const std::string &name, bool recursive) const;
76
78 template <class T>
79 void addTypedParameter(const size_t componentIndex, const std::string &type, const std::string &name, const T &value,
80 const std::string *const pDescription, const std::string &pVisible);
81
84 ParameterInfo &mutableParameterInfo();
85
86 BoundingBox componentBoundingBox(const size_t index, const BoundingBox *reference,
87 const bool excludeMonitors = false) const;
88
90 ComponentInfo(const ComponentInfo &other);
91 void growBoundingBoxAsRectuangularBank(size_t index, const Geometry::BoundingBox *reference,
92 Geometry::BoundingBox &mutableBB, const bool excludeMonitors = false) const;
93 void growBoundingBoxAsOutline(size_t index, const Geometry::BoundingBox *reference, Geometry::BoundingBox &mutableBB,
94 const bool excludeMonitors = false) const;
95
96public:
98 size_t topLeft;
99 size_t bottomLeft;
101 size_t topRight;
102 size_t nX;
103 size_t nY;
104 };
105
106 ComponentInfo(std::unique_ptr<Beamline::ComponentInfo> componentInfo,
107 std::shared_ptr<const std::vector<Mantid::Geometry::IComponent *>> componentIds,
108 std::shared_ptr<const std::unordered_map<Geometry::IComponent const *, size_t>> componentIdToIndexMap,
109 std::shared_ptr<std::vector<std::shared_ptr<const Geometry::IObject>>> shapes,
110 std::shared_ptr<ParameterInfo> parameterInfo = nullptr,
111 std::shared_ptr<const ReferenceFrame> referenceFrame = nullptr);
115 std::unique_ptr<ComponentInfo> cloneWithoutDetectorInfo() const;
116 std::vector<size_t> detectorsInSubtree(size_t componentIndex) const;
117 std::vector<size_t> componentsInSubtree(size_t componentIndex) const;
118 const std::vector<size_t> &children(size_t componentIndex) const;
119 size_t size() const;
120 size_t getMemorySize() const;
121 QuadrilateralComponent quadrilateralComponent(const size_t componentIndex) const;
122 size_t indexOf(Geometry::IComponent const *id) const;
124 size_t indexOfOrInvalid(Geometry::IComponent const *id) const;
127 size_t indexOfAny(const std::string &name) const;
128 bool uniqueName(const std::string &name) const;
129 bool isDetector(const size_t componentIndex) const;
130 Kernel::V3D position(const size_t componentIndex) const;
131 Kernel::V3D position(const std::pair<size_t, size_t> &index) const;
132 Kernel::Quat rotation(const size_t componentIndex) const;
133 Kernel::Quat rotation(const std::pair<size_t, size_t> &index) const;
134 Kernel::V3D relativePosition(const size_t componentIndex) const;
135 Kernel::Quat relativeRotation(const size_t componentIndex) const;
136 void setPosition(size_t componentIndex, const Kernel::V3D &newPosition);
137 void setRotation(size_t componentIndex, const Kernel::Quat &newRotation);
138 void setPosition(const std::pair<size_t, size_t> &index, const Kernel::V3D &newPosition);
139 void setRotation(const std::pair<size_t, size_t> &index, const Kernel::Quat &newRotation);
140 void scaleComponent(const size_t componentIndex, const Kernel::V3D &newScaling);
141 void scaleComponent(const std::pair<size_t, size_t> &index, const Kernel::V3D &newScaling);
142 size_t parent(const size_t componentIndex) const;
143 bool hasParent(const size_t componentIndex) const;
144 bool hasDetectorInfo() const;
145 Kernel::V3D sourcePosition() const;
146 Kernel::V3D samplePosition() const;
147 bool hasSource() const;
148 bool hasEquivalentSource(const ComponentInfo &other) const;
149 bool hasSample() const;
150 bool hasEquivalentSample(const ComponentInfo &other) const;
151 bool hasDetectors(const size_t componentIndex) const;
152 size_t source() const;
153 size_t sample() const;
154 double l1() const;
155 Kernel::V3D scaleFactor(const size_t componentIndex) const;
156 const std::string &name(const size_t componentIndex) const;
157 void setScaleFactor(const size_t componentIndex, const Kernel::V3D &scaleFactor);
158 Kernel::V2D sideBySideViewPosition(const size_t componentIndex) const;
159 Beamline::PixelGridComponent pixelGridComponent(const size_t componentIndex) const;
160 size_t detectorIndexAtXYZ(const size_t componentIndex, const int x, const int y, const int z) const;
161 std::tuple<int, int, int> xyzForDetectorID(const size_t componentIndex, const detid_t detectorID) const;
162 bool isGridDetector(size_t const componentIndex) const;
164 const Beamline::StructuredGridComponent &structuredGridComponent(const size_t componentIndex) const;
165 bool isStructuredDetector(size_t const componentIndex) const;
166 size_t root() const;
169 std::shared_ptr<const ReferenceFrame> referenceFrame() const;
170
171 const IComponent *componentID(const size_t componentIndex) const { return (*m_componentIds)[componentIndex]; }
172 bool hasValidShape(const size_t componentIndex) const;
173
174 const Geometry::IObject &shape(const size_t componentIndex) const;
175 std::unordered_map<std::shared_ptr<const Geometry::IObject>, std::vector<size_t>> shapeToComponentIndices() const;
176
177 double solidAngle(const size_t componentIndex, const Geometry::SolidAngleParams &params) const;
178 BoundingBox boundingBox(const size_t componentIndex, const BoundingBox *reference = nullptr,
179 const bool excludeMonitors = false) const;
180 Beamline::ComponentType componentType(const size_t componentIndex) const;
181 void setScanInterval(const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> &interval);
182 size_t scanCount() const;
183 void merge(const ComponentInfo &other);
184
189
190 size_t findBankParent(size_t index, const std::string &bankPart) const;
191
193 std::string fullName(const size_t componentIndex) const;
194
196 size_t indexOfFullName(const std::string &fullName) const;
197
199 bool hasParameter(const size_t componentIndex, const std::string &name, bool recursive = true) const;
200 std::set<std::string> getParameterNames(const size_t componentIndex, bool recursive = true) const;
202 const ParameterInfo::ComponentParameters &parameters(const size_t componentIndex) const;
204 std::shared_ptr<const Parameter> parameter(const size_t componentIndex, const std::string &name,
205 const std::string &type = "", bool recursive = true) const;
207 std::shared_ptr<const Parameter> parameterByType(const size_t componentIndex, const std::string &type,
208 bool recursive = true) const;
209 std::vector<double> getNumberParameter(const size_t componentIndex, const std::string &name,
210 bool recursive = true) const;
211 std::vector<int> getIntParameter(const size_t componentIndex, const std::string &name, bool recursive = true) const;
212 std::vector<bool> getBoolParameter(const size_t componentIndex, const std::string &name, bool recursive = true) const;
213 std::vector<std::string> getStringParameter(const size_t componentIndex, const std::string &name,
214 bool recursive = true) const;
215 std::vector<Kernel::V3D> getPositionParameter(const size_t componentIndex, const std::string &name,
216 bool recursive = true) const;
217 std::vector<Kernel::Quat> getRotationParameter(const size_t componentIndex, const std::string &name,
218 bool recursive = true) const;
220 bool getParameterVisible(const size_t componentIndex, const std::string &name, bool recursive = true) const;
222 std::string getParameterType(const size_t componentIndex, const std::string &name, bool recursive = true) const;
224 std::string getParameterAsString(size_t const componentIndex, std::string const &name,
225 bool const recursive = true) const;
226 double getFittingParameter(const size_t componentIndex, const std::string &name, double xvalue) const;
228 std::string getParamDescription(const size_t componentIndex, const std::string &name, bool recursive = true) const;
230 std::string getParamShortDescription(const size_t componentIndex, const std::string &name,
231 bool recursive = true) const;
233 std::string getDescription(const size_t componentIndex) const;
235 std::string getShortDescription(const size_t componentIndex) const;
236
238 void addParameter(const size_t componentIndex, const std::string &type, const std::string &name,
239 const std::string &value, const std::string *const pDescription = nullptr,
240 const std::string &pVisible = "true");
242 void addDouble(const size_t componentIndex, const std::string &name, double value,
243 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
245 void addInt(const size_t componentIndex, const std::string &name, int value,
246 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
248 void addBool(const size_t componentIndex, const std::string &name, bool value,
249 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
251 void addString(const size_t componentIndex, const std::string &name, const std::string &value,
252 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
254 void addV3D(const size_t componentIndex, const std::string &name, const Kernel::V3D &value,
255 const std::string *const pDescription = nullptr);
257 void addQuat(const size_t componentIndex, const std::string &name, const Kernel::Quat &value,
258 const std::string *const pDescription = nullptr);
260 void addFittingParameter(const size_t componentIndex, const std::string &name, const std::string &fittingFunction,
261 const std::string &value, const std::string *const pDescription = nullptr,
262 const std::string &pVisible = "true");
265 void setDescription(const size_t componentIndex, const std::string &description);
268 void clearParameter(const size_t componentIndex, const std::string &name);
270 void clearParameters();
271
273 const ParameterInfo::LogfileParameters &logfileParameters() const;
276 void addLogfileParameter(size_t const componentIndex, std::string const &cacheKey,
277 std::shared_ptr<const XMLInstrumentParameter> const &parameter);
278
281 const std::shared_ptr<ParameterInfo> &sharedParameterInfo() const { return m_parameterInfo; }
282
283 friend class Instrument;
284};
285
288
289} // namespace Geometry
290} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double position
Definition GetAllEi.cpp:154
std::map< DeltaEMode::Type, std::string > index
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
void(ComponentInfo::* setPosition)(const size_t, const Mantid::Kernel::V3D &)
void(ComponentInfo::* setRotation)(const size_t, const Mantid::Kernel::Quat &)
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
ComponentInfoIterator for random access iteration over ComponentInfo.
ComponentInfo : Provides a component centric view on to the instrument.
std::shared_ptr< const ReferenceFrame > m_referenceFrame
The instrument's reference frame (up, along-beam and handedness), or null if none was given.
const std::shared_ptr< ParameterInfo > & sharedParameterInfo() const
This allows ParameterMap to delegate to ParameterInfo, rather than keeping a parallel copy that would...
ComponentInfo & operator=(const ComponentInfo &)=delete
Copy assignment is not possible for ComponentInfo.
std::shared_ptr< std::vector< std::shared_ptr< const Geometry::IObject > > > m_shapes
Shapes for each component.
std::shared_ptr< const std::unordered_map< Geometry::IComponent const *, size_t > > m_compIDToIndex
Map of component ids to indexes.
const IComponent * componentID(const size_t componentIndex) const
std::shared_ptr< ParameterInfo > m_parameterInfo
The instrument's named parameters, keyed by component index.
std::unique_ptr< Beamline::ComponentInfo > m_componentInfo
Pointer to the actual ComponentInfo object (non-wrapping part).
std::shared_ptr< const std::vector< Geometry::IComponent * > > m_componentIds
Collection of component ids.
base class for Geometric IComponent
Definition IComponent.h:53
IObject : Interface for geometry objects.
Definition IObject.h:43
Base Instrument Class.
Definition Instrument.h:50
ParameterInfo : the named parameters of an instrument, addressed by component index.
std::multimap< std::string, std::shared_ptr< Parameter >, Kernel::CaseInsensitiveStringComparator > ComponentParameters
Parameters of a single component, ordered by name.
std::map< std::pair< size_t, std::string >, std::shared_ptr< const XMLInstrumentParameter > > LogfileParameters
Parameters whose values are taken from the sample logs when ExperimentInfo::populateInstrumentParamet...
Class for quaternions.
Definition Quat.h:38
Implements a 2-dimensional vector embedded in a 3D space, i.e.
Definition V2D.h:29
Class for 3D vectors.
Definition V3D.h:35
ComponentInfoIterator< const ComponentInfo > ComponentInfoConstIt
ComponentInfoIterator< ComponentInfo > ComponentInfoIt
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.