Skip to content

Commit

Permalink
WIP Add code to start reading SPE headers.
Browse files Browse the repository at this point in the history
Refs #11056
  • Loading branch information
martyngigg committed Dec 4, 2015
1 parent 9acb79d commit 6527f46
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
10 changes: 9 additions & 1 deletion Framework/MDAlgorithms/inc/MantidMDAlgorithms/LoadSQW2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#include <fstream>

namespace Mantid {

// Forward declarations
namespace API {
class ExperimentInfo;
}

namespace MDAlgorithms {

/**
Expand Down Expand Up @@ -53,11 +59,13 @@ class DLLExport LoadSQW2 : public API::Algorithm {
struct SQWHeader {
int32_t nfiles;
};

void init();
void exec();
void initFileReader();
SQWHeader readMainHeader();
void readAllSPEHeaders(const int32_t nfiles);
void readSingleSPEHeader(API::ExperimentInfo &experiment);
void createOutputWorkspace();

std::unique_ptr<std::ifstream> m_file;
Expand Down
39 changes: 32 additions & 7 deletions Framework/MDAlgorithms/src/LoadSQW2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Mantid {
namespace MDAlgorithms {

using API::ExperimentInfo;
using Kernel::BinaryStreamReader;
using Kernel::Logger;
using Kernel::make_unique;
Expand Down Expand Up @@ -39,6 +40,10 @@ const std::string LoadSQW2::summary() const {
return "Load an N-dimensional workspace from a .sqw file produced by Horace.";
}

//------------------------------------------------------------------------------
// Private methods
//------------------------------------------------------------------------------

/// Initialize the algorithm's properties.
void LoadSQW2::init() {
using namespace API;
Expand All @@ -54,8 +59,9 @@ void LoadSQW2::init() {
/// Execute the algorithm.
void LoadSQW2::exec() {
initFileReader();
readMainHeader();
auto mainHeader = readMainHeader();
createOutputWorkspace();
readAllSPEHeaders(mainHeader.nfiles);

setProperty("OutputWorkspace", m_outputWS);
}
Expand Down Expand Up @@ -86,27 +92,46 @@ LoadSQW2::SQWHeader LoadSQW2::readMainHeader() {

if (g_log.is(Logger::Priority::PRIO_DEBUG)) {
std::ostringstream os;
os << "Skipped preamable section:\n"
os << "Main header:\n"
<< " app_name: " << appName << "\n"
<< " app_version: " << appVersion << "\n"
<< " sqw_type: " << sqwType << "\n"
<< " ndims: " << numDims << "\n"
<< " filename: " << filename << "\n"
<< " filepath: " << filepath << "\n"
<< " title: " << title << "\n";
<< " title: " << title << "\n"
<< " nfiles: " << header.nfiles << "\n";
g_log.debug(os.str());
}
return header;
}

/**
* Read all of the SPE headers and fill in the experiment details on the
* output workspace
* @param nfiles The number of expected spe header sections
*/
void LoadSQW2::readAllSPEHeaders(const int32_t nfiles) {
for (int32_t i = 0; i < nfiles; ++i) {
auto expt = boost::make_shared<ExperimentInfo>();
readSingleSPEHeader(*expt);
m_outputWS->addExperimentInfo(expt);
}
}

/**
* Read single SPE header from the file. It assumes the file stream
* points at the start of a header section
* @param experiment A reference to an ExperimentInfo object to store the data
*/
void LoadSQW2::readSingleSPEHeader(API::ExperimentInfo &experiment) {

}

/// Create the output workspace object
void LoadSQW2::createOutputWorkspace() {
m_outputWS = boost::make_shared<SQWWorkspace>();
}

//------------------------------------------------------------------------------
// Public methods
//------------------------------------------------------------------------------

} // namespace MDAlgorithms
} // namespace Mantid
5 changes: 3 additions & 2 deletions Framework/MDAlgorithms/test/LoadSQW2Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class LoadSQW2Test : public CxxTest::TestSuite {
alg->setProperty("Filename", m_filename));
}

void test_OutputWorkspace_Is_4D_MDEventWorkspace() {
auto outputWS = runAlgorithm();
void test_OutputWorkspace_Has_Correct_Data() {
IMDEventWorkspace_sptr outputWS = runAlgorithm();
TS_ASSERT_EQUALS(4, outputWS->getNumDims());
TS_ASSERT_EQUALS(2, outputWS->getNumExperimentInfo());
}

//----------------------------------------------------------------------------
Expand Down

0 comments on commit 6527f46

Please sign in to comment.