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

namespace Mantid
{
namespace Algorithms
{

// Algorithm must be declared
DECLARE_ALGORITHM(WorkspaceAlgorithm);

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


// Get a reference to the logger. It is used to print out information,
// warning, and error messages
Logger& WorkspaceAlgorithm::g_log = Logger::get("WorkspaceAlgorithm");

/**  Initialization code
 *    
 *   Properties have to be declared here before they can be used
*/
void WorkspaceAlgorithm::init()
{
    
    // Declare a 1D workspace property. 
    declareProperty(new WorkspaceProperty<Workspace1D>("Workspace","",Direction::Input));

}

/** Executes the algorithm
 */
void WorkspaceAlgorithm::exec() 
{ 
    g_log.information() << "Running algorithm " << name() << " version " << version() << std::endl; 

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

    // Number of single indexable items in the workspace 
    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;
    }

}

}
}