Skip to content

Commit

Permalink
Re #9541. Add a monitor workspace member to MatrixWorkspace.
Browse files Browse the repository at this point in the history
Along with simple getter, setter and test.
  • Loading branch information
RussellTaylor committed May 30, 2014
1 parent 779b78c commit 3d067a3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h
Expand Up @@ -256,6 +256,10 @@ namespace Mantid
typedef std::map<size_t,double> MaskList;
const MaskList& maskedBins(const size_t& spectrumIndex) const;

// Methods handling the internal monitor workspace
void setMonitorWorkspace(const boost::shared_ptr<MatrixWorkspace>& monitorWS);
boost::shared_ptr<MatrixWorkspace> monitorWorkspace() const;

void saveInstrumentNexus(::NeXus::File * file) const;
void loadInstrumentNexus(::NeXus::File * file);
void saveSpectraMapNexus(::NeXus::File * file, const std::vector<int>& spec,
Expand Down Expand Up @@ -331,6 +335,9 @@ namespace Mantid
/// The set of masked bins in a map keyed on spectrum index
std::map< int64_t, MaskList > m_masks;

/// A workspace holding monitor data relating to the main data in the containing workspace (null if none).
boost::shared_ptr<MatrixWorkspace> m_monitorWorkspace;

protected:
/// Assists conversions to and from 2D histogram indexing to 1D indexing.
MatrixWSIndexCalculator m_indexCalculator;
Expand Down
19 changes: 19 additions & 0 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Expand Up @@ -1060,6 +1060,25 @@ namespace Mantid
return it->second;
}

/** Sets the internal monitor workspace to the provided workspace.
* This method is intended for use by data-loading algorithms.
* Note that no checking is performed as to whether this workspace actually contains data
* pertaining to monitors, or that the spectra point to Detector objects marked as monitors.
* It simply has to be of the correct type to be accepted.
* @param The workspace containing the monitor data.
*/
void MatrixWorkspace::setMonitorWorkspace(const boost::shared_ptr<MatrixWorkspace>& monitorWS)
{
m_monitorWorkspace = monitorWS;
}

/** Returns a pointer to the internal monitor workspace.
*/
boost::shared_ptr<MatrixWorkspace> MatrixWorkspace::monitorWorkspace() const
{
return m_monitorWorkspace;
}

//---------------------------------------------------------------------------------------------
/** Return memory used by the workspace, in bytes.
* @return bytes used.
Expand Down
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h
Expand Up @@ -787,6 +787,17 @@ class MatrixWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(ws->getXMax(), 1.0);
}

void test_monitorWorkspace()
{
WorkspaceTester ws;
TS_ASSERT( ! ws.monitorWorkspace() )
auto ws2 = boost::make_shared<WorkspaceTester>();
ws.setMonitorWorkspace(ws2);
TS_ASSERT_EQUALS( ws.monitorWorkspace(), ws2 )
ws.setMonitorWorkspace(boost::shared_ptr<MatrixWorkspace>());
TS_ASSERT( ! ws.monitorWorkspace() )
}

private:
boost::shared_ptr<MatrixWorkspace> ws;

Expand Down

0 comments on commit 3d067a3

Please sign in to comment.