Skip to content

Commit

Permalink
More loaders converted. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jun 30, 2013
1 parent c0744c5 commit 7170674
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 218 deletions.
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 @@ -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
70 changes: 21 additions & 49 deletions Code/Mantid/Framework/DataHandling/src/LoadEventPreNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Specific pulse ID and mapping files can be specified if needed; these are guesse

#include "MantidDataHandling/LoadEventPreNexus.h"
#include "MantidAPI/FileFinder.h"
#include "MantidAPI/LoadAlgorithmFactory.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/EventList.h"
#include "MantidKernel/ArrayProperty.h"
Expand Down Expand Up @@ -52,9 +52,8 @@ namespace Mantid
{
namespace DataHandling
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadEventPreNexus)
DECLARE_LOADALGORITHM(LoadEventPreNexus)

DECLARE_FILELOADER_ALGORITHM(LoadEventPreNexus);

/// Sets documentation strings for this algorithm
void LoadEventPreNexus::initDocs()
Expand Down Expand Up @@ -103,7 +102,7 @@ static const double TOF_CONVERSION = .1;
/// Conversion factor between picoColumbs and microAmp*hours
static const double CURRENT_CONVERSION = 1.e-6 / 3600.;

LoadEventPreNexus::LoadEventPreNexus() : Mantid::API::IDataFileChecker(), eventfile(NULL), max_events(0)
LoadEventPreNexus::LoadEventPreNexus() : Mantid::API::IFileLoader(), eventfile(NULL), max_events(0)
{
}

Expand All @@ -113,52 +112,25 @@ LoadEventPreNexus::~LoadEventPreNexus()
}

/**
* Returns the name of the property to be considered as the Filename for Load
* @returns A character string containing the file property's name
*/
const char * LoadEventPreNexus::filePropertyName() const
{
return EVENT_PARAM.c_str();
}

/**
* 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
* 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
*/
bool LoadEventPreNexus::quickFileCheck(const std::string& filePath,size_t,const file_header&)
int LoadEventPreNexus::confidence(Kernel::FileDescriptor & descriptor) const
{
std::string ext = extension(filePath);
return (ext.rfind("dat") != std::string::npos);
}

/**
* 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 LoadEventPreNexus::fileCheck(const std::string& filePath)
{
int confidence(0);
try
{
// If this looks like a binary file where the exact file length is a multiple
// of the DasEvent struct then we're probably okay.
// NOTE: Putting this on the stack gives a segfault on Windows when for some reason
// the BinaryFile destructor is called twice! I'm sure there is something I don't understand there
// but heap allocation seems to work so go for that.
BinaryFile<DasEvent> *event_file = new BinaryFile<DasEvent>(filePath);
confidence = 80;
delete event_file;
}
catch(std::runtime_error &)
{
// This BinaryFile constructor throws if the file does not contain an
// exact multiple of the sizeof(DasEvent) objects.
}
return confidence;
if(descriptor.extension().rfind("dat") == std::string::npos) return 0;

// If this looks like a binary file where the exact file length is a multiple
// of the DasEvent struct then we're probably okay.
const size_t objSize = sizeof(DasEvent);
auto &handle = descriptor.data();
// get the size of the file in bytes and reset the handle back to the beginning
handle.seekg(0, std::ios::end);
const size_t filesize = static_cast<size_t>(handle.tellg());
handle.seekg(0, std::ios::beg);

if (filesize % objSize != 0) return 80;
else return 0;
}


Expand Down
81 changes: 25 additions & 56 deletions Code/Mantid/Framework/DataHandling/src/LoadEventPreNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The ChunkNumber and TotalChunks properties can be used to load only a section of
#include <Poco/Path.h>
#include <boost/timer.hpp>
#include "MantidAPI/FileFinder.h"
#include "MantidAPI/LoadAlgorithmFactory.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/EventList.h"
Expand Down Expand Up @@ -56,9 +56,7 @@ namespace Mantid
{
namespace DataHandling
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadEventPreNexus2)
DECLARE_LOADALGORITHM(LoadEventPreNexus2)
DECLARE_FILELOADER_ALGORITHM(LoadEventPreNexus2);

using namespace Kernel;
using namespace API;
Expand Down Expand Up @@ -190,10 +188,32 @@ static string generateMappingfileName(EventWorkspace_sptr &wksp)
}
//-----------------------------------------------------------------------------

/**
* 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 LoadEventPreNexus2::confidence(Kernel::FileDescriptor & descriptor) const
{
if(descriptor.extension().rfind("dat") == std::string::npos) return 0;

// If this looks like a binary file where the exact file length is a multiple
// of the DasEvent struct then we're probably okay.
const size_t objSize = sizeof(DasEvent);
auto &handle = descriptor.data();
// get the size of the file in bytes and reset the handle back to the beginning
handle.seekg(0, std::ios::end);
const size_t filesize = static_cast<size_t>(handle.tellg());
handle.seekg(0, std::ios::beg);

if (filesize % objSize != 0) return 80;
else return 0;
}

/*
* Constructor
*/
LoadEventPreNexus2::LoadEventPreNexus2() : Mantid::API::IDataFileChecker(), eventfile(NULL), max_events(0)
LoadEventPreNexus2::LoadEventPreNexus2() : Mantid::API::IFileLoader(), eventfile(NULL), max_events(0)
{
}

Expand Down Expand Up @@ -457,57 +477,6 @@ void LoadEventPreNexus2::addToWorkspaceLog(std::string logtitle, size_t mindex){
return;
}

/**
* Returns the name of the property to be considered as the Filename for Load
* @returns A character string containing the file property's name
*/
const char * LoadEventPreNexus2::filePropertyName() const
{
return EVENT_PARAM.c_str();
}

/**
* 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 LoadEventPreNexus2::quickFileCheck(const std::string& filePath,size_t,const file_header&)
{
std::string ext = extension(filePath);
return (ext.rfind("dat") != std::string::npos);
}

/**
* 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 LoadEventPreNexus2::fileCheck(const std::string& filePath)
{
int confidence(0);
try
{
// If this looks like a binary file where the exact file length is a multiple
// of the DasEvent struct then we're probably okay.
// NOTE: Putting this on the stack gives a segfault on Windows when for some reason
// the BinaryFile destructor is called twice! I'm sure there is something I don't understand there
// but heap allocation seems to work so go for that.
BinaryFile<DasEvent> *event_file = new BinaryFile<DasEvent>(filePath);
confidence = 80;
delete event_file;
}
catch(std::runtime_error &)
{
// This BinaryFile constructor throws if the file does not contain an
// exact multiple of the sizeof(DasEvent) objects.
}
return confidence;
}



//-----------------------------------------------------------------------------
/** Load the instrument geometry File
* @param eventfilename :: Used to pick the instrument.
Expand Down

0 comments on commit 7170674

Please sign in to comment.