Commit b7ca8747 authored by Anthony Lim's avatar Anthony Lim
Browse files

refs #26878 remove multiple inheritance from ALF view

parent 2aee77bb
......@@ -27,10 +27,8 @@ namespace CustomInterfaces {
ALFCustomInstrumentModel::ALFCustomInstrumentModel()
: m_numberOfTubesInAverage(0) {
m_tmpName = "ALF_tmp";
m_instrumentName = "ALF";
m_wsName = "ALFData";
m_currentRun = 0;
m_base =
new MantidWidgets::BaseCustomInstrumentModel("ALF_tmp", "ALF", "ALFData");
}
/*
......@@ -41,7 +39,7 @@ void ALFCustomInstrumentModel::loadAlg(const std::string &name) {
auto alg = AlgorithmManager::Instance().create("Load");
alg->initialize();
alg->setProperty("Filename", name);
alg->setProperty("OutputWorkspace", m_tmpName); // write to tmp ws
alg->setProperty("OutputWorkspace", getTmpName()); // write to tmp ws
alg->execute();
}
......@@ -55,7 +53,7 @@ std::pair<int, std::string>
ALFCustomInstrumentModel::loadData(const std::string &name) {
loadAlg(name);
auto ws =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(m_tmpName);
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(getTmpName());
int runNumber = ws->getRunNumber();
std::string message = "success";
auto bools = isDataValid();
......@@ -64,7 +62,7 @@ ALFCustomInstrumentModel::loadData(const std::string &name) {
m_numberOfTubesInAverage = 0;
} else {
// reset to the previous data
message = "Not the correct instrument, expected " + m_instrumentName;
message = "Not the correct instrument, expected " + getInstrument();
remove();
}
if (bools["IsValidInstrument"] && !bools["IsItDSpace"]) {
......@@ -79,10 +77,10 @@ ALFCustomInstrumentModel::loadData(const std::string &name) {
*/
std::map<std::string, bool> ALFCustomInstrumentModel::isDataValid() {
auto ws =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(m_tmpName);
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(getTmpName());
bool isItALF = false;
if (ws->getInstrument()->getName() == m_instrumentName) {
if (ws->getInstrument()->getName() == getInstrument()) {
isItALF = true;
}
auto axis = ws->getAxis(0);
......@@ -101,15 +99,15 @@ std::map<std::string, bool> ALFCustomInstrumentModel::isDataValid() {
void ALFCustomInstrumentModel::transformData() {
auto normAlg = AlgorithmManager::Instance().create("NormaliseByCurrent");
normAlg->initialize();
normAlg->setProperty("InputWorkspace", m_wsName);
normAlg->setProperty("OutputWorkspace", m_wsName);
normAlg->setProperty("InputWorkspace", getWSName());
normAlg->setProperty("OutputWorkspace", getWSName());
normAlg->execute();
auto dSpacingAlg = AlgorithmManager::Instance().create("ConvertUnits");
dSpacingAlg->initialize();
dSpacingAlg->setProperty("InputWorkspace", m_wsName);
dSpacingAlg->setProperty("InputWorkspace", getWSName());
dSpacingAlg->setProperty("Target", "dSpacing");
dSpacingAlg->setProperty("OutputWorkspace", m_wsName);
dSpacingAlg->setProperty("OutputWorkspace", getWSName());
dSpacingAlg->execute();
}
......@@ -131,12 +129,12 @@ void ALFCustomInstrumentModel::storeSingleTube(const std::string &name) {
}
std::string ALFCustomInstrumentModel::WSName() {
std::string name = m_instrumentName + std::to_string(getCurrentRun());
std::string name = getInstrument() + std::to_string(getCurrentRun());
return EXTRACTEDWS + name;
}
void ALFCustomInstrumentModel::averageTube() {
const std::string name = m_instrumentName + std::to_string(getCurrentRun());
const std::string name = getInstrument() + std::to_string(getCurrentRun());
const int oldTotalNumber = m_numberOfTubesInAverage;
// multiply up current average
auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
......@@ -192,14 +190,14 @@ bool ALFCustomInstrumentModel::averageTubeConditon(
tabBools.find("hasCurve")->second);
return (m_numberOfTubesInAverage > 0 && tabBools.find("isTube")->second &&
ifCurve &&
hasTubeBeenExtracted(m_instrumentName +
hasTubeBeenExtracted(getInstrument() +
std::to_string(getCurrentRun())));
} catch (...) {
return false;
}
}
void ALFCustomInstrumentModel::extractSingleTube() {
storeSingleTube(m_instrumentName + std::to_string(getCurrentRun()));
storeSingleTube(getInstrument() + std::to_string(getCurrentRun()));
m_numberOfTubesInAverage = 1;
}
......
......@@ -36,8 +36,7 @@ public:
class DLLExport ALFCustomInstrumentModel
: public virtual IALFCustomInstrumentModel, public
MantidWidgets::BaseCustomInstrumentModel {
: public virtual IALFCustomInstrumentModel{
public:
ALFCustomInstrumentModel();
......@@ -56,8 +55,23 @@ public:
std::string WSName() override;
Mantid::API::CompositeFunction_sptr getDefaultFunction() override;
void loadEmptyInstrument() override { m_base->loadEmptyInstrument(); };
void setCurrentRun(int &run) override { m_base->setCurrentRun(run); };
int getCurrentRun() override { return m_base->getCurrentRun(); };
void rename() override { m_base->rename(); };
void remove() override { m_base->remove(); };
std::string dataFileName() override { return m_base->dataFileName(); };
int currentRun() override {return m_base->currentRun(); };
bool isErrorCode(const int run) override { return m_base->isErrorCode(run); };
const std::string getInstrument() override { return m_base->getInstrument(); };
const std::string getTmpName() override { return m_base->getTmpName(); };
const std::string getWSName() override { return m_base->getWSName(); };
private:
int m_numberOfTubesInAverage;
MantidWidgets::BaseCustomInstrumentModel *m_base;
};
} // namespace CustomInterfaces
......
......@@ -27,6 +27,8 @@ public:
virtual int currentRun()=0;
virtual bool isErrorCode(const int run)=0;
virtual const std::string getInstrument()=0;
virtual const std::string getTmpName()=0;
virtual const std::string getWSName()=0;
};
......@@ -35,6 +37,7 @@ class EXPORT_OPT_MANTIDQT_INSTRUMENTVIEW BaseCustomInstrumentModel
public:
BaseCustomInstrumentModel();
BaseCustomInstrumentModel(const std::string &tmpName, const std::string instrumentName, const std::string wsName);
~BaseCustomInstrumentModel(){};
void loadEmptyInstrument() override;
std::pair<int, std::string> loadData(const std::string &name) override;
......@@ -46,6 +49,8 @@ public:
int currentRun() override;
bool isErrorCode(const int run) override;
const std::string getInstrument() override { return m_instrumentName; };
const std::string getTmpName() override { return m_tmpName; };
const std::string getWSName() override { return m_wsName; };
protected:
int m_currentRun;
......
......@@ -28,6 +28,13 @@ BaseCustomInstrumentModel::BaseCustomInstrumentModel()
: m_currentRun(0), m_tmpName("tmp"), m_instrumentName("MUSR"),
m_wsName("testData") {}
BaseCustomInstrumentModel::BaseCustomInstrumentModel(
const std::string &tmpName,
const std::string instrumentName,
const std::string wsName) : m_currentRun(0),
m_tmpName(tmpName), m_instrumentName(instrumentName), m_wsName(wsName) {}
void BaseCustomInstrumentModel::loadEmptyInstrument() {
auto alg =
Mantid::API::AlgorithmManager::Instance().create("LoadEmptyInstrument");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment