Skip to content

Commit

Permalink
Re #37 Now using clang-format and const references
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljturner committed Aug 23, 2017
1 parent 46ab521 commit dd1e9fd
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 176 deletions.
75 changes: 39 additions & 36 deletions Framework/DataHandling/inc/MantidDataHandling/LoadNexusGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,52 @@

#include "Eigen/Core"

namespace Mantid{
namespace DataHandling{
namespace Mantid {
namespace DataHandling {

class DLLExport LoadNexusGeometry
: public API::IFileLoader<Kernel::NexusDescriptor> {
: public API::IFileLoader<Kernel::NexusDescriptor> {

public:
/// Default constructor
LoadNexusGeometry() = default;
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "LoadNexusGeometry"; }
/// Algorithm's version for identification overriding a virtual method
int version() const override { return 1; }
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "DataHandling\\Nexus"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Loads Instrument Geometry from a NeXus file.";
}

/// Returns a confidence value that this algorithm can load a file
int confidence(Kernel::NexusDescriptor &descriptor) const override;

/// Add component to instrument
Geometry::IComponent* addComponent(std::string &name, Eigen::Vector3d &position, Geometry::Instrument_sptr instrument);
/// Add source to instrument
void addSource(std::string &name, Eigen::Vector3d &position, Geometry::Instrument_sptr instrument);
/// Add sample to instrument
void addSample(std::string &name, Eigen::Vector3d &position, Geometry::Instrument_sptr instrument);
/// Add detector to instrument
void addDetector(std::string &name, Eigen::Vector3d &position, int detId, Geometry::Instrument_sptr instrument);
private:
/// Overwrites Algorithm method.
void init() override;
/// Overwrites Algorithm method
void exec() override;
//Instrument pointer
std::string defaultName = "defaultInstrumentName";
/// Default constructor
LoadNexusGeometry() = default;
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "LoadNexusGeometry"; }
/// Algorithm's version for identification overriding a virtual method
int version() const override { return 1; }
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "DataHandling\\Nexus"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Loads Instrument Geometry from a NeXus file.";
}

/// Returns a confidence value that this algorithm can load a file
int confidence(Kernel::NexusDescriptor &descriptor) const override;

/// Add component to instrument
Geometry::IComponent *addComponent(const std::string &name,
const Eigen::Vector3d &position,
Geometry::Instrument_sptr instrument);
/// Add source to instrument
void addSource(const std::string &name, const Eigen::Vector3d &position,
Geometry::Instrument_sptr instrument);
/// Add sample to instrument
void addSample(const std::string &name, const Eigen::Vector3d &position,
Geometry::Instrument_sptr instrument);
/// Add detector to instrument
void addDetector(const std::string &name, const Eigen::Vector3d &position, const int detId,
Geometry::Instrument_sptr instrument);

private:
/// Overwrites Algorithm method.
void init() override;
/// Overwrites Algorithm method
void exec() override;
// Instrument pointer
std::string defaultName = "defaultInstrumentName";
};

}
}

#endif // LOAD_NEXUS_GEOMETRY_H_

95 changes: 50 additions & 45 deletions Framework/DataHandling/src/LoadNexusGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,70 @@
#include "MantidGeometry/Instrument/InstrumentVisitor.h"

namespace Mantid {
namespace DataHandling
{
//Register the algorithm into the algorithm factory
namespace DataHandling {
// Register the algorithm into the algorithm factory
DECLARE_NEXUS_FILELOADER_ALGORITHM(LoadNexusGeometry)

///Initialises algorithm
void LoadNexusGeometry::init()
{
declareProperty("InstrumentName", " ", "Name of Instrument");
/// Initialises algorithm
void LoadNexusGeometry::init() {
declareProperty("InstrumentName", " ", "Name of Instrument");
}

//Executes algorithm
void LoadNexusGeometry::exec()
{
//Add instrument to data service
std::string instName = getPropertyValue("InstrumentName");
Geometry::Instrument_sptr instrument(new Geometry::Instrument(instName));
// Executes algorithm
void LoadNexusGeometry::exec() {
// Add instrument to data service
std::string instName = getPropertyValue("InstrumentName");
Geometry::Instrument_sptr instrument(new Geometry::Instrument(instName));

API::InstrumentDataService::Instance().add(instName, instrument);
API::InstrumentDataService::Instance().add(instName, instrument);
}

//Set confidence level for successful loading
int LoadNexusGeometry::confidence(Kernel::NexusDescriptor &descriptor) const
{ return 0; }

//Add component to instrument
Geometry::IComponent* LoadNexusGeometry::addComponent(std::string &name, Eigen::Vector3d &position, Geometry::Instrument_sptr instrument)
{
Geometry::IComponent *component(new Geometry::ObjCompAssembly(name));
component->setPos (position(0), position(1), position(2));
instrument->add(component);
//Return the component
return component;
// Set confidence level for successful loading
int LoadNexusGeometry::confidence(Kernel::NexusDescriptor &descriptor) const {
return 0;
}

//Add source to instrument
void LoadNexusGeometry::addSource(std::string &name, Eigen::Vector3d &position, Geometry::Instrument_sptr instrument)
{
auto *source(this->addComponent(name, position, instrument));
instrument->markAsSource(source);
// Add component to instrument
Geometry::IComponent *
LoadNexusGeometry::addComponent(const std::string &name,
const Eigen::Vector3d &position,
Geometry::Instrument_sptr instrument) {
Geometry::IComponent *component(new Geometry::ObjCompAssembly(name));
component->setPos(position(0), position(1), position(2));
instrument->add(component);
// Return the component
return component;
}

//Add sample to instrument
void LoadNexusGeometry::addSample(std::string &name, Eigen::Vector3d &position, Geometry::Instrument_sptr instrument)
{
auto *sample(this->addComponent(name, position, instrument));
instrument->markAsSamplePos(sample);
// Add source to instrument
void LoadNexusGeometry::addSource(const std::string &name,
const Eigen::Vector3d &position,
Geometry::Instrument_sptr instrument) {
auto *source(this->addComponent(name, position, instrument));
instrument->markAsSource(source);
}

//Add detector to instrument
void LoadNexusGeometry::addDetector(std::string &name, Eigen::Vector3d &position, int detId, Geometry::Instrument_sptr instrument)
{
auto *detector(new Geometry::Detector(name, detId, const_cast<Geometry::IComponent *>(instrument->getBaseComponent())));
detector->setPos(position(0), position(1), position(2));
instrument->add(detector);
instrument->markAsDetectorIncomplete(detector);
//Will be moved to exec, when more than one detector created
instrument->markAsDetectorFinalize();
// Add sample to instrument
void LoadNexusGeometry::addSample(const std::string &name,
const Eigen::Vector3d &position,
Geometry::Instrument_sptr instrument) {
auto *sample(this->addComponent(name, position, instrument));
instrument->markAsSamplePos(sample);
}

// Add detector to instrument
void LoadNexusGeometry::addDetector(const std::string &name,
const Eigen::Vector3d &position,
const int detId,
Geometry::Instrument_sptr instrument) {
auto *detector(new Geometry::Detector(
name, detId,
const_cast<Geometry::IComponent *>(instrument->getBaseComponent())));
detector->setPos(position(0), position(1), position(2));
instrument->add(detector);
instrument->markAsDetectorIncomplete(detector);
// Will be moved to exec, when more than one detector created
instrument->markAsDetectorFinalize();
}
}
}
Loading

0 comments on commit dd1e9fd

Please sign in to comment.