Skip to content

Commit

Permalink
General file loader conversion. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jul 3, 2013
1 parent d94c7d2 commit 5fa890f
Show file tree
Hide file tree
Showing 30 changed files with 321 additions and 632 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/IFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Mantid
{
public:
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(const Kernel::FileDescriptor & descriptor) const = 0;
virtual int confidence(Kernel::FileDescriptor & descriptor) const = 0;
};

} // namespace API
Expand Down
18 changes: 17 additions & 1 deletion Code/Mantid/Framework/API/src/FileLoaderRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ namespace Mantid
//----------------------------------------------------------------------------------------------
// Anonymous namespace helpers
//----------------------------------------------------------------------------------------------
/// @cond
template<typename T>
struct DescriptorCallback
{
void apply(T &) {} //general one does nothing
};
template<>
struct DescriptorCallback<Kernel::FileDescriptor>
{
void apply(Kernel::FileDescriptor & descriptor) { descriptor.resetStreamToStart(); }
};
///endcond

/**
* @param descriptor A descriptor object describing the file
* @param names The collection of names to search through
Expand All @@ -22,12 +35,13 @@ namespace Mantid
* was found
*/
template<typename DescriptorType, typename FileLoaderType>
const std::string searchForLoader(const DescriptorType & descriptor,const std::set<std::string> & names,
const std::string searchForLoader(DescriptorType & descriptor,const std::set<std::string> & names,
Kernel::Logger & logger)
{
const auto & factory = AlgorithmFactory::Instance();
std::string bestLoader;
int maxConfidence(0);
DescriptorCallback<DescriptorType> callback;

auto iend = names.end();
for(auto it = names.begin(); it != iend; ++it)
Expand All @@ -39,6 +53,8 @@ namespace Mantid
try
{
const int confidence = alg->confidence(descriptor);
callback.apply(descriptor);

if(confidence > maxConfidence) // strictly greater
{
bestLoader = name;
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/IFileLoader.h"

namespace Mantid
{
Expand Down Expand Up @@ -45,7 +44,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 LoadAscii :public API::IDataFileChecker
class DLLExport LoadAscii :public API::IFileLoader
{
public:
/// Default constructor
Expand All @@ -56,11 +55,8 @@ namespace Mantid
virtual int version() const { return 1; }
/// The category
virtual const std::string category() const { return "DataHandling\\Text"; }
/// 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(Kernel::FileDescriptor & descriptor) const;

static bool isAscii(FILE *file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAPI/IDataFileChecker.h"
#include <Poco/DOM/Element.h>
#include <Poco/DOM/Node.h>
//----------------------------------------------------------------------
Expand Down Expand Up @@ -54,7 +53,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 LoadCanSAS1D : public API::IDataFileChecker
class DLLExport LoadCanSAS1D : public API::IFileLoader
{
public:
///default constructor
Expand All @@ -68,10 +67,8 @@ namespace Mantid
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\XML"; }

/// 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(Kernel::FileDescriptor & descriptor) const;

protected:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//----------------------------------------------------------------------
#include "LoadCanSAS1D.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAPI/IDataFileChecker.h"
#include <Poco/DOM/Element.h>
#include <Poco/DOM/Node.h>
//----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef MANTID_DATAHANDLING_LOADDAVEGRP_H_
#define MANTID_DATAHANDLING_LOADDAVEGRP_H_

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidAPI/IFileLoader.h"
#include <fstream>
#include <string>

Expand Down Expand Up @@ -43,7 +42,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 LoadDaveGrp : public API::IDataFileChecker
class DLLExport LoadDaveGrp : public API::IFileLoader
{
public:
/// Constructor
Expand All @@ -56,24 +55,8 @@ class DLLExport LoadDaveGrp : public API::IDataFileChecker
virtual int version() const { return (1); }
/// Algorithm's category for identification
virtual const std::string category() const { return "DataHandling\\Text;Inelastic"; }
/**
* Do a quick check that this file can be loaded
*
* @param filePath the location of and the file to check
* @param nread number of bytes to read
* @param header the first 100 bytes of the file as a union
* @return true if the file can be loaded, otherwise false
*/
virtual bool quickFileCheck(const std::string& filePath, std::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
*
* @param filePath the location of and the file to check
* @return a confidence level indicator between 0 and 100
*/
virtual int fileCheck(const std::string& filePath);
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(Kernel::FileDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <fstream>
#include <string>
#include <vector>
#include "MantidAPI/IDataFileChecker.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidKernel/BinaryFile.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/Events.h"
Expand Down Expand Up @@ -96,7 +96,7 @@ struct Pulse
#pragma pack(pop)


class DLLExport LoadEventPreNexus : public API::IDataFileChecker
class DLLExport LoadEventPreNexus : public API::IFileLoader
{
public:
/// Constructor
Expand All @@ -112,12 +112,8 @@ class DLLExport LoadEventPreNexus : public API::IDataFileChecker
/// Algorithm's aliases
virtual const std::string alias() const { return "LoadEventPreNeXus"; }

/// Returns the name of the property to be considered as the Filename for Load
virtual const char * filePropertyName() const;
/// 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
virtual int confidence(Kernel::FileDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <fstream>
#include <string>
#include <vector>
#include "MantidAPI/IDataFileChecker.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidKernel/BinaryFile.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/Events.h"
Expand Down Expand Up @@ -96,7 +96,7 @@ struct Pulse
#pragma pack(pop)


class DLLExport LoadEventPreNexus2 : public API::IDataFileChecker
class DLLExport LoadEventPreNexus2 : public API::IFileLoader
{
public:
/// Constructor
Expand All @@ -112,12 +112,8 @@ class DLLExport LoadEventPreNexus2 : public API::IDataFileChecker
/// Algorithm's aliases
virtual const std::string alias() const { return "LoadEventPreNeXus2"; }

/// Returns the name of the property to be considered as the Filename for Load
virtual const char * filePropertyName() const;
/// 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
virtual int confidence(Kernel::FileDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
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/IFileLoader.h"

namespace Mantid
{
Expand Down Expand Up @@ -37,7 +36,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 LoadGSS : public API::IDataFileChecker
class DLLExport LoadGSS : public API::IFileLoader
{
public:
/// (Empty) Constructor
Expand All @@ -51,10 +50,8 @@ class DLLExport LoadGSS : public API::IDataFileChecker
/// Algorithm's category for identification
virtual const std::string category() const { return "Diffraction;DataHandling\\Text"; }

/// 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(Kernel::FileDescriptor & descriptor) const;

private:
/// Sets documentation strings for this algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define MANTID_DATAHANDLING_LOADPDFGETNFILE_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidDataObjects/Workspace2D.h"

namespace Mantid
Expand Down Expand Up @@ -33,7 +32,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 LoadPDFgetNFile : public API::IDataFileChecker
class DLLExport LoadPDFgetNFile : public API::IFileLoader
{
public:
LoadPDFgetNFile();
Expand All @@ -55,16 +54,14 @@ namespace DataHandling
void init();
/// Implement abstract Algorithm methods
void exec();
/// 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(Kernel::FileDescriptor & descriptor) const;

/// Parse PDFgetN data file
void parseDataFile(std::string filename);

/// Check whether a string starts from a specified sub-string
bool startsWith(std::string s, std::string header);
bool startsWith(const std::string &s, const std::string & header) const;

/// Parse column name line staring with \#L
void parseColumnNameLine(std::string line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

#include <string>
#include <vector>
#include "MantidAPI/IDataFileChecker.h"
#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidAPI/IEventWorkspace.h"
#include "MantidKernel/System.h"

namespace Mantid
{
Expand Down Expand Up @@ -37,7 +36,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 LoadPreNexus : public API::IDataFileChecker
class DLLExport LoadPreNexus : public API::IFileLoader
{
public:
LoadPreNexus();
Expand All @@ -46,10 +45,9 @@ namespace DataHandling
virtual const std::string name() const;
virtual int version() const;
virtual const std::string category() const;
virtual const char * filePropertyName() const;
void parseRuninfo(const std::string &runinfo, std::string &dataDir, std::vector<std::string> &eventFilenames);
bool quickFileCheck(const std::string& filePath,size_t nread,const file_header& header);
int fileCheck(const std::string& filePath);
/// Returns a confidence value that this algorithm can load a file
virtual int confidence(Kernel::FileDescriptor & descriptor) const;
private:
virtual void initDocs();
void init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Mantid
namespace DataHandling
{
/**
Loads a Quokka data file. Implements API::IDataFileChecker and its file check methods to
Loads a Quokka data file. Implements API::IFileLoader and its file check methods to
recognise a file as the one containing QUOKKA data.
@author Roman Tolchenov, Tessella plc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataHandling/LoadRawHelper.h"
#include "MantidAPI/IDataFileChecker.h"
#include "MantidDataObjects/Workspace2D.h"
#include <climits>

//----------------------------------------------------------------------
Expand Down Expand Up @@ -61,12 +59,6 @@ namespace Mantid
/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\Raw"; }

/// 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);


private:
/// Sets documentation strings for this algorithm
virtual void initDocs();
Expand Down

0 comments on commit 5fa890f

Please sign in to comment.