Mantid
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
Mantid::DataHandling::SampleEnvironmentSpecParser Class Reference

Read an XML definition of a SampleEnvironmentSpec and produce a new SampleEnvironmentSpec object. More...

#include <SampleEnvironmentSpecParser.h>

Public Member Functions

SampleEnvironmentSpec_uptr parse (const std::string &name, const std::string &filename, std::istream &istr)
 Takes a stream that is assumed to contain a single complete SampleEnvironmentSpec definition, reads the definition and produces a new SampleEnvironmentSpec object. More...
 
SampleEnvironmentSpec_uptr parse (const std::string &name, Poco::XML::Element *element)
 Takes a pointer to an XML node that is assumed to point at a "environmentspec" tag. More...
 

Static Public Attributes

static constexpr const char * ROOT_TAG = "environmentspec"
 

Private Types

using MaterialsIndex = std::unordered_map< std::string, Kernel::Material >
 

Private Member Functions

std::string findFile (const std::string &filename) const
 
void loadFullSpecification (SampleEnvironmentSpec *spec, Poco::XML::Element *element)
 
std::shared_ptr< Geometry::MeshObjectloadMeshFromSTL (Poco::XML::Element *stlFileElement) const
 Create a mesh shape from an STL input file. More...
 
void LoadOptionalDoubleFromXML (Poco::XML::Element *componentElement, const std::string &elementName, double &targetVariable) const
 Load a double from an optional XML element. More...
 
void parseAndAddComponents (SampleEnvironmentSpec *spec, Poco::XML::Element *element) const
 Take a <components> tag, parse the definitions and add them to the spec. More...
 
void parseAndAddContainers (SampleEnvironmentSpec *spec, Poco::XML::Element *element) const
 Take a <containers> tag, parse the definitions and add them to the spec. More...
 
std::shared_ptr< Geometry::IObjectparseComponent (Poco::XML::Element *element) const
 Parse a single definition of a component. More...
 
Geometry::Container_const_sptr parseContainer (Poco::XML::Element *element) const
 Parse a single definition of a Can. More...
 
void parseMaterials (Poco::XML::Element *element)
 Parse the set of materials in the document. More...
 
std::vector< double > parseTranslationVector (const std::string &translationVectorStr) const
 Take a comma separated translation vector and return it as a std::vector. More...
 
void validateRootElement (Poco::XML::Element *element) const
 Validate that the element points to the expected root element. More...
 

Private Attributes

std::string m_filepath
 
MaterialsIndex m_materials
 

Detailed Description

Read an XML definition of a SampleEnvironmentSpec and produce a new SampleEnvironmentSpec object.

Definition at line 29 of file SampleEnvironmentSpecParser.h.

Member Typedef Documentation

◆ MaterialsIndex

Definition at line 39 of file SampleEnvironmentSpecParser.h.

Member Function Documentation

◆ findFile()

std::string Mantid::DataHandling::SampleEnvironmentSpecParser::findFile ( const std::string &  filename) const
private

◆ loadFullSpecification()

void Mantid::DataHandling::SampleEnvironmentSpecParser::loadFullSpecification ( SampleEnvironmentSpec spec,
Poco::XML::Element *  element 
)
private

◆ loadMeshFromSTL()

std::shared_ptr< Geometry::MeshObject > Mantid::DataHandling::SampleEnvironmentSpecParser::loadMeshFromSTL ( Poco::XML::Element *  stlFileElement) const
private

Create a mesh shape from an STL input file.

This can't be in the ShapeFactory because that is in Geometry. This function needs acccess to the STL readers

Parameters
stlFileElementA pointer to an XML <stlfile> element
Returns
A new Object instance of the given type

Definition at line 373 of file SampleEnvironmentSpecParser.cpp.

References Mantid::DataHandling::LoadStlFactory::createReader(), Mantid::DataHandling::exists(), findFile(), Mantid::DataHandling::getScaleTypeFromStr(), LoadOptionalDoubleFromXML(), parseTranslationVector(), and rotation.

Referenced by parseComponent(), and parseContainer().

◆ LoadOptionalDoubleFromXML()

void Mantid::DataHandling::SampleEnvironmentSpecParser::LoadOptionalDoubleFromXML ( Poco::XML::Element *  componentElement,
const std::string &  attributeName,
double &  targetVariable 
) const
private

Load a double from an optional XML element.

Parameters
componentElementXML element
attributeNameAttribute that double should be loaded from
targetVariableValue read from element attribute

Definition at line 303 of file SampleEnvironmentSpecParser.cpp.

Referenced by loadMeshFromSTL().

◆ parse() [1/2]

SampleEnvironmentSpec_uptr Mantid::DataHandling::SampleEnvironmentSpecParser::parse ( const std::string &  name,
const std::string &  filename,
std::istream &  istr 
)

Takes a stream that is assumed to contain a single complete SampleEnvironmentSpec definition, reads the definition and produces a new SampleEnvironmentSpec object.

Parameters
nameThe name of the environment
filenameOptional file name for .xml spec file
istrA reference to a stream
Returns
A new SampleEnvironmentSpec object

Definition at line 84 of file SampleEnvironmentSpecParser.cpp.

References m_filepath, and parse().

Referenced by parse(), and Mantid::DataHandling::SampleEnvironmentSpecFileFinder::parseSpec().

◆ parse() [2/2]

SampleEnvironmentSpec_uptr Mantid::DataHandling::SampleEnvironmentSpecParser::parse ( const std::string &  name,
Poco::XML::Element *  element 
)

Takes a pointer to an XML node that is assumed to point at a "environmentspec" tag.

It reads the definition and produces a new SampleEnvironmentSpec object.

Parameters
nameThe name of the environment
elementA pointer to an Element node that is a "environmentspec" tag
Returns
A new SampleEnvironmentSpec object

Definition at line 114 of file SampleEnvironmentSpecParser.cpp.

References loadFullSpecification(), parseAndAddComponents(), parseMaterials(), and validateRootElement().

◆ parseAndAddComponents()

void Mantid::DataHandling::SampleEnvironmentSpecParser::parseAndAddComponents ( SampleEnvironmentSpec spec,
Poco::XML::Element *  element 
) const
private

Take a <components> tag, parse the definitions and add them to the spec.

It requires the materials to have been parsed

Parameters
specA pointer to a SampleEnvironmentSpec to update
elementA pointer to a components element

Definition at line 180 of file SampleEnvironmentSpecParser.cpp.

References Mantid::DataHandling::SampleEnvironmentSpec::addComponent(), m_materials, parseAndAddContainers(), and parseComponent().

Referenced by parse().

◆ parseAndAddContainers()

void Mantid::DataHandling::SampleEnvironmentSpecParser::parseAndAddContainers ( SampleEnvironmentSpec spec,
Poco::XML::Element *  element 
) const
private

Take a <containers> tag, parse the definitions and add them to the spec.

It requires the materials to have been parsed.

Parameters
specA pointer to a SampleEnvironmentSpec to update
elementA pointer to a cans element

Definition at line 255 of file SampleEnvironmentSpecParser.cpp.

References Mantid::DataHandling::SampleEnvironmentSpec::addContainer(), and parseContainer().

Referenced by parseAndAddComponents().

◆ parseComponent()

std::shared_ptr< Geometry::IObject > Mantid::DataHandling::SampleEnvironmentSpecParser::parseComponent ( Poco::XML::Element *  element) const
private

Parse a single definition of a component.

If the component is a can the sample geometry, if available, is also parsed.

Parameters
elementA pointer to an XML <container> element
Returns
A new Object instance of the given type

Definition at line 425 of file SampleEnvironmentSpecParser.cpp.

References Mantid::Geometry::ShapeFactory::createShape(), loadMeshFromSTL(), and m_materials.

Referenced by parseAndAddComponents(), and parseContainer().

◆ parseContainer()

Geometry::Container_const_sptr Mantid::DataHandling::SampleEnvironmentSpecParser::parseContainer ( Poco::XML::Element *  element) const
private

Parse a single definition of a Can.

Parameters
elementA pointer to an XML <container> element
Returns
A new Can instance

Definition at line 273 of file SampleEnvironmentSpecParser.cpp.

References loadMeshFromSTL(), and parseComponent().

Referenced by parseAndAddContainers().

◆ parseMaterials()

void Mantid::DataHandling::SampleEnvironmentSpecParser::parseMaterials ( Poco::XML::Element *  element)
private

Parse the set of materials in the document.

Parameters
elementA pointer to the materials tag

Definition at line 157 of file SampleEnvironmentSpecParser.cpp.

References m_filepath, m_materials, and Mantid::Kernel::MaterialXMLParser::parse().

Referenced by parse().

◆ parseTranslationVector()

std::vector< double > Mantid::DataHandling::SampleEnvironmentSpecParser::parseTranslationVector ( const std::string &  translationVectorStr) const
private

Take a comma separated translation vector and return it as a std::vector.

Parameters
translationVectorStrTranslation vector string
Returns
vector containing translations

Definition at line 322 of file SampleEnvironmentSpecParser.cpp.

References Mantid::Kernel::StringTokenizer::cbegin(), Mantid::Kernel::StringTokenizer::cend(), Mantid::Kernel::StringTokenizer::count(), Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY, and Mantid::Kernel::StringTokenizer::TOK_TRIM.

Referenced by loadMeshFromSTL().

◆ validateRootElement()

void Mantid::DataHandling::SampleEnvironmentSpecParser::validateRootElement ( Poco::XML::Element *  element) const
private

Validate that the element points to the expected root element.

Parameters
elementA pointer to the root element

Definition at line 143 of file SampleEnvironmentSpecParser.cpp.

References ROOT_TAG.

Referenced by parse().

Member Data Documentation

◆ m_filepath

std::string Mantid::DataHandling::SampleEnvironmentSpecParser::m_filepath
private

Definition at line 56 of file SampleEnvironmentSpecParser.h.

Referenced by findFile(), parse(), and parseMaterials().

◆ m_materials

MaterialsIndex Mantid::DataHandling::SampleEnvironmentSpecParser::m_materials
private

◆ ROOT_TAG

constexpr const char* Mantid::DataHandling::SampleEnvironmentSpecParser::ROOT_TAG = "environmentspec"
staticconstexpr

Definition at line 31 of file SampleEnvironmentSpecParser.h.

Referenced by validateRootElement().


The documentation for this class was generated from the following files: