16#include <nexus/NeXusException.hpp>
31 : m_name(), m_shape(
ShapeFactory().createShape(
"")), m_environment(), m_lattice(nullptr), m_crystalStructure(),
32 m_samples(), m_geom_id(0), m_thick(0.0), m_height(0.0), m_width(0.0) {}
39 : m_name(copy.m_name), m_shape(copy.m_shape), m_environment(copy.m_environment), m_lattice(nullptr),
40 m_crystalStructure(), m_samples(copy.m_samples), m_geom_id(copy.m_geom_id), m_thick(copy.m_thick),
41 m_height(copy.m_height), m_width(copy.m_width) {
65 m_samples = std::vector<std::shared_ptr<Sample>>(
rhs.m_samples);
70 m_lattice = std::make_unique<OrientedLattice>(
rhs.getOrientedLattice());
75 if (
rhs.hasCrystalStructure()) {
138 throw std::runtime_error(
"Sample::getEnvironment - No sample enviroment has been defined.");
156 throw std::runtime_error(
"Sample::getOrientedLattice - No OrientedLattice has been defined.");
167 throw std::runtime_error(
"Sample::getOrientedLattice - No OrientedLattice has been defined.");
183 throw std::runtime_error(
"Sample::getCrystalStructure - No CrystalStructure has been defined.");
263 throw std::out_of_range(
"The index value provided was out of range");
287 file->makeGroup(group,
"NXsample",
true);
288 file->putAttr(
"name",
m_name);
290 file->putAttr(
"name_empty", 1);
292 file->putAttr(
"version", 1);
293 std::string shapeXML(
"");
294 if (
auto csgObject = std::dynamic_pointer_cast<Mantid::Geometry::CSGObject>(
m_shape)) {
295 shapeXML = csgObject->getShapeXML();
297 file->putAttr(
"shape_xml", shapeXML);
299 m_shape->material().saveNexus(file,
"material");
301 file->writeData(
"num_other_samples",
int(
m_samples.size()));
302 for (
size_t i = 0; i <
m_samples.size(); i++)
307 file->writeData(
"num_oriented_lattice", 1);
308 m_lattice->saveNexus(file,
"oriented_lattice");
310 file->writeData(
"num_oriented_lattice", 0);
314 file->writeData(
"geom_thickness",
m_thick);
315 file->writeData(
"geom_height",
m_height);
316 file->writeData(
"geom_width",
m_width);
328 file->openGroup(group,
"NXsample");
333 file->getAttr(
"version", version);
334 }
catch (::NeXus::Exception &) {
341 file->readData(
"name",
m_name);
342 }
catch (::NeXus::Exception &) {
349 file->getAttr(
"name",
m_name);
350 if (file->hasAttr(
"name_empty")) {
352 file->getAttr(
"name_empty", isEmpty);
359 std::string shape_xml;
360 file->getAttr(
"shape_xml", shape_xml);
362 if (!shape_xml.empty()) {
369 if (
auto csgObj = std::dynamic_pointer_cast<Geometry::CSGObject>(
m_shape)) {
370 csgObj->setMaterial(material);
374 int num_other_samples;
375 file->readData(
"num_other_samples", num_other_samples);
376 for (
int i = 0; i < num_other_samples; i++) {
377 auto extra = std::make_shared<Sample>();
383 int num_oriented_lattice;
384 file->readData(
"num_oriented_lattice", num_oriented_lattice);
385 if (num_oriented_lattice > 0) {
386 m_lattice = std::make_unique<OrientedLattice>();
387 m_lattice->loadNexus(file,
"oriented_lattice");
394 file->readData(
"geom_thickness",
m_thick);
395 file->readData(
"geom_height",
m_height);
396 file->readData(
"geom_width",
m_width);
415 if (
m_samples.size() != other.m_samples.size())
417 for (
size_t i = 0; i <
m_samples.size(); ++i) {
418 if (*
m_samples[i] != *other.m_samples[i])
421 auto compare = [](
const auto &a,
const auto &b,
auto call_on) {
423 if (
bool(a) ^ bool(b))
426 return call_on(a) == call_on(b);
433 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 saveNexus(::NeXus::File *file, const std::string &group) const
Save the object to an open NeXus file.
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
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.
int loadNexus(::NeXus::File *file, const std::string &group)
Load the object from an open NeXus file.
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.
Three components are required to describe a crystal structure:
IObject : Interface for geometry objects.
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< 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.