From facf7dc75ab97d6f47109bb7a902b7c00c734d2d Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Tue, 7 Oct 2014 10:06:22 +0100 Subject: [PATCH 01/22] Added slot to update run button, reset when tab switched Refs #10306 --- .../IndirectDataReduction.h | 20 +- .../IndirectDataReductionTab.h | 2 + .../src/IndirectConvertToEnergy.cpp | 11 +- .../src/IndirectDataReduction.cpp | 215 +++++++++--------- 4 files changed, 120 insertions(+), 128 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.h index d772b475a258..06e0856a287e 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReduction.h @@ -84,16 +84,16 @@ namespace MantidQt void userSelectInstrument(const QString& name); void openDirectoryDialog(); void showMessageBox(const QString& message); /// Slot showing a message box to the user + void updateRunButton(bool enabled = true, QString message = "Run", QString tooltip = ""); private: - void loadSettings(); void readSettings(); void saveSettings(); + void setDefaultInstrument(const QString & name); void instrumentSelectChanged(const QString& name); - ///// Find path to instrument's _Definition.xml file (and check there is a parameter file). - //QString getIDFPath(const QString& prefix); - /// set and show an instrument-specific widget + + /// Set and show an instrument-specific widget void setInstSpecificWidget(const std::string & parameterName, QCheckBox * checkBox, QCheckBox::ToggleState defaultState); virtual void closeEvent(QCloseEvent* close); @@ -106,15 +106,11 @@ namespace MantidQt /// Runner for insturment load algorithm MantidQt::API::AlgorithmRunner* m_algRunner; - //All indirect tabs - IndirectDataReductionTab* m_tab_convert_to_energy; - IndirectDataReductionTab* m_tab_sqw; - IndirectDataReductionTab* m_tab_diagnostics; - IndirectDataReductionTab* m_tab_calibration; - IndirectDataReductionTab* m_tab_trans; - IndirectDataReductionTab* m_tab_moments; + // All indirect tabs + std::map m_tabs; - Poco::NObserver m_changeObserver; ///< Poco observer for changes in user directory settings + /// Poco observer for changes in user directory settings + Poco::NObserver m_changeObserver; QString m_dataDir; ///< default data search directory QString m_saveDir; ///< default data save directory }; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h index e5bed025214c..9a7443b076cf 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h @@ -158,6 +158,8 @@ namespace CustomInterfaces void showMessageBox(const QString& message); /// Run a python script void runAsPythonScript(const QString & code, bool no_output); + /// Update the Run button on the IDR main window + void updateRunButton(bool enabled = true, QString message = "Run", QString tooltip = ""); private: /// Overidden by child class. diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectConvertToEnergy.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectConvertToEnergy.cpp index a98585c4673a..7cf597b1e8d4 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectConvertToEnergy.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectConvertToEnergy.cpp @@ -778,8 +778,7 @@ namespace CustomInterfaces */ void IndirectConvertToEnergy::pbRunEditing() { - m_uiForm.pbRun->setEnabled(false); - m_uiForm.pbRun->setText("Editing..."); + emit updateRunButton(false, "Editing...", "Run numbers are curently being edited."); } /** @@ -787,7 +786,7 @@ namespace CustomInterfaces */ void IndirectConvertToEnergy::pbRunFinding() { - m_uiForm.pbRun->setText("Finding files..."); + emit updateRunButton(false, "Finding files...", "Searchig for data files for the run numbers entered..."); m_uiForm.ind_runFiles->setEnabled(false); } @@ -798,13 +797,13 @@ namespace CustomInterfaces { if(!m_uiForm.ind_runFiles->isValid()) { - m_uiForm.pbRun->setText("Invalid Run"); + emit updateRunButton(false, "Invalid Run(s)", "Cannot find data files for some of the run numbers enetered."); } else { - m_uiForm.pbRun->setText("Run"); - m_uiForm.pbRun->setEnabled(true); + emit updateRunButton(); } + m_uiForm.ind_runFiles->setEnabled(true); } diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp index ed47aa0f798b..afc1f0f629d9 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp @@ -60,7 +60,7 @@ IndirectDataReduction::IndirectDataReduction(QWidget *parent) : */ IndirectDataReduction::~IndirectDataReduction() { - //Make sure no algos are sunning after the window has been closed + //Make sure no algos are running after the window has been closed m_algRunner->cancelRunningAlgorithm(); saveSettings(); @@ -74,7 +74,9 @@ void IndirectDataReduction::helpClicked() { QString tabName = m_uiForm.tabWidget->tabText( m_uiForm.tabWidget->currentIndex()); + QString url = "http://www.mantidproject.org/Indirect:"; + if ( tabName == "Energy Transfer" ) url += "EnergyTransfer"; else if ( tabName == "Calibration" ) @@ -87,6 +89,7 @@ void IndirectDataReduction::helpClicked() url += "Transmission"; else if (tabName == "Moments") url += "Moments"; + QDesktopServices::openUrl(QUrl(url)); } @@ -97,18 +100,7 @@ void IndirectDataReduction::helpClicked() void IndirectDataReduction::runClicked() { QString tabName = m_uiForm.tabWidget->tabText(m_uiForm.tabWidget->currentIndex()); - if ( tabName == "Energy Transfer" ) - m_tab_convert_to_energy->runTab(); - else if ( tabName == "Calibration" ) - m_tab_calibration->runTab(); - else if ( tabName == "Diagnostics" ) - m_tab_diagnostics->runTab(); - else if ( tabName == "S(Q, w)" ) - m_tab_sqw->runTab(); - else if (tabName == "Transmission") - m_tab_trans->runTab(); - else if(tabName == "Moments") - m_tab_moments->runTab(); + m_tabs[tabName]->runTab(); } /** @@ -118,51 +110,38 @@ void IndirectDataReduction::initLayout() { m_uiForm.setupUi(this); - m_tab_convert_to_energy = new IndirectConvertToEnergy(m_uiForm, this); - m_tab_sqw = new IndirectSqw(m_uiForm, this); - m_tab_diagnostics = new IndirectDiagnostics(m_uiForm, this); - m_tab_calibration = new IndirectCalibration(m_uiForm, this); - m_tab_trans = new IndirectTransmission(m_uiForm, this); - m_tab_moments = new IndirectMoments(m_uiForm, this); + // Do not allow running until setup and instrument laoding are done + updateRunButton(false, "Loading UI", "Initialising user interface components..."); - // Assume we get a incompatiable instrument to start with - m_uiForm.pbRun->setEnabled(false); + // Create the tabs + m_tabs["Energy Transfer"] = new IndirectConvertToEnergy(m_uiForm, this); + m_tabs["Calibration"] = new IndirectCalibration(m_uiForm, this); + m_tabs["Diagnostics"] = new IndirectDiagnostics(m_uiForm, this); + m_tabs["Transmission"] = new IndirectTransmission(m_uiForm, this); + m_tabs["S(Q, w)"] = new IndirectSqw(m_uiForm, this); + m_tabs["Moments"] = new IndirectMoments(m_uiForm, this); - // Signal / Slot Connections Set Up Here - - // signal/slot connections to respond to changes in instrument selection combo boxes + // Signal/slot connections to respond to changes in instrument selection combo boxes connect(m_uiForm.cbInst, SIGNAL(instrumentSelectionChanged(const QString&)), this, SLOT(userSelectInstrument(const QString&))); - // connect "?" (Help) Button + // Connect "?" (Help) Button connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(helpClicked())); - // connect the "Run" button + // Connect the "Run" button connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked())); - // connect the "Manage User Directories" Button + // Connect the "Manage User Directories" Button connect(m_uiForm.pbManageDirectories, SIGNAL(clicked()), this, SLOT(openDirectoryDialog())); - // ignals for tabs running Python - connect(m_tab_convert_to_energy, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); - connect(m_tab_sqw, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); - connect(m_tab_calibration, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); - connect(m_tab_diagnostics, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); - connect(m_tab_trans, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); - connect(m_tab_moments, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); - - // ignals for tabs showing mesage boxes - connect(m_tab_convert_to_energy, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&))); - connect(m_tab_sqw, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&))); - connect(m_tab_calibration, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&))); - connect(m_tab_diagnostics, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&))); - connect(m_tab_trans, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&))); - connect(m_tab_moments, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&))); - - // Run any tab setup code - m_tab_convert_to_energy->setupTab(); - m_tab_sqw->setupTab(); - m_tab_diagnostics->setupTab(); - m_tab_calibration->setupTab(); - m_tab_trans->setupTab(); - m_tab_moments->setupTab(); + // Reset the Run button state when the tab is changed + connect(m_uiForm.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateRunButton())); + + // Connect tab signals and run any setup code + for(auto it = m_tabs.begin(); it != m_tabs.end(); ++it) + { + connect(it->second, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); + connect(it->second, SIGNAL(showMessageBox(const QString&)), this, SLOT(showMessageBox(const QString&))); + connect(it->second, SIGNAL(updateRunButton(bool, QString, QString)), this, SLOT(updateRunButton(bool, QString, QString))); + it->second->setupTab(); + } } /** @@ -175,38 +154,8 @@ void IndirectDataReduction::initLocalPython() // select starting instrument readSettings(); - if ( m_curInterfaceSetup == "" ) - { + if(m_curInterfaceSetup == "") userSelectInstrument(m_uiForm.cbInst->currentText()); - } -} - -/** - * Read settings from the persistent store - */ -void IndirectDataReduction::readSettings() -{ - QSettings settings; - settings.beginGroup(m_settingsGroup); - QString instrName = settings.value("instrument-name", "").toString(); - settings.endGroup(); - - setDefaultInstrument(instrName); -} - -/** - * Save settings to a persistent storage - */ -void IndirectDataReduction::saveSettings() -{ - QSettings settings; - settings.beginGroup(m_settingsGroup); - QString instrName; - - instrName = m_uiForm.cbInst->currentText(); - - settings.setValue("instrument-name", instrName); - settings.endGroup(); } /** @@ -237,7 +186,7 @@ void IndirectDataReduction::instrumentSelectChanged(const QString& name) { g_log.error("Instument loading failed!"); m_uiForm.cbInst->setEnabled(true); - m_uiForm.pbRun->setEnabled(true); + updateRunButton(false, "No Instrument", "No instrument is currently loaded."); return; } @@ -267,14 +216,14 @@ void IndirectDataReduction::instrumentLoadingDone(bool error) { g_log.error("Instument loading failed! (this can be caused by having both direct and indirect interfaces open)"); m_uiForm.cbInst->setEnabled(true); - m_uiForm.pbRun->setEnabled(true); + updateRunButton(false, "No Instrument", "No instrument is currently loaded."); return; } performInstSpecific(); setIDFValues(curInstPrefix); - m_uiForm.pbRun->setEnabled(true); + updateRunButton(); m_uiForm.cbInst->setEnabled(true); } @@ -284,7 +233,7 @@ void IndirectDataReduction::instrumentLoadingDone(bool error) */ void IndirectDataReduction::userSelectInstrument(const QString& prefix) { - if ( prefix != m_curInterfaceSetup ) + if(prefix != m_curInterfaceSetup) { // Remove the old empty instrument workspace if it is there std::string ws_name = "__empty_" + m_curInterfaceSetup.toStdString(); @@ -294,7 +243,7 @@ void IndirectDataReduction::userSelectInstrument(const QString& prefix) dataStore.remove(ws_name); } - m_uiForm.pbRun->setEnabled(false); + updateRunButton(false, "Loading Inst.", "Loading the selected instrument..."); m_uiForm.cbInst->setEnabled(false); instrumentSelectChanged(prefix); } @@ -308,19 +257,19 @@ void IndirectDataReduction::openDirectoryDialog() } /** -* This function holds any steps that must be performed on the selection of an instrument, -* for example loading values from the Instrument Definition File (IDF). -* @param prefix :: The selected instruments prefix in Mantid. -*/ + * This function holds any steps that must be performed on the selection of an instrument, + * for example loading values from the Instrument Definition File (IDF). + * @param prefix :: The selected instruments prefix in Mantid. + */ void IndirectDataReduction::setIDFValues(const QString & prefix) { - dynamic_cast(m_tab_convert_to_energy)->setIDFValues(prefix); + dynamic_cast(m_tabs["Energy Transfer"])->setIDFValues(prefix); } /** -* This function holds any steps that must be performed on the layout that are specific -* to the currently selected instrument. -*/ + * This function holds any steps that must be performed on the layout that are specific + * to the currently selected instrument. + */ void IndirectDataReduction::performInstSpecific() { setInstSpecificWidget("cm-1-convert-choice", m_uiForm.ckCm1Units, QCheckBox::Off); @@ -328,14 +277,14 @@ void IndirectDataReduction::performInstSpecific() } /** -* This function either shows or hides the given QCheckBox, based on the named property -* inside the instrument param file. When hidden, the default state will be used to -* reset to the "unused" state of the checkbox. -* -* @param parameterName :: The name of the property to look for inside the current inst param file. -* @param checkBox :: The checkbox to set the state of, and to either hide or show based on the current inst. -* @param defaultState :: The state to which the checkbox will be set upon hiding it. -*/ + * This function either shows or hides the given QCheckBox, based on the named property + * inside the instrument param file. When hidden, the default state will be used to + * reset to the "unused" state of the checkbox. + * + * @param parameterName :: The name of the property to look for inside the current inst param file. + * @param checkBox :: The checkbox to set the state of, and to either hide or show based on the current inst. + * @param defaultState :: The state to which the checkbox will be set upon hiding it. + */ void IndirectDataReduction::setInstSpecificWidget(const std::string & parameterName, QCheckBox * checkBox, QCheckBox::ToggleState defaultState) { // Get access to instrument specific parameters via the loaded empty workspace. @@ -362,32 +311,42 @@ void IndirectDataReduction::setInstSpecificWidget(const std::string & parameterN } } +/** + * Remove the Poco observer on the config service when the interfaces is closed. + * + * @param close CLose event (unused) + */ void IndirectDataReduction::closeEvent(QCloseEvent* close) { - (void) close; + UNUSED_ARG(close); Mantid::Kernel::ConfigService::Instance().removeObserver(m_changeObserver); } +/** + * Reloads settings if the default sata search or save directories have been changed. + */ void IndirectDataReduction::handleDirectoryChange(Mantid::Kernel::ConfigValChangeNotification_ptr pNf) { std::string key = pNf->key(); - if ( key == "datasearch.directories" || key == "defaultsave.directory" ) - { - loadSettings(); - } + if(key == "datasearch.directories" || key == "defaultsave.directory") + readSettings(); } -void IndirectDataReduction::loadSettings() +/** + * Read Qt settings for the interface. + */ +void IndirectDataReduction::readSettings() { - // set values of m_dataDir and m_saveDir + // Set values of m_dataDir and m_saveDir m_dataDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories")); - m_dataDir.replace(" ",""); + m_dataDir.replace(" ", ""); if(m_dataDir.length() > 0) m_dataDir = m_dataDir.split(";", QString::SkipEmptyParts)[0]; m_saveDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory")); QSettings settings; + // Load settings for MWRunFile widgets settings.beginGroup(m_settingsGroup + "DataFiles"); settings.setValue("last_directory", m_dataDir); @@ -404,6 +363,28 @@ void IndirectDataReduction::loadSettings() m_uiForm.moment_dsInput->readSettings(settings.group()); m_uiForm.sqw_dsSampleInput->readSettings(settings.group()); settings.endGroup(); + + // Load the last used instrument + settings.beginGroup(m_settingsGroup); + QString instrName = settings.value("instrument-name", "").toString(); + settings.endGroup(); + + setDefaultInstrument(instrName); +} + +/** + * Save settings to a persistent storage + */ +void IndirectDataReduction::saveSettings() +{ + QSettings settings; + settings.beginGroup(m_settingsGroup); + QString instrName; + + instrName = m_uiForm.cbInst->currentText(); + + settings.setValue("instrument-name", instrName); + settings.endGroup(); } /** @@ -416,3 +397,17 @@ void IndirectDataReduction::showMessageBox(const QString& message) { showInformationBox(message); } + +/** + * Slot to allow setting the state of the Run button. + * + * @param enabled If the button is clickable + * @param message Message shown on the button + * @parm tooltip Tooltip shown when hovering over button + */ +void IndirectDataReduction::updateRunButton(bool enabled, QString message, QString tooltip) +{ + m_uiForm.pbRun->setEnabled(enabled); + m_uiForm.pbRun->setText(message); + m_uiForm.pbRun->setToolTip(tooltip); +} From 4023bc425e91ebae1190df14098ea5f643f68498 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Tue, 7 Oct 2014 10:22:51 +0100 Subject: [PATCH 02/22] Disable the rRun button when tab is already running Refs #10306 --- .../IndirectDataReductionTab.h | 9 ++++-- .../src/IndirectDataReductionTab.cpp | 29 ++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h index 9a7443b076cf..f2fae505f012 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDataReductionTab.h @@ -127,6 +127,9 @@ namespace CustomInterfaces /// Tree of the properties std::map m_propTrees; + /// If algorithms are currently running on this tab + bool m_tabRunning; + /// Internal list of the properties QMap m_properties; @@ -153,6 +156,8 @@ namespace CustomInterfaces /// Validator for positive double inputs QDoubleValidator *m_valPosDbl; + Ui::IndirectDataReduction m_uiForm; + signals: /// Send signal to parent window to show a message box to user void showMessageBox(const QString& message); @@ -169,8 +174,8 @@ namespace CustomInterfaces /// Overidden by child class. virtual bool validate() = 0; - protected: - Ui::IndirectDataReduction m_uiForm; + private slots: + void tabExecutionComplete(bool error); }; } // namespace CustomInterfaces diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp index 437dd8812226..a9c913ada173 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp @@ -20,8 +20,11 @@ namespace CustomInterfaces */ IndirectDataReductionTab::IndirectDataReductionTab(Ui::IndirectDataReduction& uiForm, QObject* parent) : QObject(parent), m_plots(), m_curves(), m_rangeSelectors(), + m_tabRunning(false), m_properties(), - m_dblManager(new QtDoublePropertyManager()), m_blnManager(new QtBoolPropertyManager()), m_grpManager(new QtGroupPropertyManager()), + m_dblManager(new QtDoublePropertyManager()), + m_blnManager(new QtBoolPropertyManager()), + m_grpManager(new QtGroupPropertyManager()), m_dblEdFac(new DoubleEditorFactory()), m_uiForm(uiForm) { @@ -36,6 +39,8 @@ namespace CustomInterfaces m_valPosDbl->setBottom(tolerance); connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(algorithmFinished(bool))); + connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(tabExecutionComplete(bool))); + connect(&m_pythonRunner, SIGNAL(runAsPythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool))); } @@ -49,9 +54,15 @@ namespace CustomInterfaces void IndirectDataReductionTab::runTab() { if(validate()) + { + m_tabRunning = true; + emit updateRunButton(false, "Running...", "Running data reduction..."); run(); + } else + { g_log.warning("Failed to validate indirect tab input!"); + } } void IndirectDataReductionTab::setupTab() @@ -64,6 +75,22 @@ namespace CustomInterfaces validate(); } + /** + * Slot used to update the run button when an algorithm that was strted by the Run button complete. + * + * @parm error Unused + */ + void IndirectDataReductionTab::tabExecutionComplete(bool error) + { + UNUSED_ARG(error); + + if(m_tabRunning) + { + m_tabRunning = false; + emit updateRunButton(); + } + } + /** * Run the load algorithm with the supplied filename and spectrum range * From 718d34808e6a6326430a308402d5675fc1246b77 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Tue, 7 Oct 2014 17:14:17 +0100 Subject: [PATCH 03/22] refs #9989 Crude fix allowing monitors loading when the later are placed after the detectors. Ignoring different time channels, if any are in the file. --- .../Framework/DataHandling/src/LoadISISNexus2.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 401cca9753e1..856998251548 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -132,6 +133,9 @@ namespace Mantid //Pull out the monitor blocks, if any exist size_t nmons(0); + std::vector mon_spectra_num; + int64_t max_spectra_num(LONG_MIN); + int64_t min_spectra_num(LONG_MAX); for(std::vector::const_iterator it = entry.groups().begin(); it != entry.groups().end(); ++it) { @@ -139,7 +143,12 @@ namespace Mantid { NXInt index = entry.openNXInt(std::string(it->nxname) + "/spectrum_index"); index.load(); - m_monitors[*index()] = it->nxname; + int64_t ind = *index(); + m_monitors[ind ] = it->nxname; + mon_spectra_num.push_back(ind); + + if (ind > max_spectra_num)max_spectra_num=ind; + if (ind < min_spectra_num)min_spectra_num=ind; ++nmons; } } @@ -166,6 +175,8 @@ namespace Mantid m_numberOfPeriodsInFile = m_numberOfPeriods = data.dim0(); m_numberOfSpectraInFile = m_numberOfSpectra = nsp1[0]; m_numberOfChannelsInFile = m_numberOfChannels = data.dim2(); + if(max_spectra_num > m_numberOfSpectra) + m_numberOfSpectra += mon_spectra_num.size(); if( nmons > 0 && m_numberOfSpectra == static_cast(data.dim1()) ) { From b77cff67a3621caf021209b9ceda85d24e3db4b1 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Tue, 7 Oct 2014 18:07:07 +0100 Subject: [PATCH 04/22] refs #9989 new property to load monitors --- .../inc/MantidDataHandling/LoadRaw3.h | 2 +- .../DataHandling/src/LoadEventNexus.cpp | 2 +- .../DataHandling/src/LoadISISNexus2.cpp | 23 +++++++++++++++++++ .../Framework/DataHandling/src/LoadRaw3.cpp | 2 +- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h index 1203d8d98bfd..a74ae830e539 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h @@ -21,7 +21,7 @@ namespace Mantid Loads an file in ISIS RAW format and stores it in a 2D workspace (Workspace2D class). LoadRaw is an algorithm and LoadRawHelper class and - overrides the init() & exec() methods. + overrides the init() & exec() methods. LoadRaw3 uses less memory by only loading up the datablocks as required. Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory diff --git a/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp b/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp index cbbf619213de..506300ffdf71 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp @@ -194,7 +194,7 @@ namespace Mantid } } - // Check for cancelled algorithm + // Check for canceled algorithm if (alg->getCancel()) { return; diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 856998251548..4b88cd81c1d9 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -7,6 +7,7 @@ #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/BoundedValidator.h" #include "MantidKernel/ConfigService.h" +#include "MantidKernel/ListValidator.h" #include "MantidKernel/LogParser.h" #include "MantidKernel/LogFilter.h" #include "MantidKernel/TimeSeriesProperty.h" @@ -83,6 +84,28 @@ namespace Mantid declareProperty(new ArrayProperty("SpectrumList")); declareProperty("EntryNumber", (int64_t)0, mustBePositive, "The particular entry number to read (default: Load all workspaces and creates a workspace group)"); + + declareProperty(new PropertyWithValue("LoadMonitorsSeparately", false, Direction::Input), + "If true, loads monitors and puts them into separate workspace"); + + std::vector monitorOptions; + monitorOptions.push_back("Include"); + monitorOptions.push_back("Exclude"); + monitorOptions.push_back("Separate"); + std::map monitorOptionsAliases; + monitorOptionsAliases["1"] = "Separate"; + monitorOptionsAliases["0"] = "Exclude"; + declareProperty("LoadMonitors","Exclude", boost::make_shared(monitorOptions,monitorOptionsAliases), + "Option to control the loading of monitors.\n" + "Allowed options are Include,Exclude, Separate.\n" + "Include:Include option would load monitors with the workspace. If the time binning for the monitors is different from the\n" + "binning of the detectors this option is equivalent to Separate option\n" + "Exclude:The default is Exclude option excludes monitors from the output workspace.\n" + "Separate:The Separate option loads monitors into a separate workspace called OutputWorkspace_monitor.\n" + "Defined aliases:\n" + "1: Equivalent to Separate.\n" + "0: Equivalent to Exclude.\n"); + } /** Executes the algorithm. Reading in the file and creating and populating diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp index 59989f261980..696403d6c32e 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp @@ -74,7 +74,7 @@ namespace Mantid "Allowed options are Include,Exclude, Separate.\n" "Include:The default is Include option which loads the monitors into the output workspace.\n" "Exclude:The Exclude option excludes monitors from the output workspace.\n" - "Separate:The Separate option loads monitors into a separate workspace called OutputWorkspace_Monitor.\n" + "Separate:The Separate option loads monitors into a separate workspace called OutputWorkspace_monitor.\n" "Defined aliases:\n" "1: Equivalent to Separate.\n" "0: Equivalent to Exclude.\n"); From 492991c5556949a413eb3aa3b851a342fa397933 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Wed, 8 Oct 2014 09:11:11 +0100 Subject: [PATCH 05/22] refs #9989 Make LoadRaw monitor loading options transferable to provide common code for LoadRaw3 and LoadISISNexus --- .../inc/MantidDataHandling/LoadRaw3.h | 6 --- .../inc/MantidDataHandling/LoadRawHelper.h | 43 +++++++++++-------- .../Framework/DataHandling/src/LoadRaw3.cpp | 36 ++-------------- .../DataHandling/src/LoadRawHelper.cpp | 32 ++++++++++++++ 4 files changed, 61 insertions(+), 56 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h index a74ae830e539..326f4830d43e 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRaw3.h @@ -71,12 +71,6 @@ namespace Mantid /// returns true if the given spectrum is a monitor bool isMonitor(const std::vector& monitorIndexes,specid_t spectrumNum); - /// returns true if the Exclude Monitor option(property) selected - bool isExcludeMonitors(const std::string &monitorOption); - /// returns true if the Separate Monitor Option selected - bool isSeparateMonitors(const std::string &monitorOption); - /// returns true if the Include Monitor Option selected - bool isIncludeMonitors(const std::string &monitorOption); /// validate workspace sizes void validateWorkspaceSizes( bool bexcludeMonitors ,bool bseparateMonitors, diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h index 70178fc433c2..752b3dc0a8f9 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h @@ -27,31 +27,31 @@ namespace Mantid { /** @class LoadRawHelper DataHandling/LoadRawHelper.h - Helper class for LoadRaw algorithms. + Helper class for LoadRaw algorithms. - @author Sofia Antony, ISIS,RAL - @date 14/04/2010 + @author Sofia Antony, ISIS,RAL + @date 14/04/2010 - Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory - This file is part of Mantid. + This file is part of Mantid. - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . - File change history is stored at: . - Code Documentation is available at: + File change history is stored at: . + Code Documentation is available at: */ class DLLExport LoadRawHelper: public API::IFileLoader { @@ -74,6 +74,15 @@ namespace Mantid /// Returns a confidence value that this algorithm can load a file virtual int confidence(Kernel::FileDescriptor & descriptor) const; + /// returns true if the Exclude Monitor option(property) selected + static bool isExcludeMonitors(const std::string &monitorOption); + /// returns true if the Separate Monitor Option selected + static bool isSeparateMonitors(const std::string &monitorOption); + /// returns true if the Include Monitor Option selected + static bool isIncludeMonitors(const std::string &monitorOption); + + + protected: /// Overwrites Algorithm method. void init(); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp index 696403d6c32e..4c70948539df 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp @@ -102,13 +102,13 @@ namespace Mantid if (monitorOption=="0") monitorOption = "Exclude"; - bool bincludeMonitors = isIncludeMonitors(monitorOption); + bool bincludeMonitors = LoadRawHelper::isIncludeMonitors(monitorOption); bool bseparateMonitors = false; bool bexcludeMonitors = false; if (!bincludeMonitors) { - bseparateMonitors = isSeparateMonitors(monitorOption); - bexcludeMonitors = isExcludeMonitors(monitorOption); + bseparateMonitors = LoadRawHelper::isSeparateMonitors(monitorOption); + bexcludeMonitors = LoadRawHelper::isExcludeMonitors(monitorOption); } // @@ -577,36 +577,6 @@ namespace Mantid } } - /** This method checks the value of LoadMonitors property and returns true or false - * @return true if Exclude Monitors option is selected,otherwise false - */ - bool LoadRaw3::isExcludeMonitors(const std::string &monitorOption) - { - bool bExclude; - monitorOption.compare("Exclude") ? (bExclude = false) : (bExclude = true); - return bExclude; - } - - /**This method checks the value of LoadMonitors property and returns true or false - * @return true if Include Monitors option is selected,otherwise false - */ - bool LoadRaw3::isIncludeMonitors(const std::string &monitorOption) - { - bool bExclude; - monitorOption.compare("Include") ? (bExclude = false) : (bExclude = true); - - return bExclude; - } - - /** This method checks the value of LoadMonitors property and returns true or false - * @return true if Separate Monitors option is selected,otherwise false - */ - bool LoadRaw3::isSeparateMonitors(const std::string &monitorOption) - { - bool bSeparate; - monitorOption.compare("Separate") ? (bSeparate = false) : (bSeparate = true); - return bSeparate; - } /** This method checks given spectrum is a monitor * @param monitorIndexes :: a vector holding the list of monitors diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 6b5a1c179df6..0e87a26eb333 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -1289,5 +1289,37 @@ namespace Mantid return true; } + /** This method checks the value of LoadMonitors property and returns true or false + * @return true if Exclude Monitors option is selected,otherwise false + */ + bool LoadRawHelper::isExcludeMonitors(const std::string &monitorOption) + { + bool bExclude; + monitorOption.compare("Exclude") ? (bExclude = false) : (bExclude = true); + return bExclude; + } + + /**This method checks the value of LoadMonitors property and returns true or false + * @return true if Include Monitors option is selected,otherwise false + */ + bool LoadRawHelper::isIncludeMonitors(const std::string &monitorOption) + { + bool bExclude; + monitorOption.compare("Include") ? (bExclude = false) : (bExclude = true); + + return bExclude; + } + + /** This method checks the value of LoadMonitors property and returns true or false + * @return true if Separate Monitors option is selected,otherwise false + */ + bool LoadRawHelper::isSeparateMonitors(const std::string &monitorOption) + { + bool bSeparate; + monitorOption.compare("Separate") ? (bSeparate = false) : (bSeparate = true); + return bSeparate; + } + + } // namespace DataHandling } // namespace Mantid From 9ab7bfb1df9963f243a324fcc990bd249c76dd19 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Wed, 8 Oct 2014 15:28:46 +0100 Subject: [PATCH 06/22] refs #9909 Load detectors with the data works though incorrectly for different number of monitors --- .../inc/MantidDataHandling/LoadISISNexus2.h | 4 +- .../DataHandling/src/LoadISISNexus2.cpp | 192 +++++++++++++----- 2 files changed, 139 insertions(+), 57 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index 9181a2be9b27..ea497530d610 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -192,8 +192,10 @@ namespace Mantid static double dblSqrt(double in); // C++ interface to the NXS file - ::NeXus::File * m_cppFile; + boost::scoped_ptr<::NeXus::File> m_cppFile; + bool findSpectraDetRangeInFile(NeXus::NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, + std::map &monitors,bool excludeMonitors,bool separateMonitors,bool &spectraExcluded); }; } // namespace DataHandling diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 4b88cd81c1d9..f9c2b77e4df6 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -3,6 +3,7 @@ //---------------------------------------------------------------------- #include "MantidDataHandling/LoadISISNexus2.h" #include "MantidDataHandling/LoadEventNexus.h" +#include "MantidDataHandling/LoadRawHelper.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/BoundedValidator.h" @@ -85,9 +86,6 @@ namespace Mantid declareProperty("EntryNumber", (int64_t)0, mustBePositive, "The particular entry number to read (default: Load all workspaces and creates a workspace group)"); - declareProperty(new PropertyWithValue("LoadMonitorsSeparately", false, Direction::Input), - "If true, loads monitors and puts them into separate workspace"); - std::vector monitorOptions; monitorOptions.push_back("Include"); monitorOptions.push_back("Exclude"); @@ -95,16 +93,17 @@ namespace Mantid std::map monitorOptionsAliases; monitorOptionsAliases["1"] = "Separate"; monitorOptionsAliases["0"] = "Exclude"; - declareProperty("LoadMonitors","Exclude", boost::make_shared(monitorOptions,monitorOptionsAliases), - "Option to control the loading of monitors.\n" - "Allowed options are Include,Exclude, Separate.\n" - "Include:Include option would load monitors with the workspace. If the time binning for the monitors is different from the\n" - "binning of the detectors this option is equivalent to Separate option\n" - "Exclude:The default is Exclude option excludes monitors from the output workspace.\n" - "Separate:The Separate option loads monitors into a separate workspace called OutputWorkspace_monitor.\n" - "Defined aliases:\n" - "1: Equivalent to Separate.\n" - "0: Equivalent to Exclude.\n"); + declareProperty("LoadMonitors","Include", boost::make_shared(monitorOptions,monitorOptionsAliases), + "Option to control the loading of monitors.\n" + "Allowed options are Include,Exclude, Separate.\n" + "Include:The default is Include option would load monitors with the workspace if monitors spectra are within the range of loaded detectors.\n" + "If the time binning for the monitors is different from the\n" + "binning of the detectors this option is equivalent to the Separate option\n" + "Exclude:Exclude option excludes monitors from the output workspace.\n" + "Separate:Separate option loads monitors into a separate workspace called: OutputWorkspace_monitors.\n" + "Defined aliases:\n" + "1: Equivalent to Separate.\n" + "0: Equivalent to Exclude.\n"); } @@ -116,12 +115,31 @@ namespace Mantid */ void LoadISISNexus2::exec() { + + //********************************************************************** + // process primary monitor options + std::string monitorOption = getProperty("LoadMonitors"); + if (monitorOption =="1") + monitorOption = "Separate"; + if (monitorOption=="0") + monitorOption = "Exclude"; + + bool bincludeMonitors = LoadRawHelper::isIncludeMonitors(monitorOption); + bool bseparateMonitors = false; + bool bexcludeMonitors = false; + if (!bincludeMonitors) + { + bseparateMonitors = LoadRawHelper::isSeparateMonitors(monitorOption); + bexcludeMonitors = LoadRawHelper::isExcludeMonitors(monitorOption); + } + //********************************************************************** + m_filename = getPropertyValue("Filename"); // Create the root Nexus class NXRoot root(m_filename); // "Open" the same file but with the C++ interface - m_cppFile = new ::NeXus::File(root.m_fileID); + m_cppFile.reset( new ::NeXus::File(root.m_fileID)); // Open the raw data group 'raw_data_1' NXEntry entry = root.openEntry("raw_data_1"); @@ -154,58 +172,41 @@ namespace Mantid NXInt spec = entry.openNXInt("isis_vms_compat/SPEC"); spec.load(); - //Pull out the monitor blocks, if any exist size_t nmons(0); - std::vector mon_spectra_num; - int64_t max_spectra_num(LONG_MIN); - int64_t min_spectra_num(LONG_MAX); - for(std::vector::const_iterator it = entry.groups().begin(); - it != entry.groups().end(); ++it) + if (bincludeMonitors) { - if (it->nxclass == "NXmonitor") // Count monitors + //Pull out the monitor blocks, if any exist + for(std::vector::const_iterator it = entry.groups().begin(); + it != entry.groups().end(); ++it) { - NXInt index = entry.openNXInt(std::string(it->nxname) + "/spectrum_index"); - index.load(); - int64_t ind = *index(); - m_monitors[ind ] = it->nxname; - mon_spectra_num.push_back(ind); - - if (ind > max_spectra_num)max_spectra_num=ind; - if (ind < min_spectra_num)min_spectra_num=ind; - ++nmons; + if (it->nxclass == "NXmonitor") // Count monitors + { + NXInt index = entry.openNXInt(std::string(it->nxname) + "/spectrum_index"); + index.load(); + int64_t ind = *index(); + m_monitors[ind ] = it->nxname; + + ++nmons; + } } } if( ndets == 0 && nmons == 0 ) { - g_log.error() << "Invalid NeXus structure, cannot find detector or monitor blocks."; - throw std::runtime_error("Inconsistent NeXus file structure."); - } - - if( ndets == 0 ) - { - - //Grab the number of channels - NXInt chans = entry.openNXInt(m_monitors.begin()->second + "/data"); - m_numberOfPeriodsInFile = m_numberOfPeriods = chans.dim0(); - m_numberOfSpectraInFile = m_numberOfSpectra = nmons; - m_numberOfChannelsInFile = m_numberOfChannels = chans.dim2(); - } - else - { - NXData nxData = entry.openNXData("detector_1"); - NXInt data = nxData.openIntData(); - m_numberOfPeriodsInFile = m_numberOfPeriods = data.dim0(); - m_numberOfSpectraInFile = m_numberOfSpectra = nsp1[0]; - m_numberOfChannelsInFile = m_numberOfChannels = data.dim2(); - if(max_spectra_num > m_numberOfSpectra) - m_numberOfSpectra += mon_spectra_num.size(); - - if( nmons > 0 && m_numberOfSpectra == static_cast(data.dim1()) ) + if (bexcludeMonitors) { - m_monitors.clear(); + g_log.warning() << "Nothing to do. No detectors found and no monitor loading requested"; + return; + } + else + { + g_log.error() << "Invalid NeXus structure, cannot find detector or monitor blocks."; + throw std::runtime_error("Inconsistent NeXus file structure."); } } + bool spectraExcluded(false); + bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,spectraExcluded); + const size_t x_length = m_numberOfChannels + 1; // Check input is consistent with the file, throwing if not @@ -245,7 +246,7 @@ namespace Mantid // Load logs and sample information m_cppFile->openPath(entry.path()); - local_workspace->loadSampleAndLogInfoNexus(m_cppFile); + local_workspace->loadSampleAndLogInfoNexus(m_cppFile.get()); // Load logs and sample information further information... See maintenance ticket #8697 loadSampleData(local_workspace, entry); @@ -988,5 +989,84 @@ namespace Mantid return sqrt(in); } + bool LoadISISNexus2::findSpectraDetRangeInFile(NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, + std::map &monitors,bool excludeMonitors,bool separateMonitors,bool &spectraExcluded) + { + spectraExcluded = false; + size_t nmons = monitors.size(); + + //Grab the number of channels + NXInt chans = entry.openNXInt(m_monitors.begin()->second + "/data"); + + int nMonitorPeriods = chans.dim0(); + size_t nMonitorChannels = chans.dim2(); + m_numberOfPeriodsInFile = m_numberOfPeriods = nMonitorPeriods ; + m_numberOfSpectraInFile = m_numberOfSpectra = nmons; + m_numberOfChannelsInFile = m_numberOfChannels = nMonitorChannels; + + if( ndets == 0 ) + { + separateMonitors = true; + return separateMonitors; + } + + NXData nxData = entry.openNXData("detector_1"); + NXInt data = nxData.openIntData(); + + m_numberOfPeriodsInFile = m_numberOfPeriods = data.dim0(); + m_numberOfChannelsInFile = m_numberOfChannels = data.dim2(); + if ((m_numberOfPeriodsInFile !=nMonitorPeriods) || (m_numberOfChannelsInFile!=nMonitorChannels)) + { + if(!separateMonitors) + { + g_log.warning()<<" Performing separate loading as can not load spectra and monitors in the single workspace:\n" ; + g_log.warning()<<" Monitors data contain :"<( n_vms_compat_spectra )&& !separateMonitors) + { + // workspace contain the same number of bins for spectra and monitors. Total number of spectra in workspace will be equal to + // n_vms_compat_spectra + m_numberOfSpectraInFile = m_numberOfSpectra; + m_numberOfSpectra=n_vms_compat_spectra; + return separateMonitors; + } + + + //Now check if monitors expand the spectra range + + // We assume again that this spectrum list increases monotonically + int64_t min_index = spectrum_index[0]; + int64_t max_index = spectrum_index[ndets-1]; + std::map remaining_monitors; + for(auto it = monitors.begin(); it!=monitors.end(); it++) + { + if(it->first>=min_index && it->first <=max_index) + { + if(excludeMonitors || separateMonitors) + { + m_numberOfSpectra--; + spectraExcluded = true; + spectrum_index[it->first]=-1; + } + } + else + { + remaining_monitors.insert(*it); + m_numberOfSpectra++; + } + } + monitors.swap(remaining_monitors); + return separateMonitors; + + } + + } // namespace DataHandling } // namespace Mantid From e31757fedad009457665cd2d3c12d27bd61afb94 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Wed, 8 Oct 2014 18:58:21 +0100 Subject: [PATCH 07/22] refs #9989 Load monitors "Exclude&Separate" works for main workspace though unit tests are needed and prospective include LoadNexusMonitors for "Separate" option --- .../inc/MantidDataHandling/LoadISISNexus2.h | 6 +- .../DataHandling/src/LoadISISNexus2.cpp | 182 +++++++++++------- 2 files changed, 111 insertions(+), 77 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index ea497530d610..8d8b54862d36 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -102,7 +102,7 @@ namespace Mantid /// Overwrites Algorithm method void exec(); // Validate the optional input properties - void checkOptionalProperties(); + void checkOptionalProperties(const std::set &ExcludedSpectra); /// Prepare a vector of SpectraBlock structures to simplify loading size_t prepareSpectraBlocks(); /// Run LoadInstrument as a ChildAlgorithm @@ -126,7 +126,7 @@ namespace Mantid // Validate multi-period logs void validateMultiPeriodLogs(Mantid::API::MatrixWorkspace_sptr); // build the list of spectra numbers to load and include in the spectra list - void buildSpectraInd2SpectraNumMap(const std::vector &spec_list); + void buildSpectraInd2SpectraNumMap(const std::vector &spec_list,const std::set &ExcludedSpectra); /// The name and path of the input file @@ -195,7 +195,7 @@ namespace Mantid boost::scoped_ptr<::NeXus::File> m_cppFile; bool findSpectraDetRangeInFile(NeXus::NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, - std::map &monitors,bool excludeMonitors,bool separateMonitors,bool &spectraExcluded); + std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &ExcludedSpectra); }; } // namespace DataHandling diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index f9c2b77e4df6..a261fe5059ed 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -173,24 +173,24 @@ namespace Mantid spec.load(); size_t nmons(0); - if (bincludeMonitors) + + + //Pull out the monitor blocks, if any exist + for(std::vector::const_iterator it = entry.groups().begin(); + it != entry.groups().end(); ++it) { - //Pull out the monitor blocks, if any exist - for(std::vector::const_iterator it = entry.groups().begin(); - it != entry.groups().end(); ++it) + if (it->nxclass == "NXmonitor") // Count monitors { - if (it->nxclass == "NXmonitor") // Count monitors - { - NXInt index = entry.openNXInt(std::string(it->nxname) + "/spectrum_index"); - index.load(); - int64_t ind = *index(); - m_monitors[ind ] = it->nxname; + NXInt index = entry.openNXInt(std::string(it->nxname) + "/spectrum_index"); + index.load(); + int64_t ind = *index(); + m_monitors[ind ] = it->nxname; - ++nmons; - } + ++nmons; } } + if( ndets == 0 && nmons == 0 ) { if (bexcludeMonitors) @@ -204,13 +204,13 @@ namespace Mantid throw std::runtime_error("Inconsistent NeXus file structure."); } } - bool spectraExcluded(false); - bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,spectraExcluded); + std::set ExcluedSpectra; + bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,ExcluedSpectra); const size_t x_length = m_numberOfChannels + 1; - // Check input is consistent with the file, throwing if not - checkOptionalProperties(); + // Check input is consistent with the file, throwing if not, exclude spectra selected at findSpectraDetRangeInFile; + checkOptionalProperties(ExcluedSpectra); // Fill up m_spectraBlocks size_t total_specs = prepareSpectraBlocks(); @@ -332,36 +332,6 @@ namespace Mantid }; } - /** - build the list of spectra to load and include into spectra-detectors map - @param spec_list -- list of spectra to load - **/ - void LoadISISNexus2::buildSpectraInd2SpectraNumMap(const std::vector &spec_list) - { - - int64_t ic(0); - - if(spec_list.size()>0) - { - auto start_point = spec_list.begin(); - for(auto it =start_point ;it!=spec_list.end();it++) - { - ic = it-start_point; - m_specInd2specNum_map.insert(std::pair(ic,static_cast(*it))); - } - } - else - { - if(m_range_supplied) - { - ic = m_specInd2specNum_map.size(); - for(int64_t i=m_spec_min;i(i-m_spec_min+ic,static_cast(i))); - - } - } - } - /** Check for a set of synthetic logs associated with multi-period log data. Raise warnings where necessary. @@ -385,11 +355,19 @@ namespace Mantid /** * Check the validity of the optional properties of the algorithm and identify if partial data should be loaded. + * @param SpectraExclued :: set of spectra ID-s to exclude from spectra list to load */ - void LoadISISNexus2::checkOptionalProperties() + void LoadISISNexus2::checkOptionalProperties(const std::set &SpectraExcluded) { // optional properties specify that only some spectra have to be loaded - m_load_selected_spectra = false; + size_t numSpectraExclued=0; + if (!SpectraExcluded.empty()) + { + m_load_selected_spectra = true; + numSpectraExclued = SpectraExcluded.size(); + } + + // m_spec_min = getProperty("SpectrumMin"); m_spec_max = getProperty("SpectrumMax"); @@ -415,11 +393,11 @@ namespace Mantid throw std::invalid_argument("Inconsistent range properties. SpectrumMin is larger than SpectrumMax."); } - if( static_cast(m_spec_max) > m_numberOfSpectra ) + if( static_cast(m_spec_max) > m_numberOfSpectra+numSpectraExclued ) { - std::string err="Inconsistent range property. SpectrumMax is larger than number of spectra: "+boost::lexical_cast(m_numberOfSpectra ); - throw std::invalid_argument(err); - } + std::string err="Inconsistent range property. SpectrumMax is larger than number of spectra: "+boost::lexical_cast(m_numberOfSpectra+numSpectraExclued ); + throw std::invalid_argument(err); + } // Check the entry number m_entrynumber = getProperty("EntryNumber"); @@ -442,9 +420,9 @@ namespace Mantid // Sort the list so that we can check it's range std::sort(spec_list.begin(), spec_list.end()); - if( spec_list.back() > static_cast(m_numberOfSpectra) ) + if( spec_list.back() > static_cast(m_numberOfSpectra+numSpectraExclued) ) { - std::string err="A spectra number in the spectra list exceeds total number of "+boost::lexical_cast(m_numberOfSpectra )+ " spectra "; + std::string err="A spectra number in the spectra list exceeds total number of "+boost::lexical_cast(m_numberOfSpectra+numSpectraExclued )+ " spectra "; throw std::invalid_argument(err); } @@ -455,6 +433,7 @@ namespace Mantid { throw std::invalid_argument("Negative SpectraList property encountered."); } + range_check in_range(m_spec_min, m_spec_max); if( m_range_supplied ) { @@ -463,7 +442,11 @@ namespace Mantid if (spec_list.size()>0) { for(int64_t i=m_spec_min;i(i)); + { + specid_t spec_num = static_cast(i); + if (SpectraExcluded.find(spec_num)==SpectraExcluded.end() ) + spec_list.push_back(spec_num); + } // Sort the list so that lower spectra indexes correspond to smaller spectra ID-s std::sort(spec_list.begin(), spec_list.end()); @@ -474,12 +457,53 @@ namespace Mantid { m_range_supplied = true; } + // if (m_load_selected_spectra) { - buildSpectraInd2SpectraNumMap(spec_list); + buildSpectraInd2SpectraNumMap(spec_list,SpectraExcluded); } } + /** + build the list of spectra to load and include into spectra-detectors map + @param spec_list -- list of spectra numbers to load + @param SpectraExcluded set of the spectra ID-s to exclude from loading + **/ + void LoadISISNexus2::buildSpectraInd2SpectraNumMap(const std::vector &spec_list,const std::set &SpectraExcluded) + { + + int64_t ic(0); + + if(spec_list.size()>0) + { + auto start_point = spec_list.begin(); + for(auto it =start_point ;it!=spec_list.end();it++) + { + ic = it-start_point; + m_specInd2specNum_map.insert(std::pair(ic,static_cast(*it))); + } + } + else + { + if(m_range_supplied) + { + ic = 0; + int64_t max_range = m_spec_max+SpectraExcluded.size()+1; + for(int64_t i=m_spec_min;i(i); + if(SpectraExcluded.find(spectra)==SpectraExcluded.end()) + { + m_specInd2specNum_map.insert(std::pair(ic,spectra)); + ic++; + } + } + + } + } + } + + namespace { @@ -990,19 +1014,24 @@ namespace Mantid } bool LoadISISNexus2::findSpectraDetRangeInFile(NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, - std::map &monitors,bool excludeMonitors,bool separateMonitors,bool &spectraExcluded) + std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &ExcludedSpectra) { - spectraExcluded = false; + ExcludedSpectra.clear(); size_t nmons = monitors.size(); //Grab the number of channels - NXInt chans = entry.openNXInt(m_monitors.begin()->second + "/data"); + int nMonitorPeriods(0); + size_t nMonitorChannels(0); + if (nmons>0) + { + NXInt chans = entry.openNXInt(m_monitors.begin()->second + "/data"); - int nMonitorPeriods = chans.dim0(); - size_t nMonitorChannels = chans.dim2(); - m_numberOfPeriodsInFile = m_numberOfPeriods = nMonitorPeriods ; - m_numberOfSpectraInFile = m_numberOfSpectra = nmons; - m_numberOfChannelsInFile = m_numberOfChannels = nMonitorChannels; + nMonitorPeriods = chans.dim0(); + nMonitorChannels = chans.dim2(); + m_numberOfPeriodsInFile = m_numberOfPeriods = nMonitorPeriods ; + m_numberOfSpectraInFile = m_numberOfSpectra = nmons; + m_numberOfChannelsInFile = m_numberOfChannels = nMonitorChannels; + } if( ndets == 0 ) { @@ -1015,7 +1044,7 @@ namespace Mantid m_numberOfPeriodsInFile = m_numberOfPeriods = data.dim0(); m_numberOfChannelsInFile = m_numberOfChannels = data.dim2(); - if ((m_numberOfPeriodsInFile !=nMonitorPeriods) || (m_numberOfChannelsInFile!=nMonitorChannels)) + if (((m_numberOfPeriodsInFile !=nMonitorPeriods) || (m_numberOfChannelsInFile!=nMonitorChannels)) && nmons>0) { if(!separateMonitors) { @@ -1029,7 +1058,10 @@ namespace Mantid - if(m_numberOfSpectra+nmons ==static_cast( n_vms_compat_spectra )&& !separateMonitors) + bool removeMonitors = excludeMonitors || separateMonitors; + + + if(m_numberOfSpectra+nmons ==static_cast( n_vms_compat_spectra )&& !removeMonitors) { // workspace contain the same number of bins for spectra and monitors. Total number of spectra in workspace will be equal to // n_vms_compat_spectra @@ -1038,28 +1070,30 @@ namespace Mantid return separateMonitors; } - - //Now check if monitors expand the spectra range - + //Now check if monitors expand or shrink the workspace's spectra range + // We assume again that this spectrum list increases monotonically int64_t min_index = spectrum_index[0]; int64_t max_index = spectrum_index[ndets-1]; + std::map remaining_monitors; for(auto it = monitors.begin(); it!=monitors.end(); it++) { if(it->first>=min_index && it->first <=max_index) { - if(excludeMonitors || separateMonitors) + if(removeMonitors) { m_numberOfSpectra--; - spectraExcluded = true; - spectrum_index[it->first]=-1; + ExcludedSpectra.insert(static_cast(it->first)); } } else { - remaining_monitors.insert(*it); - m_numberOfSpectra++; + if(!removeMonitors) + { + remaining_monitors.insert(*it); + m_numberOfSpectra++; + } } } monitors.swap(remaining_monitors); From 23863776bab89d3e9133805e1a02907a383eac7e Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Thu, 9 Oct 2014 10:22:44 +0100 Subject: [PATCH 08/22] refs #9989 Unit test for LoadMonitorsSeparately option and some small niceness to the code, which performs this operation (comments, var names, code duplication). --- .../inc/MantidDataHandling/LoadRawHelper.h | 2 +- .../DataHandling/src/LoadISISNexus2.cpp | 51 ++++---- .../Framework/DataHandling/src/LoadRaw3.cpp | 19 +-- .../DataHandling/src/LoadRawHelper.cpp | 25 ++++ .../DataHandling/test/LoadISISNexusTest.h | 113 ++++++++++++++++++ 5 files changed, 170 insertions(+), 40 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h index 752b3dc0a8f9..fafd84121516 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h @@ -82,7 +82,7 @@ namespace Mantid static bool isIncludeMonitors(const std::string &monitorOption); - + static void ProcessLoadMonitorOptions(bool &bincludeMonitors,bool &bseparateMonitors,bool &bexcludeMonitors,API::Algorithm *pAlgo); protected: /// Overwrites Algorithm method. void init(); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index a261fe5059ed..4f784d33ab61 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -117,23 +117,11 @@ namespace Mantid { //********************************************************************** - // process primary monitor options - std::string monitorOption = getProperty("LoadMonitors"); - if (monitorOption =="1") - monitorOption = "Separate"; - if (monitorOption=="0") - monitorOption = "Exclude"; - - bool bincludeMonitors = LoadRawHelper::isIncludeMonitors(monitorOption); - bool bseparateMonitors = false; - bool bexcludeMonitors = false; - if (!bincludeMonitors) - { - bseparateMonitors = LoadRawHelper::isSeparateMonitors(monitorOption); - bexcludeMonitors = LoadRawHelper::isExcludeMonitors(monitorOption); - } - //********************************************************************** + // process load monitor options request + bool bincludeMonitors,bseparateMonitors, bexcludeMonitors; + LoadRawHelper::ProcessLoadMonitorOptions(bincludeMonitors,bseparateMonitors, bexcludeMonitors,this); + //********************************************************************** m_filename = getPropertyValue("Filename"); // Create the root Nexus class NXRoot root(m_filename); @@ -204,13 +192,13 @@ namespace Mantid throw std::runtime_error("Inconsistent NeXus file structure."); } } - std::set ExcluedSpectra; - bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,ExcluedSpectra); + std::set ExcluedMonitorsSpectra; + bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,ExcluedMonitorsSpectra); const size_t x_length = m_numberOfChannels + 1; // Check input is consistent with the file, throwing if not, exclude spectra selected at findSpectraDetRangeInFile; - checkOptionalProperties(ExcluedSpectra); + checkOptionalProperties(ExcluedMonitorsSpectra); // Fill up m_spectraBlocks size_t total_specs = prepareSpectraBlocks(); @@ -311,6 +299,7 @@ namespace Mantid m_tof_data.reset(); m_spec.reset(); m_monitors.clear(); + m_specInd2specNum_map.clear(); } // Function object for remove_if STL algorithm @@ -1012,11 +1001,27 @@ namespace Mantid { return sqrt(in); } - + /**Method takes input parameters which describe monitor loading and analyze them against spectra/monitor information in the file. + * The result is the option if monitors can be loaded together with spectra or mast be treated separately + * and additional information on how to treat monitor spectra. + * + *@param entry :: entry to the NeXus file, opened at root folder + *@param spectrum_index :: array of spectra indexes of the data present in the file + *@param ndets :: size of the spectrum index array + *@param n_vms_compat_spectra :: number of data entries containing common time bins (e.g. all spectra, or all spectra and monitors or some spectra (this is not fully supported) + *@param monitors :: map connecting monitor spectra ID against monitor group name in the file. + *@param excludeMonitors :: input property indicating if it is requested to exclude monitors from the target workspace + *@param separateMonitors :: input property indicating if it is requested to load monitors separately (and exclude them from target data workspace this way) + * + *@param MonitorSpectra :: output property containing the list of monitors which should be loaded separately. + *@return excludeMonitors :: indicator if monitors should or mast be excluded from the main data workspace if they can not be loaded with the data + * (contain different number of time channels) + * + */ bool LoadISISNexus2::findSpectraDetRangeInFile(NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, - std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &ExcludedSpectra) + std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &MonitorSpectra) { - ExcludedSpectra.clear(); + MonitorSpectra.clear(); size_t nmons = monitors.size(); //Grab the number of channels @@ -1084,7 +1089,7 @@ namespace Mantid if(removeMonitors) { m_numberOfSpectra--; - ExcludedSpectra.insert(static_cast(it->first)); + MonitorSpectra.insert(static_cast(it->first)); } } else diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp index 4c70948539df..4305719e5c43 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp @@ -95,22 +95,9 @@ namespace Mantid bool bLoadlogFiles = getProperty("LoadLogFiles"); - // process monitor option - std::string monitorOption = getProperty("LoadMonitors"); - if (monitorOption =="1") - monitorOption = "Separate"; - if (monitorOption=="0") - monitorOption = "Exclude"; - - bool bincludeMonitors = LoadRawHelper::isIncludeMonitors(monitorOption); - bool bseparateMonitors = false; - bool bexcludeMonitors = false; - if (!bincludeMonitors) - { - bseparateMonitors = LoadRawHelper::isSeparateMonitors(monitorOption); - bexcludeMonitors = LoadRawHelper::isExcludeMonitors(monitorOption); - } - // + bool bincludeMonitors,bseparateMonitors, bexcludeMonitors; + LoadRawHelper::ProcessLoadMonitorOptions(bincludeMonitors,bseparateMonitors, bexcludeMonitors,this); + std::string title; //read workspace title from raw file diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 0e87a26eb333..95897381a5b9 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -1319,7 +1319,32 @@ namespace Mantid monitorOption.compare("Separate") ? (bSeparate = false) : (bSeparate = true); return bSeparate; } + /**The method to interpret LoadMonitors property options and convert then into boolean values + * @param bincludeMonitors :: if monitors requested to be included with workspace + * @param bseparateMonitors :: if monitors requested to be loaded separately from the workspace + * @param bexcludeMonitors :: if monitors should not be loaded at all. + * @param pAlgo :: pointer to the algorithm, which has LoadMonitors property. + */ + void LoadRawHelper::ProcessLoadMonitorOptions(bool &bincludeMonitors,bool &bseparateMonitors,bool &bexcludeMonitors,API::Algorithm *pAlgo) + { + // process monitor option + std::string monitorOption = pAlgo->getProperty("LoadMonitors"); + if (monitorOption =="1") + monitorOption = "Separate"; + if (monitorOption=="0") + monitorOption = "Exclude"; + + bincludeMonitors = LoadRawHelper::isIncludeMonitors(monitorOption); + bseparateMonitors = false; + bexcludeMonitors = false; + if (!bincludeMonitors) + { + bseparateMonitors = LoadRawHelper::isSeparateMonitors(monitorOption); + bexcludeMonitors = LoadRawHelper::isExcludeMonitors(monitorOption); + } + // + } } // namespace DataHandling } // namespace Mantid diff --git a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h index 7124eec12d54..bae2a9591039 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h @@ -67,6 +67,8 @@ class LoadISISNexusTest : public CxxTest::TestSuite } public: + + void testExec() { Mantid::API::FrameworkManager::Instance(); @@ -451,6 +453,117 @@ class LoadISISNexusTest : public CxxTest::TestSuite TS_ASSERT_THROWS_NOTHING( v1.initialize() ); TS_ASSERT_THROWS( v1.execute(), Exception::NotImplementedError) } + void testExecMonExcluded() + { + Mantid::API::FrameworkManager::Instance(); + LoadISISNexus2 ld; + ld.initialize(); + ld.setPropertyValue("Filename","LOQ49886.nxs"); + ld.setPropertyValue("OutputWorkspace","outWS"); + ld.setPropertyValue("LoadMonitors","0"); // should read "exclude" + TS_ASSERT_THROWS_NOTHING(ld.execute()); + TS_ASSERT(ld.isExecuted()); + + MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS("outWS"); + TS_ASSERT_EQUALS(ws->blocksize(),5); + TS_ASSERT_EQUALS(ws->getNumberHistograms(),17790); + + // Two monitors which form two first spectra are excluded by load separately + + // spectrum with ID 5 is now spectrum N 3 as 2 monitors + TS_ASSERT_EQUALS(ws->readY(5-2)[1],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(5-2)->getSpectrumNo(),6); + TS_ASSERT_EQUALS(*(ws->getSpectrum(5-2)->getDetectorIDs().begin()), 6); + // spectrum with ID 7 is now spectrum N 4 + TS_ASSERT_EQUALS(ws->readY(6-2)[0],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(6-2)->getSpectrumNo(),7); + TS_ASSERT_EQUALS(*(ws->getSpectrum(6-2)->getDetectorIDs().begin()), 7); + // + TS_ASSERT_EQUALS(ws->readY(9-2)[3],1.); + // spectrum with ID 9 is now spectrum N 6 + TS_ASSERT_EQUALS(ws->getSpectrum(8-2)->getSpectrumNo(),9); + TS_ASSERT_EQUALS(*(ws->getSpectrum(8-2)->getDetectorIDs().begin()), 9); + // spectrum with ID 14 is now spectrum N 11 + TS_ASSERT_EQUALS(ws->readY(13-2)[1],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(13-2)->getSpectrumNo(),14); + TS_ASSERT_EQUALS(*(ws->getSpectrum(13-2)->getDetectorIDs().begin()), 14); + // spectrum with ID 18 is now spectrum N 15 + TS_ASSERT_EQUALS(ws->readY(17-2)[1],2.); + TS_ASSERT_EQUALS(ws->getSpectrum(17-2)->getSpectrumNo(),18); + TS_ASSERT_EQUALS(*(ws->getSpectrum(17-2)->getDetectorIDs().begin()), 18); + // spectrum with ID 19 is now spectrum N 16 + TS_ASSERT_EQUALS(ws->readY(18-2)[1],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(18-2)->getSpectrumNo(),19); + TS_ASSERT_EQUALS(*(ws->getSpectrum(18-2)->getDetectorIDs().begin()), 19); + + + TS_ASSERT_EQUALS(ws->readY(33-2)[2],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(33-2)->getSpectrumNo(),34); + TS_ASSERT_EQUALS(*(ws->getSpectrum(33-2)->getDetectorIDs().begin()), 34); + // + TS_ASSERT_EQUALS(ws->readY(34-2)[1],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(34-2)->getSpectrumNo(),35); + TS_ASSERT_EQUALS(*(ws->getSpectrum(34-2)->getDetectorIDs().begin()), 35); + + TS_ASSERT_EQUALS(ws->readY(37-2)[3],1.); + TS_ASSERT_EQUALS(ws->readY(37-2)[4],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(37-2)->getSpectrumNo(),38); + TS_ASSERT_EQUALS(*(ws->getSpectrum(37-2)->getDetectorIDs().begin()), 38); + + + TS_ASSERT_EQUALS(ws->getSpectrum(1234-2)->getDetectorIDs().size(), 1); + TS_ASSERT_EQUALS(*(ws->getSpectrum(1234-2)->getDetectorIDs().begin()), 1235); + + TS_ASSERT_EQUALS(ws->getSpectrum(1234-2)->getSpectrumNo(), 1235 ); + TS_ASSERT(ws->getSpectrum(1234-2)->hasDetectorID(1235) ); + + const std::vector< Property* >& logs = ws->run().getLogData(); + TS_ASSERT_EQUALS(logs.size(), 62); + + std::string header = ws->run().getPropertyValueAsType("run_header"); + TS_ASSERT_EQUALS(86, header.size()); + TS_ASSERT_EQUALS("LOQ 49886 Team LOQ Quiet Count, ISIS Off, N 28-APR-2009 09:20:29 0.00", header); + + TimeSeriesProperty* slog = dynamic_cast*>(ws->run().getLogData("icp_event")); + TS_ASSERT(slog); + std::string str = slog->value(); + TS_ASSERT_EQUALS(str.size(),1023); + TS_ASSERT_EQUALS(str.substr(0,37),"2009-Apr-28 09:20:29 CHANGE_PERIOD 1"); + + slog = dynamic_cast*>(ws->run().getLogData("icp_debug")); + TS_ASSERT(slog); + TS_ASSERT_EQUALS(slog->size(),50); + + TimeSeriesProperty* ilog = dynamic_cast*>(ws->run().getLogData("total_counts")); + TS_ASSERT(ilog); + TS_ASSERT_EQUALS(ilog->size(),172); + + ilog = dynamic_cast*>(ws->run().getLogData("period")); + TS_ASSERT(ilog); + TS_ASSERT_EQUALS(ilog->size(),172); + + TimeSeriesProperty *dlog = dynamic_cast*>(ws->run().getLogData("proton_charge")); + TS_ASSERT(dlog); + TS_ASSERT_EQUALS(dlog->size(),172); + + + TimeSeriesProperty* blog = dynamic_cast*>(ws->run().getLogData("period 1")); + TS_ASSERT(blog); + TS_ASSERT_EQUALS(blog->size(),1); + + blog = dynamic_cast*>(ws->run().getLogData("running")); + TS_ASSERT(blog); + TS_ASSERT_EQUALS(blog->size(),6); + + TS_ASSERT_EQUALS(ws->sample().getName(),"PMMA_SAN25_1.5%_TRANS_150"); + + Property *l_property = ws->run().getLogData( "run_number" ); + TS_ASSERT_EQUALS( l_property->value(), "49886" ); + AnalysisDataService::Instance().remove("outWS"); + } + + + }; //------------------------------------------------------------------------------ From f0092432761e177c4f3bcebe8c3fbfaefa44f9f3 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Thu, 9 Oct 2014 10:42:00 +0100 Subject: [PATCH 09/22] refs #9989 Fixing unit test --- Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h index bae2a9591039..1b4b5e4fc369 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h @@ -479,7 +479,8 @@ class LoadISISNexusTest : public CxxTest::TestSuite TS_ASSERT_EQUALS(ws->getSpectrum(6-2)->getSpectrumNo(),7); TS_ASSERT_EQUALS(*(ws->getSpectrum(6-2)->getDetectorIDs().begin()), 7); // - TS_ASSERT_EQUALS(ws->readY(9-2)[3],1.); + TS_ASSERT_EQUALS(ws->readY(8-2)[3],1.); + // spectrum with ID 9 is now spectrum N 6 TS_ASSERT_EQUALS(ws->getSpectrum(8-2)->getSpectrumNo(),9); TS_ASSERT_EQUALS(*(ws->getSpectrum(8-2)->getDetectorIDs().begin()), 9); From 1597485ebe8b4dade55cded2288ea1c1d2e336fa Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Thu, 9 Oct 2014 10:46:54 +0100 Subject: [PATCH 10/22] refs #9989 Unix compilation error --- .../DataHandling/inc/MantidDataHandling/LoadISISNexus2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index 8d8b54862d36..36551826d4ad 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -192,7 +192,7 @@ namespace Mantid static double dblSqrt(double in); // C++ interface to the NXS file - boost::scoped_ptr<::NeXus::File> m_cppFile; + boost::scoped_ptr< ::NeXus::File> m_cppFile; bool findSpectraDetRangeInFile(NeXus::NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &ExcludedSpectra); From 294cfddc9fdb82f7bc18d582d062cac0c1923c1f Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Thu, 9 Oct 2014 10:53:21 +0100 Subject: [PATCH 11/22] refs #9989 doxygen error --- Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 4f784d33ab61..2289e4fb65cb 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -344,7 +344,7 @@ namespace Mantid /** * Check the validity of the optional properties of the algorithm and identify if partial data should be loaded. - * @param SpectraExclued :: set of spectra ID-s to exclude from spectra list to load + * @param SpectraExcluded :: set of spectra ID-s to exclude from spectra list to load */ void LoadISISNexus2::checkOptionalProperties(const std::set &SpectraExcluded) { From 87a745864ca0afef98a5e9e20a833bff8843f629 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Thu, 9 Oct 2014 17:48:36 +0100 Subject: [PATCH 12/22] refs #9989 Preparing LoadRawHelper for use with LoadISISNexus2 + changes intended to make logic of LoadISISNexus2 simpler --- .../inc/MantidDataHandling/LoadISISNexus2.h | 53 ++-- .../inc/MantidDataHandling/LoadRawHelper.h | 83 +++--- .../DataHandling/src/LoadISISNexus2.cpp | 120 ++++---- .../Framework/DataHandling/src/LoadRaw3.cpp | 12 +- .../DataHandling/src/LoadRawBin0.cpp | 78 ++--- .../DataHandling/src/LoadRawHelper.cpp | 34 +-- .../DataHandling/src/LoadRawSpectrum0.cpp | 272 +++++++++--------- .../DataHandling/test/LoadISISNexusTest.h | 1 + 8 files changed, 340 insertions(+), 313 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index 36551826d4ad..f7882de3d306 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -96,6 +96,25 @@ namespace Mantid int64_t last; ///< last spectrum number of the block bool isMonitor; ///< is the data in a monitor group }; + + /// The structure describes parameters of a single time-block written in the nexus file + struct DataBlock + { + /// The number of data periods + int numberOfPeriods; + /// The number of time channels per spectrum (N histogram bins -1) + std::size_t numberOfChannels; + /// The number of spectra + std::size_t numberOfSpectra; + + DataBlock():numberOfPeriods(0),numberOfChannels(0),numberOfSpectra(0){} + + DataBlock(const NeXus::NXInt &data): + numberOfPeriods(data.dim0()), + numberOfChannels(data.dim2()), + numberOfSpectra (data.dim1()) + {}; + }; private: /// Overwrites Algorithm method. void init(); @@ -106,25 +125,25 @@ namespace Mantid /// Prepare a vector of SpectraBlock structures to simplify loading size_t prepareSpectraBlocks(); /// Run LoadInstrument as a ChildAlgorithm - void runLoadInstrument(DataObjects::Workspace2D_sptr); + void runLoadInstrument(DataObjects::Workspace2D_sptr &); /// Load in details about the run - void loadRunDetails(DataObjects::Workspace2D_sptr local_workspace, Mantid::NeXus::NXEntry & entry); + void loadRunDetails(DataObjects::Workspace2D_sptr &local_workspace, Mantid::NeXus::NXEntry & entry); /// Parse an ISO formatted date-time string into separate date and time strings void parseISODateTime(const std::string & datetime_iso, std::string & date, std::string & time) const; /// Load in details about the sample - void loadSampleData(DataObjects::Workspace2D_sptr, Mantid::NeXus::NXEntry & entry); + void loadSampleData(DataObjects::Workspace2D_sptr &, Mantid::NeXus::NXEntry & entry); /// Load log data from the nexus file - void loadLogs(DataObjects::Workspace2D_sptr ws, Mantid::NeXus::NXEntry & entry); + void loadLogs(DataObjects::Workspace2D_sptr &ws, Mantid::NeXus::NXEntry & entry); // Load a given period into the workspace - void loadPeriodData(int64_t period, Mantid::NeXus::NXEntry & entry, DataObjects::Workspace2D_sptr local_workspace); + void loadPeriodData(int64_t period, Mantid::NeXus::NXEntry & entry, DataObjects::Workspace2D_sptr &local_workspace); // Load a data block void loadBlock(Mantid::NeXus::NXDataSetTyped & data, int64_t blocksize, int64_t period, int64_t start, - int64_t &hist, int64_t& spec_num, DataObjects::Workspace2D_sptr localWorkspace); + int64_t &hist, int64_t& spec_num, DataObjects::Workspace2D_sptr &localWorkspace); // Create period logs - void createPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr local_workspace); + void createPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr &local_workspace); // Validate multi-period logs - void validateMultiPeriodLogs(Mantid::API::MatrixWorkspace_sptr); + void validateMultiPeriodLogs(Mantid::API::MatrixWorkspace_sptr ); // build the list of spectra numbers to load and include in the spectra list void buildSpectraInd2SpectraNumMap(const std::vector &spec_list,const std::set &ExcludedSpectra); @@ -136,18 +155,12 @@ namespace Mantid /// The sample name read from Nexus std::string m_samplename; - /// The number of spectra - std::size_t m_numberOfSpectra; - /// The number of spectra in the raw file - std::size_t m_numberOfSpectraInFile; - /// The number of periods - int m_numberOfPeriods; - /// The number of periods in the raw file - int m_numberOfPeriodsInFile; - /// The number of time channels per spectrum - std::size_t m_numberOfChannels; - /// The number of time channels per spectrum in the raw file - std::size_t m_numberOfChannelsInFile; + // the description of the data block, containing in the file. May include monitors and detectors with the same time binning + DataBlock m_detFileDataInfo; + // the description of single time-range data block, obtained from detectors + DataBlock m_detBlockInfo; + // the description of single time-range data block, obtained from monitors + DataBlock m_monBlockInfo; /// Is there a detector block bool m_have_detector; diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h index fafd84121516..0db15d00eca9 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h @@ -27,32 +27,32 @@ namespace Mantid { /** @class LoadRawHelper DataHandling/LoadRawHelper.h - Helper class for LoadRaw algorithms. + Helper class for LoadRaw algorithms. - @author Sofia Antony, ISIS,RAL - @date 14/04/2010 + @author Sofia Antony, ISIS,RAL + @date 14/04/2010 - Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory + Copyright © 2007-9 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory - This file is part of Mantid. + This file is part of Mantid. - Mantid is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. - Mantid is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . - File change history is stored at: . - Code Documentation is available at: - */ + File change history is stored at: . + Code Documentation is available at: + */ class DLLExport LoadRawHelper: public API::IFileLoader { public: @@ -83,6 +83,28 @@ namespace Mantid static void ProcessLoadMonitorOptions(bool &bincludeMonitors,bool &bseparateMonitors,bool &bexcludeMonitors,API::Algorithm *pAlgo); + ///creates monitor workspace + static void createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr, + DataObjects::Workspace2D_sptr& ws_sptr,API::WorkspaceGroup_sptr& mongrp_sptr, + const int64_t mwsSpecs,const int64_t nwsSpecs,const int64_t numberOfPeriods,const int64_t lenthIn,std::string title,API::Algorithm *pAlg); + /// creates shared pointer to group workspace + static API::WorkspaceGroup_sptr createGroupWorkspace(); + + ///creates shared pointer to workspace from parent workspace + static DataObjects::Workspace2D_sptr createWorkspace(DataObjects::Workspace2D_sptr ws_sptr, + int64_t nVectors=-1,int64_t xLengthIn=-1,int64_t yLengthIn=-1); + + /// overloaded method to create shared pointer to workspace + static DataObjects::Workspace2D_sptr createWorkspace(int64_t nVectors,int64_t xlengthIn,int64_t ylengthIn,const std::string& title); + + /// sets the workspace property + static void setWorkspaceProperty(const std::string & propertyName,const std::string& title, + API::WorkspaceGroup_sptr grpws_sptr,DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods,bool bMonitor,API::Algorithm *pAlg); + + /// overloaded method to set the workspace property + static void setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr,API::WorkspaceGroup_sptr grpws_sptr,const int64_t period,bool bmonitors,API::Algorithm *pAlg); + + protected: /// Overwrites Algorithm method. void init(); @@ -104,19 +126,6 @@ namespace Mantid bool readData(FILE* file,int histToRead); bool readData(FILE* file,int64_t histToRead); - ///creates shared pointer to workspace from parent workspace - DataObjects::Workspace2D_sptr createWorkspace(DataObjects::Workspace2D_sptr ws_sptr, - int64_t nVectors=-1,int64_t xLengthIn=-1,int64_t yLengthIn=-1); - - /// overloaded method to create shared pointer to workspace - DataObjects::Workspace2D_sptr createWorkspace(int64_t nVectors,int64_t xlengthIn,int64_t ylengthIn,const std::string& title); - ///creates monitor workspace - void createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr, - DataObjects::Workspace2D_sptr& ws_sptr,API::WorkspaceGroup_sptr& mongrp_sptr, - const int64_t mwsSpecs,const int64_t nwsSpecs,const int64_t numberOfPeriods,const int64_t lenthIn,std::string title); - - /// creates shared pointer to group workspace - API::WorkspaceGroup_sptr createGroupWorkspace(); //Constructs the time channel (X) vector(s) std::vector > getTimeChannels(const int64_t& regimes, const int64_t& lengthIn); @@ -135,16 +144,10 @@ namespace Mantid ///gets the monitor spectrum list from the workspace std::vector getmonitorSpectrumList(const API::SpectrumDetectorMapping& mapping); - /// sets the workspace property - void setWorkspaceProperty(const std::string & propertyName,const std::string& title, - API::WorkspaceGroup_sptr grpws_sptr,DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods,bool bMonitor); - - /// overloaded method to set the workspace property - void setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr,API::WorkspaceGroup_sptr grpws_sptr,const int64_t period,bool bmonitors); /// This method sets the raw file data to workspace vectors void setWorkspaceData(DataObjects::Workspace2D_sptr newWorkspace,const std::vector >& - timeChannelsVec,int64_t wsIndex,specid_t nspecNum,int64_t noTimeRegimes,int64_t lengthIn,int64_t binStart); + timeChannelsVec,int64_t wsIndex,specid_t nspecNum,int64_t noTimeRegimes,int64_t lengthIn,int64_t binStart); /// ISISRAW class instance which does raw file reading. Shared pointer to prevent memory leak when an exception is thrown. @@ -170,10 +173,10 @@ namespace Mantid specid_t calculateWorkspaceSize(); /// calculate workspace sizes if separate or exclude monitors are selected void calculateWorkspacesizes(const std::vector& monitorSpecList, - specid_t& normalwsSpecs, specid_t& monitorwsSpecs); + specid_t& normalwsSpecs, specid_t& monitorwsSpecs); /// load the specra void loadSpectra(FILE* file,const int& period, const int& m_total_specs, - DataObjects::Workspace2D_sptr ws_sptr,std::vector >); + DataObjects::Workspace2D_sptr ws_sptr,std::vector >); /// Has the spectrum_list property been set? bool m_list; diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 2289e4fb65cb..a529e3ebaf08 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -49,8 +49,8 @@ namespace Mantid /// Empty default constructor LoadISISNexus2::LoadISISNexus2() : - m_filename(), m_instrument_name(), m_samplename(), m_numberOfSpectra(0), m_numberOfSpectraInFile(0), - m_numberOfPeriods(0), m_numberOfPeriodsInFile(0), m_numberOfChannels(0), m_numberOfChannelsInFile(0), + m_filename(), m_instrument_name(), m_samplename(), + m_detFileDataInfo(),m_detBlockInfo(),m_monBlockInfo(), m_have_detector(false),m_range_supplied(true), m_spec_min(0), m_spec_max(EMPTY_INT()), m_load_selected_spectra(false),m_specInd2specNum_map(),m_spec2det_map(), m_entrynumber(0), m_tof_data(), m_proton_charge(0.), @@ -195,17 +195,17 @@ namespace Mantid std::set ExcluedMonitorsSpectra; bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,ExcluedMonitorsSpectra); - const size_t x_length = m_numberOfChannels + 1; + const size_t x_length = m_detBlockInfo.numberOfChannels + 1; // Check input is consistent with the file, throwing if not, exclude spectra selected at findSpectraDetRangeInFile; checkOptionalProperties(ExcluedMonitorsSpectra); // Fill up m_spectraBlocks size_t total_specs = prepareSpectraBlocks(); - m_progress = boost::shared_ptr(new Progress(this, 0.0, 1.0, total_specs * m_numberOfPeriods)); + m_progress = boost::shared_ptr(new Progress(this, 0.0, 1.0, total_specs * m_detFileDataInfo.numberOfPeriods)); DataObjects::Workspace2D_sptr local_workspace = boost::dynamic_pointer_cast - (WorkspaceFactory::Instance().create("Workspace2D", total_specs, x_length, m_numberOfChannels)); + (WorkspaceFactory::Instance().create("Workspace2D", total_specs, x_length, m_detFileDataInfo.numberOfChannels)); // Set the units on the workspace to TOF & Counts local_workspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); local_workspace->setYUnit("Counts"); @@ -259,7 +259,7 @@ namespace Mantid createPeriodLogs(firstentry, local_workspace); - if( m_numberOfPeriods > 1 && m_entrynumber == 0 ) + if( m_detFileDataInfo.numberOfPeriods > 1 && m_entrynumber == 0 ) { WorkspaceGroup_sptr wksp_group(new WorkspaceGroup); @@ -269,7 +269,7 @@ namespace Mantid const std::string base_name = getPropertyValue("OutputWorkspace") + "_"; const std::string prop_name = "OutputWorkspace_"; - for( int p = 1; p <= m_numberOfPeriods; ++p ) + for( int p = 1; p <= m_detFileDataInfo.numberOfPeriods; ++p ) { std::ostringstream os; os << p; @@ -288,11 +288,20 @@ namespace Mantid setProperty(prop_name + os.str(), boost::static_pointer_cast(local_workspace)); } // The group is the root property value - setProperty("OutputWorkspace", boost::dynamic_pointer_cast(wksp_group)); + if(!bseparateMonitors) + setProperty("OutputWorkspace", boost::dynamic_pointer_cast(wksp_group)); } else { - setProperty("OutputWorkspace", boost::dynamic_pointer_cast(local_workspace)); + if(!bseparateMonitors) + setProperty("OutputWorkspace", boost::dynamic_pointer_cast(local_workspace)); + } + + //*************************************************************************************************** + // Workspace or group of workspaces without monitors is loaded. Now we are loading monitors separately. + if(bseparateMonitors) + { + } // Clear off the member variable containers @@ -372,7 +381,7 @@ namespace Mantid if( m_spec_max == EMPTY_INT() ) - m_spec_max = m_numberOfSpectra; + m_spec_max = m_detBlockInfo.numberOfSpectra; else m_load_selected_spectra = true; @@ -382,20 +391,20 @@ namespace Mantid throw std::invalid_argument("Inconsistent range properties. SpectrumMin is larger than SpectrumMax."); } - if( static_cast(m_spec_max) > m_numberOfSpectra+numSpectraExclued ) + if( static_cast(m_spec_max) > m_detBlockInfo.numberOfSpectra+numSpectraExclued ) { - std::string err="Inconsistent range property. SpectrumMax is larger than number of spectra: "+boost::lexical_cast(m_numberOfSpectra+numSpectraExclued ); + std::string err="Inconsistent range property. SpectrumMax is larger than number of spectra: "+boost::lexical_cast(m_detFileDataInfo.numberOfSpectra+numSpectraExclued ); throw std::invalid_argument(err); } // Check the entry number m_entrynumber = getProperty("EntryNumber"); - if( static_cast(m_entrynumber) > m_numberOfPeriods || m_entrynumber < 0 ) + if( static_cast(m_entrynumber) > m_detBlockInfo.numberOfPeriods || m_entrynumber < 0 ) { - std::string err="Invalid entry number entered. File contains "+boost::lexical_cast(m_numberOfPeriods )+ " period. "; + std::string err="Invalid entry number entered. File contains "+boost::lexical_cast(m_detBlockInfo.numberOfPeriods)+ " period. "; throw std::invalid_argument(err); } - if( m_numberOfPeriods == 1 ) + if(m_detBlockInfo.numberOfPeriods== 1 ) { m_entrynumber = 1; } @@ -409,9 +418,9 @@ namespace Mantid // Sort the list so that we can check it's range std::sort(spec_list.begin(), spec_list.end()); - if( spec_list.back() > static_cast(m_numberOfSpectra+numSpectraExclued) ) + if( spec_list.back() > static_cast(m_detBlockInfo.numberOfSpectra+numSpectraExclued) ) { - std::string err="A spectra number in the spectra list exceeds total number of "+boost::lexical_cast(m_numberOfSpectra+numSpectraExclued )+ " spectra "; + std::string err="A spectra number in the spectra list exceeds total number of "+boost::lexical_cast(m_detBlockInfo.numberOfSpectra+numSpectraExclued )+ " spectra "; throw std::invalid_argument(err); } @@ -620,7 +629,7 @@ namespace Mantid * @param entry :: The opened root entry node for accessing the monitor and data nodes * @param local_workspace :: The workspace to place the data in */ - void LoadISISNexus2::loadPeriodData(int64_t period, NXEntry & entry, DataObjects::Workspace2D_sptr local_workspace) + void LoadISISNexus2::loadPeriodData(int64_t period, NXEntry & entry, DataObjects::Workspace2D_sptr &local_workspace) { int64_t hist_index = 0; int64_t period_index(period - 1); @@ -637,7 +646,7 @@ namespace Mantid m_progress->report("Loading monitor"); mondata.load(1,static_cast(period-1)); // TODO this is just wrong MantidVec& Y = local_workspace->dataY(hist_index); - Y.assign(mondata(),mondata() + m_numberOfChannels); + Y.assign(mondata(),mondata() + m_monBlockInfo.numberOfChannels); MantidVec& E = local_workspace->dataE(hist_index); std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt); @@ -706,7 +715,7 @@ namespace Mantid * @param period :: period number * @param local_workspace :: workspace to add period log data to. */ - void LoadISISNexus2::createPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr local_workspace) + void LoadISISNexus2::createPeriodLogs(int64_t period, DataObjects::Workspace2D_sptr &local_workspace) { m_logCreator->addPeriodLogs(static_cast(period), local_workspace->mutableRun()); } @@ -724,18 +733,19 @@ namespace Mantid */ void LoadISISNexus2::loadBlock(NXDataSetTyped & data, int64_t blocksize, int64_t period, int64_t start, int64_t &hist, int64_t& spec_num, - DataObjects::Workspace2D_sptr local_workspace) + DataObjects::Workspace2D_sptr &local_workspace) { data.load(static_cast(blocksize), static_cast(period), static_cast(start)); // TODO this is just wrong int *data_start = data(); - int *data_end = data_start + m_numberOfChannels; + int *data_end = data_start + m_detBlockInfo.numberOfChannels; int64_t final(hist + blocksize); while( hist < final ) { m_progress->report("Loading data"); MantidVec& Y = local_workspace->dataY(hist); Y.assign(data_start, data_end); - data_start += m_numberOfChannels; data_end += m_numberOfChannels; + data_start += m_detBlockInfo.numberOfChannels; + data_end += m_detBlockInfo.numberOfChannels; MantidVec& E = local_workspace->dataE(hist); std::transform(Y.begin(), Y.end(), E.begin(), dblSqrt); // Populate the workspace. Loop starts from 1, hence i-1 @@ -757,7 +767,7 @@ namespace Mantid } /// Run the Child Algorithm LoadInstrument (or LoadInstrumentFromNexus) - void LoadISISNexus2::runLoadInstrument(DataObjects::Workspace2D_sptr localWorkspace) + void LoadISISNexus2::runLoadInstrument(DataObjects::Workspace2D_sptr &localWorkspace) { IAlgorithm_sptr loadInst = createChildAlgorithm("LoadInstrument"); @@ -816,7 +826,7 @@ namespace Mantid * @param local_workspace :: The workspace to load the run information in to * @param entry :: The Nexus entry */ - void LoadISISNexus2::loadRunDetails(DataObjects::Workspace2D_sptr local_workspace, NXEntry & entry) + void LoadISISNexus2::loadRunDetails(DataObjects::Workspace2D_sptr &local_workspace, NXEntry & entry) { API::Run & runDetails = local_workspace->mutableRun(); // Charge is stored as a float @@ -859,9 +869,9 @@ namespace Mantid runDetails.addProperty("run_header", std::string(header, header + 86)); // Data details on run not the workspace - runDetails.addProperty("nspectra", static_cast(m_numberOfSpectraInFile)); - runDetails.addProperty("nchannels", static_cast(m_numberOfChannelsInFile)); - runDetails.addProperty("nperiods", static_cast(m_numberOfPeriodsInFile)); + runDetails.addProperty("nspectra", static_cast(m_detFileDataInfo.numberOfSpectra)); + runDetails.addProperty("nchannels", static_cast(m_detFileDataInfo.numberOfChannels)); + runDetails.addProperty("nperiods", static_cast(m_detFileDataInfo.numberOfPeriods)); // RPB struct info NXInt rpb_int = vms_compat.openNXInt("IRPB"); @@ -932,7 +942,7 @@ namespace Mantid * @param local_workspace :: The workspace to load the logs to. * @param entry :: The Nexus entry */ - void LoadISISNexus2::loadSampleData(DataObjects::Workspace2D_sptr local_workspace, NXEntry & entry) + void LoadISISNexus2::loadSampleData(DataObjects::Workspace2D_sptr &local_workspace, NXEntry & entry) { /// Sample geometry NXInt spb = entry.openNXInt("isis_vms_compat/SPB"); @@ -958,7 +968,7 @@ namespace Mantid * @param ws :: The workspace to load the logs to. * @param entry :: Nexus entry */ - void LoadISISNexus2::loadLogs(DataObjects::Workspace2D_sptr ws, NXEntry & entry) + void LoadISISNexus2::loadLogs(DataObjects::Workspace2D_sptr &ws, NXEntry & entry) { IAlgorithm_sptr alg = createChildAlgorithm("LoadNexusLogs", 0.0, 0.5); alg->setPropertyValue("Filename", this->getProperty("Filename")); @@ -993,7 +1003,7 @@ namespace Mantid ws->populateInstrumentParameters(); // Make log creator object and add the run status log - m_logCreator.reset(new ISISRunLogs(ws->run(), m_numberOfPeriods)); + m_logCreator.reset(new ISISRunLogs(ws->run(), m_detBlockInfo.numberOfPeriods)); m_logCreator->addStatusLog(ws->mutableRun()); } @@ -1031,52 +1041,50 @@ namespace Mantid { NXInt chans = entry.openNXInt(m_monitors.begin()->second + "/data"); - nMonitorPeriods = chans.dim0(); - nMonitorChannels = chans.dim2(); - m_numberOfPeriodsInFile = m_numberOfPeriods = nMonitorPeriods ; - m_numberOfSpectraInFile = m_numberOfSpectra = nmons; - m_numberOfChannelsInFile = m_numberOfChannels = nMonitorChannels; + m_monBlockInfo = DataBlock(chans); + m_monBlockInfo.numberOfSpectra = nmons; // each monitor is in separate group so number of spectra is equal to number of groups. + // at this stage let's set up all other detector information to monitors + m_detFileDataInfo = m_monBlockInfo; + m_detBlockInfo = m_monBlockInfo; } if( ndets == 0 ) { - separateMonitors = true; + separateMonitors = false; // load monitors in the main workspace. No detectors return separateMonitors; } + // detectors are present in the file NXData nxData = entry.openNXData("detector_1"); NXInt data = nxData.openIntData(); - m_numberOfPeriodsInFile = m_numberOfPeriods = data.dim0(); - m_numberOfChannelsInFile = m_numberOfChannels = data.dim2(); - if (((m_numberOfPeriodsInFile !=nMonitorPeriods) || (m_numberOfChannelsInFile!=nMonitorChannels)) && nmons>0) + m_detBlockInfo = DataBlock(data); + m_detFileDataInfo = m_detBlockInfo; + if (((m_detBlockInfo.numberOfPeriods!=m_monBlockInfo.numberOfPeriods) || (m_detBlockInfo.numberOfChannels!=m_monBlockInfo.numberOfChannels)) && nmons>0) { + // detectors and monitors have different characteristics. Can be loaded only to separate workspaces. if(!separateMonitors) { g_log.warning()<<" Performing separate loading as can not load spectra and monitors in the single workspace:\n" ; - g_log.warning()<<" Monitors data contain :"<( n_vms_compat_spectra )&& !removeMonitors) + // workspace contain the same number of bins for spectra and monitors. Total number of spectra in workspace will be equal to + // n_vms_compat_spectra + if(!removeMonitors) { - // workspace contain the same number of bins for spectra and monitors. Total number of spectra in workspace will be equal to - // n_vms_compat_spectra - m_numberOfSpectraInFile = m_numberOfSpectra; - m_numberOfSpectra=n_vms_compat_spectra; - return separateMonitors; + m_detFileDataInfo.numberOfSpectra = n_vms_compat_spectra; + if(m_detBlockInfo.numberOfSpectra+nmons ==static_cast( n_vms_compat_spectra )) + return separateMonitors; } //Now check if monitors expand or shrink the workspace's spectra range - + // We assume again that this spectrum list increases monotonically int64_t min_index = spectrum_index[0]; int64_t max_index = spectrum_index[ndets-1]; @@ -1088,16 +1096,18 @@ namespace Mantid { if(removeMonitors) { - m_numberOfSpectra--; MonitorSpectra.insert(static_cast(it->first)); + m_detBlockInfo.numberOfSpectra--; } + } else { if(!removeMonitors) { remaining_monitors.insert(*it); - m_numberOfSpectra++; + m_detBlockInfo.numberOfSpectra++; + } } } diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp index 4305719e5c43..812d7336ba51 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRaw3.cpp @@ -159,7 +159,7 @@ namespace Mantid if (bincludeMonitors) { - setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods, false); + setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods, false,this); } else { @@ -181,13 +181,13 @@ namespace Mantid if(normalwsSpecs > 0) { localWorkspace = createWorkspace(localWorkspace,normalwsSpecs,m_lengthIn,m_lengthIn-1); - setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods,false); + setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods,false,this); } //now create monitor workspace if separateMonitors selected if (bseparateMonitors) { createMonitorWorkspace(monitorWorkspace,localWorkspace,monitorws_grp,monitorwsSpecs, - normalwsSpecs,m_numberOfPeriods,m_lengthIn,title); + normalwsSpecs,m_numberOfPeriods,m_lengthIn,title,this); } } @@ -285,18 +285,18 @@ namespace Mantid if(normalwsSpecs > 0) { // declare and set monitor workspace for each period - setWorkspaceProperty(monitorWorkspace, monitorws_grp, period, true); + setWorkspaceProperty(monitorWorkspace, monitorws_grp, period, true,this); } else { localWorkspace = monitorWorkspace; } // declare and set output workspace for each period - setWorkspaceProperty(localWorkspace, ws_grp, period, false); + setWorkspaceProperty(localWorkspace, ws_grp, period, false,this); } else { - setWorkspaceProperty(localWorkspace, ws_grp, period, false); + setWorkspaceProperty(localWorkspace, ws_grp, period, false,this); } // progress for workspace groups setProg ( static_cast(period) / static_cast(m_numberOfPeriods - 1) ); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawBin0.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawBin0.cpp index a1db683630ff..5c5d402850c8 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawBin0.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawBin0.cpp @@ -65,31 +65,31 @@ void LoadRawBin0::init() */ void LoadRawBin0::exec() { - // Retrieve the filename from the properties - m_filename = getPropertyValue("Filename"); + // Retrieve the filename from the properties + m_filename = getPropertyValue("Filename"); - bool bLoadlogFiles = getProperty("LoadLogFiles"); + bool bLoadlogFiles = getProperty("LoadLogFiles"); - //open the raw file - FILE* file=openRawFile(m_filename); + //open the raw file + FILE* file=openRawFile(m_filename); - // Need to check that the file is not a text file as the ISISRAW routines don't deal with these very well, i.e - // reading continues until a bad_alloc is encountered. - if( isAscii(file) ) - { - g_log.error() << "File \"" << m_filename << "\" is not a valid RAW file.\n"; - throw std::invalid_argument("Incorrect file type encountered."); - } - std::string title; - readTitle(file,title); + // Need to check that the file is not a text file as the ISISRAW routines don't deal with these very well, i.e + // reading continues until a bad_alloc is encountered. + if( isAscii(file) ) + { + g_log.error() << "File \"" << m_filename << "\" is not a valid RAW file.\n"; + throw std::invalid_argument("Incorrect file type encountered."); + } + std::string title; + readTitle(file,title); - readworkspaceParameters(m_numberOfSpectra,m_numberOfPeriods,m_lengthIn,m_noTimeRegimes); + readworkspaceParameters(m_numberOfSpectra,m_numberOfPeriods,m_lengthIn,m_noTimeRegimes); - /// - setOptionalProperties(); + /// + setOptionalProperties(); - // to validate the optional parameters, if set - checkOptionalProperties(); + // to validate the optional parameters, if set + checkOptionalProperties(); // Calculate the size of a workspace, given its number of periods & spectra to read m_total_specs = calculateWorkspaceSize(); @@ -114,7 +114,7 @@ void LoadRawBin0::exec() setProtonCharge(run); WorkspaceGroup_sptr ws_grp = createGroupWorkspace(); - setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods, false); + setWorkspaceProperty("OutputWorkspace", title, ws_grp, localWorkspace,m_numberOfPeriods, false,this); // Loop over the number of periods in the raw file, putting each period in a separate workspace for (int period = 0; period < m_numberOfPeriods; ++period) @@ -147,14 +147,14 @@ void LoadRawBin0::exec() { progress(m_prog, "Reading raw file data..."); //readData(file, histToRead); - //read spectrum - if (!readData(file, histToRead)) - { - throw std::runtime_error("Error reading raw file"); - } - int64_t binStart=0; - setWorkspaceData(localWorkspace, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes,1,binStart); - ++wsIndex; + //read spectrum + if (!readData(file, histToRead)) + { + throw std::runtime_error("Error reading raw file"); + } + int64_t binStart=0; + setWorkspaceData(localWorkspace, m_timeChannelsVec, wsIndex, i, m_noTimeRegimes,1,binStart); + ++wsIndex; if (m_numberOfPeriods == 1) { @@ -166,19 +166,19 @@ void LoadRawBin0::exec() } } - else - { - skipData(file, histToRead); - } + else + { + skipData(file, histToRead); + } } - - if(m_numberOfPeriods>1) - { - setWorkspaceProperty(localWorkspace, ws_grp, period, false); - // progress for workspace groups - m_prog = static_cast(period) / static_cast(m_numberOfPeriods - 1); - } + + if(m_numberOfPeriods>1) + { + setWorkspaceProperty(localWorkspace, ws_grp, period, false,this); + // progress for workspace groups + m_prog = static_cast(period) / static_cast(m_numberOfPeriods - 1); + } } // loop over periods // Clean up diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 95897381a5b9..f6d2f88132ab 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -237,11 +237,11 @@ namespace Mantid *@param numberOfPeriods :: total number of periods from raw file *@param lengthIn :: size of workspace vectors *@param title :: title of the workspace - + *@param pAlg :: pointer to the algorithm, this method works with. */ void LoadRawHelper::createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr,DataObjects::Workspace2D_sptr& normalws_sptr, WorkspaceGroup_sptr& mongrp_sptr,const int64_t mwsSpecs,const int64_t nwsSpecs, - const int64_t numberOfPeriods,const int64_t lengthIn,const std::string title) + const int64_t numberOfPeriods,const int64_t lengthIn,const std::string title,API::Algorithm *pAlg) { try { @@ -262,31 +262,31 @@ namespace Mantid } if(!monws_sptr) return ; - std::string wsName= getPropertyValue("OutputWorkspace"); + std::string wsName= pAlg->getPropertyValue("OutputWorkspace"); // if the normal output workspace size>0 then set the workspace as "MonitorWorkspace" // otherwise set the workspace as "OutputWorkspace" if (nwsSpecs> 0) { std::string monitorwsName = wsName + "_monitors"; - declareProperty(new WorkspaceProperty ("MonitorWorkspace", monitorwsName, + pAlg->declareProperty(new WorkspaceProperty ("MonitorWorkspace", monitorwsName, Direction::Output)); - setWorkspaceProperty("MonitorWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, true); + setWorkspaceProperty("MonitorWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, true,pAlg); } else { //if only monitors range selected //then set the monitor workspace as the outputworkspace - setWorkspaceProperty("OutputWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, false); + setWorkspaceProperty("OutputWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, false,pAlg); } } catch(std::out_of_range& ) { - g_log.debug()<<"Error in creating monitor workspace"<getLogger().debug()<<"Error in creating monitor workspace"<getLogger().debug()<<"Error in creating monitor workspace"<getProperty("OutputWorkspace"); std::stringstream suffix; suffix << (period + 1); if (bmonitors) @@ -328,8 +328,8 @@ namespace Mantid outputWorkspace = "OutputWorkspace"; } outws = outputWorkspace + "_" + suffix.str(); - declareProperty(new WorkspaceProperty (outws, wsName, Direction::Output)); - setProperty(outws, boost::static_pointer_cast(ws_sptr)); + pAlg->declareProperty(new WorkspaceProperty (outws, wsName, Direction::Output)); + pAlg->setProperty(outws, boost::static_pointer_cast(ws_sptr)); grpws_sptr->addWorkspace( ws_sptr ); } @@ -338,14 +338,14 @@ namespace Mantid * @param title :: title of the workspace * @param grpws_sptr :: shared pointer to group workspace * @param ws_sptr :: shared pointer to workspace - * @param numberOfPeriods :: numer periods in the raw file + * @param numberOfPeriods :: number periods in the raw file * @param bMonitor to identify the workspace is an output workspace or monitor workspace */ void LoadRawHelper::setWorkspaceProperty(const std::string& propertyName, const std::string& title, - WorkspaceGroup_sptr grpws_sptr, DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods, bool bMonitor) + WorkspaceGroup_sptr grpws_sptr, DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods, bool bMonitor,API::Algorithm *pAlg) { UNUSED_ARG(bMonitor); - Property *ws = getProperty("OutputWorkspace"); + Property *ws = pAlg->getProperty("OutputWorkspace"); if(!ws) return; if(!grpws_sptr) return; if(!ws_sptr)return; @@ -353,11 +353,11 @@ namespace Mantid ws_sptr->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); if (numberOfPeriods > 1) { - setProperty(propertyName, boost::dynamic_pointer_cast(grpws_sptr)); + pAlg->setProperty(propertyName, boost::dynamic_pointer_cast(grpws_sptr)); } else { - setProperty(propertyName, boost::dynamic_pointer_cast(ws_sptr)); + pAlg->setProperty(propertyName, boost::dynamic_pointer_cast(ws_sptr)); } } diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawSpectrum0.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawSpectrum0.cpp index 888e0d29496e..a79ee46b980e 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawSpectrum0.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawSpectrum0.cpp @@ -19,155 +19,155 @@ namespace Mantid { - namespace DataHandling - { - // Register the algorithm into the algorithm factory - DECLARE_ALGORITHM(LoadRawSpectrum0) - - - using namespace Kernel; - using namespace API; - - /// Constructor - LoadRawSpectrum0::LoadRawSpectrum0() : - m_filename(), m_numberOfSpectra(0), - m_specTimeRegimes(), m_prog(0.0) - { - } - - LoadRawSpectrum0::~LoadRawSpectrum0() - { - } - - /// Initialisation method. - void LoadRawSpectrum0::init() - { - LoadRawHelper::init(); - - } - - /** Executes the algorithm. Reading in the file and creating and populating - * the output workspace - * - * @throw Exception::FileError If the RAW file cannot be found/opened - * @throw std::invalid_argument If the optional properties are set to invalid values - */ - void LoadRawSpectrum0::exec() - { - // Retrieve the filename from the properties - m_filename = getPropertyValue("Filename"); - - bool bLoadlogFiles = getProperty("LoadLogFiles"); - - //open the raw file + namespace DataHandling + { + // Register the algorithm into the algorithm factory + DECLARE_ALGORITHM(LoadRawSpectrum0) + + + using namespace Kernel; + using namespace API; + + /// Constructor + LoadRawSpectrum0::LoadRawSpectrum0() : + m_filename(), m_numberOfSpectra(0), + m_specTimeRegimes(), m_prog(0.0) + { + } + + LoadRawSpectrum0::~LoadRawSpectrum0() + { + } + + /// Initialisation method. + void LoadRawSpectrum0::init() + { + LoadRawHelper::init(); + + } + + /** Executes the algorithm. Reading in the file and creating and populating + * the output workspace + * + * @throw Exception::FileError If the RAW file cannot be found/opened + * @throw std::invalid_argument If the optional properties are set to invalid values + */ + void LoadRawSpectrum0::exec() + { + // Retrieve the filename from the properties + m_filename = getPropertyValue("Filename"); + + bool bLoadlogFiles = getProperty("LoadLogFiles"); + + //open the raw file FILE* file=openRawFile(m_filename); - // Need to check that the file is not a text file as the ISISRAW routines don't deal with these very well, i.e - // reading continues until a bad_alloc is encountered. - if( isAscii(file) ) - { - g_log.error() << "File \"" << m_filename << "\" is not a valid RAW file.\n"; - throw std::invalid_argument("Incorrect file type encountered."); - } + // Need to check that the file is not a text file as the ISISRAW routines don't deal with these very well, i.e + // reading continues until a bad_alloc is encountered. + if( isAscii(file) ) + { + g_log.error() << "File \"" << m_filename << "\" is not a valid RAW file.\n"; + throw std::invalid_argument("Incorrect file type encountered."); + } - std::string title; - readTitle(file,title); + std::string title; + readTitle(file,title); readworkspaceParameters(m_numberOfSpectra,m_numberOfPeriods,m_lengthIn,m_noTimeRegimes); - // Calculate the size of a workspace, given its number of periods & spectra to read - const int64_t total_specs = 1; + // Calculate the size of a workspace, given its number of periods & spectra to read + const int64_t total_specs = 1; - // Get the time channel array(s) and store in a vector inside a shared pointer - std::vector > timeChannelsVec = - getTimeChannels(m_noTimeRegimes, m_lengthIn); + // Get the time channel array(s) and store in a vector inside a shared pointer + std::vector > timeChannelsVec = + getTimeChannels(m_noTimeRegimes, m_lengthIn); - double histTotal = static_cast(total_specs * m_numberOfPeriods); - int64_t histCurrent = -1; + double histTotal = static_cast(total_specs * m_numberOfPeriods); + int64_t histCurrent = -1; - // Create the 2D workspace for the output - DataObjects::Workspace2D_sptr localWorkspace =createWorkspace(total_specs, m_lengthIn,m_lengthIn-1,title); - - Run& run = localWorkspace->mutableRun(); + // Create the 2D workspace for the output + DataObjects::Workspace2D_sptr localWorkspace =createWorkspace(total_specs, m_lengthIn,m_lengthIn-1,title); + + Run& run = localWorkspace->mutableRun(); - if(bLoadlogFiles) - { - runLoadLog(m_filename,localWorkspace, 0.0, 0.0); + if(bLoadlogFiles) + { + runLoadLog(m_filename,localWorkspace, 0.0, 0.0); const int period_number = 1; createPeriodLogs(period_number, localWorkspace); - } - // Set the total proton charge for this run - setProtonCharge(run); - - WorkspaceGroup_sptr wsgrp_sptr = createGroupWorkspace(); - setWorkspaceProperty("OutputWorkspace", title, wsgrp_sptr, localWorkspace,m_numberOfPeriods, false); - - // Loop over the number of periods in the raw file, putting each period in a separate workspace - for (int period = 0; period < m_numberOfPeriods; ++period) - { - if (period > 0) - { - localWorkspace = boost::dynamic_pointer_cast( - WorkspaceFactory::Instance().create(localWorkspace)); - - if(bLoadlogFiles) - { - //remove previous period data - std::stringstream prevPeriod; - prevPeriod << "PERIOD " << (period); - Run& runObj = localWorkspace->mutableRun(); - runObj.removeLogData(prevPeriod.str()); + } + // Set the total proton charge for this run + setProtonCharge(run); + + WorkspaceGroup_sptr wsgrp_sptr = createGroupWorkspace(); + setWorkspaceProperty("OutputWorkspace", title, wsgrp_sptr, localWorkspace,m_numberOfPeriods, false,this); + + // Loop over the number of periods in the raw file, putting each period in a separate workspace + for (int period = 0; period < m_numberOfPeriods; ++period) + { + if (period > 0) + { + localWorkspace = boost::dynamic_pointer_cast( + WorkspaceFactory::Instance().create(localWorkspace)); + + if(bLoadlogFiles) + { + //remove previous period data + std::stringstream prevPeriod; + prevPeriod << "PERIOD " << (period); + Run& runObj = localWorkspace->mutableRun(); + runObj.removeLogData(prevPeriod.str()); runObj.removeLogData("current_period"); - //add current period data + //add current period data int period_number = static_cast(period+1); createPeriodLogs(period_number, localWorkspace); - } - //skip all spectra except the first one in each period - for(int i=1;i<=m_numberOfSpectra;++i) - { - skipData(file, i+ (period-1)*(m_numberOfSpectra+1) ); - } - } - - int64_t wsIndex = 0; - // for each period read first spectrum - int64_t histToRead = period*(m_numberOfSpectra+1); - - progress(m_prog, "Reading raw file data..."); - //isisRaw->readData(file, histToRead); - //readData(file, histToRead); - //read spectrum - if (!readData(file, histToRead)) - { - throw std::runtime_error("Error reading raw file"); - } - - //set the workspace data - setWorkspaceData(localWorkspace, timeChannelsVec, wsIndex, 0, m_noTimeRegimes,m_lengthIn,1); - - if (m_numberOfPeriods == 1) - { - if (++histCurrent % 100 == 0) - { - m_prog = double(histCurrent) / histTotal; - } - interruption_point(); - } - if(m_numberOfPeriods>1) - { - setWorkspaceProperty(localWorkspace, wsgrp_sptr, period, false); - // progress for workspace groups - m_prog = static_cast(period) / static_cast(m_numberOfPeriods - 1); - } - - } // loop over periods - - // Clean up - reset(); - fclose(file); - - } - - - } + } + //skip all spectra except the first one in each period + for(int i=1;i<=m_numberOfSpectra;++i) + { + skipData(file, i+ (period-1)*(m_numberOfSpectra+1) ); + } + } + + int64_t wsIndex = 0; + // for each period read first spectrum + int64_t histToRead = period*(m_numberOfSpectra+1); + + progress(m_prog, "Reading raw file data..."); + //isisRaw->readData(file, histToRead); + //readData(file, histToRead); + //read spectrum + if (!readData(file, histToRead)) + { + throw std::runtime_error("Error reading raw file"); + } + + //set the workspace data + setWorkspaceData(localWorkspace, timeChannelsVec, wsIndex, 0, m_noTimeRegimes,m_lengthIn,1); + + if (m_numberOfPeriods == 1) + { + if (++histCurrent % 100 == 0) + { + m_prog = double(histCurrent) / histTotal; + } + interruption_point(); + } + if(m_numberOfPeriods>1) + { + setWorkspaceProperty(localWorkspace, wsgrp_sptr, period, false,this); + // progress for workspace groups + m_prog = static_cast(period) / static_cast(m_numberOfPeriods - 1); + } + + } // loop over periods + + // Clean up + reset(); + fclose(file); + + } + + + } } diff --git a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h index 1b4b5e4fc369..5f17b3feaa9d 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h @@ -464,6 +464,7 @@ class LoadISISNexusTest : public CxxTest::TestSuite TS_ASSERT_THROWS_NOTHING(ld.execute()); TS_ASSERT(ld.isExecuted()); + MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS("outWS"); TS_ASSERT_EQUALS(ws->blocksize(),5); TS_ASSERT_EQUALS(ws->getNumberHistograms(),17790); From da40d52c8c56ccbef7f5973f98891316ad05737d Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Fri, 10 Oct 2014 15:33:36 +0100 Subject: [PATCH 13/22] refs #9989 Include&Exclude monitors seems work fine (with groups too) --- .../inc/MantidDataHandling/LoadISISNexus2.h | 37 +-- .../DataHandling/src/LoadISISNexus2.cpp | 281 +++++++++++------- 2 files changed, 189 insertions(+), 129 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index f7882de3d306..198d0dce7fc7 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -100,19 +100,25 @@ namespace Mantid /// The structure describes parameters of a single time-block written in the nexus file struct DataBlock { - /// The number of data periods + // The number of data periods int numberOfPeriods; - /// The number of time channels per spectrum (N histogram bins -1) + // The number of time channels per spectrum (N histogram bins -1) std::size_t numberOfChannels; - /// The number of spectra - std::size_t numberOfSpectra; + // The number of spectra + size_t numberOfSpectra; + // minimal spectra Id (by default 1, undefined -- max_value) + int64_t spectraID_min; + // maximal spectra Id (by default 1, undefined -- 0) + int64_t spectraID_max; - DataBlock():numberOfPeriods(0),numberOfChannels(0),numberOfSpectra(0){} + DataBlock():numberOfPeriods(0),numberOfChannels(0),numberOfSpectra(0),spectraID_min(std::numeric_limits::max()),spectraID_max(0){} DataBlock(const NeXus::NXInt &data): numberOfPeriods(data.dim0()), numberOfChannels(data.dim2()), - numberOfSpectra (data.dim1()) + numberOfSpectra (data.dim1()), + spectraID_min(1), + spectraID_max(numberOfSpectra) {}; }; private: @@ -145,7 +151,7 @@ namespace Mantid // Validate multi-period logs void validateMultiPeriodLogs(Mantid::API::MatrixWorkspace_sptr ); // build the list of spectra numbers to load and include in the spectra list - void buildSpectraInd2SpectraNumMap(const std::vector &spec_list,const std::set &ExcludedSpectra); + void buildSpectraInd2SpectraNumMap(bool range_supplied,int64_t range_min,int64_t range_max,const std::vector &spec_list,const std::set &ExcludedSpectra); /// The name and path of the input file @@ -155,22 +161,19 @@ namespace Mantid /// The sample name read from Nexus std::string m_samplename; - // the description of the data block, containing in the file. May include monitors and detectors with the same time binning - DataBlock m_detFileDataInfo; - // the description of single time-range data block, obtained from detectors + // the description of the data block in the file to load. + // the description of single time-range data block, obtained from detectors DataBlock m_detBlockInfo; // the description of single time-range data block, obtained from monitors DataBlock m_monBlockInfo; + // description of the block to be loaded may include monitors and detectors with the same time binning if the detectors and monitors are loaded together + // in single workspace or equal to the detectorBlock if monitors are excluded + // or monBlockInfo if only monitors are loaded. + DataBlock m_loadBlockInfo; + /// Is there a detector block bool m_have_detector; - - /// Have the spectrum_min/max properties been set? - bool m_range_supplied; - /// The value of the SpectrumMin property - int64_t m_spec_min; - /// The value of the SpectrumMax property - int64_t m_spec_max; /// if true, a spectra list or range of spectra is supplied bool m_load_selected_spectra; /// map of spectra Index to spectra Number (spectraID) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index a529e3ebaf08..6b45d8219b40 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -50,8 +50,8 @@ namespace Mantid /// Empty default constructor LoadISISNexus2::LoadISISNexus2() : m_filename(), m_instrument_name(), m_samplename(), - m_detFileDataInfo(),m_detBlockInfo(),m_monBlockInfo(), - m_have_detector(false),m_range_supplied(true), m_spec_min(0), m_spec_max(EMPTY_INT()), + m_detBlockInfo(),m_monBlockInfo(),m_loadBlockInfo(), + m_have_detector(false), m_load_selected_spectra(false),m_specInd2specNum_map(),m_spec2det_map(), m_entrynumber(0), m_tof_data(), m_proton_charge(0.), m_spec(), m_monitors(), m_logCreator(), m_progress() @@ -161,7 +161,7 @@ namespace Mantid spec.load(); size_t nmons(0); - + //Pull out the monitor blocks, if any exist for(std::vector::const_iterator it = entry.groups().begin(); @@ -202,10 +202,10 @@ namespace Mantid // Fill up m_spectraBlocks size_t total_specs = prepareSpectraBlocks(); - m_progress = boost::shared_ptr(new Progress(this, 0.0, 1.0, total_specs * m_detFileDataInfo.numberOfPeriods)); + m_progress = boost::shared_ptr(new Progress(this, 0.0, 1.0, total_specs * m_detBlockInfo.numberOfPeriods)); DataObjects::Workspace2D_sptr local_workspace = boost::dynamic_pointer_cast - (WorkspaceFactory::Instance().create("Workspace2D", total_specs, x_length, m_detFileDataInfo.numberOfChannels)); + (WorkspaceFactory::Instance().create("Workspace2D", total_specs, x_length, m_detBlockInfo.numberOfChannels)); // Set the units on the workspace to TOF & Counts local_workspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); local_workspace->setYUnit("Counts"); @@ -259,7 +259,7 @@ namespace Mantid createPeriodLogs(firstentry, local_workspace); - if( m_detFileDataInfo.numberOfPeriods > 1 && m_entrynumber == 0 ) + if( m_detBlockInfo.numberOfPeriods > 1 && m_entrynumber == 0 ) { WorkspaceGroup_sptr wksp_group(new WorkspaceGroup); @@ -269,7 +269,7 @@ namespace Mantid const std::string base_name = getPropertyValue("OutputWorkspace") + "_"; const std::string prop_name = "OutputWorkspace_"; - for( int p = 1; p <= m_detFileDataInfo.numberOfPeriods; ++p ) + for( int p = 1; p <= m_detBlockInfo.numberOfPeriods; ++p ) { std::ostringstream os; os << p; @@ -301,7 +301,8 @@ namespace Mantid // Workspace or group of workspaces without monitors is loaded. Now we are loading monitors separately. if(bseparateMonitors) { - + // debug!!! + setProperty("OutputWorkspace", boost::dynamic_pointer_cast(local_workspace)); } // Clear off the member variable containers @@ -359,52 +360,66 @@ namespace Mantid { // optional properties specify that only some spectra have to be loaded size_t numSpectraExclued=0; + bool range_supplied(false); + if (!SpectraExcluded.empty()) { + range_supplied = true; m_load_selected_spectra = true; - numSpectraExclued = SpectraExcluded.size(); } - + + int64_t spec_min(0); + int64_t spec_max(EMPTY_INT()); // - m_spec_min = getProperty("SpectrumMin"); - m_spec_max = getProperty("SpectrumMax"); + spec_min = getProperty("SpectrumMin"); + spec_max = getProperty("SpectrumMax"); - if( m_spec_min == 0 && m_spec_max == EMPTY_INT() ) + + // default spectra ID-s would not work if spectraID_min!=1 + if(m_loadBlockInfo.spectraID_min!=1) { - m_range_supplied = false; + range_supplied = true; + m_load_selected_spectra = true; } - if( m_spec_min == 0 ) - m_spec_min = 1; + + if( spec_min == 0 ) + spec_min = m_loadBlockInfo.spectraID_min; else + { + range_supplied = true; m_load_selected_spectra = true; + } - if( m_spec_max == EMPTY_INT() ) - m_spec_max = m_detBlockInfo.numberOfSpectra; + if( spec_max == EMPTY_INT() ) + spec_max = m_loadBlockInfo.spectraID_max; else + { + range_supplied = true; m_load_selected_spectra = true; + } // Sanity check for min/max - if( m_spec_min > m_spec_max ) + if( spec_min > spec_max ) { throw std::invalid_argument("Inconsistent range properties. SpectrumMin is larger than SpectrumMax."); } - if( static_cast(m_spec_max) > m_detBlockInfo.numberOfSpectra+numSpectraExclued ) + if( spec_max > m_loadBlockInfo.spectraID_max) { - std::string err="Inconsistent range property. SpectrumMax is larger than number of spectra: "+boost::lexical_cast(m_detFileDataInfo.numberOfSpectra+numSpectraExclued ); - throw std::invalid_argument(err); - } + std::string err="Inconsistent range property. SpectrumMax is larger than number of spectra: "+boost::lexical_cast(m_loadBlockInfo.spectraID_max ); + throw std::invalid_argument(err); + } // Check the entry number m_entrynumber = getProperty("EntryNumber"); - if( static_cast(m_entrynumber) > m_detBlockInfo.numberOfPeriods || m_entrynumber < 0 ) + if( static_cast(m_entrynumber) > m_loadBlockInfo.numberOfPeriods || m_entrynumber < 0 ) { - std::string err="Invalid entry number entered. File contains "+boost::lexical_cast(m_detBlockInfo.numberOfPeriods)+ " period. "; + std::string err="Invalid entry number entered. File contains "+boost::lexical_cast(m_loadBlockInfo.numberOfPeriods)+ " period. "; throw std::invalid_argument(err); } - if(m_detBlockInfo.numberOfPeriods== 1 ) + if(m_loadBlockInfo.numberOfPeriods== 1 ) { m_entrynumber = 1; } @@ -418,47 +433,49 @@ namespace Mantid // Sort the list so that we can check it's range std::sort(spec_list.begin(), spec_list.end()); - if( spec_list.back() > static_cast(m_detBlockInfo.numberOfSpectra+numSpectraExclued) ) + if( spec_list.back() > m_loadBlockInfo.spectraID_max ) { - std::string err="A spectra number in the spectra list exceeds total number of "+boost::lexical_cast(m_detBlockInfo.numberOfSpectra+numSpectraExclued )+ " spectra "; + std::string err="A spectra number in the spectra list exceeds maximal spectra ID: "+boost::lexical_cast(m_loadBlockInfo.spectraID_max )+ " in the file "; throw std::invalid_argument(err); } - - //Check no negative numbers have been passed - std::vector::iterator itr = - std::find_if(spec_list.begin(), spec_list.end(), std::bind2nd(std::less(), 0)); - if( itr != spec_list.end() ) + if( spec_list.front() < m_loadBlockInfo.spectraID_min ) { - throw std::invalid_argument("Negative SpectraList property encountered."); + std::string err="A spectra number in the spectra list smaller then minimal spectra ID: "+boost::lexical_cast(m_loadBlockInfo.spectraID_min )+ " in the file"; + throw std::invalid_argument(err); } - range_check in_range(m_spec_min, m_spec_max); - if( m_range_supplied ) + + range_check in_range(spec_min, spec_max); + if(range_supplied ) { spec_list.erase(remove_if(spec_list.begin(), spec_list.end(), in_range), spec_list.end()); // combine spectra numbers from ranges and the list if (spec_list.size()>0) { - for(int64_t i=m_spec_min;i(i); + // remove excluded spectra now rather then inserting it here and removing later if (SpectraExcluded.find(spec_num)==SpectraExcluded.end() ) - spec_list.push_back(spec_num); + spec_list.push_back(spec_num); } // Sort the list so that lower spectra indexes correspond to smaller spectra ID-s std::sort(spec_list.begin(), spec_list.end()); - + // supplied range converted into the list, so no more supplied range + range_supplied =false; } } - } - else - { - m_range_supplied = true; + } // if (m_load_selected_spectra) { - buildSpectraInd2SpectraNumMap(spec_list,SpectraExcluded); + buildSpectraInd2SpectraNumMap(range_supplied,spec_min,spec_max,spec_list,SpectraExcluded); + } + else // may be just range supplied and the range have to start from 1 to use defaults in spectra num to spectra ID map! + { + m_loadBlockInfo.spectraID_max=spec_max; + m_loadBlockInfo.numberOfSpectra = m_loadBlockInfo.spectraID_max-m_loadBlockInfo.spectraID_min+1; } } @@ -467,32 +484,38 @@ namespace Mantid @param spec_list -- list of spectra numbers to load @param SpectraExcluded set of the spectra ID-s to exclude from loading **/ - void LoadISISNexus2::buildSpectraInd2SpectraNumMap(const std::vector &spec_list,const std::set &SpectraExcluded) + void LoadISISNexus2::buildSpectraInd2SpectraNumMap(bool range_supplied,int64_t range_min,int64_t range_max, + const std::vector &spec_list,const std::set &SpectraExcluded) { int64_t ic(0); if(spec_list.size()>0) { + ic = 0; auto start_point = spec_list.begin(); for(auto it =start_point ;it!=spec_list.end();it++) { - ic = it-start_point; - m_specInd2specNum_map.insert(std::pair(ic,static_cast(*it))); + + specid_t spec_num = static_cast(*it); + if (SpectraExcluded.find(spec_num)==SpectraExcluded.end() ) + { + m_specInd2specNum_map.insert(std::pair(ic,spec_num)); + ic++; + } } } else { - if(m_range_supplied) + if(range_supplied) { ic = 0; - int64_t max_range = m_spec_max+SpectraExcluded.size()+1; - for(int64_t i=m_spec_min;i(i); - if(SpectraExcluded.find(spectra)==SpectraExcluded.end()) + specid_t spec_num = static_cast(i); + if (SpectraExcluded.find(spec_num)==SpectraExcluded.end() ) { - m_specInd2specNum_map.insert(std::pair(ic,spectra)); + m_specInd2specNum_map.insert(std::pair(ic,spec_num)); ic++; } } @@ -558,10 +581,11 @@ namespace Mantid return m_specInd2specNum_map.size(); } - + // here we are only if ranges are not supplied + // // put in the spectra range, possibly breaking it into parts by monitors - int64_t first = m_spec_min; - for(int64_t hist = first; hist < m_spec_max; ++hist) + int64_t first = m_loadBlockInfo.spectraID_min; + for(int64_t hist = first; hist < m_loadBlockInfo.spectraID_max; ++hist) { if ( m_monitors.find( hist ) != m_monitors.end() ) { @@ -574,14 +598,15 @@ namespace Mantid first = hist + 1; } } - if ( first == m_spec_max && m_monitors.find( first ) != m_monitors.end() ) + int64_t spec_max = m_loadBlockInfo.spectraID_max; + if ( first == spec_max && m_monitors.find( first ) != m_monitors.end() ) { - m_spectraBlocks.push_back( SpectraBlock( first, m_spec_max, true ) ); - includedMonitors.push_back( m_spec_max ); + m_spectraBlocks.push_back( SpectraBlock( first, spec_max, true ) ); + includedMonitors.push_back( spec_max ); } else { - m_spectraBlocks.push_back( SpectraBlock( first, m_spec_max, false ) ); + m_spectraBlocks.push_back( SpectraBlock( first, spec_max, false ) ); } // sort and check for overlapping @@ -737,7 +762,7 @@ namespace Mantid { data.load(static_cast(blocksize), static_cast(period), static_cast(start)); // TODO this is just wrong int *data_start = data(); - int *data_end = data_start + m_detBlockInfo.numberOfChannels; + int *data_end = data_start + m_loadBlockInfo.numberOfChannels; int64_t final(hist + blocksize); while( hist < final ) { @@ -869,9 +894,9 @@ namespace Mantid runDetails.addProperty("run_header", std::string(header, header + 86)); // Data details on run not the workspace - runDetails.addProperty("nspectra", static_cast(m_detFileDataInfo.numberOfSpectra)); - runDetails.addProperty("nchannels", static_cast(m_detFileDataInfo.numberOfChannels)); - runDetails.addProperty("nperiods", static_cast(m_detFileDataInfo.numberOfPeriods)); + runDetails.addProperty("nspectra", static_cast(m_loadBlockInfo.numberOfSpectra)); + runDetails.addProperty("nchannels", static_cast(m_loadBlockInfo.numberOfChannels)); + runDetails.addProperty("nperiods", static_cast(m_loadBlockInfo.numberOfPeriods)); // RPB struct info NXInt rpb_int = vms_compat.openNXInt("IRPB"); @@ -1011,27 +1036,27 @@ namespace Mantid { return sqrt(in); } - /**Method takes input parameters which describe monitor loading and analyze them against spectra/monitor information in the file. - * The result is the option if monitors can be loaded together with spectra or mast be treated separately - * and additional information on how to treat monitor spectra. - * - *@param entry :: entry to the NeXus file, opened at root folder - *@param spectrum_index :: array of spectra indexes of the data present in the file - *@param ndets :: size of the spectrum index array - *@param n_vms_compat_spectra :: number of data entries containing common time bins (e.g. all spectra, or all spectra and monitors or some spectra (this is not fully supported) - *@param monitors :: map connecting monitor spectra ID against monitor group name in the file. - *@param excludeMonitors :: input property indicating if it is requested to exclude monitors from the target workspace - *@param separateMonitors :: input property indicating if it is requested to load monitors separately (and exclude them from target data workspace this way) - * - *@param MonitorSpectra :: output property containing the list of monitors which should be loaded separately. - *@return excludeMonitors :: indicator if monitors should or mast be excluded from the main data workspace if they can not be loaded with the data - * (contain different number of time channels) - * + /**Method takes input parameters which describe monitor loading and analyze them against spectra/monitor block information in the file. + * The result is the option if monitors can be loaded together with spectra or mast be treated separately + * and additional information on how to treat monitor spectra. + * + *@param entry :: entry to the NeXus file, opened at root folder + *@param spectrum_index :: array of spectra indexes of the data present in the file + *@param ndets :: size of the spectrum index array + *@param n_vms_compat_spectra :: number of data entries containing common time bins (e.g. all spectra, or all spectra and monitors or some spectra (this is not fully supported) + *@param monitors :: map connecting monitor spectra ID against monitor group name in the file. + *@param excludeMonitors :: input property indicating if it is requested to exclude monitors from the target workspace + *@param separateMonitors :: input property indicating if it is requested to load monitors separately (and exclude them from target data workspace this way) + * + *@param OvelapMonitorSpectra :: output property containing the list of monitors ID for monitors, which are also included with spectra. + *@return excludeMonitors :: indicator if monitors should or mast be excluded from the main data workspace if they can not be loaded with the data + * (contain different number of time channels) + * */ bool LoadISISNexus2::findSpectraDetRangeInFile(NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, - std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &MonitorSpectra) + std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &OvelapMonitorSpectra) { - MonitorSpectra.clear(); + OvelapMonitorSpectra.clear(); size_t nmons = monitors.size(); //Grab the number of channels @@ -1043,14 +1068,26 @@ namespace Mantid m_monBlockInfo = DataBlock(chans); m_monBlockInfo.numberOfSpectra = nmons; // each monitor is in separate group so number of spectra is equal to number of groups. - // at this stage let's set up all other detector information to monitors - m_detFileDataInfo = m_monBlockInfo; - m_detBlockInfo = m_monBlockInfo; + + // identify monitor ID range. + for(auto it = monitors.begin(); it!=monitors.end(); it++) + { + int64_t mon_id = static_cast(it->first); + if(m_monBlockInfo.spectraID_min>mon_id )m_monBlockInfo.spectraID_min=mon_id; + if(m_monBlockInfo.spectraID_max(nmons)) + { + g_log.warning()<<" non-consequent monitor ID-s in the monitor block. Unexpected situation for the loader\n"; + } + // at this stage we assume that the only going to load monitors + m_loadBlockInfo = m_monBlockInfo; + } if( ndets == 0 ) { - separateMonitors = false; // load monitors in the main workspace. No detectors + separateMonitors = false; // only monitors in the main workspace. No detectors. Will be loaded in the main workspace return separateMonitors; } @@ -1059,59 +1096,79 @@ namespace Mantid NXInt data = nxData.openIntData(); m_detBlockInfo = DataBlock(data); - m_detFileDataInfo = m_detBlockInfo; + // We assume again that this spectrum list ID increase monotonically + m_detBlockInfo.spectraID_min = spectrum_index[0]; + m_detBlockInfo.spectraID_max = spectrum_index[ndets-1]; + if(m_detBlockInfo.spectraID_max-m_detBlockInfo.spectraID_min+1!=static_cast(m_detBlockInfo.numberOfSpectra)) + { + g_log.warning()<<" non-consequent spectra ID-s in the detectors block. Unexpected situation for the loader\n"; + } + + + m_loadBlockInfo = m_detBlockInfo; + + + // now we are analyzing what is actually going or can be loaded + + bool removeMonitors = excludeMonitors || separateMonitors; if (((m_detBlockInfo.numberOfPeriods!=m_monBlockInfo.numberOfPeriods) || (m_detBlockInfo.numberOfChannels!=m_monBlockInfo.numberOfChannels)) && nmons>0) { // detectors and monitors have different characteristics. Can be loaded only to separate workspaces. - if(!separateMonitors) + if(!removeMonitors) { g_log.warning()<<" Performing separate loading as can not load spectra and monitors in the single workspace:\n" ; g_log.warning()<<" Monitors data contain :"<( n_vms_compat_spectra )) - return separateMonitors; + m_loadBlockInfo.numberOfSpectra =totNumOfSpectra; + m_loadBlockInfo.spectraID_min = spectraID_min; + m_loadBlockInfo.spectraID_max = spectraID_max; + } + if (separateMonitors) + m_loadBlockInfo = m_detBlockInfo; + + + // verify integrity of the monitor and detector information + + if((totNumOfSpectra ==static_cast( n_vms_compat_spectra )) && (spectraID_max-spectraID_min+1 ==static_cast(n_vms_compat_spectra))) + { + // all information written in the file is correct, there are no spurious spectra and detectors & monitors form continuous block on HDD + return separateMonitors; } - //Now check if monitors expand or shrink the workspace's spectra range - // We assume again that this spectrum list increases monotonically - int64_t min_index = spectrum_index[0]; - int64_t max_index = spectrum_index[ndets-1]; + // something is wrong and we need to analyze spectra map. Currently we can identify and manage the case when all monitor's spectra are written together with detectors + //make settings for this situation + m_detBlockInfo.numberOfSpectra -= m_monBlockInfo.numberOfSpectra; + m_loadBlockInfo.numberOfSpectra-= m_monBlockInfo.numberOfSpectra; std::map remaining_monitors; - for(auto it = monitors.begin(); it!=monitors.end(); it++) + if(removeMonitors) { - if(it->first>=min_index && it->first <=max_index) + for(auto it = monitors.begin(); it!=monitors.end(); it++) { - if(removeMonitors) - { - MonitorSpectra.insert(static_cast(it->first)); - m_detBlockInfo.numberOfSpectra--; + if(it->first>=m_detBlockInfo.spectraID_min && it->first <=m_detBlockInfo.spectraID_max) + { //monitors ID-s are included with spectra ID-s -- let's try not to load it twice. + OvelapMonitorSpectra.insert(static_cast(it->first)); } - - } - else - { - if(!removeMonitors) + else { remaining_monitors.insert(*it); - m_detBlockInfo.numberOfSpectra++; - } } } monitors.swap(remaining_monitors); + + return separateMonitors; } From 10c743471f93ded9d13285196ba8fb393e5022db Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Fri, 10 Oct 2014 15:53:17 +0100 Subject: [PATCH 14/22] refs #9989 Doxygen errors and compiler warnings --- .../inc/MantidDataHandling/LoadRawHelper.h | 6 +++--- .../Framework/DataHandling/src/LoadISISNexus2.cpp | 8 +++++--- .../Framework/DataHandling/src/LoadRawHelper.cpp | 10 ++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h index 0db15d00eca9..e4d7e0c37833 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h @@ -86,7 +86,7 @@ namespace Mantid ///creates monitor workspace static void createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr, DataObjects::Workspace2D_sptr& ws_sptr,API::WorkspaceGroup_sptr& mongrp_sptr, - const int64_t mwsSpecs,const int64_t nwsSpecs,const int64_t numberOfPeriods,const int64_t lenthIn,std::string title,API::Algorithm *pAlg); + const int64_t mwsSpecs,const int64_t nwsSpecs,const int64_t numberOfPeriods,const int64_t lenthIn,std::string title,API::Algorithm *const pAlg); /// creates shared pointer to group workspace static API::WorkspaceGroup_sptr createGroupWorkspace(); @@ -99,10 +99,10 @@ namespace Mantid /// sets the workspace property static void setWorkspaceProperty(const std::string & propertyName,const std::string& title, - API::WorkspaceGroup_sptr grpws_sptr,DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods,bool bMonitor,API::Algorithm *pAlg); + API::WorkspaceGroup_sptr grpws_sptr,DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods,bool bMonitor,API::Algorithm * const pAlg); /// overloaded method to set the workspace property - static void setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr,API::WorkspaceGroup_sptr grpws_sptr,const int64_t period,bool bmonitors,API::Algorithm *pAlg); + static void setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr,API::WorkspaceGroup_sptr grpws_sptr,const int64_t period,bool bmonitors,API::Algorithm *const pAlg); protected: diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 6b45d8219b40..741b1a38b85f 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -359,7 +359,6 @@ namespace Mantid void LoadISISNexus2::checkOptionalProperties(const std::set &SpectraExcluded) { // optional properties specify that only some spectra have to be loaded - size_t numSpectraExclued=0; bool range_supplied(false); if (!SpectraExcluded.empty()) @@ -481,8 +480,11 @@ namespace Mantid } /** build the list of spectra to load and include into spectra-detectors map - @param spec_list -- list of spectra numbers to load - @param SpectraExcluded set of the spectra ID-s to exclude from loading + @param range_supplied -- if true specifies that the range of values provided below have to be processed rather then spectra list + @param range_min -- min value for spectra-ID to load + @param range_max -- max value for spectra-ID to load + @param spec_list -- list of spectra numbers to load + @param SpectraExcluded -- set of the spectra ID-s to exclude from loading **/ void LoadISISNexus2::buildSpectraInd2SpectraNumMap(bool range_supplied,int64_t range_min,int64_t range_max, const std::vector &spec_list,const std::set &SpectraExcluded) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index f6d2f88132ab..45bd59f35d76 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -275,7 +275,7 @@ namespace Mantid else { //if only monitors range selected - //then set the monitor workspace as the outputworkspace + //then set the monitor workspace as the output workspace setWorkspaceProperty("OutputWorkspace", title, mongrp_sptr, monws_sptr,numberOfPeriods, false,pAlg); } @@ -305,9 +305,10 @@ namespace Mantid * @param grpws_sptr :: shared pointer to group workspace * @param period period number * @param bmonitors :: boolean flag to name the workspaces + * @param pAlg :: pointer to algorithm this method works with. */ void LoadRawHelper::setWorkspaceProperty(DataObjects::Workspace2D_sptr ws_sptr, WorkspaceGroup_sptr grpws_sptr, - const int64_t period, bool bmonitors,API::Algorithm *pAlg) + const int64_t period, bool bmonitors, API::Algorithm *const pAlg) { if(!ws_sptr) return; if(!grpws_sptr) return; @@ -340,9 +341,10 @@ namespace Mantid * @param ws_sptr :: shared pointer to workspace * @param numberOfPeriods :: number periods in the raw file * @param bMonitor to identify the workspace is an output workspace or monitor workspace + * @param pAlg :: pointer to algorithm this method works with. */ void LoadRawHelper::setWorkspaceProperty(const std::string& propertyName, const std::string& title, - WorkspaceGroup_sptr grpws_sptr, DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods, bool bMonitor,API::Algorithm *pAlg) + WorkspaceGroup_sptr grpws_sptr, DataObjects::Workspace2D_sptr ws_sptr,int64_t numberOfPeriods, bool bMonitor, API::Algorithm *const pAlg) { UNUSED_ARG(bMonitor); Property *ws = pAlg->getProperty("OutputWorkspace"); @@ -364,7 +366,7 @@ namespace Mantid /** This method sets the raw file data to workspace vectors * @param newWorkspace :: shared pointer to the workspace * @param timeChannelsVec :: vector holding the X data - * @param wsIndex variable used for indexing the ouputworkspace + * @param wsIndex variable used for indexing the output workspace * @param nspecNum spectrum number * @param noTimeRegimes :: regime no. * @param lengthIn :: length of the workspace From b87d6c18e408a5dd172e33f941ad30118a9f67bc Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Fri, 10 Oct 2014 15:58:49 +0100 Subject: [PATCH 15/22] refs #9989 C++ check and doxygen warnings --- .../DataHandling/inc/MantidDataHandling/LoadRawHelper.h | 4 ++-- Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp | 3 --- Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h index e4d7e0c37833..96fd62201711 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadRawHelper.h @@ -82,7 +82,7 @@ namespace Mantid static bool isIncludeMonitors(const std::string &monitorOption); - static void ProcessLoadMonitorOptions(bool &bincludeMonitors,bool &bseparateMonitors,bool &bexcludeMonitors,API::Algorithm *pAlgo); + static void ProcessLoadMonitorOptions(bool &bincludeMonitors,bool &bseparateMonitors,bool &bexcludeMonitors,API::Algorithm *const pAlgo); ///creates monitor workspace static void createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr, DataObjects::Workspace2D_sptr& ws_sptr,API::WorkspaceGroup_sptr& mongrp_sptr, @@ -174,7 +174,7 @@ namespace Mantid /// calculate workspace sizes if separate or exclude monitors are selected void calculateWorkspacesizes(const std::vector& monitorSpecList, specid_t& normalwsSpecs, specid_t& monitorwsSpecs); - /// load the specra + /// load the spectra void loadSpectra(FILE* file,const int& period, const int& m_total_specs, DataObjects::Workspace2D_sptr ws_sptr,std::vector >); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 741b1a38b85f..bca6fb88f82f 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -1061,9 +1061,6 @@ namespace Mantid OvelapMonitorSpectra.clear(); size_t nmons = monitors.size(); - //Grab the number of channels - int nMonitorPeriods(0); - size_t nMonitorChannels(0); if (nmons>0) { NXInt chans = entry.openNXInt(m_monitors.begin()->second + "/data"); diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 45bd59f35d76..0e0a4290d86e 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -241,7 +241,7 @@ namespace Mantid */ void LoadRawHelper::createMonitorWorkspace(DataObjects::Workspace2D_sptr& monws_sptr,DataObjects::Workspace2D_sptr& normalws_sptr, WorkspaceGroup_sptr& mongrp_sptr,const int64_t mwsSpecs,const int64_t nwsSpecs, - const int64_t numberOfPeriods,const int64_t lengthIn,const std::string title,API::Algorithm *pAlg) + const int64_t numberOfPeriods,const int64_t lengthIn,const std::string title,API::Algorithm *const pAlg) { try { From 3f35bb777a57a6db4ecd8d4aa2249335b4cc5d15 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Fri, 10 Oct 2014 20:02:53 +0100 Subject: [PATCH 16/22] refs #9989 Kind of works --- .../inc/MantidDataHandling/LoadISISNexus2.h | 17 ++- .../DataHandling/src/LoadISISNexus2.cpp | 134 ++++++++++++------ .../DataHandling/src/LoadRawHelper.cpp | 2 +- .../DataHandling/test/LoadISISNexusTest.h | 69 +++++++++ 4 files changed, 172 insertions(+), 50 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index 198d0dce7fc7..fe9acf88471f 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -91,10 +91,13 @@ namespace Mantid struct SpectraBlock { /// Constructor - initialize the block - SpectraBlock(int64_t f,int64_t l,bool m):first(f),last(l),isMonitor(m){} + SpectraBlock(int64_t f,int64_t l,bool is_mon,const std::string &monname): + first(f),last(l),isMonitor(is_mon),monName(monname){} + int64_t first; ///< first spectrum number of the block int64_t last; ///< last spectrum number of the block bool isMonitor; ///< is the data in a monitor group + std::string monName; }; /// The structure describes parameters of a single time-block written in the nexus file @@ -117,8 +120,8 @@ namespace Mantid numberOfPeriods(data.dim0()), numberOfChannels(data.dim2()), numberOfSpectra (data.dim1()), - spectraID_min(1), - spectraID_max(numberOfSpectra) + spectraID_min(std::numeric_limits::max()), + spectraID_max(0) {}; }; private: @@ -127,9 +130,9 @@ namespace Mantid /// Overwrites Algorithm method void exec(); // Validate the optional input properties - void checkOptionalProperties(const std::set &ExcludedSpectra); + void checkOptionalProperties(const std::map &ExcludedMonitors); /// Prepare a vector of SpectraBlock structures to simplify loading - size_t prepareSpectraBlocks(); + size_t prepareSpectraBlocks(std::map &monitors, const std::map &specInd2specNum_map,const DataBlock &LoadBlock); /// Run LoadInstrument as a ChildAlgorithm void runLoadInstrument(DataObjects::Workspace2D_sptr &); /// Load in details about the run @@ -151,7 +154,7 @@ namespace Mantid // Validate multi-period logs void validateMultiPeriodLogs(Mantid::API::MatrixWorkspace_sptr ); // build the list of spectra numbers to load and include in the spectra list - void buildSpectraInd2SpectraNumMap(bool range_supplied,int64_t range_min,int64_t range_max,const std::vector &spec_list,const std::set &ExcludedSpectra); + void buildSpectraInd2SpectraNumMap(bool range_supplied,int64_t range_min,int64_t range_max,const std::vector &spec_list,const std::map &ExcludedMonitors); /// The name and path of the input file @@ -211,7 +214,7 @@ namespace Mantid boost::scoped_ptr< ::NeXus::File> m_cppFile; bool findSpectraDetRangeInFile(NeXus::NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, - std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &ExcludedSpectra); + std::map &monitors,bool excludeMonitors,bool separateMonitors,std::map &ExcludedMonitors); }; } // namespace DataHandling diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index bca6fb88f82f..7dee72182d39 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -192,15 +192,15 @@ namespace Mantid throw std::runtime_error("Inconsistent NeXus file structure."); } } - std::set ExcluedMonitorsSpectra; + std::map ExcluedMonitorsSpectra; bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,ExcluedMonitorsSpectra); - const size_t x_length = m_detBlockInfo.numberOfChannels + 1; + size_t x_length = m_detBlockInfo.numberOfChannels + 1; // Check input is consistent with the file, throwing if not, exclude spectra selected at findSpectraDetRangeInFile; checkOptionalProperties(ExcluedMonitorsSpectra); // Fill up m_spectraBlocks - size_t total_specs = prepareSpectraBlocks(); + size_t total_specs = prepareSpectraBlocks(m_monitors,m_specInd2specNum_map,m_loadBlockInfo); m_progress = boost::shared_ptr(new Progress(this, 0.0, 1.0, total_specs * m_detBlockInfo.numberOfPeriods)); @@ -301,8 +301,48 @@ namespace Mantid // Workspace or group of workspaces without monitors is loaded. Now we are loading monitors separately. if(bseparateMonitors) { - // debug!!! setProperty("OutputWorkspace", boost::dynamic_pointer_cast(local_workspace)); + if(m_detBlockInfo.numberOfPeriods>1) + { + g_log.error()<<" Separate monitor workspace loading have not been implemented for multiperiod workspaces. Performed separate monitors loading\n"; + } + else + { + std::string wsName = getProperty("OutputWorkspace"); + if(m_monBlockInfo.numberOfSpectra==0) + { + g_log.information()<<" no monitors to load for workspace: "< + (WorkspaceFactory::Instance().create(local_workspace, m_monBlockInfo.numberOfSpectra,x_length,m_monBlockInfo.numberOfChannels)); + + m_spectraBlocks.clear(); + m_specInd2specNum_map.clear(); + std::vector dummyS1; + std::map dummySpectr; + buildSpectraInd2SpectraNumMap(true,m_monBlockInfo.spectraID_min,m_monBlockInfo.spectraID_max,dummyS1,dummySpectr); + // lo + prepareSpectraBlocks(m_monitors,m_specInd2specNum_map,m_monBlockInfo); + + NXFloat timeBins = entry.openNXFloat("monitor_1/time_of_flight"); + timeBins.load(); + m_tof_data.reset(new MantidVec(timeBins(), timeBins() + x_length)); + + + + int64_t firstentry = (m_entrynumber > 0) ? m_entrynumber : 1; + loadPeriodData(firstentry, entry, monitor_workspace); + + + std::string monitorwsName = wsName + "_monitors"; + declareProperty(new WorkspaceProperty ("MonitorWorkspace", monitorwsName,Direction::Output)); + setProperty("MonitorWorkspace", boost::static_pointer_cast(monitor_workspace)); + } + } + } // Clear off the member variable containers @@ -356,7 +396,7 @@ namespace Mantid * Check the validity of the optional properties of the algorithm and identify if partial data should be loaded. * @param SpectraExcluded :: set of spectra ID-s to exclude from spectra list to load */ - void LoadISISNexus2::checkOptionalProperties(const std::set &SpectraExcluded) + void LoadISISNexus2::checkOptionalProperties(const std::map &SpectraExcluded) { // optional properties specify that only some spectra have to be loaded bool range_supplied(false); @@ -487,7 +527,7 @@ namespace Mantid @param SpectraExcluded -- set of the spectra ID-s to exclude from loading **/ void LoadISISNexus2::buildSpectraInd2SpectraNumMap(bool range_supplied,int64_t range_min,int64_t range_max, - const std::vector &spec_list,const std::set &SpectraExcluded) + const std::vector &spec_list,const std::map &SpectraExcluded) { int64_t ic(0); @@ -547,68 +587,84 @@ namespace Mantid * in a separate block. * @return :: Number of spectra to load. */ - size_t LoadISISNexus2::prepareSpectraBlocks() + size_t LoadISISNexus2::prepareSpectraBlocks(std::map &monitors, const std::map &specInd2specNum_map,const DataBlock &LoadBlock) { std::vector includedMonitors; // fill in the data block descriptor vector - if ( ! m_specInd2specNum_map.empty() ) + if ( ! specInd2specNum_map.empty() ) { - auto itSpec= m_specInd2specNum_map.begin(); + auto itSpec= specInd2specNum_map.begin(); int64_t hist = itSpec->second; - SpectraBlock block(hist,hist,false); + SpectraBlock block(hist,hist,false,""); itSpec++; - for(; itSpec != m_specInd2specNum_map.end(); ++itSpec) + for(; itSpec != specInd2specNum_map.end(); ++itSpec) { // try to put all consecutive numbers in same block - bool isMonitor = m_monitors.find( hist ) != m_monitors.end(); + + auto it_mon = monitors.find( hist ); + bool isMonitor = it_mon != monitors.end(); if ( isMonitor || itSpec->second!= hist + 1 ) { + + if ( isMonitor ) + { + includedMonitors.push_back( hist ); + block.monName = it_mon->second; + } + block.last = hist; block.isMonitor = isMonitor; m_spectraBlocks.push_back( block ); - if ( isMonitor ) includedMonitors.push_back( hist ); - block = SpectraBlock(itSpec ->second,itSpec ->second,false); + + block = SpectraBlock(itSpec ->second,itSpec ->second,false,""); } hist = itSpec ->second; } + // push the last block - hist = m_specInd2specNum_map.rbegin()->second; + hist = specInd2specNum_map.rbegin()->second; block.last = hist; - if ( m_monitors.find( hist ) != m_monitors.end() ) + + auto it_mon = monitors.find( hist ); + if (it_mon != monitors.end() ) { includedMonitors.push_back( hist ); block.isMonitor = true; + block.monName = it_mon->second; } m_spectraBlocks.push_back( block ); - return m_specInd2specNum_map.size(); + return specInd2specNum_map.size(); } + // here we are only if ranges are not supplied // // put in the spectra range, possibly breaking it into parts by monitors - int64_t first = m_loadBlockInfo.spectraID_min; - for(int64_t hist = first; hist < m_loadBlockInfo.spectraID_max; ++hist) + int64_t first = LoadBlock.spectraID_min; + for(int64_t hist = first; hist < LoadBlock.spectraID_max; ++hist) { - if ( m_monitors.find( hist ) != m_monitors.end() ) + auto it_mon = monitors.find( hist ); + if ( it_mon != monitors.end() ) { if ( hist != first ) { - m_spectraBlocks.push_back( SpectraBlock( first, hist - 1, false ) ); + m_spectraBlocks.push_back( SpectraBlock(first,hist - 1,false,"") ); } - m_spectraBlocks.push_back( SpectraBlock( hist, hist, true) ); + m_spectraBlocks.push_back( SpectraBlock( hist, hist, true,it_mon->second) ); includedMonitors.push_back( hist ); first = hist + 1; } } - int64_t spec_max = m_loadBlockInfo.spectraID_max; - if ( first == spec_max && m_monitors.find( first ) != m_monitors.end() ) + int64_t spec_max = LoadBlock.spectraID_max; + auto it_mon = monitors.find( first); + if ( first == spec_max && it_mon != monitors.end() ) { - m_spectraBlocks.push_back( SpectraBlock( first, spec_max, true ) ); + m_spectraBlocks.push_back( SpectraBlock( first, spec_max, true, it_mon->second ) ); includedMonitors.push_back( spec_max ); } else { - m_spectraBlocks.push_back( SpectraBlock( first, spec_max, false ) ); + m_spectraBlocks.push_back( SpectraBlock(first,spec_max,false,"") ); } // sort and check for overlapping @@ -617,22 +673,18 @@ namespace Mantid std::sort( m_spectraBlocks.begin(), m_spectraBlocks.end(), compareSpectraBlocks ); } - // remove monitors that weren't requested - if ( m_monitors.size() != includedMonitors.size() ) + // remove monitors that have been used + if ( monitors.size() != includedMonitors.size() ) { - if ( includedMonitors.empty() ) - { - m_monitors.clear(); - } - else + if ( !includedMonitors.empty() ) { - for(auto it = m_monitors.begin(); it != m_monitors.end(); ) + for(auto it = monitors.begin(); it != monitors.end(); ) { - if ( std::find( includedMonitors.begin(), includedMonitors.end(), it->first ) == includedMonitors.end() ) + if ( std::find( includedMonitors.begin(), includedMonitors.end(), it->first ) != includedMonitors.end() ) { auto it1 = it; ++it; - m_monitors.erase( it1 ); + monitors.erase( it1 ); } else { @@ -666,9 +718,7 @@ namespace Mantid { if ( block->isMonitor ) { - auto it = m_monitors.find( block->first ); - assert( it != m_monitors.end() ); - NXData monitor = entry.openNXData(it->second); + NXData monitor = entry.openNXData(block->monName); NXInt mondata = monitor.openIntData(); m_progress->report("Loading monitor"); mondata.load(1,static_cast(period-1)); // TODO this is just wrong @@ -1056,9 +1106,9 @@ namespace Mantid * */ bool LoadISISNexus2::findSpectraDetRangeInFile(NXEntry &entry,boost::shared_array &spectrum_index,int64_t ndets,int64_t n_vms_compat_spectra, - std::map &monitors,bool excludeMonitors,bool separateMonitors,std::set &OvelapMonitorSpectra) + std::map &monitors,bool excludeMonitors,bool separateMonitors,std::map &OvelapMonitors) { - OvelapMonitorSpectra.clear(); + OvelapMonitors.clear(); size_t nmons = monitors.size(); if (nmons>0) @@ -1157,7 +1207,7 @@ namespace Mantid { if(it->first>=m_detBlockInfo.spectraID_min && it->first <=m_detBlockInfo.spectraID_max) { //monitors ID-s are included with spectra ID-s -- let's try not to load it twice. - OvelapMonitorSpectra.insert(static_cast(it->first)); + OvelapMonitors.insert(*it); } else { diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp index 0e0a4290d86e..fc8579dc9bd4 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp @@ -170,7 +170,7 @@ namespace Mantid run.addLogData( new PropertyWithValue("run_number", run_num) ); } /**reads workspace dimensions,number of periods etc from raw data - * @param numberOfSpectra :: number of spectrums + * @param numberOfSpectra :: number of spectra * @param numberOfPeriods :: number of periods * @param lengthIn :: size of workspace vectors * @param noTimeRegimes :: number of time regime. diff --git a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h index 5f17b3feaa9d..9335317a294e 100644 --- a/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h +++ b/Code/Mantid/Framework/DataHandling/test/LoadISISNexusTest.h @@ -68,6 +68,75 @@ class LoadISISNexusTest : public CxxTest::TestSuite public: + void testExecMonSeparated() + { + Mantid::API::FrameworkManager::Instance(); + LoadISISNexus2 ld; + ld.initialize(); + ld.setPropertyValue("Filename","LOQ49886.nxs"); + ld.setPropertyValue("OutputWorkspace","outWS"); + ld.setPropertyValue("LoadMonitors","1"); // should read "Separate" + TS_ASSERT_THROWS_NOTHING(ld.execute()); + TS_ASSERT(ld.isExecuted()); + + + MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS("outWS"); + MatrixWorkspace_sptr mon_ws = AnalysisDataService::Instance().retrieveWS("outWS_monitors"); + + TS_ASSERT_EQUALS(ws->blocksize(),5); + TS_ASSERT_EQUALS(ws->getNumberHistograms(),17790); + + TS_ASSERT_EQUALS(mon_ws->blocksize(),5); + TS_ASSERT_EQUALS(mon_ws->getNumberHistograms(),2); + + // Two monitors which form two first spectra are excluded by load separately + + // spectrum with ID 5 is now spectrum N 3 as 2 monitors + TS_ASSERT_EQUALS(ws->readY(5-2)[1],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(5-2)->getSpectrumNo(),6); + TS_ASSERT_EQUALS(*(ws->getSpectrum(5-2)->getDetectorIDs().begin()), 6); + // spectrum with ID 7 is now spectrum N 4 + TS_ASSERT_EQUALS(ws->readY(6-2)[0],1.); + TS_ASSERT_EQUALS(ws->getSpectrum(6-2)->getSpectrumNo(),7); + TS_ASSERT_EQUALS(*(ws->getSpectrum(6-2)->getDetectorIDs().begin()), 7); + // + TS_ASSERT_EQUALS(ws->readY(8-2)[3],1.); + + TS_ASSERT_EQUALS(mon_ws->readX(0)[0],5.); + TS_ASSERT_EQUALS(mon_ws->readX(0)[1],4005.); + TS_ASSERT_EQUALS(mon_ws->readX(0)[2],8005.); + + // these spectra are not loaded as above so their values are different (occasionally 0) + TS_ASSERT_EQUALS(mon_ws->readY(0)[1],0); + TS_ASSERT_EQUALS(mon_ws->readY(1)[0],0.); + TS_ASSERT_EQUALS(mon_ws->readY(0)[3],0.); + + + + const std::vector< Property* >& logs = mon_ws->run().getLogData(); + TS_ASSERT_EQUALS(logs.size(), 62); + + std::string header = mon_ws->run().getPropertyValueAsType("run_header"); + TS_ASSERT_EQUALS(86, header.size()); + TS_ASSERT_EQUALS("LOQ 49886 Team LOQ Quiet Count, ISIS Off, N 28-APR-2009 09:20:29 0.00", header); + + TimeSeriesProperty* slog = dynamic_cast*>(mon_ws->run().getLogData("icp_event")); + TS_ASSERT(slog); + std::string str = slog->value(); + TS_ASSERT_EQUALS(str.size(),1023); + TS_ASSERT_EQUALS(str.substr(0,37),"2009-Apr-28 09:20:29 CHANGE_PERIOD 1"); + + slog = dynamic_cast*>(mon_ws->run().getLogData("icp_debug")); + TS_ASSERT(slog); + TS_ASSERT_EQUALS(slog->size(),50); + + AnalysisDataService::Instance().remove("outWS"); + AnalysisDataService::Instance().remove("outWS_monitors"); + } + + + + void testExec() { From 8dae714e806ff0c9bbd44ab951e6dc6c87c04237 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Fri, 10 Oct 2014 20:09:45 +0100 Subject: [PATCH 17/22] refs #9989 Doxygen errors --- Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 7dee72182d39..22b91386c338 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -1100,7 +1100,7 @@ namespace Mantid *@param excludeMonitors :: input property indicating if it is requested to exclude monitors from the target workspace *@param separateMonitors :: input property indicating if it is requested to load monitors separately (and exclude them from target data workspace this way) * - *@param OvelapMonitorSpectra :: output property containing the list of monitors ID for monitors, which are also included with spectra. + *@param OvelapMonitors :: output property containing the list of monitors ID for monitors, which are also included with spectra. *@return excludeMonitors :: indicator if monitors should or mast be excluded from the main data workspace if they can not be loaded with the data * (contain different number of time channels) * From 862b30f67c561bc5892adc577b7f8c03ac9472a1 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Sat, 11 Oct 2014 15:35:56 +0100 Subject: [PATCH 18/22] refs #9989 Should fix SANS2D data loading --- Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 22b91386c338..83c6ca915498 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -195,7 +195,7 @@ namespace Mantid std::map ExcluedMonitorsSpectra; bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,ExcluedMonitorsSpectra); - size_t x_length = m_detBlockInfo.numberOfChannels + 1; + size_t x_length = m_loadBlockInfo.numberOfChannels + 1; // Check input is consistent with the file, throwing if not, exclude spectra selected at findSpectraDetRangeInFile; checkOptionalProperties(ExcluedMonitorsSpectra); @@ -205,7 +205,7 @@ namespace Mantid m_progress = boost::shared_ptr(new Progress(this, 0.0, 1.0, total_specs * m_detBlockInfo.numberOfPeriods)); DataObjects::Workspace2D_sptr local_workspace = boost::dynamic_pointer_cast - (WorkspaceFactory::Instance().create("Workspace2D", total_specs, x_length, m_detBlockInfo.numberOfChannels)); + (WorkspaceFactory::Instance().create("Workspace2D", total_specs, x_length, m_loadBlockInfo.numberOfChannels)); // Set the units on the workspace to TOF & Counts local_workspace->getAxis(0)->unit() = UnitFactory::Instance().create("TOF"); local_workspace->setYUnit("Counts"); From 1bad2767406af308561cd8c11ffaa6d988cb2e64 Mon Sep 17 00:00:00 2001 From: Alex Buts Date: Mon, 13 Oct 2014 10:58:42 +0100 Subject: [PATCH 19/22] refs #9989 Setup monitor workspace attached to data ws and little code improvements. --- .../Framework/DataHandling/src/LoadISISNexus2.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp index 83c6ca915498..8e8fe0ca6bc4 100644 --- a/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Code/Mantid/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -318,20 +318,18 @@ namespace Mantid x_length = m_monBlockInfo.numberOfChannels+1; DataObjects::Workspace2D_sptr monitor_workspace = boost::dynamic_pointer_cast (WorkspaceFactory::Instance().create(local_workspace, m_monBlockInfo.numberOfSpectra,x_length,m_monBlockInfo.numberOfChannels)); + local_workspace->setMonitorWorkspace(monitor_workspace); m_spectraBlocks.clear(); m_specInd2specNum_map.clear(); std::vector dummyS1; - std::map dummySpectr; - buildSpectraInd2SpectraNumMap(true,m_monBlockInfo.spectraID_min,m_monBlockInfo.spectraID_max,dummyS1,dummySpectr); + // at the moment here we clear this map to enable possibility to load monitors from the spectra block (wiring table bug). + // if monitor's spectra present in the detectors block due to this bug should be read from monitors, this map should be dealt with properly. + ExcluedMonitorsSpectra.clear(); + buildSpectraInd2SpectraNumMap(true,m_monBlockInfo.spectraID_min,m_monBlockInfo.spectraID_max,dummyS1,ExcluedMonitorsSpectra); // lo prepareSpectraBlocks(m_monitors,m_specInd2specNum_map,m_monBlockInfo); - NXFloat timeBins = entry.openNXFloat("monitor_1/time_of_flight"); - timeBins.load(); - m_tof_data.reset(new MantidVec(timeBins(), timeBins() + x_length)); - - int64_t firstentry = (m_entrynumber > 0) ? m_entrynumber : 1; loadPeriodData(firstentry, entry, monitor_workspace); From 24cca11a93f054ce766ace34be1c16edf4574872 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Tue, 21 Oct 2014 16:03:17 +0100 Subject: [PATCH 20/22] Added file finder feddback to Calib and Diag run buttons Refs #10306 --- .../IndirectCalibration.h | 3 ++ .../IndirectDiagnostics.h | 3 ++ .../src/IndirectCalibration.cpp | 41 +++++++++++++++++ .../src/IndirectDiagnostics.cpp | 45 ++++++++++++++++++- 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectCalibration.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectCalibration.h index cfbc8c83e732..3d035e9c605a 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectCalibration.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectCalibration.h @@ -59,6 +59,9 @@ namespace CustomInterfaces void intensityScaleMultiplierCheck(bool state); /// Toggle the intensity scale multiplier box void calibValidateIntensity(const QString & text); /// Check that the scale multiplier is valid void setDefaultInstDetails(); + void pbRunEditing(); //< Called when a user starts to type / edit the runs to load. + void pbRunFinding(); //< Called when the FileFinder starts finding the files. + void pbRunFinished(); //< Called when the FileFinder has finished finding the files. private: void createRESfile(const QString& file); diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDiagnostics.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDiagnostics.h index 53ad5f130fd9..decaea8f79e0 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDiagnostics.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/IndirectDiagnostics.h @@ -74,6 +74,9 @@ namespace CustomInterfaces void setDefaultInstDetails(); void updatePreviewPlot(); void sliceAlgDone(bool error); + void pbRunEditing(); //< Called when a user starts to type / edit the runs to load. + void pbRunFinding(); //< Called when the FileFinder starts finding the files. + void pbRunFinished(); //< Called when the FileFinder has finished finding the files. private: QString m_lastDiagFilename; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectCalibration.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectCalibration.cpp index e0cac72a4e7f..9198f5886121 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectCalibration.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectCalibration.cpp @@ -146,6 +146,13 @@ namespace CustomInterfaces // Validate the value entered in scale factor option whenever it changes connect(m_uiForm.cal_leIntensityScaleMultiplier, SIGNAL(textChanged(const QString &)), this, SLOT(calibValidateIntensity(const QString &))); + // Shows message on run buton when user is inputting a run number + connect(m_uiForm.cal_leRunNo, SIGNAL(fileTextChanged(const QString &)), this, SLOT(pbRunEditing())); + // Shows message on run button when Mantid is finding the file for a given run number + connect(m_uiForm.cal_leRunNo, SIGNAL(findingFiles()), this, SLOT(pbRunFinding())); + // Reverts run button back to normal when file finding has finished + connect(m_uiForm.cal_leRunNo, SIGNAL(fileFindingFinished()), this, SLOT(pbRunFinished())); + // Nudge resCheck to ensure res range selectors are only shown when Create RES file is checked resCheck(m_uiForm.cal_ckRES->isChecked()); } @@ -607,5 +614,39 @@ namespace CustomInterfaces } } + /** + * Called when a user starts to type / edit the runs to load. + */ + void IndirectCalibration::pbRunEditing() + { + emit updateRunButton(false, "Editing...", "Run numbers are curently being edited."); + } + + /** + * Called when the FileFinder starts finding the files. + */ + void IndirectCalibration::pbRunFinding() + { + emit updateRunButton(false, "Finding files...", "Searchig for data files for the run numbers entered..."); + m_uiForm.cal_leRunNo->setEnabled(false); + } + + /** + * Called when the FileFinder has finished finding the files. + */ + void IndirectCalibration::pbRunFinished() + { + if(!m_uiForm.cal_leRunNo->isValid()) + { + emit updateRunButton(false, "Invalid Run(s)", "Cannot find data files for some of the run numbers enetered."); + } + else + { + emit updateRunButton(); + } + + m_uiForm.cal_leRunNo->setEnabled(true); + } + } // namespace CustomInterfaces } // namespace Mantid diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp index 6610843ae5c9..5b221f3c6f49 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp @@ -98,11 +98,18 @@ namespace CustomInterfaces connect(m_dblManager, SIGNAL(valueChanged(QtProperty*, double)), this, SLOT(sliceUpdateRS(QtProperty*, double))); // Enable/disable second range options when checkbox is toggled connect(m_blnManager, SIGNAL(valueChanged(QtProperty*, bool)), this, SLOT(sliceTwoRanges(QtProperty*, bool))); - // Plot slice miniplot when file has finished loading - connect(m_uiForm.slice_inputFile, SIGNAL(filesFound()), this, SLOT(slicePlotRaw())); // Enables/disables calibration file selection when user toggles Use Calibratin File checkbox connect(m_uiForm.slice_ckUseCalib, SIGNAL(toggled(bool)), this, SLOT(sliceCalib(bool))); + // Plot slice miniplot when file has finished loading + connect(m_uiForm.slice_inputFile, SIGNAL(filesFound()), this, SLOT(slicePlotRaw())); + // Shows message on run buton when user is inputting a run number + connect(m_uiForm.slice_inputFile, SIGNAL(fileTextChanged(const QString &)), this, SLOT(pbRunEditing())); + // Shows message on run button when Mantid is finding the file for a given run number + connect(m_uiForm.slice_inputFile, SIGNAL(findingFiles()), this, SLOT(pbRunFinding())); + // Reverts run button back to normal when file finding has finished + connect(m_uiForm.slice_inputFile, SIGNAL(fileFindingFinished()), this, SLOT(pbRunFinished())); + // Update preview plot when slice algorithm completes connect(m_batchAlgoRunner, SIGNAL(batchComplete(bool)), this, SLOT(sliceAlgDone(bool))); @@ -398,5 +405,39 @@ namespace CustomInterfaces m_plots["SlicePreviewPlot"]->replot(); } + /** + * Called when a user starts to type / edit the runs to load. + */ + void IndirectDiagnostics::pbRunEditing() + { + emit updateRunButton(false, "Editing...", "Run numbers are curently being edited."); + } + + /** + * Called when the FileFinder starts finding the files. + */ + void IndirectDiagnostics::pbRunFinding() + { + emit updateRunButton(false, "Finding files...", "Searchig for data files for the run numbers entered..."); + m_uiForm.slice_inputFile->setEnabled(false); + } + + /** + * Called when the FileFinder has finished finding the files. + */ + void IndirectDiagnostics::pbRunFinished() + { + if(!m_uiForm.slice_inputFile->isValid()) + { + emit updateRunButton(false, "Invalid Run(s)", "Cannot find data files for some of the run numbers enetered."); + } + else + { + emit updateRunButton(); + } + + m_uiForm.slice_inputFile->setEnabled(true); + } + } // namespace CustomInterfaces } // namespace Mantid From 03038b770efca289a48a178202f459a038eee90c Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Thu, 23 Oct 2014 15:14:54 +0100 Subject: [PATCH 21/22] Fix doxygen warnings Refs #10306 --- .../MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp | 2 +- .../MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp index 4b06fc7b8e9a..c063b3233783 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReduction.cpp @@ -405,7 +405,7 @@ void IndirectDataReduction::showMessageBox(const QString& message) * * @param enabled If the button is clickable * @param message Message shown on the button - * @parm tooltip Tooltip shown when hovering over button + * @param tooltip Tooltip shown when hovering over button */ void IndirectDataReduction::updateRunButton(bool enabled, QString message, QString tooltip) { diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp index 7072dab874d8..003ca1f0cac5 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDataReductionTab.cpp @@ -79,7 +79,7 @@ namespace CustomInterfaces /** * Slot used to update the run button when an algorithm that was strted by the Run button complete. * - * @parm error Unused + * @param error Unused */ void IndirectDataReductionTab::tabExecutionComplete(bool error) { From 179cdc9c07090ecfa60854b84a25295f005aea75 Mon Sep 17 00:00:00 2001 From: Jose Borreguero Date: Fri, 31 Oct 2014 11:11:32 -0400 Subject: [PATCH 22/22] Refs #10466 Include inelastic banks in new silicon component --- Code/Mantid/instrument/BASIS_Definition.xml | 30 +++++++++------- .../BASIS_silicon_111_Parameters.xml | 35 +++++-------------- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/Code/Mantid/instrument/BASIS_Definition.xml b/Code/Mantid/instrument/BASIS_Definition.xml index 6acf0bce38d3..82684ef3a9f2 100644 --- a/Code/Mantid/instrument/BASIS_Definition.xml +++ b/Code/Mantid/instrument/BASIS_Definition.xml @@ -1,5 +1,5 @@ - + @@ -28,10 +28,25 @@ - + + - + + + + + + + + + + + + + + + @@ -22715,9 +22730,6 @@ - - - @@ -45402,9 +45414,6 @@ - - - @@ -68089,9 +68098,6 @@ - - - diff --git a/Code/Mantid/instrument/BASIS_silicon_111_Parameters.xml b/Code/Mantid/instrument/BASIS_silicon_111_Parameters.xml index f4ca952eead0..c3f972fadbb9 100644 --- a/Code/Mantid/instrument/BASIS_silicon_111_Parameters.xml +++ b/Code/Mantid/instrument/BASIS_silicon_111_Parameters.xml @@ -36,7 +36,6 @@ - @@ -47,31 +46,13 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + +