Skip to content
Snippets Groups Projects
Commit b05fa72a authored by Matt King's avatar Matt King
Browse files

Added null check when fetching parameters from IDF

Recent build failures happened because some of the components
being fetched did not exist for some IDFs. resulting in
a null pointer being returned. a null check has been implmeneted
so that if the component pointer in null then we just set the
value in slitCalculator to zero.

Refs #13758
parent 75da2452
No related branches found
No related tags found
No related merge requests found
...@@ -40,10 +40,7 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SlitCalculator : public QDialog { ...@@ -40,10 +40,7 @@ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SlitCalculator : public QDialog {
public: public:
SlitCalculator(QWidget *parent); SlitCalculator(QWidget *parent);
virtual ~SlitCalculator(); virtual ~SlitCalculator();
void setInstrument(std::string instrumentName);
Mantid::Geometry::Instrument_const_sptr getInstrument();
void setCurrentInstrumentName(std::string instrumentName); void setCurrentInstrumentName(std::string instrumentName);
std::string getCurrentInstrumentName();
void processInstrumentHasBeenChanged(); void processInstrumentHasBeenChanged();
protected: protected:
...@@ -54,6 +51,9 @@ private: ...@@ -54,6 +51,9 @@ private:
std::string currentInstrumentName; std::string currentInstrumentName;
void setupSlitCalculatorWithInstrumentValues( void setupSlitCalculatorWithInstrumentValues(
Mantid::Geometry::Instrument_const_sptr); Mantid::Geometry::Instrument_const_sptr);
std::string getCurrentInstrumentName();
Mantid::Geometry::Instrument_const_sptr getInstrument();
void setInstrument(std::string instrumentName);
private slots: private slots:
void on_recalculate_triggered(); void on_recalculate_triggered();
}; };
......
...@@ -11,12 +11,16 @@ SlitCalculator::SlitCalculator(QWidget *parent) { ...@@ -11,12 +11,16 @@ SlitCalculator::SlitCalculator(QWidget *parent) {
Q_UNUSED(parent); Q_UNUSED(parent);
ui.setupUi(this); ui.setupUi(this);
if (currentInstrumentName == "") { if (currentInstrumentName == "") {
// set up the initial instrument if there is not one associated
// with slit calculator
currentInstrumentName = "INTER"; currentInstrumentName = "INTER";
setInstrument(currentInstrumentName); setInstrument(currentInstrumentName);
} }
on_recalculate_triggered(); on_recalculate_triggered();
} }
void SlitCalculator::processInstrumentHasBeenChanged() { void SlitCalculator::processInstrumentHasBeenChanged() {
// used in refl main window to indicate that slitCalculator fields
// need to update because another instrument has been selected.
on_recalculate_triggered(); on_recalculate_triggered();
} }
SlitCalculator::~SlitCalculator() {} SlitCalculator::~SlitCalculator() {}
...@@ -41,7 +45,7 @@ void SlitCalculator::setInstrument(std::string instrumentName) { ...@@ -41,7 +45,7 @@ void SlitCalculator::setInstrument(std::string instrumentName) {
this->instrument = Mantid::API::InstrumentDataService::Instance().retrieve( this->instrument = Mantid::API::InstrumentDataService::Instance().retrieve(
instrumentNameMangled); instrumentNameMangled);
} else { } else {
// We set the XML that we have found for the instrument. // We set the instrument from XML that we have found.
Mantid::API::Progress *prog = new Mantid::API::Progress(); Mantid::API::Progress *prog = new Mantid::API::Progress();
this->instrument = parser.parseXML(prog); this->instrument = parser.parseXML(prog);
delete prog; delete prog;
...@@ -51,14 +55,28 @@ void SlitCalculator::setInstrument(std::string instrumentName) { ...@@ -51,14 +55,28 @@ void SlitCalculator::setInstrument(std::string instrumentName) {
void SlitCalculator::setupSlitCalculatorWithInstrumentValues( void SlitCalculator::setupSlitCalculatorWithInstrumentValues(
Mantid::Geometry::Instrument_const_sptr instrument) { Mantid::Geometry::Instrument_const_sptr instrument) {
// fetch the components that we need for values from IDF
auto slit1Component = instrument->getComponentByName("slit1"); auto slit1Component = instrument->getComponentByName("slit1");
auto slit2Component = instrument->getComponentByName("slit2"); auto slit2Component = instrument->getComponentByName("slit2");
auto sampleComponent = instrument->getComponentByName("some-surface-holder"); auto sampleComponent = instrument->getComponentByName("some-surface-holder");
// convert between metres and millimetres // check that they have been fetched from the IDF
const double s1s2 = 1e3 * slit1Component->getDistance(*slit2Component); if (slit1Component.get() != NULL && slit2Component.get() != NULL &&
ui.spinSlit1Slit2->setValue(s1s2); sampleComponent.get() != NULL) {
const double s2sa = 1e3 * slit2Component->getDistance(*sampleComponent); // convert from meters to millimeters
ui.spinSlit2Sample->setValue(s2sa); const double s1s2 = 1e3 * (slit1Component->getDistance(*slit2Component));
// set value in field of slitCalculator
ui.spinSlit1Slit2->setValue(s1s2);
// convert from meters to millimeters
const double s2sa = 1e3 * (slit2Component->getDistance(*sampleComponent));
// set value in field of slitCalculator
ui.spinSlit2Sample->setValue(s2sa);
} else {
// the parameters slit1, slit2 and sample-holder where not found
// set the values in SlitCalculator up so that it is obvious
// we did not retrieve them from any IDF.
ui.spinSlit1Slit2->setValue(0.0);
ui.spinSlit2Sample->setValue(0.0);
}
} }
Mantid::Geometry::Instrument_const_sptr SlitCalculator::getInstrument() { Mantid::Geometry::Instrument_const_sptr SlitCalculator::getInstrument() {
return instrument; return instrument;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment