Skip to content

Commit

Permalink
Refs #6185 DetermineChunking for SNS histo.nxs
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Dec 7, 2012
1 parent ec800e1 commit 24e1712
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ class DLLExport LoadTOFRawNexus : public API::IDataFileChecker
/// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded
int fileCheck(const std::string& filePath);

void countPixels(const std::string &nexusfilename, const std::string & entry_name,
std::vector<std::string> & bankNames);

/// Number of pixels
size_t numPixels;

/// Signal # to load. Default 1
int signalNo;

protected:
void init();
void initDocs();
Expand All @@ -86,21 +95,12 @@ class DLLExport LoadTOFRawNexus : public API::IDataFileChecker
void loadBank(const std::string &nexusfilename, const std::string & entry_name,
const std::string &bankName, Mantid::API::MatrixWorkspace_sptr WS);

void countPixels(const std::string &nexusfilename, const std::string & entry_name,
std::vector<std::string> & bankNames);

/// List of the absolute time of each pulse
std::vector<Kernel::DateAndTime> pulseTimes;

/// Map where key = detector ID, value = workspace index
detid2index_map * id_to_wi;

/// Signal # to load. Default 1
int m_signal;

/// Number of pixels
size_t numPixels;

/// Number of bins
size_t numBins;

Expand Down
22 changes: 19 additions & 3 deletions Code/Mantid/Framework/DataHandling/src/DetermineChunking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Workflow algorithm to determine chunking strategy.
#include "MantidDataHandling/DetermineChunking.h"
#include "MantidDataHandling/LoadPreNexus.h"
#include "MantidDataHandling/LoadEventNexus.h"
#include "MantidDataHandling/LoadTOFRawNexus.h"
#include "LoadRaw/isisraw.h"
#include "MantidDataHandling/LoadRaw.h"
#include "MantidDataHandling/LoadRawHelper.h"
Expand Down Expand Up @@ -129,7 +130,7 @@ namespace DataHandling
strategy->addColumn("int","ChunkNumber");
strategy->addColumn("int","TotalChunks");
}
else if( ext.compare("raw") == 0)
else if( ext.compare("raw") == 0|| runinfo.compare(runinfo.size()-10,10,"_histo.nxs") == 0)
{
strategy->addColumn("int","SpectrumMin");
strategy->addColumn("int","SpectrumMax");
Expand All @@ -151,7 +152,7 @@ namespace DataHandling
lp.parseRuninfo(runinfo, dataDir, eventFilenames);
for (size_t i = 0; i < eventFilenames.size(); i++) {
Mantid::Kernel::BinaryFile<DasEvent> * eventfile = new BinaryFile<DasEvent>(dataDir + eventFilenames[i]);
// Factor fo 2 for compression
// Factor of 2 for compression
filesize += static_cast<double>(eventfile->getNumElements()) * 48.0 / (1024.0*1024.0*1024.0);
}
}
Expand Down Expand Up @@ -232,6 +233,21 @@ namespace DataHandling
m_numberOfSpectra = iraw.t_nsp1;
g_log.notice() << "Spectra size is " << m_numberOfSpectra << " spectra" << std::endl;
}
else if( runinfo.compare(runinfo.size()-10,10,"_histo.nxs") == 0)
{
// Check the size of the file loaded
Poco::File info(runinfo);
filesize = double(info.getSize())/(1024.*1024.*1024.0);
g_log.notice() << "File size is " << filesize << " GB" << std::endl;
LoadTOFRawNexus lp;
lp.signalNo = 1;
// Find the entry name we want.
std::string entry_name = LoadTOFRawNexus::getEntryName(runinfo);
std::vector<std::string> bankNames;
lp.countPixels(runinfo, entry_name, bankNames);
m_numberOfSpectra = static_cast<int>(lp.numPixels);
g_log.notice() << "Spectra size is " << m_numberOfSpectra << " spectra" << std::endl;
}
else
{
return;
Expand Down Expand Up @@ -263,7 +279,7 @@ namespace DataHandling
{
row << i << numChunks;
}
else if( ext.compare("raw") == 0)
else if( ext.compare("raw") == 0 || runinfo.compare(runinfo.size()-10,10,"_histo.nxs") == 0)
{
int spectraPerChunk = m_numberOfSpectra/numChunks;
int first = (i-1) * spectraPerChunk;
Expand Down
14 changes: 7 additions & 7 deletions Code/Mantid/Framework/DataHandling/src/LoadTOFRawNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void LoadTOFRawNexus::countPixels(const std::string &nexusfilename, const std::s
{
int signal = 0;
file->getAttr("signal", signal);
if (signal == m_signal)
if (signal == signalNo)
{
// That's the right signal!
m_dataField = it->first;
Expand All @@ -210,9 +210,9 @@ void LoadTOFRawNexus::countPixels(const std::string &nexusfilename, const std::s
m_assumeOldFile = false;
if (!file->hasAttr("axes"))
{
if (1 != m_signal)
if (1 != signalNo)
{
throw std::runtime_error("Your chosen signal number, " + Strings::toString(m_signal) + ", corresponds to the data field '" +
throw std::runtime_error("Your chosen signal number, " + Strings::toString(signalNo) + ", corresponds to the data field '" +
m_dataField + "' has no 'axes' attribute specifying.");
}
else
Expand All @@ -230,11 +230,11 @@ void LoadTOFRawNexus::countPixels(const std::string &nexusfilename, const std::s
std::vector<std::string> allAxes;
boost::split( allAxes, axes, boost::algorithm::detail::is_any_ofF<char>(","));
if (allAxes.size() != 3)
throw std::runtime_error("Your chosen signal number, " + Strings::toString(m_signal) + ", corresponds to the data field '" +
throw std::runtime_error("Your chosen signal number, " + Strings::toString(signalNo) + ", corresponds to the data field '" +
m_dataField + "' which has only " + Strings::toString(allAxes.size()) + " dimension. Expected 3 dimensions.");

m_axisField = allAxes.back();
g_log.information() << "Loading signal " << m_signal << ", " << m_dataField << " with axis " << m_axisField << std::endl;
g_log.information() << "Loading signal " << signalNo << ", " << m_dataField << " with axis " << m_axisField << std::endl;
file->closeData();
break;
} // Data has a 'signal' attribute
Expand All @@ -249,7 +249,7 @@ void LoadTOFRawNexus::countPixels(const std::string &nexusfilename, const std::s
} // each entry

if (m_dataField.empty())
throw std::runtime_error("Your chosen signal number, " + Strings::toString(m_signal) + ", was not found in any of the data fields of any 'bankX' group. Cannot load file.");
throw std::runtime_error("Your chosen signal number, " + Strings::toString(signalNo) + ", was not found in any of the data fields of any 'bankX' group. Cannot load file.");


for (it = entries.begin(); it != entries.end(); ++it)
Expand Down Expand Up @@ -524,7 +524,7 @@ void LoadTOFRawNexus::exec()
{
// The input properties
std::string filename = getPropertyValue("Filename");
m_signal = getProperty("Signal");
signalNo = getProperty("Signal");

// Find the entry name we want.
std::string entry_name = LoadTOFRawNexus::getEntryName(filename);
Expand Down

0 comments on commit 24e1712

Please sign in to comment.