8#include "MantidBeamline/ComponentInfo.h"
9#include "MantidBeamline/DetectorInfo.h"
32std::shared_ptr<const std::unordered_map<detid_t, size_t>> makeDetIdToIndexMap(
const std::vector<detid_t> &detIds) {
34 const size_t nDetIds = detIds.size();
35 auto detIdToIndex = std::make_shared<std::unordered_map<detid_t, size_t>>();
36 detIdToIndex->reserve(nDetIds);
37 for (
size_t i = 0; i < nDetIds; ++i) {
38 (*detIdToIndex)[detIds[i]] = i;
43void clearLegacyParameters(ParameterMap *
pmap,
const IComponent &comp) {
57bool hasValidShape(
const ObjCompAssembly &
obj) {
58 const auto *shape =
obj.shape().get();
59 return shape !=
nullptr && shape->hasValidShape();
66Beamline::PixelGridComponent makePixelGridComponent(
const GridDetector &grid) {
67 Beamline::PixelGridComponent pixelGrid;
68 pixelGrid.nX = grid.xpixels();
69 pixelGrid.nY = grid.ypixels();
70 pixelGrid.nZ = grid.zpixels();
71 pixelGrid.xStart = grid.xstart();
72 pixelGrid.yStart = grid.ystart();
73 pixelGrid.zStart = grid.zstart();
74 pixelGrid.xStep = grid.xstep();
75 pixelGrid.yStep = grid.ystep();
76 pixelGrid.zStep = grid.zstep();
77 pixelGrid.idStart = grid.idstart();
78 pixelGrid.idStep = grid.idstep();
79 pixelGrid.idStepByRow = grid.idstepbyrow();
80 pixelGrid.idFillOrder = grid.idFillOrder();
81 pixelGrid.minDetectorID = grid.minDetectorID();
82 pixelGrid.maxDetectorID = grid.maxDetectorID();
88Beamline::StructuredGridComponent makeStructuredGridComponent(
const StructuredDetector &bank) {
89 Beamline::StructuredGridComponent structuredGrid;
90 structuredGrid.nX =
static_cast<int>(bank.xPixels());
91 structuredGrid.nY =
static_cast<int>(bank.yPixels());
92 structuredGrid.idStart = bank.idStart();
93 structuredGrid.idStep = bank.idStep();
94 structuredGrid.idStepByRow = bank.idStepByRow();
95 structuredGrid.idFillByFirstY = bank.idFillByFirstY();
96 structuredGrid.xVertices = bank.getXValues();
97 structuredGrid.yVertices = bank.getYValues();
98 return structuredGrid;
107 : m_orderedDetectorIds(
108 std::make_shared<
std::vector<
detid_t>>(instrument->getDetectorIDs(false ))),
109 m_componentIds(
std::make_shared<
std::vector<
ComponentID>>(m_orderedDetectorIds->size(), nullptr)),
110 m_assemblySortedDetectorIndices(
std::make_shared<
std::vector<size_t>>()),
111 m_assemblySortedComponentIndices(
std::make_shared<
std::vector<size_t>>()),
112 m_parentComponentIndices(
std::make_shared<
std::vector<size_t>>(m_orderedDetectorIds->size(), 0)),
113 m_children(
std::make_shared<
std::vector<
std::vector<size_t>>>()),
114 m_detectorRanges(
std::make_shared<
std::vector<
std::pair<size_t, size_t>>>()),
115 m_componentRanges(
std::make_shared<
std::vector<
std::pair<size_t, size_t>>>()),
116 m_componentIdToIndexMap(
std::make_shared<
std::unordered_map<
Mantid::Geometry::
IComponent const *, size_t>>()),
117 m_detectorIdToIndexMap(makeDetIdToIndexMap(*m_orderedDetectorIds)),
118 m_positions(
std::make_shared<
std::vector<Eigen::Vector3d>>()),
119 m_detectorPositions(
std::make_shared<
std::vector<Eigen::Vector3d>>(m_orderedDetectorIds->size())),
120 m_rotations(
std::make_shared<
std::vector<Eigen::Quaterniond, Eigen::aligned_allocator<Eigen::Quaterniond>>>()),
122 std::make_shared<
std::vector<Eigen::Quaterniond, Eigen::aligned_allocator<Eigen::Quaterniond>>>(
123 m_orderedDetectorIds->size())),
124 m_monitorIndices(
std::make_shared<
std::vector<size_t>>()), m_instrument(
std::move(instrument)), m_pmap(nullptr),
127 std::make_shared<
std::vector<
std::shared_ptr<const
IObject>>>(m_orderedDetectorIds->size(), m_nullShape)),
129 std::make_shared<
std::vector<Eigen::Vector3d>>(m_orderedDetectorIds->size(), Eigen::Vector3d{1, 1, 1})),
130 m_componentType(
std::make_shared<
std::vector<Beamline::ComponentType>>()),
131 m_names(
std::make_shared<
std::vector<
std::string>>(m_orderedDetectorIds->size())),
132 m_sideBySideViewPositions(
std::make_shared<
std::map<size_t, Eigen::Vector2d>>()),
133 m_pixelGridComponents(
std::make_shared<
std::map<size_t, Beamline::PixelGridComponent>>()),
134 m_structuredGridComponents(
std::make_shared<
std::map<size_t, Beamline::StructuredGridComponent>>()) {
169 (*m_componentIdToIndexMap)[componentId] = componentIndex;
178 (*m_sideBySideViewPositions)[componentIndex] =
Kernel::toVector2d(*sideBySideViewPos);
180 clearLegacyParameters(
m_pmap, component);
181 return componentIndex;
186 std::vector<IComponent_const_sptr> assemblyChildren;
191 std::vector<size_t> children(assemblyChildren.size());
192 for (
size_t i = 0; i < assemblyChildren.size(); ++i) {
194 children[i] = assemblyChildren[i]->registerContents(*
this);
209 for (
const auto &child : children) {
210 (*m_parentComponentIndices)[child] = componentIndex;
212 m_children->emplace_back(std::move(children));
213 return componentIndex;
232 m_componentRanges->emplace_back(std::make_pair(componentStart, componentStart + 1));
239 return componentIndex;
265 return componentIndex;
287 (*m_componentType)[rangesIndex] = Beamline::ComponentType::Rectangular;
288 (*m_pixelGridComponents)[
index] = makePixelGridComponent(
dynamic_cast<const GridDetector &
>(bank));
300 (*m_componentType)[rangesIndex] = Beamline::ComponentType::Grid;
301 (*m_pixelGridComponents)[
index] = makePixelGridComponent(
dynamic_cast<const GridDetector &
>(bank));
324 (*m_componentType)[rangesIndex] = Beamline::ComponentType::Structured;
325 (*m_structuredGridComponents)[
index] = makeStructuredGridComponent(
dynamic_cast<const StructuredDetector &
>(bank));
332 if (hasValidShape(
obj)) {
334 (*m_componentType)[rangesIndex] = Beamline::ComponentType::OutlineComposite;
378 clearLegacyParameters(
m_pmap, detector);
413std::shared_ptr<const std::unordered_map<Mantid::Geometry::IComponent const *, size_t>>
423 return std::make_unique<Mantid::Beamline::ComponentInfo>(
446 compInfo->setDetectorInfo(detInfo.get());
450 auto const referenceFrame =
m_instrument->getReferenceFrame();
452 m_shapes, parameterInfo, referenceFrame);
456 return {std::move(compInfoWrapper), std::move(detInfoWrapper)};
459std::pair<std::unique_ptr<ComponentInfo>, std::unique_ptr<DetectorInfo>>
461 std::shared_ptr<const Instrument> visiteeInstrument;
470 auto const mapCopy = std::make_shared<ParameterMap>(*instrument.
getParameterMap());
473 visiteeInstrument = 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.
bool isParametrized() const override
Return true if the Component is, in fact, parametrized (that is - it has a valid parameter map)
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.
std::shared_ptr< std::map< size_t, Beamline::StructuredGridComponent > > m_structuredGridComponents
Pixel counts, ID numbering and pixel vertices of Structured banks, keyed by component index.
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
Make the wrappers from the data collected by walkInstrument(), which must be called first.
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.
std::shared_ptr< const Instrument > baseInstrument() const
Pointer to the 'real' instrument, for parametrized instruments.
std::shared_ptr< ParameterMap > getParameterMap() const
Pointer to the NOT const ParameterMap holding the parameters of the modified instrument components.
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.
std::shared_ptr< ParameterInfo > rekey(std::shared_ptr< const ComponentIDs > componentIds, std::shared_ptr< const ComponentIndices > componentIndices)
Attach this map to an instrument's component index domain, rekeying its parameters onto the instrumen...
bool empty() const
Returns true if the map is empty, false otherwise.
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()
StructuredDetector is a type of CompAssembly, an assembly of components.
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.