31void saveShapeToFile(Nexus::File *file,
const IObject_const_sptr &shape,
const std::string &tag =
"") {
33 if (
auto csgObject = std::dynamic_pointer_cast<const Mantid::Geometry::CSGObject>(shape)) {
34 shapeXML = csgObject->getShapeXML();
36 file->putAttr(tag +
"shape_xml", shapeXML);
37 if (
auto meshObject = std::dynamic_pointer_cast<const Mantid::Geometry::MeshObject>(shape)) {
38 meshObject->saveNexus(file, tag +
"shape_mesh");
40 file->putAttr(tag +
"shape_id", shape->id());
43IObject_sptr loadShapeFromFile(Nexus::File *file,
const std::string &tag =
"") {
46 material.
loadNexus(file, tag +
"material");
48 std::string shape_xml;
49 file->getAttr(tag +
"shape_xml", shape_xml);
51 if (!shape_xml.empty()) {
53 shape = shapeMaker.
createShape(std::move(shape_xml),
false );
54 }
else if (file->hasGroup(tag +
"shape_mesh",
"NXoff_geometry")) {
60 shape->setMaterial(material);
62 if (file->hasAttr(tag +
"shape_id")) {
64 file->getAttr(tag +
"shape_id",
id);
75 : m_name(), m_shape(
ShapeFactory().createShape(
"")), m_environment(), m_lattice(nullptr), m_crystalStructure(),
76 m_samples(), m_geom_id(0), m_thick(0.0), m_height(0.0), m_width(0.0) {}
83 : m_name(copy.m_name), m_shape(copy.m_shape), m_environment(copy.m_environment), m_lattice(nullptr),
84 m_crystalStructure(), m_samples(copy.m_samples), m_geom_id(copy.m_geom_id), m_thick(copy.m_thick),
85 m_height(copy.m_height), m_width(copy.m_width) {
109 m_samples = std::vector<std::shared_ptr<Sample>>(
rhs.m_samples);
114 m_lattice = std::make_unique<OrientedLattice>(
rhs.getOrientedLattice());
119 if (
rhs.hasCrystalStructure()) {
182 throw std::runtime_error(
"Sample::getEnvironment - No sample enviroment has been defined.");
200 throw std::runtime_error(
"Sample::getOrientedLattice - No OrientedLattice has been defined.");
211 throw std::runtime_error(
"Sample::getOrientedLattice - No OrientedLattice has been defined.");
227 throw std::runtime_error(
"Sample::getCrystalStructure - No CrystalStructure has been defined.");
307 throw std::out_of_range(
"The index value provided was out of range");
331 file->makeGroup(
group,
"NXsample",
true);
332 file->putAttr(
"name",
m_name);
334 file->putAttr(
"name_empty", 1);
336 file->putAttr(
"version", 1);
337 saveShapeToFile(file,
m_shape);
338 m_shape->material().saveNexus(file,
"material");
341 file->writeData(
"num_other_samples",
int(
m_samples.size()));
342 for (
size_t i = 0; i <
m_samples.size(); i++)
348 file->writeData(
"num_env_comp",
int(nElem));
349 for (
size_t i = 0; i < nElem; ++i) {
355 saveShapeToFile(file, comp, tag);
356 comp->material().saveNexus(file, tag +
"material");
362 file->writeData(
"num_oriented_lattice", 1);
363 m_lattice->saveNexus(file,
"oriented_lattice");
365 file->writeData(
"num_oriented_lattice", 0);
369 file->writeData(
"geom_thickness",
m_thick);
370 file->writeData(
"geom_height",
m_height);
371 file->writeData(
"geom_width",
m_width);
383 file->openGroup(
group,
"NXsample");
387 if (file->hasAttr(
"version")) {
388 file->getAttr(
"version", version);
395 if (file->hasData(
"name")) {
396 file->readData(
"name",
m_name);
404 file->getAttr(
"name",
m_name);
405 if (file->hasAttr(
"name_empty")) {
407 file->getAttr(
"name_empty", isEmpty);
416 m_shape = std::move(loadedShape);
419 if (file->hasAttr(
"env_name")) {
420 std::string env_name;
421 file->getAttr(
"env_name", env_name);
424 file->readData(
"num_env_comp", nElem);
426 if (
IObject_sptr container_shape = (nElem > 0) ? loadShapeFromFile(file,
"env_0_") :
nullptr) {
427 auto env = std::make_shared<SampleEnvironment>(env_name, std::make_shared<Container>(container_shape));
428 for (
int i = 1; i < nElem; ++i) {
438 int num_other_samples;
439 file->readData(
"num_other_samples", num_other_samples);
440 for (
int i = 0; i < num_other_samples; i++) {
441 auto extra = std::make_shared<Sample>();
447 int num_oriented_lattice;
448 file->readData(
"num_oriented_lattice", num_oriented_lattice);
449 if (num_oriented_lattice > 0) {
450 m_lattice = std::make_unique<OrientedLattice>();
451 m_lattice->loadNexus(file,
"oriented_lattice");
458 file->readData(
"geom_thickness",
m_thick);
459 file->readData(
"geom_height",
m_height);
460 file->readData(
"geom_width",
m_width);
479 if (
m_samples.size() != other.m_samples.size())
481 for (
size_t i = 0; i <
m_samples.size(); ++i) {
482 if (*
m_samples[i] != *other.m_samples[i])
485 auto compare = [](
const auto &a,
const auto &b,
auto call_on) {
487 if (
bool(a) ^ bool(b))
490 return call_on(a) == call_on(b);
497 compare(
m_shape, other.m_shape, [](
const auto &
x) { return x->shape(); }) &&
const std::vector< double > & rhs
std::map< DeltaEMode::Type, std::string > index
This class stores information about the sample used in particular run.
void setShape(const Geometry::IObject_sptr &shape)
Update the shape of the object.
double m_width
The sample width from the SPB_STRUCT in the raw file.
double m_thick
The sample thickness from the SPB_STRUCT in the raw file.
void clearOrientedLattice()
Delete the oriented lattice.
const Kernel::Material & getMaterial() const
Return the material (convenience method)
std::string m_name
The sample name.
bool hasEnvironment() const
int loadNexus(Nexus::File *file, const std::string &group)
Load the object from an open NeXus file.
void saveNexus(Nexus::File *file, const std::string &group) const
Save the object to an open NeXus file.
const std::string & getName() const
Returns the name of the sample.
const Geometry::IObject & getShape() const
Return the sample shape.
bool operator!=(const Sample &other) const
void setEnvironment(std::shared_ptr< Geometry::SampleEnvironment > env)
Set the environment used to contain the sample.
int getGeometryFlag() const
Returns the geometry flag.
void setOrientedLattice(std::unique_ptr< Geometry::OrientedLattice > lattice)
Set the pointer to OrientedLattice defining the sample's lattice and orientation.
Sample & operator[](const int index)
index operator for accessing multiple samples
std::unique_ptr< Geometry::OrientedLattice > m_lattice
Pointer to the OrientedLattice of the sample, NULL if not set.
const Geometry::OrientedLattice & getOrientedLattice() const
Get a reference to the sample's OrientedLattice.
void addSample(const std::shared_ptr< Sample > &childSample)
Adds a sample to the list.
std::shared_ptr< Geometry::SampleEnvironment > m_environment
An owned pointer to the SampleEnvironment object.
void setCrystalStructure(const Geometry::CrystalStructure &newCrystalStructure)
Resets the internal pointer to the new CrystalStructure (it's copied).
bool hasOrientedLattice() const
std::unique_ptr< Geometry::CrystalStructure > m_crystalStructure
CrystalStructure of the sample.
void setGeometryFlag(int geom_id)
Sets the geometry flag.
void setName(const std::string &name)
Set the name of the sample.
Sample()
Default constructor.
std::size_t size() const
the number of samples
std::vector< std::shared_ptr< Sample > > m_samples
Vector of child samples.
void setWidth(double width)
Sets the width.
double getWidth() const
Returns the width.
bool hasCrystalStructure() const
Returns true if the sample actually holds a CrystalStructure.
void setHeight(double height)
Sets the height.
int m_geom_id
The sample geometry flag.
double getHeight() const
Returns the height.
void clearCrystalStructure()
Destroys the internally stored CrystalStructure-object.
double m_height
The sample height from the SPB_STRUCT in the raw file.
Geometry::IObject_sptr m_shape
The sample shape object.
const Geometry::SampleEnvironment & getEnvironment() const
Get a reference to the sample's environment.
Sample & operator=(const Sample &rhs)
Assignment operator.
void setThickness(double thick)
Sets the thickness.
const Geometry::CrystalStructure & getCrystalStructure() const
double getThickness() const
Returns the thickness.
bool operator==(const Sample &other) const
const Geometry::IObject_sptr getShapePtr() const
Return a pointer to the sample shape.
bool hasShape() const
Check if sample has a valid shape.
Models a Container is used to hold a sample in the beam.
Three components are required to describe a crystal structure:
IObject : Interface for geometry objects.
static std::shared_ptr< MeshObject > loadNexus(Nexus::File *file, const std::string &group, const Kernel::Material &material)
Load mesh from an NXoff_geometry group in a NeXus file.
Class to implement UB matrix.
Defines a single instance of a SampleEnvironment.
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
A material is defined as being composed of a given element, defined as a PhysicalConstants::NeutronAt...
void loadNexus(Nexus::File *file, const std::string &group)
Load the object from an open NeXus file.
bool compare(const mypair &left, const mypair &right)
std::shared_ptr< const IObject > IObject_const_sptr
Typdef for a shared pointer to a const object.
std::shared_ptr< IObject > IObject_sptr
Typdef for a shared pointer.
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
std::string toString(const T &value)
Convert a number to a string.