30 : m_name(), m_shape(
ShapeFactory().createShape(
"")), m_environment(), m_lattice(nullptr), m_crystalStructure(),
31 m_samples(), m_geom_id(0), m_thick(0.0), m_height(0.0), m_width(0.0) {}
38 : m_name(copy.m_name), m_shape(copy.m_shape), m_environment(copy.m_environment), m_lattice(nullptr),
39 m_crystalStructure(), m_samples(copy.m_samples), m_geom_id(copy.m_geom_id), m_thick(copy.m_thick),
40 m_height(copy.m_height), m_width(copy.m_width) {
64 m_samples = std::vector<std::shared_ptr<Sample>>(
rhs.m_samples);
69 m_lattice = std::make_unique<OrientedLattice>(
rhs.getOrientedLattice());
74 if (
rhs.hasCrystalStructure()) {
137 throw std::runtime_error(
"Sample::getEnvironment - No sample enviroment has been defined.");
155 throw std::runtime_error(
"Sample::getOrientedLattice - No OrientedLattice has been defined.");
166 throw std::runtime_error(
"Sample::getOrientedLattice - No OrientedLattice has been defined.");
182 throw std::runtime_error(
"Sample::getCrystalStructure - No CrystalStructure has been defined.");
262 throw std::out_of_range(
"The index value provided was out of range");
286 file->makeGroup(
group,
"NXsample",
true);
287 file->putAttr(
"name",
m_name);
289 file->putAttr(
"name_empty", 1);
291 file->putAttr(
"version", 1);
292 std::string shapeXML(
"");
293 if (
auto csgObject = std::dynamic_pointer_cast<Mantid::Geometry::CSGObject>(
m_shape)) {
294 shapeXML = csgObject->getShapeXML();
296 file->putAttr(
"shape_xml", shapeXML);
298 m_shape->material().saveNexus(file,
"material");
300 file->writeData(
"num_other_samples",
int(
m_samples.size()));
301 for (
size_t i = 0; i <
m_samples.size(); i++)
306 file->writeData(
"num_oriented_lattice", 1);
307 m_lattice->saveNexus(file,
"oriented_lattice");
309 file->writeData(
"num_oriented_lattice", 0);
313 file->writeData(
"geom_thickness",
m_thick);
314 file->writeData(
"geom_height",
m_height);
315 file->writeData(
"geom_width",
m_width);
327 file->openGroup(
group,
"NXsample");
331 if (file->hasAttr(
"version")) {
332 file->getAttr(
"version", version);
339 if (file->hasData(
"name")) {
340 file->readData(
"name",
m_name);
348 file->getAttr(
"name",
m_name);
349 if (file->hasAttr(
"name_empty")) {
351 file->getAttr(
"name_empty", isEmpty);
358 std::string shape_xml;
359 file->getAttr(
"shape_xml", shape_xml);
361 if (!shape_xml.empty()) {
368 if (
auto csgObj = std::dynamic_pointer_cast<Geometry::CSGObject>(
m_shape)) {
369 csgObj->setMaterial(material);
373 int num_other_samples;
374 file->readData(
"num_other_samples", num_other_samples);
375 for (
int i = 0; i < num_other_samples; i++) {
376 auto extra = std::make_shared<Sample>();
382 int num_oriented_lattice;
383 file->readData(
"num_oriented_lattice", num_oriented_lattice);
384 if (num_oriented_lattice > 0) {
385 m_lattice = std::make_unique<OrientedLattice>();
386 m_lattice->loadNexus(file,
"oriented_lattice");
393 file->readData(
"geom_thickness",
m_thick);
394 file->readData(
"geom_height",
m_height);
395 file->readData(
"geom_width",
m_width);
414 if (
m_samples.size() != other.m_samples.size())
416 for (
size_t i = 0; i <
m_samples.size(); ++i) {
417 if (*
m_samples[i] != *other.m_samples[i])
420 auto compare = [](
const auto &a,
const auto &b,
auto call_on) {
422 if (
bool(a) ^ bool(b))
425 return call_on(a) == call_on(b);
432 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.
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.