Mantid
Loading...
Searching...
No Matches
InstrumentDefinitionParser.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
11#include "MantidKernel/V3D.h"
12#include <Poco/AutoPtr.h>
13#include <Poco/DOM/Document.h>
14#include <string>
15#include <vector>
16
17namespace Poco {
18namespace XML {
19class Element;
20}
21} // namespace Poco
22
23namespace Mantid {
24namespace Kernel {
25class ProgressBase;
26}
27
28namespace Geometry {
29class ICompAssembly;
30class IComponent;
31class Instrument;
32class ObjComponent;
33class IObject;
34class ShapeFactory;
35
43class MANTID_GEOMETRY_DLL InstrumentDefinitionParser {
44public:
46 InstrumentDefinitionParser(const std::string &filename, const std::string &instName, const std::string &xmlText);
47 InstrumentDefinitionParser(const IDFObject_const_sptr &xmlFile, const IDFObject_const_sptr &expectedCacheFile,
48 const std::string &instName, const std::string &xmlText);
50
52 enum CachingOption { NoneApplied, ReadGeomCache, ReadFallBack, WroteGeomCache, WroteCacheTemp };
53
55 std::shared_ptr<Instrument> parseXML(Kernel::ProgressBase *progressReporter);
56
59 void setComponentLinks(std::shared_ptr<Geometry::Instrument> &instrument, Poco::XML::Element *pRootElem,
60 Kernel::ProgressBase *progress = nullptr, const std::string &requestedDate = std::string());
61
62 std::string getMangledName();
63
65 static Poco::XML::Element *getParentComponent(const Poco::XML::Element *pLocElem);
66
68 static std::string getNameOfLocationElement(const Poco::XML::Element *pElem, const Poco::XML::Element *pCompElem);
69
71 void saveDOM_Tree(const std::string &outFilename);
72
74 CachingOption getAppliedCachingOption() const;
75
77 const std::string createVTPFileName();
78
79private:
81 void initialise(const std::string &filename, const std::string &instName, const std::string &xmlText,
82 const std::string &vtpFilename);
83
85 Poco::AutoPtr<Poco::XML::Document> getDocument();
86
88 void setLocation(Geometry::IComponent *comp, const Poco::XML::Element *pElem, const double angleConvertConst,
89 const bool deltaOffsets = false);
91 void setSideBySideViewLocation(Geometry::IComponent *comp, const Poco::XML::Element *pCompElem);
92
95 Kernel::V3D getRelativeTranslation(const Geometry::IComponent *comp, const Poco::XML::Element *pElem,
96 const double angleConvertConst, const bool deltaOffsets = false);
97
99 void setValidityRange(const Poco::XML::Element *pRootElem);
100
102 void readDefaults(Poco::XML::Element *defaults);
103
105 struct IdList {
109 std::vector<int> vec;
111 std::string idname;
112
114 IdList() : counted(0) {};
115
117 bool empty() { return vec.empty(); };
118
120 void reset() {
121 counted = 0;
122 vec.clear();
123 };
124 };
125
127 void populateIdList(Poco::XML::Element *pE, IdList &idList);
128
129 std::vector<std::string> buildExcludeList(const Poco::XML::Element *const location);
130
133 void appendAssembly(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
134 const Poco::XML::Element *pCompElem, IdList &idList);
137 bool isAssembly(const std::string &) const;
138
141 void appendLeaf(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
142 const Poco::XML::Element *pCompElem, IdList &idList);
143
144 void createDetectorOrMonitor(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
145 const Poco::XML::Element *pCompElem, const std::string &filename, IdList &idList,
146 const std::string &category);
147
148 void createGridDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
149 const Poco::XML::Element *pCompElem, const std::string &filename,
150 const Poco::XML::Element *pType);
151
152 void createRectangularDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
153 const Poco::XML::Element *pCompElem, const std::string &filename,
154 const Poco::XML::Element *pType);
155
156 void createStructuredDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
157 const Poco::XML::Element *pCompElem, const std::string &filename,
158 const Poco::XML::Element *pType);
159
161 void appendLocations(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElems,
162 const Poco::XML::Element *pCompElem, IdList &idList);
163
165 void setLogfile(const Geometry::IComponent *comp, const Poco::XML::Element *pElem,
166 InstrumentParameterCache &logfileCache, const std::string &requestedDate = std::string());
167
169 Kernel::V3D parseFacingElementToV3D(Poco::XML::Element *pElem);
171 void setFacing(Geometry::IComponent *comp, const Poco::XML::Element *pElem);
174 void makeXYplaneFaceComponent(Geometry::IComponent *&in, const Geometry::ObjComponent *facing);
177 void makeXYplaneFaceComponent(Geometry::IComponent *&in, const Kernel::V3D &facingPoint);
178
180 CachingOption setupGeometryCache();
181
184 void createNeutronicInstrument();
185
192 void adjust(Poco::XML::Element *pElem, const std::map<std::string, bool> &isTypeAssembly,
193 std::map<std::string, Poco::XML::Element *> &getTypeElement);
194
198 Poco::AutoPtr<Poco::XML::Document> convertLocationsElement(const Poco::XML::Element *pElem);
199
202 double attrToDouble(const Poco::XML::Element *pElem, const std::string &name);
203
205 void getTypeAndComponentPointers(const Poco::XML::Element *pRootElem, std::vector<Poco::XML::Element *> &typeElems,
206 std::vector<Poco::XML::Element *> &compElems) const;
207
209 void throwIfTypeNameNotUnique(const std::string &filename, const std::string &typeName) const;
210
213 void createShapeIfTypeIsNotAnAssembly(Mantid::Geometry::ShapeFactory &shapeCreator, size_t iType,
214 Poco::XML::Element *pTypeElem, const std::string &typeName);
215
218 void adjustTypesContainingCombineComponentsElement(ShapeFactory &shapeCreator, const std::string &filename,
219 const std::vector<Poco::XML::Element *> &typeElems,
220 size_t numberOfTypes);
221
223 void createVectorOfElementsContainingAParameterElement(Poco::XML::Element *pRootElem);
224
226 void checkIdListExistsAndDefinesEnoughIDs(const IdList &idList, Poco::XML::Element *pElem,
227 const std::string &filename) const;
228
230 void checkComponentContainsLocationElement(Poco::XML::Element *pElem, const std::string &filename) const;
231
233 void parseLocationsForEachTopLevelComponent(Kernel::ProgressBase *progressReporter, const std::string &filename,
234 const std::vector<Poco::XML::Element *> &compElems);
235
237 void collateTypeInformation(const std::string &filename, const std::vector<Poco::XML::Element *> &typeElems,
238 ShapeFactory &shapeCreator);
239
240public: // for testing
243 Kernel::V3D getAbsolutPositionInCompCoorSys(Geometry::ICompAssembly *comp, Kernel::V3D);
244
245private:
247 void applyCache(const IDFObject_const_sptr &cacheToApply);
248
250 CachingOption writeAndApplyCache(IDFObject_const_sptr firstChoiceCache, IDFObject_const_sptr fallBackCache);
251
254 std::string getShapeCoorSysComp(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
255 std::map<std::string, Poco::XML::Element *> &getTypeElement,
256 Geometry::ICompAssembly *&endAssembly);
257
259 std::string translateRotateXMLcuboid(Geometry::ICompAssembly *comp, const Poco::XML::Element *cuboidEle,
260 const std::string &cuboidName);
262 std::string translateRotateXMLcuboid(Geometry::ICompAssembly *comp, const std::string &cuboidXML,
263 const std::string &cuboidName);
264
266 Poco::XML::Element *getShapeElement(const Poco::XML::Element *pElem, const std::string &name);
267
269 Kernel::V3D parsePosition(Poco::XML::Element *pElem);
270
273
276
278 std::string m_instName;
279
282
284 Poco::AutoPtr<Poco::XML::Document> m_pDoc;
285
294 std::vector<Poco::XML::Element *> m_hasParameterElement;
303 std::map<std::string, bool> isTypeAssembly;
305 std::map<std::string, std::shared_ptr<Geometry::IObject>> mapTypeNameToShape;
309 std::vector<Geometry::ObjComponent *> m_facingComponent;
316 std::map<std::string, Poco::XML::Element *> getTypeElement;
317
319 std::shared_ptr<Geometry::Instrument> m_instrument;
320
325
331
336 std::map<Geometry::IComponent *, Poco::XML::Element *> m_neutronicPos;
337
343 struct SphVec {
345 double r, theta, phi;
346 SphVec() : r(0.0), theta(0.0), phi(0.0) {}
347 SphVec(const double &r, const double &theta, const double &phi) : r(r), theta(theta), phi(phi) {}
349 };
350
352 std::map<const Geometry::IComponent *, SphVec> m_tempPosHolder;
353
356};
357
358} // namespace Geometry
359} // namespace Mantid
std::string name
Definition Run.cpp:60
std::vector< T > const * vec
Class for Assembly of geometric components.
base class for Geometric IComponent
Definition IComponent.h:53
Creates an instrument data from a XML instrument description file.
bool m_deltaOffsets
Flag to indicate whether offsets given in spherical coordinates are to be added to the current positi...
std::map< const Geometry::IComponent *, SphVec > m_tempPosHolder
Map to store positions of parent components in spherical coordinates.
double m_angleConvertConst
when this const equals 1 it means that angle=degree (default) is set in IDF otherwise if this const e...
bool m_haveDefaultFacing
True if defaults->components-are-facing is set in instrument def. file.
Kernel::V3D m_defaultFacing
Hold default facing position.
std::map< Geometry::IComponent *, Poco::XML::Element * > m_neutronicPos
A map containing the neutronic position for each detector.
std::shared_ptr< Geometry::Instrument > m_instrument
For convenience added pointer to instrument here.
std::vector< Poco::XML::Element * > m_hasParameterElement
Holds all the xml elements that have a <parameter> child element.
Poco::AutoPtr< Poco::XML::Document > m_pDoc
XML document is lazy loaded.
std::map< std::string, std::shared_ptr< Geometry::IObject > > mapTypeNameToShape
map which maps the type name to a shared pointer to a geometric shape
std::map< std::string, bool > isTypeAssembly
map which holds names of types and whether or not they are categorized as being assemblies,...
std::map< std::string, Poco::XML::Element * > getTypeElement
map which holds names of types and pointers to these type for fast retrieval in code
bool m_hasParameterElement_beenSet
has m_hasParameterElement been set - used when public method setComponentLinks is used
std::vector< Geometry::ObjComponent * > m_facingComponent
Container to hold all detectors and monitors added to the instrument.
bool m_sideBySideViewLocation_exists
Store if xml text contains side-by-side-view-location string.
bool m_indirectPositions
Flag to indicate whether IDF contains physical & neutronic positions.
Object Component class, this class brings together the physical attributes of the component to the po...
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Class for 3D vectors.
Definition V3D.h:34
std::map< std::pair< std::string, const IComponent * >, std::shared_ptr< XMLInstrumentParameter > > InstrumentParameterCache
Convenience typedef.
Definition Instrument.h:37
std::shared_ptr< const AbstractIDFObject > IDFObject_const_sptr
Definition IDFObject.h:92
Helper class which provides the Collimation Length for SANS instruments.
int counted
Used to count the number of detector encounted so far.
Stripped down vector that holds position in terms of spherical coordinates, Needed when processing in...