Newer
Older
Russell Taylor
committed
#include "MantidAPI/RefAxis.h"
#include "MantidAPI/WorkspaceIterator.h"
#include "MantidAPI/WorkspaceIteratorCode.h"
#include "MantidAPI/WorkspaceFactory.h"
DECLARE_WORKSPACE(Workspace2D)
namespace Mantid
{
Russell Taylor
committed
// Get a reference to the logger
Kernel::Logger& Workspace2D::g_log = Kernel::Logger::get("Workspace2D");
Russell Taylor
committed
{}
///Destructor
Workspace2D::~Workspace2D()
{}
/** Sets the size of the workspace and initializes arrays to zero
* @param NVectors The number of vectors/histograms/detectors in the workspace
* @param XLength The number of X data points/bin boundaries in each vector (must all be the same)
* @param YLength The number of data/error points in each vector (must all be the same)
*/
void Workspace2D::init(const int &NVectors, const int &XLength, const int &YLength)
{
Russell Taylor
committed
m_noVectors = NVectors;
data.resize(m_noVectors);
m_axes.resize(2);
m_axes[0] = new API::RefAxis(XLength, this);
Russell Taylor
committed
// This axis is always a spectra one for now
m_axes[1] = new API::Axis(API::AxisType::Spectra,m_noVectors);
Histogram1D::RCtype t1,t2;
t1.access().resize(XLength); //this call initializes array to zero
Russell Taylor
committed
for (int i=0;i<m_noVectors;i++)
// Y,E arrays populated
this->setData(i,t2,t2);
Russell Taylor
committed
void
Workspace2D::setX(const int histnumber, const Histogram1D::RCtype::ptr_type& Vec)
{
Russell Taylor
committed
if (histnumber<0 || histnumber>=m_noVectors)
throw std::range_error("Workspace2D::setX, histogram number out of range");
Set the x values
\param histnumber :: Index to the histogram
\param PA :: Reference counted histogram
Russell Taylor
committed
void
Workspace2D::setX(const int histnumber, const Histogram1D::RCtype& PA)
{
Russell Taylor
committed
if (histnumber<0 || histnumber>=m_noVectors)
throw std::range_error("Workspace2D::setX, histogram number out of range");
Russell Taylor
committed
\param PY A reference counted data range
Russell Taylor
committed
void
Workspace2D::setData(const int histnumber, const Histogram1D::RCtype& PY)
{
Russell Taylor
committed
if (histnumber<0 || histnumber>=m_noVectors)
throw std::range_error("Workspace2D::setData, histogram number out of range");
Russell Taylor
committed
\param PY A reference counted data range
Russell Taylor
committed
void Workspace2D::setData(const int histnumber, const Histogram1D::RCtype& PY,
Russell Taylor
committed
if (histnumber<0 || histnumber>=m_noVectors)
throw std::range_error("Workspace2D::setData, histogram number out of range");
Russell Taylor
committed
\param PY A reference counted data range
Russell Taylor
committed
void Workspace2D::setData(const int histnumber, const Histogram1D::RCtype::ptr_type& PY,
Russell Taylor
committed
if (histnumber<0 || histnumber>=m_noVectors)
throw std::range_error("Workspace2D::setData, histogram number out of range");
Russell Taylor
committed
Russell Taylor
committed
const int
Matt Clarke
committed
Workspace2D::getNumberHistograms() const
/**
Get the x data of a specified histogram
@param index The number of the histogram
@return A vector of doubles containing the x data
*/
const MantidVec&
Russell Taylor
committed
if (index<0 || index>=m_noVectors)
throw std::range_error("Workspace2D::dataX, histogram number out of range");
/**
Get the y data of a specified histogram
@param index The number of the histogram
@return A vector of doubles containing the y data
*/
const MantidVec&
Russell Taylor
committed
if (index<0 || index>=m_noVectors)
throw std::range_error("Workspace2D::dataY, histogram number out of range");
/**
Get the error data for a specified histogram
@param index The number of the histogram
@return A vector of doubles containing the error data
*/
const MantidVec&
Russell Taylor
committed
if (index<0 || index>=m_noVectors)
throw std::range_error("Workspace2D::dataE, histogram number out of range");
Russell Taylor
committed
int Workspace2D::size() const
{
return data.size() * blocksize();
}
///get the size of each vector
int Workspace2D::blocksize() const
{
return (data.size() > 0) ? data[0].size() : 0;
}
MantidVec& Workspace2D::dataX(int const index)
Russell Taylor
committed
if (index<0 || index>=m_noVectors)
throw std::range_error("Workspace2D::dataX, histogram number out of range");
Russell Taylor
committed
MantidVec& Workspace2D::dataY(int const index)
Russell Taylor
committed
if (index<0 || index>=m_noVectors)
throw std::range_error("Workspace2D::dataY, histogram number out of range");
Russell Taylor
committed
MantidVec& Workspace2D::dataE(int const index)
Russell Taylor
committed
if (index<0 || index>=m_noVectors)
throw std::range_error("Workspace2D::dataE, histogram number out of range");
Russell Taylor
committed
/// Returns a pointer to the x data
Kernel::cow_ptr<MantidVec> Workspace2D::refX(const int index) const
{
if (index<0 || index>=m_noVectors)
throw std::range_error("Workspace2D::refX, histogram number out of range");
return data[index].ptrX();
}
Russell Taylor
committed
For some reason Visual Studio couldn't deal with the main getHistogramNumber() method
being virtual so it now just calls this private (and virtual) method which does the work.
*/
const int Workspace2D::getHistogramNumberHelper() const
{
return static_cast<const int>(data.size());
}
} // namespace DataObjects
} //NamespaceMantid
Dickon Champion
committed
template DLLExport class Mantid::API::workspace_iterator<Mantid::API::LocatedDataRef, Mantid::DataObjects::Workspace2D>;
template DLLExport class Mantid::API::workspace_iterator<const Mantid::API::LocatedDataRef, const Mantid::DataObjects::Workspace2D>;
template DLLExport class Mantid::API::WorkspaceProperty<Mantid::DataObjects::Workspace2D>;
Russell Taylor
committed
namespace Mantid
{
Russell Taylor
committed
Mantid::DataObjects::Workspace2D_sptr IPropertyManager::getValue<Mantid::DataObjects::Workspace2D_sptr>(const std::string &name) const
Russell Taylor
committed
PropertyWithValue<Mantid::DataObjects::Workspace2D_sptr>* prop =
dynamic_cast<PropertyWithValue<Mantid::DataObjects::Workspace2D_sptr>*>(getPointerToProperty(name));
if (prop)
{
return *prop;
}
else
{
std::string message = "Attempt to assign property "+ name +" to incorrect type";
throw std::runtime_error(message);
Russell Taylor
committed
Russell Taylor
committed
Mantid::DataObjects::Workspace2D_const_sptr IPropertyManager::getValue<Mantid::DataObjects::Workspace2D_const_sptr>(const std::string &name) const
Russell Taylor
committed
PropertyWithValue<Mantid::DataObjects::Workspace2D_sptr>* prop =
dynamic_cast<PropertyWithValue<Mantid::DataObjects::Workspace2D_sptr>*>(getPointerToProperty(name));
Russell Taylor
committed
return prop->operator()();
std::string message = "Attempt to assign property "+ name +" to incorrect type";
throw std::runtime_error(message);
Russell Taylor
committed
} // namespace Mantid