Skip to content

Commit

Permalink
WIP Add progress reporting.
Browse files Browse the repository at this point in the history
Refs #11056
  • Loading branch information
martyngigg committed Dec 10, 2015
1 parent 084e444 commit 0bf2d6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Framework/MDAlgorithms/inc/MantidMDAlgorithms/LoadSQW2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Mantid {
// Forward declarations
namespace API {
class ExperimentInfo;
class Progress;
}

namespace MDAlgorithms {
Expand Down Expand Up @@ -80,6 +81,7 @@ class DLLExport LoadSQW2 : public API::Algorithm {
std::unique_ptr<std::ifstream> m_file;
std::unique_ptr<Kernel::BinaryStreamReader> m_reader;
boost::shared_ptr<SQWWorkspace> m_outputWS;
std::unique_ptr<API::Progress> m_progress;
};

} // namespace MDAlgorithms
Expand Down
26 changes: 18 additions & 8 deletions Framework/MDAlgorithms/src/LoadSQW2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MantidMDAlgorithms/LoadSQW2.h"

#include "MantidAPI/FileProperty.h"
#include "MantidAPI/Progress.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidGeometry/MDGeometry/MDHistoDimension.h"
Expand All @@ -17,14 +18,10 @@
namespace Mantid {
namespace MDAlgorithms {

using API::ExperimentInfo;
using Geometry::Goniometer;
using Geometry::OrientedLattice;
using Geometry::MDHistoDimension;
using Geometry::MDHistoDimensionBuilder;
using Kernel::BinaryStreamReader;
using Kernel::Logger;
using Kernel::make_unique;
using Kernel::Matrix;
using Kernel::V3D;

Expand All @@ -43,7 +40,8 @@ DECLARE_ALGORITHM(LoadSQW2)
// Public methods
//------------------------------------------------------------------------------
/// Default constructor
LoadSQW2::LoadSQW2() : API::Algorithm(), m_file(), m_reader(), m_outputWS() {}
LoadSQW2::LoadSQW2()
: API::Algorithm(), m_file(), m_reader(), m_outputWS(), m_progress() {}

/// Default destructor
LoadSQW2::~LoadSQW2() {}
Expand Down Expand Up @@ -97,9 +95,13 @@ void LoadSQW2::exec() {
* Opens the file given to the algorithm and initializes the reader
*/
void LoadSQW2::initFileReader() {
using API::Progress;
using Kernel::make_unique;
m_file = make_unique<std::ifstream>(getPropertyValue("Filename"),
std::ios_base::binary);
m_reader = make_unique<BinaryStreamReader>(*m_file);
// steps are reset once we know what we are reading
m_progress = make_unique<Progress>(this, 0.0, 1.0, 100);
}

/**
Expand Down Expand Up @@ -145,6 +147,7 @@ void LoadSQW2::createOutputWorkspace() {
* @param nfiles The number of expected spe header sections
*/
void LoadSQW2::readAllSPEHeadersToWorkspace(const int32_t nfiles) {
using API::ExperimentInfo;
for (int32_t i = 0; i < nfiles; ++i) {
auto expt = boost::make_shared<ExperimentInfo>();
readSingleSPEHeader(*expt);
Expand Down Expand Up @@ -276,6 +279,9 @@ void LoadSQW2::skipDataSectionMetadata() {
* ulimit entry
*/
void LoadSQW2::readSQWDimensions() {
using Geometry::MDHistoDimension;
using Geometry::MDHistoDimensionBuilder;

// dimension labels
std::vector<int32_t> ulabelShape(2);
m_reader->read(ulabelShape, 2);
Expand Down Expand Up @@ -368,10 +374,10 @@ void LoadSQW2::readSQWDimensions() {
void LoadSQW2::setupBoxController() {
using Kernel::Timer;
Timer timer;

auto boxController = m_outputWS->getBoxController();
for (size_t i = 0; i < 4; i++) {
boxController->setSplitInto(i, m_outputWS->getDimension(i)->getNBins());
boxController->setSplitInto(i, m_outputWS->getDimension(i)->getNBins());
}
boxController->setMaxDepth(1);
m_outputWS->initialize();
Expand All @@ -387,12 +393,13 @@ void LoadSQW2::setupBoxController() {
void LoadSQW2::readPixelData() {
using Kernel::Timer;
Timer timer;

// skip redundant field
m_file->seekg(sizeof(int32_t), std::ios_base::cur);
int64_t npixtot(0);
*m_reader >> npixtot;
g_log.debug() << " npixtot: " << npixtot << "\n";
m_progress->setNumSteps(npixtot);

// Each pixel has 9 float fields. Do a chunked read to avoid
// using too much memory for the buffer
Expand All @@ -408,6 +415,7 @@ void LoadSQW2::readPixelData() {
m_reader->read(pixBuffer, numFields * readNPix);
for (int64_t i = 0; i < readNPix; ++i) {
addEventFromBuffer(pixBuffer.data() + i * 9);
m_progress->report();
}
pixelsToRead -= readNPix;
}
Expand All @@ -433,6 +441,7 @@ void LoadSQW2::addEventFromBuffer(const float *pixel) {
m_outputWS->addEvent(MDEvent<4>(signal, error * error, irun, idet, centres));
}


/**
* Transform the given coordinates from U to the HKL frame
* using the transformation defined for the given run
Expand All @@ -445,6 +454,7 @@ void LoadSQW2::toHKL(float &u1, float &u2, float &u3, const uint16_t runIndex) {
constexpr double invTwoPi = 0.5 / M_PI;
const auto &sample = m_outputWS->getExperimentInfo(runIndex)->sample();
const auto &uToRLU = sample.getOrientedLattice().getBinv();

V3D uVec(static_cast<double>(u1), static_cast<double>(u2),
static_cast<double>(u3));
V3D qhkl = (uToRLU * uVec) * invTwoPi;
Expand Down

0 comments on commit 0bf2d6b

Please sign in to comment.