Skip to content

Commit

Permalink
Refs #5146 initial source file
Browse files Browse the repository at this point in the history
  • Loading branch information
jmborr committed May 10, 2012
1 parent ddc9afc commit 9ddb15f
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Mantid
{
public:
/// Constructor
LoadSassena();
LoadSassena(): IDataFileChecker(), m_filename(""), GWS(NULL) {};
/// Virtual Destructor
virtual ~LoadSassena();
/// Algorithm's name
Expand Down Expand Up @@ -85,8 +85,6 @@ namespace Mantid
std::string m_filename;
/// Group workspace being filled
API::WorkspaceGroup_const_sptr GWS;
/// Reference to the logger class
static Kernel::Logger& g_log;

}; // class LoadSassena

Expand Down
88 changes: 88 additions & 0 deletions Code/Mantid/Framework/DataHandling/src/LoadSassena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*WIKI*
This algorithm loads a Sassena output file into a group workspace.
It will create a workspace for each scattering intensity and one workspace for the Q-values
*WIKI*/

#include "MantidDataHandling/LoadSassena.h"
#include "MantidAPI/LoadAlgorithmFactory.h"
#include "MantidAPI/FileProperty.h"
#include "MantidDataObjects/Workspace2D.h"
#include "H5Cpp.h"

namespace Mantid
{
namespace DataHandling
{

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(LoadSassena)
//register the algorithm into LoadAlgorithmFactory
DECLARE_LOADALGORITHM(LoadSassena)

/// Sets documentation strings for this algorithm
void LoadSassena::initDocs()
{
this->setWikiSummary("This algorithm loads a Sassena output file into a group workspace.");
this->setOptionalMessage(" Algorithm to load an NXSPE file into a group workspace.");
this->setWikiDescription("This algorithm loads a Sassena output file into a group workspace. It will create a workspace for each scattering intensity and one workspace for the Q-values");
}

/**
* 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 LoadSassena::quickFileCheck(const std::string& filePath,size_t nread, const file_header& header)
{
std::string ext = this->extension(filePath);
// 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 LoadSassena::fileCheck(const std::string &filePath)
{
int confidence(50);
return confidence;
}

/**
* Initialise the algorithm. Declare properties which can be set before execution (input) or
* read from after the execution (output).
*/
void LoadSassena::init()
{
std::vector<std::string> exts; // Specify file extensions which can be associated with an output Sassena file
exts.push_back(".h5");
exts.push_back(".hd5");

// Declare the Filename algorithm property. Mandatory. Sets the path to the file to load.
this->declareProperty(new API::FileProperty("Filename", "", API::FileProperty::Load, exts),"A Sassena file");
// Declare the OutputWorkspace property
this->declareProperty(new API::WorkspaceProperty<>("OutputWorkspace","",Kernel::Direction::Output), "The name of the group workspace to be created.");
}

/**
* Execute the algorithm.
*/
void LoadSassena::exec()
{
this->m_filename = this->getPropertyValue("Filename");
}



} // endof namespace DataHandling
} // endof namespace Mantid

0 comments on commit 9ddb15f

Please sign in to comment.