Skip to content

Commit

Permalink
Convert more loaders to new structure. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jun 29, 2013
1 parent 79e76cb commit ff828f6
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define MANTID_DATAHANDLING_LOADLLB_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidAPI/IHDFFileLoader.h"
#include "MantidNexus/NexusClasses.h"

namespace Mantid
Expand Down Expand Up @@ -33,26 +32,24 @@ namespace DataHandling
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport LoadLLB: public API::IDataFileChecker {
class DLLExport LoadLLB: public API::IHDFFileLoader {
public:
LoadLLB();
virtual ~LoadLLB();

virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;
///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
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;

private:
virtual void initDocs();
void init();
void exec();
void setInstrumentName(NeXus::NXEntry& entry);
std::string getInstrumentName(NeXus::NXEntry& entry);
std::string getInstrumentName(NeXus::NXEntry& entry) const;
void initWorkSpace(NeXus::NXEntry&);
void loadTimeDetails(NeXus::NXEntry& entry);
void loadDataIntoTheWorkSpace(NeXus::NXEntry&);
Expand All @@ -71,7 +68,6 @@ class DLLExport LoadLLB: public API::IDataFileChecker {
void runLoadInstrument();

std::vector<std::string> supportedInstruments;
std::string m_nexusInstrumentEntryName;
std::string m_instrumentName;
API::MatrixWorkspace_sptr m_localWorkspace;
size_t m_numberOfTubes; // number of tubes - X
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define MANTID_DATAHANDLING_LOADMCSTASNEXUS_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidAPI/IHDFFileLoader.h"

namespace Mantid
{
Expand Down Expand Up @@ -32,7 +31,7 @@ namespace DataHandling
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport LoadMcStasNexus : public API::IDataFileChecker
class DLLExport LoadMcStasNexus : public API::IHDFFileLoader
{
public:
LoadMcStasNexus();
Expand All @@ -42,10 +41,8 @@ namespace DataHandling
virtual int version() const;
virtual const std::string category() const;

/// do a quick check that this file can be loaded
virtual 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
virtual int fileCheck(const std::string& filePath);
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;

private:
virtual void initDocs();
Expand All @@ -59,4 +56,4 @@ namespace DataHandling
} // namespace DataHandling
} // namespace Mantid

#endif /* MANTID_DATAHANDLING_LOADMCSTASNEXUS_H_ */
#endif /* MANTID_DATAHANDLING_LOADMCSTASNEXUS_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IHDFFileLoader.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidKernel/System.h"

//----------------------------------------------------------------------
Expand Down Expand Up @@ -59,7 +58,7 @@ namespace Mantid
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport LoadMuonNexus : public API::IDataFileChecker
class DLLExport LoadMuonNexus : public API::IHDFFileLoader
{
public:
/// Default constructor
Expand All @@ -73,10 +72,9 @@ namespace Mantid
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\Nexus;Muon"; }

/// do a quick check that this file can be loaded
virtual 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
virtual int fileCheck(const std::string& filePath);
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;

protected:

virtual void runLoadInstrumentFromNexus(DataObjects::Workspace2D_sptr) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ namespace Mantid
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\Nexus;Muon"; }

/// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded
virtual int fileCheck(const std::string& filePath);
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;

protected:
/// Overwrites Algorithm method
void exec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Includes
//----------------------------------------------------------------------
#include "MantidDataHandling/LoadMuonNexus.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidNexus/NexusClasses.h"

namespace Mantid
Expand Down Expand Up @@ -70,8 +69,9 @@ namespace Mantid
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\Nexus;Muon"; }

/// check the structure of the file and return a value between 0 and 100 of how much this file can be loaded
virtual int fileCheck(const std::string& filePath);
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
Expand Down
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"
#include <nexus/NeXusFile.hpp>
Expand Down Expand Up @@ -48,7 +47,7 @@ namespace Mantid
File change history is stored at: <https://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport LoadNexusProcessed : public API::IDataFileChecker
class DLLExport LoadNexusProcessed : public API::IHDFFileLoader
{

public:
Expand All @@ -63,10 +62,8 @@ namespace Mantid
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\Nexus";}

/// do a quick check that this file can be loaded
virtual 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
virtual int fileCheck(const std::string& filePath);
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::HDFDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
71 changes: 22 additions & 49 deletions Code/Mantid/Framework/DataHandling/src/LoadLLB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "MantidDataHandling/LoadLLB.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 <limits>
Expand All @@ -22,10 +22,7 @@ using namespace Kernel;
using namespace API;
using namespace NeXus;

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadLLB)
//register the algorithm into loadalgorithm factory
DECLARE_LOADALGORITHM(LoadLLB)
DECLARE_HDF_FILELOADER_ALGORITHM(LoadLLB);

//----------------------------------------------------------------------------------------------
/** Constructor
Expand Down Expand Up @@ -59,54 +56,31 @@ const std::string LoadLLB::category() const {
return "DataHandling";
}

/**
* 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 LoadLLB::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;
}

//----------------------------------------------------------------------------------------------
/// Sets documentation strings for this algorithm
void LoadLLB::initDocs() {
this->setWikiSummary("Loads LLB nexus file.");
this->setOptionalMessage("Loads LLB nexus file.");
}


bool LoadLLB::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 LoadLLB::fileCheck(const std::string& filePath) {
// Create the root Nexus class
NXRoot root(filePath);
NXEntry entry = root.openFirstEntry();
std::string instrumentName = getInstrumentName(entry);
if (std::find(supportedInstruments.begin(), supportedInstruments.end(),
instrumentName) != supportedInstruments.end()) {
// FOUND
return 80;
}
return 0;
}

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
Expand Down Expand Up @@ -156,7 +130,7 @@ void LoadLLB::setInstrumentName(NeXus::NXEntry& entry) {

}

std::string LoadLLB::getInstrumentName(NeXus::NXEntry& entry) {
std::string LoadLLB::getInstrumentName(NeXus::NXEntry& entry) const {

// format: /entry0/?????/name

Expand All @@ -165,8 +139,7 @@ std::string LoadLLB::getInstrumentName(NeXus::NXEntry& entry) {
std::vector<NXClassInfo> v = entry.groups();
for (auto it = v.begin(); it < v.end(); it++) {
if (it->nxclass == "NXinstrument" || it->nxname == "nxinstrument") {
m_nexusInstrumentEntryName = it->nxname;
std::string insNamePath = m_nexusInstrumentEntryName + "/name";
std::string insNamePath = it->nxname + "/name";
if ( !entry.isValid(insNamePath) )
throw std::runtime_error("Error reading the instrument name: " + insNamePath + " is not a valid path!");
instrumentName = entry.getString(insNamePath);
Expand Down

0 comments on commit ff828f6

Please sign in to comment.