Skip to content

Commit

Permalink
Refs #6185 chunking working for LoadTOFRawNexus
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed Dec 11, 2012
1 parent 64ebf61 commit e45cd4b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class DLLExport LoadTOFRawNexus : public API::IDataFileChecker
/// Number of bins
size_t numBins;

/// Interval of chunk
specid_t m_spec_min, m_spec_max;

/// Name of the 'data' field to load (depending on Signal)
std::string m_dataField;

Expand Down
13 changes: 7 additions & 6 deletions Code/Mantid/Framework/DataHandling/src/DetermineChunking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace DataHandling
exts.push_back("_runinfo.xml");
exts.push_back("_event.nxs");
exts.push_back(".nxs");
exts.push_back(".raw");
this->declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts),
"The name of the runinfo file to read, including its full or relative path. \n"
"Or the name of the Event NeXus file to read, including its full or relative path. \n"
Expand Down Expand Up @@ -213,16 +214,16 @@ namespace DataHandling
//Close up the file
file.closeGroup();
file.close();
// Factor fo 2 for compression
// Factor of 2 for compression
filesize = static_cast<double>(total_events) * 48.0 / (1024.0*1024.0*1024.0);
}
//Histo Nexus
else if( ext.compare("raw") == 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;
filesize = double(info.getSize()) * 24.0 / (1024.0*1024.0*1024.0);
g_log.notice() << "Wksp size is " << filesize << " GB" << std::endl;

LoadRawHelper *helper = new LoadRawHelper;
FILE* file = helper->openRawFile(runinfo);
Expand All @@ -237,8 +238,8 @@ namespace DataHandling
{
// 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;
filesize = double(info.getSize()) * 144.0 / (1024.0*1024.0*1024.0);
g_log.notice() << "Wksp size is " << filesize << " GB" << std::endl;
LoadTOFRawNexus lp;
lp.signalNo = 1;
// Find the entry name we want.
Expand Down Expand Up @@ -282,7 +283,7 @@ namespace DataHandling
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;
int first = (i-1) * spectraPerChunk + 1;
int last = first + spectraPerChunk - 1;
if (i == numChunks) last = m_numberOfSpectra;
row << first << last;
Expand Down
54 changes: 51 additions & 3 deletions Code/Mantid/Framework/DataHandling/src/LoadTOFRawNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ void LoadTOFRawNexus::init()
"Number of the signal to load from the file. Default is 1 = time_of_flight.\n"
"Some NXS files have multiple data fields giving binning in other units (e.g. d-spacing or momentum).\n"
"Enter the right signal number for your desired field.");
auto mustBePositive = boost::make_shared<BoundedValidator<int> >();
mustBePositive->setLower(1);
declareProperty(new PropertyWithValue<specid_t>("SpectrumMin", 1, mustBePositive),
"The index number of the first spectrum to read. Only used if\n"
"spectrum_max is set.");
declareProperty(new PropertyWithValue<specid_t>("SpectrumMax", Mantid::EMPTY_INT(), mustBePositive),
"The number of the last spectrum to read. Only used if explicitly\n"
"set.");
}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -323,6 +331,36 @@ void LoadTOFRawNexus::countPixels(const std::string &nexusfilename, const std::s
delete file;
}

/*for (std::vector<uint32_t>::iterator it = pixel_id.begin(); it != pixel_id.end();)
{
detid_t pixelID = *it;
specid_t wi = static_cast<specid_t>((*id_to_wi)[pixelID]);
// spectrum is just wi+1
if (wi+1 < m_spec_min || wi+1 > m_spec_max) pixel_id.erase(it);
else ++it;
}*/
// Function object for remove_if STL algorithm
namespace
{
//Check the numbers supplied are not in the range and erase the ones that are
struct range_check
{
range_check(specid_t min, specid_t max, detid2index_map id_to_wi) : m_min(min), m_max(max), m_id_to_wi(id_to_wi) {}

bool operator()(specid_t x)
{
specid_t wi = static_cast<specid_t>((m_id_to_wi)[x]);
return (wi+1 < m_min || wi+1 > m_max);
}

private:
specid_t m_min;
specid_t m_max;
detid2index_map m_id_to_wi;
};

}


/** Load a single bank into the workspace
*
Expand Down Expand Up @@ -402,6 +440,15 @@ void LoadTOFRawNexus::loadBank(const std::string &nexusfilename, const std::stri
}
}

if ( m_spec_max != Mantid::EMPTY_INT())
{
range_check out_range(m_spec_min, m_spec_max, *id_to_wi);
std::vector<uint32_t>::iterator newEnd =
std::remove_if (pixel_id.begin(), pixel_id.end(), out_range);
pixel_id.erase(newEnd, pixel_id.end());
numPixels = pixel_id.size();
if (numPixels == 0) { file->close(); m_fileMutex.unlock(); g_log.warning() << "No pixels from " << bankName << std::endl; return; } ;
}
// Load the TOF vector
std::vector<float> tof;
file->readData(m_axisField, tof);
Expand Down Expand Up @@ -442,11 +489,11 @@ void LoadTOFRawNexus::loadBank(const std::string &nexusfilename, const std::stri
}
}

if (data.size() != numBins * numPixels)
/*if (data.size() != numBins * numPixels)
{ file->close(); m_fileMutex.unlock(); g_log.warning() << "Invalid size of '" << m_dataField << "' data in " << bankName << std::endl; return; }
if (hasErrors && (errors.size() != numBins * numPixels))
{ file->close(); m_fileMutex.unlock(); g_log.warning() << "Invalid size of '" << errorsField << "' errors in " << bankName << std::endl; return; }

*/
// Have all the data I need
m_fileMutex.unlock();
file->close();
Expand Down Expand Up @@ -486,7 +533,6 @@ void LoadTOFRawNexus::loadBank(const std::string &nexusfilename, const std::stri
// Done!
}


//-------------------------------------------------------------------------------------------------
/** @return the name of the entry that we will load */
std::string LoadTOFRawNexus::getEntryName(const std::string & filename)
Expand Down Expand Up @@ -525,6 +571,8 @@ void LoadTOFRawNexus::exec()
// The input properties
std::string filename = getPropertyValue("Filename");
signalNo = getProperty("Signal");
m_spec_min = getProperty("SpectrumMin");
m_spec_max = getProperty("SpectrumMax");

// Find the entry name we want.
std::string entry_name = LoadTOFRawNexus::getEntryName(filename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ def _loadData(self, runnumber, extension, filterWall=None, **chunk):
filename = name + extension
# EMPTY_INT() from C++
if chunk:
name += "_%d" % (int(chunk["ChunkNumber"]))
if "ChunkNumber" in chunk:
name += "_%d" % (int(chunk["ChunkNumber"]))
elif "SpectrumMin" in chunk:
name += "_%d" % (1 + int(chunk["SpectrumMin"])/(int(chunk["SpectrumMax"])-int(chunk["SpectrumMin"])))
else:
name += "_%d" % 0

Expand All @@ -254,8 +257,6 @@ def _loadData(self, runnumber, extension, filterWall=None, **chunk):
chunk["FilterByTimeStart"] = filterWall[0]
if filterWall[1] > 0.:
chunk["FilterByTimeStop"] = filterWall[1]
elif extension.endswith("_histo.nxs"):
chunk = {}

wksp = api.Load(Filename=filename, OutputWorkspace=name, **chunk)
if HAVE_MPI:
Expand All @@ -282,6 +283,8 @@ def _focusChunks(self, runnumber, extension, filterWall, calib, filterLogs=["",
for chunk in strategy:
if "ChunkNumber" in chunk:
self.log().information("Working on chunk %d of %d" % (chunk["ChunkNumber"], chunk["TotalChunks"]))
elif "SpectrumMin" in chunk:
self.log().information("Working on spectrums %d through %d" % (chunk["SpectrumMin"], chunk["SpectrumMax"]))
temp = self._loadData(runnumber, extension, filterWall, **chunk)
if self._info is None:
self._info = self._getinfo(temp)
Expand Down

0 comments on commit e45cd4b

Please sign in to comment.