8#include "MantidBeamline/ComponentInfo.h"
9#include "MantidBeamline/DetectorInfo.h"
31std::shared_ptr<const std::unordered_map<detid_t, size_t>> makeDetIdToIndexMap(
const std::vector<detid_t> &detIds) {
33 const size_t nDetIds = detIds.size();
34 auto detIdToIndex = std::make_shared<std::unordered_map<detid_t, size_t>>();
35 detIdToIndex->reserve(nDetIds);
36 for (
size_t i = 0; i < nDetIds; ++i) {
37 (*detIdToIndex)[detIds[i]] = i;
42void clearLegacyParameters(ParameterMap *
pmap,
const IComponent &comp) {
56bool hasValidShape(
const ObjCompAssembly &
obj) {
57 const auto *shape =
obj.shape().get();
58 return shape !=
nullptr && shape->hasValidShape();
65Beamline::PixelGridComponent makePixelGridComponent(
const GridDetector &grid) {
66 Beamline::PixelGridComponent pixelGrid;
67 pixelGrid.nX = grid.xpixels();
68 pixelGrid.nY = grid.ypixels();
69 pixelGrid.nZ = grid.zpixels();
70 pixelGrid.xStart = grid.xstart();
71 pixelGrid.yStart = grid.ystart();
72 pixelGrid.zStart = grid.zstart();
73 pixelGrid.xStep = grid.xstep();
74 pixelGrid.yStep = grid.ystep();
75 pixelGrid.zStep = grid.zstep();
76 pixelGrid.idStart = grid.idstart();
77 pixelGrid.idStep = grid.idstep();
78 pixelGrid.idStepByRow = grid.idstepbyrow();
79 pixelGrid.idFillOrder = grid.idFillOrder();
80 pixelGrid.minDetectorID = grid.minDetectorID();
81 pixelGrid.maxDetectorID = grid.maxDetectorID();
91 : m_orderedDetectorIds(
92 std::make_shared<
std::vector<
detid_t>>(instrument->getDetectorIDs(false ))),
93 m_componentIds(
std::make_shared<
std::vector<
ComponentID>>(m_orderedDetectorIds->size(), nullptr)),
94 m_assemblySortedDetectorIndices(
std::make_shared<
std::vector<size_t>>()),
95 m_assemblySortedComponentIndices(
std::make_shared<
std::vector<size_t>>()),
96 m_parentComponentIndices(
std::make_shared<
std::vector<size_t>>(m_orderedDetectorIds->size(), 0)),
97 m_children(
std::make_shared<
std::vector<
std::vector<size_t>>>()),
98 m_detectorRanges(
std::make_shared<
std::vector<
std::pair<size_t, size_t>>>()),
99 m_componentRanges(
std::make_shared<
std::vector<
std::pair<size_t, size_t>>>()),
100 m_componentIdToIndexMap(
std::make_shared<
std::unordered_map<
Mantid::Geometry::
IComponent const *, size_t>>()),
101 m_detectorIdToIndexMap(makeDetIdToIndexMap(*m_orderedDetectorIds)),
102 m_positions(
std::make_shared<
std::vector<Eigen::Vector3d>>()),
103 m_detectorPositions(
std::make_shared<
std::vector<Eigen::Vector3d>>(m_orderedDetectorIds->size())),
104 m_rotations(
std::make_shared<
std::vector<Eigen::Quaterniond, Eigen::aligned_allocator<Eigen::Quaterniond>>>()),
106 std::make_shared<
std::vector<Eigen::Quaterniond, Eigen::aligned_allocator<Eigen::Quaterniond>>>(
107 m_orderedDetectorIds->size())),
108 m_monitorIndices(
std::make_shared<
std::vector<size_t>>()), m_instrument(
std::move(instrument)), m_pmap(nullptr),
111 std::make_shared<
std::vector<
std::shared_ptr<const
IObject>>>(m_orderedDetectorIds->size(), m_nullShape)),
113 std::make_shared<
std::vector<Eigen::Vector3d>>(m_orderedDetectorIds->size(), Eigen::Vector3d{1, 1, 1})),
114 m_componentType(
std::make_shared<
std::vector<Beamline::ComponentType>>()),
115 m_names(
std::make_shared<
std::vector<
std::string>>(m_orderedDetectorIds->size())),
116 m_sideBySideViewPositions(
std::make_shared<
std::map<size_t, Eigen::Vector2d>>()),
117 m_pixelGridComponents(
std::make_shared<
std::map<size_t, Beamline::PixelGridComponent>>()) {
152 (*m_componentIdToIndexMap)[componentId] = componentIndex;
161 (*m_sideBySideViewPositions)[componentIndex] =
Kernel::toVector2d(*sideBySideViewPos);
163 clearLegacyParameters(
m_pmap, component);
164 return componentIndex;
169 std::vector<IComponent_const_sptr> assemblyChildren;
174 std::vector<size_t> children(assemblyChildren.size());
175 for (
size_t i = 0; i < assemblyChildren.size(); ++i) {
177 children[i] = assemblyChildren[i]->registerContents(*
this);
192 for (
const auto &child : children) {
193 (*m_parentComponentIndices)[child] = componentIndex;
195 m_children->emplace_back(std::move(children));
196 return componentIndex;
215 m_componentRanges->emplace_back(std::make_pair(componentStart, componentStart + 1));
222 return componentIndex;
248 return componentIndex;
270 (*m_componentType)[rangesIndex] = Beamline::ComponentType::Rectangular;
271 (*m_pixelGridComponents)[
index] = makePixelGridComponent(
dynamic_cast<const GridDetector &
>(bank));
283 (*m_componentType)[rangesIndex] = Beamline::ComponentType::Grid;
284 (*m_pixelGridComponents)[
index] = makePixelGridComponent(
dynamic_cast<const GridDetector &
>(bank));
307 (*m_componentType)[rangesIndex] = Beamline::ComponentType::Structured;
314 if (hasValidShape(
obj)) {
316 (*m_componentType)[rangesIndex] = Beamline::ComponentType::OutlineComposite;
360 clearLegacyParameters(
m_pmap, detector);
395std::shared_ptr<const std::unordered_map<Mantid::Geometry::IComponent const *, size_t>>
405 return std::make_unique<Mantid::Beamline::ComponentInfo>(
428 compInfo->setDetectorInfo(detInfo.get());
432 auto detInfoWrapper =
435 return {std::move(compInfoWrapper), std::move(detInfoWrapper)};
438std::pair<std::unique_ptr<ComponentInfo>, std::unique_ptr<DetectorInfo>>
441 const auto visiteeInstrument =
444 : std::shared_ptr<const Instrument>(&instrument,
NoDeleting());
std::map< DeltaEMode::Type, std::string > index
double obj
the value of the quadratic function
Constructive Solid Geometry object.
GridDetector is a type of CompAssembly, an assembly of components.
Class for Assembly of geometric components.
virtual void getChildren(std::vector< IComponent_const_sptr > &outVector, bool recursive) const =0
Get all children.
base class for Geometric IComponent
virtual size_t registerContents(class ComponentVisitor &component) const =0
virtual Kernel::V3D getPos() const =0
Get the position of the IComponent. Tree structure is traverse through the.
virtual std::optional< Kernel::V2D > getSideBySideViewPos() const =0
Get the position of the IComponent for display on the side by side instrument view.
virtual Kernel::Quat getRotation() const =0
Get the absolute orientation of the IComponent.
virtual Kernel::V3D getScaleFactor() const
Gets the scaling factor of the object for the Object Component.
virtual ComponentID getComponentID() const =0
Returns the ComponentID - a unique identifier of the component.
virtual std::string getName() const =0
Get the IComponent name.
Interface class for detector objects.
virtual detid_t getID() const =0
Get the detector ID.
Object Component class, this class brings together the physical attributes of the component to the po...
virtual const std::shared_ptr< const IObject > shape() const =0
Returns the shape of the Object.
IObject : Interface for geometry objects.
InstrumentVisitor : Visitor for components with access to Info wrapping features.
std::shared_ptr< std::vector< std::pair< size_t, size_t > > > m_detectorRanges
Only Assemblies and other NON-detectors yield detector ranges.
std::shared_ptr< const std::unordered_map< detid_t, size_t > > m_detectorIdToIndexMap
Detector ID -> index mappings.
int64_t m_sourceIndex
Source index to set.
std::shared_ptr< std::vector< size_t > > m_assemblySortedComponentIndices
Component indexes sorted by assembly.
std::unique_ptr< Beamline::ComponentInfo > componentInfo() const
Mantid::Geometry::ParameterMap * m_pmap
Parameter map to purge.
InstrumentVisitor(std::shared_ptr< const Instrument > instrument)
Constructor.
virtual size_t registerComponentAssembly(const Mantid::Geometry::ICompAssembly &assembly) override
std::shared_ptr< std::vector< detid_t > > m_orderedDetectorIds
Detector indices.
size_t size() const
InstrumentVisitor::size.
std::shared_ptr< const Mantid::Geometry::IObject > m_nullShape
Null shared (empty shape)
std::shared_ptr< std::vector< Eigen::Quaterniond, Eigen::aligned_allocator< Eigen::Quaterniond > > > m_rotations
Rotations for non-detectors.
virtual size_t registerGenericObjComponent(const Mantid::Geometry::IObjComponent &objComponent) override
InstrumentVisitor::registerGenericObjComponent.
std::shared_ptr< std::vector< size_t > > m_assemblySortedDetectorIndices
Detector indexes sorted by assembly.
std::shared_ptr< std::vector< std::pair< size_t, size_t > > > m_componentRanges
Component ranges.
size_t commonRegistration(const Mantid::Geometry::IComponent &component)
Extract the common aspects relevant to all component types.
std::shared_ptr< std::vector< detid_t > > detectorIds() const
virtual size_t registerGridBank(const Mantid::Geometry::ICompAssembly &bank) override
Register a grid bank.
std::shared_ptr< std::vector< Eigen::Vector3d > > m_positions
Positions for non-detectors.
void markAsSourceOrSample(Mantid::Geometry::IComponent *componentId, const size_t componentIndex)
virtual size_t registerRectangularBank(const Mantid::Geometry::ICompAssembly &bank) override
Register a rectangular bank.
virtual size_t registerObjComponentAssembly(const ObjCompAssembly &obj) override
std::shared_ptr< std::vector< std::shared_ptr< const Mantid::Geometry::IObject > > > m_shapes
Shapes stored in fly-weight fashion.
virtual size_t registerDetector(const Mantid::Geometry::IDetector &detector) override
InstrumentVisitor::registerDetector.
std::shared_ptr< std::vector< std::vector< size_t > > > m_children
Stores instrument tree structure by storing children of all Components.
std::shared_ptr< std::map< size_t, Eigen::Vector2d > > m_sideBySideViewPositions
Side-by-side (unwrapped) instrument-view positions when declared in the IDF.
std::shared_ptr< const std::unordered_map< Mantid::Geometry::IComponent const *, size_t > > componentIdToIndexMap() const
std::shared_ptr< std::vector< Eigen::Vector3d > > m_scaleFactors
Scale factors.
std::shared_ptr< std::vector< Mantid::Geometry::IComponent * > > m_componentIds
Detectors components always specified first.
std::shared_ptr< std::vector< Eigen::Vector3d > > m_detectorPositions
Positions for detectors.
std::shared_ptr< std::vector< Beamline::ComponentType > > m_componentType
Structured bank flag.
std::shared_ptr< const std::unordered_map< detid_t, size_t > > detectorIdToIndexMap() const
std::shared_ptr< std::map< size_t, Beamline::PixelGridComponent > > m_pixelGridComponents
Rectangular/Grid bank pixel-grid metadata.
std::pair< std::unique_ptr< ComponentInfo >, std::unique_ptr< DetectorInfo > > makeWrappers() const
Mantid::Geometry::IComponent * m_sourceId
Source id to look for.
std::unique_ptr< Beamline::DetectorInfo > detectorInfo() const
virtual size_t registerStructuredBank(const Mantid::Geometry::ICompAssembly &bank) override
Register a structured bank.
std::shared_ptr< const std::vector< Mantid::Geometry::IComponent * > > componentIds() const
InstrumentVisitor::componentIds.
std::shared_ptr< std::vector< std::string > > m_names
Component names.
virtual size_t registerInfiniteComponent(const Mantid::Geometry::IComponent &component) override
InstrumentVisitor::registerInfiniteComponent.
int64_t m_sampleIndex
Sample index to set.
Mantid::Geometry::IComponent * m_sampleId
Sample id to look for.
std::shared_ptr< const Mantid::Geometry::Instrument > m_instrument
Instrument to build around.
std::shared_ptr< ParameterInfo > makeParameterInfo() const
Rekey the ParameterMap's parameters from legacy component pointers to component indices.
std::shared_ptr< std::vector< size_t > > m_parentComponentIndices
Index of the parent component.
std::shared_ptr< std::unordered_map< Mantid::Geometry::IComponent const *, size_t > > m_componentIdToIndexMap
Component ID -> Component Index map.
std::shared_ptr< std::vector< size_t > > m_monitorIndices
Monitor indexes for detectors.
virtual size_t registerInfiniteObjComponent(const IObjComponent &objComponent) override
InstrumentVisitor::registerInfiniteObjComponent.
virtual size_t registerGenericComponent(const Mantid::Geometry::IComponent &component) override
InstrumentVisitor::registerGenericComponent.
std::shared_ptr< std::vector< Eigen::Quaterniond, Eigen::aligned_allocator< Eigen::Quaterniond > > > m_detectorRotations
Rotations for detectors.
Class for Assembly of geometric components.
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.
Parameter map iterator typedef.
bool empty() const
Returns true if the map is empty, false otherwise.
std::shared_ptr< ParameterInfo > rekey(const std::unordered_map< Geometry::IComponent const *, size_t > &idToIndex)
Rekey this map's parameters from the synthetic staging indices onto an instrument's real component in...
static const std::string & scale()
static const std::string & rot()
static const std::string & posz()
static const std::string & pos()
Return string to be used in the map.
static const std::string & rotz()
static const std::string & posy()
static const std::string & posx()
static const std::string & rotx()
std::shared_ptr< Parameter > get(const IComponent *comp, const std::string &name, const std::string &type="") const
Get a parameter with a given name and type (std::string version)
static const std::string & roty()
This functor is used as the deleter object of a shared_ptr to effectively erase ownership Raw pointer...
Eigen::Vector3d toVector3d(const Kernel::V3D &vec)
Converts Kernel::V3D to Eigen::Vector3d.
Eigen::Vector2d toVector2d(const Kernel::V2D &vec)
Converts Kernel::V2D to Eigen::Vector2d.
Eigen::Quaterniond toQuaterniond(const Kernel::Quat &quat)
Converts Kernel::Quat to Eigen::Quaterniond.
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.