Mantid
Loading...
Searching...
No Matches
ParameterMap.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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 "MantidGeometry/DllConfig.h"
11#include "MantidGeometry/IDTypes.h" //For specnum_t
14
15#include "tbb/concurrent_unordered_map.h"
16
17#include <memory>
18#include <typeinfo>
19#include <vector>
20
21namespace Mantid {
22namespace Kernel {
23template <class KEYTYPE, class VALUETYPE> class Cache;
24}
25namespace Geometry {
26class ComponentInfo;
27class DetectorInfo;
28class Instrument;
29
40using component_map_it = tbb::concurrent_unordered_multimap<ComponentID, std::shared_ptr<Parameter>>::iterator;
41using component_map_cit = tbb::concurrent_unordered_multimap<ComponentID, std::shared_ptr<Parameter>>::const_iterator;
42
43class MANTID_GEOMETRY_DLL ParameterMap {
44public:
46 using pmap = tbb::concurrent_unordered_multimap<ComponentID, std::shared_ptr<Parameter>>;
48 using pmap_it = tbb::concurrent_unordered_multimap<ComponentID, std::shared_ptr<Parameter>>::iterator;
50 using pmap_cit = tbb::concurrent_unordered_multimap<ComponentID, std::shared_ptr<Parameter>>::const_iterator;
54 ParameterMap(const ParameterMap &other);
57 inline bool empty() const { return m_map.empty(); }
59 inline int size() const { return static_cast<int>(m_map.size()); }
61 size_t getMemorySize() const;
63 static const std::string &pos();
64 static const std::string &posx();
65 static const std::string &posy();
66 static const std::string &posz();
67 static const std::string &rot();
68 static const std::string &rotx();
69 static const std::string &roty();
70 static const std::string &rotz();
71 static const std::string &pDouble(); // p prefix to avoid name clash
72 static const std::string &pInt();
73 static const std::string &pBool();
74 static const std::string &pString();
75 static const std::string &pV3D();
76 static const std::string &pQuat();
77 static const std::string &scale();
78
79 const std::string diff(const ParameterMap &rhs, const bool &firstDiffOnly = false, const bool relative = false,
80 const double doubleTolerance = Kernel::Tolerance) const;
81
83 bool operator!=(const ParameterMap &rhs) const;
85 bool operator==(const ParameterMap &rhs) const;
86
88 inline void clear() {
89 m_map.clear();
90 clearPositionSensitiveCaches();
91 }
94 void swap(ParameterMap &other) {
95 m_map.swap(other.m_map);
96 clearPositionSensitiveCaches();
97 }
99 void clearParametersByName(const std::string &name);
100
102 void clearParametersByName(const std::string &name, const IComponent *comp);
103
105 void add(const std::string &type, const IComponent *comp, const std::string &name, const std::string &value,
106 const std::string *const pDescription = nullptr, const std::string &visible = "true");
107
122 template <class T>
123 void add(const std::string &type, const IComponent *comp, const std::string &name, const T &value,
124 const std::string *const pDescription = nullptr, const std::string &pVisible = "true") {
125 auto param = create(type, name, pVisible);
126 auto typedParam = std::dynamic_pointer_cast<ParameterType<T>>(param);
127 assert(typedParam); // If not true the factory has created the wrong type
128 typedParam->setValue(value);
129 this->add(comp, param, pDescription);
130 }
133 void add(const IComponent *comp, const std::shared_ptr<Parameter> &par,
134 const std::string *const pDescription = nullptr);
135
139 void addFittingParameter(const IComponent *comp, const std::string &name, const std::string &fittingFunction,
140 const std::string &value, const std::string *const pDescription = nullptr,
141 const std::string &pVisible = "true");
142
145 void addPositionCoordinate(const IComponent *comp, const std::string &name, const double value,
146 const std::string *const pDescription = nullptr);
148 void addRotationParam(const IComponent *comp, const std::string &name, const double deg,
149 const std::string *const pDescription = nullptr);
151 void addDouble(const IComponent *comp, const std::string &name, const std::string &value,
152 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
154 void addDouble(const IComponent *comp, const std::string &name, double value,
155 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
157 void addInt(const IComponent *comp, const std::string &name, const std::string &value,
158 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
160 void addInt(const IComponent *comp, const std::string &name, int value,
161 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
163 void addBool(const IComponent *comp, const std::string &name, const std::string &value,
164 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
166 void addBool(const IComponent *comp, const std::string &name, bool value,
167 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
169 void addString(const IComponent *comp, const std::string &name, const std::string &value,
170 const std::string *const pDescription = nullptr, const std::string &pVisible = "true");
172 void addV3D(const IComponent *comp, const std::string &name, const std::string &value,
173 const std::string *const pDescription = nullptr);
175 void addV3D(const IComponent *comp, const std::string &name, const Kernel::V3D &value,
176 const std::string *const pDescription = nullptr);
178 void addQuat(const IComponent *comp, const std::string &name, const Kernel::Quat &value,
179 const std::string *const pDescription = nullptr);
180 void forceUnsafeSetMasked(const IComponent *comp, bool value);
182
185 bool contains(const IComponent *comp, const std::string &name, const std::string &type = "") const;
187 bool contains(const IComponent *comp, const char *name, const char *type = "") const;
189 bool contains(const IComponent *comp, const Parameter &parameter) const;
191 std::shared_ptr<Parameter> get(const IComponent *comp, const std::string &name, const std::string &type = "") const;
193 std::shared_ptr<Parameter> get(const IComponent *comp, const char *name, const char *type = "") const;
195 std::shared_ptr<Parameter> getByType(const IComponent *comp, const std::string &type) const;
198 std::shared_ptr<Parameter> getRecursive(const IComponent *comp, const std::string &name,
199 const std::string &type = "") const;
202 std::shared_ptr<Parameter> getRecursive(const IComponent *comp, const char *name, const char *type = "") const;
205 std::shared_ptr<Parameter> getRecursiveByType(const IComponent *comp, const std::string &type) const;
206
210 std::shared_ptr<Parameter> getRecursiveFittingParameter(const IComponent *comp, const std::string &name,
211 const std::string &fittingFunction) const;
212
220 template <class T> std::vector<T> getType(const std::string &compName, const std::string &name) const {
221 std::vector<T> retval;
222
223 pmap_cit it;
224 for (it = m_map.begin(); it != m_map.end(); ++it) {
225 if (compName == it->first->getName()) {
226 std::shared_ptr<Parameter> param = get(it->first, name);
227 if (param)
228 retval.emplace_back(param->value<T>());
229 }
230 }
231 return retval;
232 }
234 const std::string getDescription(const std::string &compName, const std::string &name) const;
236 const std::string getShortDescription(const std::string &compName, const std::string &name) const;
237
239 std::string getString(const IComponent *comp, const std::string &name, bool recursive = false) const;
242 std::vector<std::string> getString(const std::string &compName, const std::string &name) const {
243 return getType<std::string>(compName, name);
244 }
252 std::vector<double> getDouble(const std::string &compName, const std::string &name) const {
253 return getType<double>(compName, name);
254 }
262 std::vector<Kernel::V3D> getV3D(const std::string &compName, const std::string &name) const {
263 return getType<Kernel::V3D>(compName, name);
264 }
265
267 std::set<std::string> names(const IComponent *comp) const;
269 std::string asString() const;
270
272 void clearPositionSensitiveCaches();
274 void setCachedLocation(const IComponent *comp, const Kernel::V3D &location) const;
276 bool getCachedLocation(const IComponent *comp, Kernel::V3D &location) const;
278 void setCachedRotation(const IComponent *comp, const Kernel::Quat &rotation) const;
280 bool getCachedRotation(const IComponent *comp, Kernel::Quat &rotation) const;
282 void saveNexus(Nexus::File *file, const std::string &group) const;
285 void copyFromParameterMap(const IComponent *oldComp, const IComponent *newComp, const ParameterMap *oldPMap);
286
288 const std::vector<std::string> &getParameterFilenames() const;
290 void addParameterFilename(const std::string &filename);
291
293 pmap_it begin() { return m_map.begin(); }
294 pmap_cit begin() const { return m_map.begin(); }
296 pmap_it end() { return m_map.end(); }
297 pmap_cit end() const { return m_map.end(); }
298
299 bool hasDetectorInfo(const Instrument *instrument) const;
300 bool hasComponentInfo(const Instrument *instrument) const;
301 const Geometry::DetectorInfo &detectorInfo() const;
302 Geometry::DetectorInfo &mutableDetectorInfo();
303 const Geometry::ComponentInfo &componentInfo() const;
304 Geometry::ComponentInfo &mutableComponentInfo();
305 size_t detectorIndex(const detid_t detID) const;
306 size_t componentIndex(const Geometry::ComponentID componentId) const;
307 const std::vector<Geometry::ComponentID> &componentIds() const;
308 void setInstrument(const Instrument *instrument);
309
310private:
311 std::shared_ptr<Parameter> create(const std::string &className, const std::string &name,
312 const std::string &visible = "true") const;
313
317 component_map_it positionOf(const IComponent *comp, const char *name, const char *type);
320 component_map_cit positionOf(const IComponent *comp, const char *name, const char *type) const;
322 bool relErr(double x1, double x2, double errorVal) const;
323
325 std::vector<std::string> m_parameterFileNames;
326
330 std::unique_ptr<Kernel::Cache<const ComponentID, Kernel::V3D>> m_cacheLocMap;
332 std::unique_ptr<Kernel::Cache<const ComponentID, Kernel::Quat>> m_cacheRotMap;
333
336 std::unique_ptr<Geometry::DetectorInfo> m_detectorInfo;
337
340 std::unique_ptr<Geometry::ComponentInfo> m_componentInfo;
341
346 const Instrument *m_instrument{nullptr};
347};
348
350using ParameterMap_sptr = std::shared_ptr<ParameterMap>;
352using ParameterMap_const_sptr = std::shared_ptr<const ParameterMap>;
353
354} // Namespace Geometry
355
356} // Namespace Mantid
std::string name
Definition Run.cpp:60
const std::vector< double > & rhs
double value
The value of the point.
Definition FitMW.cpp:51
IntArray detectorIndex
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
ComponentInfo : Provides a component centric view on to the instrument.
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
base class for Geometric IComponent
Definition IComponent.h:53
Base Instrument Class.
Definition Instrument.h:49
pmap_it begin()
access iterators. begin;
void clear()
Clears the map.
std::unique_ptr< Geometry::DetectorInfo > m_detectorInfo
Pointer to the DetectorInfo wrapper.
ParameterMap & operator=(ParameterMap *rhs)
Assignment operator.
std::vector< Kernel::V3D > getV3D(const std::string &compName, const std::string &name) const
Returns a Kernel::V3D parameter as vector's first element if exists and an empty vector if it doesn't...
tbb::concurrent_unordered_multimap< ComponentID, std::shared_ptr< Parameter > >::iterator pmap_it
Parameter map iterator typedef.
bool empty() const
Returns true if the map is empty, false otherwise.
std::vector< T > getType(const std::string &compName, const std::string &name) const
Get the values of a given parameter of all the components that have the name: compName.
std::vector< std::string > getString(const std::string &compName, const std::string &name) const
Returns a string parameter as vector's first element if exists and an empty vector if it doesn't.
int size() const
Return the size of the map.
std::vector< std::string > m_parameterFileNames
internal list of parameter files loaded
pmap_it end()
access iterators. end;
pmap m_map
internal parameter map instance
std::unique_ptr< Kernel::Cache< const ComponentID, Kernel::V3D > > m_cacheLocMap
internal cache map instance for cached position values
void add(const std::string &type, const IComponent *comp, const std::string &name, const T &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Method for adding a parameter providing its value of a particular type.
std::unique_ptr< Kernel::Cache< const ComponentID, Kernel::Quat > > m_cacheRotMap
internal cache map instance for cached rotation values
std::vector< double > getDouble(const std::string &compName, const std::string &name) const
Returns a double parameter as vector's first element if exists and an empty vector if it doesn't.
const std::vector< Geometry::ComponentID > & componentIds() const
tbb::concurrent_unordered_multimap< ComponentID, std::shared_ptr< Parameter > >::const_iterator pmap_cit
Parameter map iterator typedef.
std::unique_ptr< Geometry::ComponentInfo > m_componentInfo
Pointer to the ComponentInfo wrapper.
void swap(ParameterMap &other)
method swaps two parameter maps contents each other.
Base class for parameters of an instrument.
Definition Parameter.h:37
Class for quaternions.
Definition Quat.h:39
Class for 3D vectors.
Definition V3D.h:34
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
tbb::concurrent_unordered_multimap< ComponentID, std::shared_ptr< Parameter > >::const_iterator component_map_cit
tbb::concurrent_unordered_multimap< ComponentID, std::shared_ptr< Parameter > >::iterator component_map_it
Parameter map iterator typedef.
std::shared_ptr< ParameterMap > ParameterMap_sptr
ParameterMap shared pointer typedef.
std::shared_ptr< const ParameterMap > ParameterMap_const_sptr
ParameterMap constant shared pointer typedef.
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.
Generate a tableworkspace to store the calibration results.
constexpr bool operator==(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
constexpr bool operator!=(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)