Skip to content
Snippets Groups Projects
WorkspaceAlgorithm.cpp 1.95 KiB
Newer Older
Roman Tolchenov's avatar
Roman Tolchenov committed
#include "WorkspaceAlgorithm.h"
#include "MantidDataObjects/Workspace1D.h"
#include "MantidDataObjects/Workspace2D.h"

namespace Mantid
{
namespace Algorithms
{

// Algorithm must be declared
Roman Tolchenov's avatar
Roman Tolchenov committed

using namespace Kernel;
using namespace API;
using DataObjects::Workspace1D_sptr;
using DataObjects::Workspace1D;
using DataObjects::Workspace2D_sptr;
using DataObjects::Workspace2D;

/**  Initialization code
Roman Tolchenov's avatar
Roman Tolchenov committed
 *   Properties have to be declared here before they can be used
*/
void WorkspaceAlgorithm::init()
{
Roman Tolchenov's avatar
Roman Tolchenov committed
    declareProperty(new WorkspaceProperty<Workspace1D>("Workspace","",Direction::Input));

}

/** Executes the algorithm
 */
Nick Draper's avatar
Nick Draper committed
  	// g_log is a reference to the logger. It is used to print out information,
		// warning, and error messages  
		g_log.information() << "Running algorithm " << name() << " version " << version() << std::endl;
Roman Tolchenov's avatar
Roman Tolchenov committed

    // Get the input workspace
    Workspace1D_sptr workspace = getProperty("Workspace");

    // Number of single indexable items in the workspace
Roman Tolchenov's avatar
Roman Tolchenov committed
    g_log.information() << "Number of items = " << workspace->size() << std::endl;

    int count = 0;
    // Iterate over the workspace
    for(Workspace1D::const_iterator ti(*workspace); ti != ti.end(); ++ti)
    {
        // Get the reference to a data point
        LocatedDataRef tr = *ti;
        g_log.information() << "Point number " << count++ << " values: "
            << tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl;
    }

    count = 0;
    int loopCount = 2;
    // Do several loops
    for(Workspace1D::const_iterator ti(*workspace,loopCount,LoopOrientation::Horizontal); ti != ti.end(); ++ti)
    {
        // Get the reference to a data point
        LocatedDataRef tr = *ti;
        g_log.information() << "Point number " << count++ << " values: "
            << tr.X() << ' ' << tr.Y() << ' ' << tr.E() << std::endl;
    }

}

}
}