Skip to content

Commit

Permalink
Refs #5146 Wrote fileCheck method
Browse files Browse the repository at this point in the history
  • Loading branch information
jmborr committed May 10, 2012
1 parent 542a4de commit bfbf58d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ namespace Mantid
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* Base class to Load a sassena dataset into a MatrixWorkspace
* Derived implementations will load different scattering functions
class LoadDataSet
{
};
class DLLExport LoadSassena : public API::IDataFileChecker
{
public:
Expand Down Expand Up @@ -81,6 +89,8 @@ namespace Mantid
/// Execution code
void exec(); // Overwrites Algorithm method

///valid datasets
std::vector<const char*> m_validSets;
/// name and path of input file
std::string m_filename;
/// Group workspace being filled
Expand Down
44 changes: 32 additions & 12 deletions Code/Mantid/Framework/DataHandling/src/LoadSassena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ It will create a workspace for each scattering intensity and one workspace for t
#include "MantidAPI/LoadAlgorithmFactory.h"
#include "MantidAPI/FileProperty.h"
#include "MantidDataObjects/Workspace2D.h"
#include "H5Cpp.h"
#include <hdf5.h>
#include <hdf5_hl.h>

namespace Mantid
{
Expand Down Expand Up @@ -56,15 +57,8 @@ bool LoadSassena::quickFileCheck(const std::string& filePath,size_t nread, const
int LoadSassena::fileCheck(const std::string &filePath)
{
int confidence(0);
H5::H5File file( filePath, H5::H5F_ACC_RDONLY );

/*
* const H5std_string FILE_NAME( "SDS.h5" );
const H5std_string DATASET_NAME( "IntArray" );
H5File file( FILE_NAME, H5F_ACC_RDONLY );
DataSet dataset = file.openDataSet( DATASET_NAME );
*/
hid_t h5file = H5Fopen(filePath.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
if (H5LTfind_attribute(h5file,"sassena_version")==1) confidence = 99;
return confidence;
}

Expand All @@ -89,12 +83,38 @@ void LoadSassena::init()
*/
void LoadSassena::exec()
{

this->GWS = API::WorkspaceFactory::Instance().create("WorkspaceGroup");
//this->GWS = API::WorkspaceFactory::Instance().create("WorkspaceGroup");
// WorkspaceGroup_sptr wsgroup = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(inputs_orig[i]);
// API::WorkspaceGroup_sptr gws = boost::dynamic_pointer_cast<API::WorkspaceGroup>(rws);
// MatrixWorkspace_sptr outputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(WorkspaceFactory::Instance().create("Workspace2D",numSpectra,energies.size(),numBins));

//populate m_validSets
int nvalidSets = 5;
const char* validSets[] = { "fq", "fq0", "fq2", "fqt", "qvectors" };
this->m_validSets(validSets, validSets+nvalidSets);

this->m_filename = this->getPropertyValue("Filename");
hid_t h5file = H5Fopen(this->m_filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);

//find out the sassena version used
char *cversion = new char[16];
H5LTget_attribute_string( h5file, "/", "sassena_version", cversion );
const std::string version(cversion);
int iversion=boost::lexical_cast<int>(cversion);

//determine which loader protocol to use based on the version
//to be done at a later time, maybe implement a Version class

//iterate over the valid sets
for(std::vector<const char*>::const_iterator it=this->m_validSets.begin(); it!=this->m_validSets.end(); ++it){
if (H5LTfind_dataset(h5file,*it)==1) {
/*an implementation of the abstract base loadSet class
*
*/

}
}

}


Expand Down

0 comments on commit bfbf58d

Please sign in to comment.