Skip to content
Snippets Groups Projects
WorkspaceAlgorithm.cpp 1.52 KiB
Newer Older
Roman Tolchenov's avatar
Roman Tolchenov committed
#include "WorkspaceAlgorithm.h"

namespace Mantid {
namespace Algorithms {
Roman Tolchenov's avatar
Roman Tolchenov committed

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

using namespace Kernel;
Roman Tolchenov's avatar
Roman Tolchenov committed

/**  Initialization code
 *
 *   Properties have to be declared here before they can be used
*/
void WorkspaceAlgorithm::init() {
  // Declare a 1D workspace property.
  declareProperty(
      make_unique<WorkspaceProperty<>>("Workspace", "", Direction::Input));
void WorkspaceAlgorithm::exec() {
  // 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;

  // Get the input workspace
  MatrixWorkspace_const_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;
  size_t histogramCount = workspace->getNumberHistograms();
  for (size_t i = 0; i < histogramCount; ++i) {
    auto &XValues = workspace->x(i);
    auto &YValues = workspace->y(i);
    auto &EValues = workspace->e(i);
    const auto numBins = YValues.size();
    for (size_t j = 0; numBins; ++j) {
      g_log.information() << "Point number " << count++
                          << " values: " << XValues[j] << ' ' << YValues[j]
                          << ' ' << EValues[j] << std::endl;
Roman Tolchenov's avatar
Roman Tolchenov committed
    }
Roman Tolchenov's avatar
Roman Tolchenov committed
}
}
}