Skip to content

Commit

Permalink
LoadILL changes. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jun 29, 2013
1 parent d6aabf8 commit bc0d6b3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,9 @@ namespace Mantid
virtual int version() const { return 1;};
virtual const std::string category() const { return "DataHandling\\Nexus";}

// /// do a quick check that this file can be loaded
// bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header);
// /// 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);

/// Returns a confidence value that this algorithm can load a file
int confidence(const Kernel::HDFDescriptor & descriptor) const;


/** Sets whether the pixel counts will be pre-counted.
* @param value :: true if you want to precount. */
void setPrecount(bool value)
Expand Down
29 changes: 11 additions & 18 deletions Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/LoadILL.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
//---------------------------------------------------
// Includes
//---------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidAPI/IHDFFileLoader.h"
#include "MantidNexus/NexusClasses.h"

namespace Mantid {
Expand Down Expand Up @@ -39,14 +38,13 @@ namespace DataHandling {
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport LoadILL: public API::IDataFileChecker {
class DLLExport LoadILL: public API::IHDFFileLoader
{
public:
/// Constructor
LoadILL() :
API::IDataFileChecker(), m_instrumentName(""),
//m_nexusInstrumentEntryName(""),
m_wavelength(0), m_channelWidth(0) {

LoadILL() : API::IHDFFileLoader(), m_instrumentName(""),
m_wavelength(0), m_channelWidth(0)
{
supportedInstruments.push_back("IN4");
supportedInstruments.push_back("IN5");
supportedInstruments.push_back("IN6");
Expand All @@ -67,11 +65,10 @@ namespace DataHandling {
virtual const std::string category() const {
return "DataHandling";
}
///checks the file can be loaded by reading 1st 100 bytes and looking at the file extension.
bool quickFileCheck(const std::string& filePath, size_t nread,
const file_header& header);
/// check the structure of the file and if this file can be loaded return a value between 1 and 100
int fileCheck(const std::string& filePath);

/// Returns a confidence value that this algorithm can load a file
int confidence(const Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
Expand All @@ -81,7 +78,7 @@ namespace DataHandling {
void exec();

void setInstrumentName(NeXus::NXEntry& entry);
std::string getInstrumentName(NeXus::NXEntry& entry);
std::string getInstrumentName(NeXus::NXEntry& entry) const;
void initWorkSpace(NeXus::NXEntry& entry);
void initInstrumentSpecific();
void loadRunDetails(NeXus::NXEntry & entry);
Expand Down Expand Up @@ -122,10 +119,6 @@ namespace DataHandling {

std::vector<std::string> supportedInstruments;

// Nexus instrument entry is of the format /entry0/<XXX>/
// XXX changes from version to version
std::string m_nexusInstrumentEntryName;

};

} // namespace DataHandling
Expand Down
65 changes: 5 additions & 60 deletions Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,66 +909,11 @@ LoadEventNexus::~LoadEventNexus()
delete m_allBanksPulseTimes;
}

///**
// * Do a quick file type check by looking at the first 100 bytes of the file
// * @param filePath :: path of the file including name.
// * @param nread :: no.of bytes read
// * @param header :: The first 100 bytes of the file as a union
// * @return true if the given file is of type which can be loaded by this algorithm
// */
//bool LoadEventNexus::quickFileCheck(const std::string& filePath,size_t nread, const file_header& header)
//{
// std::string ext = this->extension(filePath);
// g_log.debug() << "LoadEventNexus::quickFileCheck() - File extension is: " << ext << std::endl;
//
// // If the extension is nxs then give it a go
// if( ext.compare("nxs") == 0 ) return true;
// // If the extension is h5 then give it a go
// if( ext.compare("h5") == 0 ) return true;
//
//
// // If not then let's see if it is a HDF file by checking for the magic cookie
// if ( nread >= sizeof(int32_t) && (ntohl(header.four_bytes) == g_hdf_cookie) ) return true;
// return false;
//}
//
///**
// * Checks the file by opening it and reading few lines
// * @param filePath :: name of the file inluding its path
// * @return an integer value how much this algorithm can load the file
// */
//int LoadEventNexus::fileCheck(const std::string& filePath)
//{
// int confidence(0);
// typedef std::map<std::string,std::string> string_map_t;
// try
// {
// ::NeXus::File file = ::NeXus::File(filePath);
// string_map_t entries = file.getEntries();
// for(string_map_t::const_iterator it = entries.begin(); it != entries.end(); ++it)
// {
// if ( ((it->first == "entry") || (it->first == "raw_data_1")) && (it->second == "NXentry") )
// {
// file.openGroup(it->first, it->second);
// string_map_t entries2 = file.getEntries();
// for(string_map_t::const_iterator it2 = entries2.begin(); it2 != entries2.end(); ++it2)
// {
// if (it2->second == "NXevent_data")
// {
// confidence = 80;
// }
// }
// file.closeGroup();
// }
// }
// }
// catch(::NeXus::Exception&)
// {
// }
// return confidence;
//}

/// Returns a confidence value that this algorithm can load a file
/**
* Return the confidence with with this algorithm can load the file
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadEventNexus::confidence(const Kernel::HDFDescriptor & descriptor) const
{
int confidence(0);
Expand Down
80 changes: 23 additions & 57 deletions Code/Mantid/Framework/DataHandling/src/LoadILL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
//---------------------------------------------------
#include "MantidDataHandling/LoadILL.h"
#include "MantidAPI/FileProperty.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidAPI/LoadAlgorithmFactory.h"
#include "MantidAPI/Progress.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidGeometry/Instrument.h"

#include "MantidKernel/UnitFactory.h"

#include <limits>
#include <algorithm>
Expand All @@ -30,11 +29,7 @@ namespace Mantid {
using namespace API;
using namespace NeXus;

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadILL)

//register the algorithm into loadalgorithm factory
DECLARE_LOADALGORITHM(LoadILL)
DECLARE_HDF_FILELOADER_ALGORITHM(LoadILL);

/**
* tostring operator to print the contents of NXClassInfo
Expand All @@ -52,6 +47,24 @@ namespace Mantid {
this->setOptionalMessage("Loads a ILL nexus file.");
}

/**
* Return the confidence with with this algorithm can load the file
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadILL::confidence(const Kernel::HDFDescriptor & descriptor) const
{
// Create the root Nexus class
NXRoot root(descriptor.filename());
NXEntry entry = root.openFirstEntry();
if (std::find(supportedInstruments.begin(), supportedInstruments.end(),
getInstrumentName(entry)) != supportedInstruments.end()) {
// FOUND
return 80;
}
return 0;
}

//---------------------------------------------------
// Private member functions
//---------------------------------------------------
Expand Down Expand Up @@ -105,7 +118,7 @@ namespace Mantid {
* @param entry :: The Nexus entry
* @return instrument name
*/
std::string LoadILL::getInstrumentName(NeXus::NXEntry& entry) {
std::string LoadILL::getInstrumentName(NeXus::NXEntry& entry) const {

// Old format: /entry0/IN5/name
// New format: /entry0/instrument/name
Expand All @@ -118,8 +131,7 @@ namespace Mantid {
std::vector<NXClassInfo> v = entry.groups();
for (auto it = v.begin(); it < v.end(); it++) {
if (it->nxclass == "NXinstrument") {
m_nexusInstrumentEntryName = it->nxname;
std::string insNamePath = m_nexusInstrumentEntryName + "/name";
std::string insNamePath = it->nxname + "/name";
instrumentName = entry.getString(insNamePath);
g_log.debug() << "Instrument Name: " << instrumentName
<< " in NxPath: " << insNamePath << std::endl;
Expand Down Expand Up @@ -548,52 +560,6 @@ namespace Mantid {
}
}

/**
* This method does a quick file check by checking the no.of bytes read nread params and header buffer
* @param filePath- path of the file including name.
* @param nread :: no.of bytes read
* @param header :: The first 100 bytes of the file as a union
* @return true if the given file is of type which can be loaded by this algorithm
*/
bool LoadILL::quickFileCheck(const std::string& filePath, size_t nread,
const file_header& header) {
std::string extn = extension(filePath);
bool bnexs(false);
(!extn.compare("nxs") || !extn.compare("nx5")) ? bnexs = true : bnexs =
false;
/*
* HDF files have magic cookie in the first 4 bytes
*/
if (((nread >= sizeof(unsigned))
&& (ntohl(header.four_bytes) == g_hdf_cookie)) || bnexs) {
//hdf
return true;
} else if ((nread >= sizeof(g_hdf5_signature))
&& (!memcmp(header.full_hdr, g_hdf5_signature,
sizeof(g_hdf5_signature)))) {
//hdf5
return true;
}
return false;
}

/**
* Checks the file by opening it and reading few lines
* @param filePath :: name of the file inluding its path
* @return an integer value how much this algorithm can load the file
*/
int LoadILL::fileCheck(const std::string& filePath) {
// Create the root Nexus class
NXRoot root(filePath);
NXEntry entry = root.openFirstEntry();
if (std::find(supportedInstruments.begin(), supportedInstruments.end(),
getInstrumentName(entry)) != supportedInstruments.end()) {
// FOUND
return 80;
}
return 0;
}

/**
* Run the Child Algorithm LoadInstrument.
*/
Expand Down

0 comments on commit bc0d6b3

Please sign in to comment.