Skip to content

Commit

Permalink
Refs #5146 first version of exec method
Browse files Browse the repository at this point in the history
modified:   CMakeLists.txt
modified:   inc/MantidDataHandling/LoadSassena.h
modified:   src/LoadSassena.cpp
  • Loading branch information
jmborr committed May 16, 2012
1 parent c5fa8d4 commit 1a95cbe
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 15 deletions.
9 changes: 7 additions & 2 deletions Code/Mantid/Framework/DataHandling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set ( SRC_FILES
src/LoadRawBin0.cpp
src/LoadRawHelper.cpp
src/LoadRawSpectrum0.cpp
src/LoadSassena.cpp
src/LoadSNSEventNexus.cpp
src/LoadSNSNexus.cpp
src/LoadSNSspec.cpp
Expand Down Expand Up @@ -185,6 +186,7 @@ set ( INC_FILES
inc/MantidDataHandling/LoadRawBin0.h
inc/MantidDataHandling/LoadRawHelper.h
inc/MantidDataHandling/LoadRawSpectrum0.h
inc/MantidDataHandling/LoadSassena.h
inc/MantidDataHandling/LoadSNSEventNexus.h
inc/MantidDataHandling/LoadSNSNexus.h
inc/MantidDataHandling/LoadSNSspec.h
Expand Down Expand Up @@ -298,6 +300,7 @@ set ( TEST_FILES
test/LoadRawBin0Test.h
test/LoadRawSpectrum0Test.h
test/LoadRawTest.h
# test/LoadSassenaTest.h
test/LoadSNSEventNexusTest.h
test/LoadSNSspecTest.h
test/LoadSPETest.h
Expand Down Expand Up @@ -358,9 +361,11 @@ set_target_properties ( DataHandling PROPERTIES OUTPUT_NAME MantidDataHandling )
# Add to the 'Framework' group in VS
set_property ( TARGET DataHandling PROPERTY FOLDER "MantidFramework" )

include_directories ( inc ../Nexus/inc)
find_package ( HDF5 COMPONENTS HL REQUIRED )

target_link_libraries ( DataHandling ${MANTIDLIBS} Nexus )
include_directories ( inc ../Nexus/inc ${HDF5_INCLUDE_DIRS})

target_link_libraries ( DataHandling ${MANTIDLIBS} Nexus ${HDF5_LIBRARIES})

if ( CXXTEST_FOUND )
include_directories ( ../TestHelpers/inc )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ namespace Mantid
void init(); // Overwrites Algorithm method.
/// Execution code
void exec(); // Overwrites Algorithm method
/// Loads one dataset
void loadSet(const std::string& version, const std::string& setName);

///valid datasets
std::vector<const char*> m_validSets;
std::vector<std::string> m_validSets;
/// name and path of input file
std::string m_filename;

Expand Down
119 changes: 107 additions & 12 deletions Code/Mantid/Framework/DataHandling/src/LoadSassena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,129 @@ void LoadSassena::exec()
// 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));

API::WorkspaceGroup_sptr gws = this->getProperty("OutputWorkspace");
const std::string gwsName = gws->name();

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

//open the HDF5 file
this->m_filename = this->getPropertyValue("Filename");
hid_t h5file = H5Fopen(this->m_filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT);
herr_t status;

//find out the sassena version used
char *cversion = new char[16];
H5LTget_attribute_string( h5file, "/", "sassena_version", cversion );
char cversion[16];
status = H5LTget_attribute_string( h5file, "/", "sassena_version", cversion );
const std::string version(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
*
*/
int rank[3]; //store dimensions
/*load vectors onto a Workspace2D with 3 bins (the three components of the vectors)
* dataX for the origin of the vector (assumed (0,0,0) )
* dataY for the tip of the vector
* dataE is assumed (0,0,0), no errors
*/
std::string setName("qvectors");
status = H5LTget_dataset_ndims( h5file, setName.c_str(), rank );
int nq = rank[0]; //number of q-vectors
DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(API::WorkspaceFactory::Instance().create("Workspace2D", nq, 3, 3));
std::string wsName = gwsName + std::string(".qvectors") + setName;
ws->setTitle(wsName);
ws->getAxis(0)->setUnit("MomemtumTransfer");
ws->setYUnit("MomemtumTransfer");
double* buf = new double[nq*3];
H5LTread_dataset_double(h5file,"qvectors",buf);
MantidVec qvmod; //store the modulus of the vector
double* curr = buf;
for(int iq=0; iq<nq; iq++){
MantidVec& Y = ws->dataY(iq);
Y.assign(curr,curr+3);
qvmod.push_back( sqrt( curr[0]*curr[0] + curr[1]*curr[1] + curr[2]*curr[2] ) );
curr += 3;
}
delete buf;
gws->add(wsName); // Add the named workspace to the group



//iterate over the valid sets
for(std::vector<std::string>::const_iterator it=this->m_validSets.begin(); it!=this->m_validSets.end(); ++it){
setName = *it;
if (H5LTfind_dataset(h5file,setName.c_str())==1)
{
if(setName == "fq" || setName == "fq0" || setName == "fq2")
/* create workspace to store the structure factor.
* First spectrum is the real part, second spectrum is the imaginary part
*/
{
DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(API::WorkspaceFactory::Instance().create("Workspace2D", 2, nq, nq));
wsName = gwsName + std::string(".") + setName;
ws->setTitle(wsName);
ws->dataX(0) = qvmod; //X-axis values are the modulus of the q vector
ws->dataX(1) = qvmod;
double* buf = new double[nq*2];
status = H5LTread_dataset_double(h5file,setName.c_str(),buf);
MantidVec& re = ws->dataY(0);
MantidVec& im = ws->dataY(1);
double* curr = buf;
for(int iq=0; iq<nq; iq++){
re[iq]=curr[0];
im[iq]=curr[1];
curr += 2;
}
delete buf;
gws->add(wsName); // Add the named workspace to the group
}

else if(setName == "fqt")
//Create one workspace to hold the real part and another to hold the imaginary part
{
double dt = 1.0; //time unit increment;
status = H5LTget_dataset_ndims( h5file, setName.c_str(), rank ); //rank = (nq,nt,2)
int nt = rank[1];
double* buf = new double[nq*nt*2];
status = H5LTread_dataset_double(h5file,setName.c_str(),buf);

DataObjects::Workspace2D_sptr wsRe = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(API::WorkspaceFactory::Instance().create("Workspace2D", nq, nt, nt));
const std::string wsReName = gwsName + std::string(".") + setName + std::string(".Re");
wsRe->setTitle(wsReName);
wsRe->getAxis(0)->setUnit("TOF");

DataObjects::Workspace2D_sptr wsIm = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(API::WorkspaceFactory::Instance().create("Workspace2D", nq, nt, nt));
const std::string wsImName = gwsName + std::string(".") + setName + std::string(".Im");
wsIm->setTitle(wsImName);
wsIm->getAxis(0)->setUnit("TOF");

double* curr = buf;
for(int iq=0; iq<nq; iq++)
{
MantidVec& reX = wsRe->dataX(iq);
MantidVec& imX = wsIm->dataX(iq);
MantidVec& reY = wsRe->dataY(iq);
MantidVec& imY = wsIm->dataY(iq);
for(int it=0; it<nt; it++)
{
reX[it] = it*dt;
imX[it] = it*dt;
reY[it] = *curr;
curr ++;
imY[it] = *curr;
curr ++;
}
}
delete buf;
gws->add(wsReName); // Add the named workspace to the group
gws->add(wsImName);
}
}
}

}

} // end of LoadSassena::exec()


} // endof namespace DataHandling
Expand Down

0 comments on commit 1a95cbe

Please sign in to comment.