Skip to content

Commit

Permalink
refs #4201 Added MDWDDescription class
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Jan 8, 2012
1 parent 6e5ca46 commit 355f75e
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,7 @@ namespace MDAlgorithms
};

class ConvertToMDEvents;
/// helper class describes the properties of target MD workspace, which should be obtained as the result of conversion algorithm.
struct MDWSDescription
{
public:
/// constructor
MDWSDescription():n_activated_dimensions(0),emode(-1){};
/// the variable which describes the number of the dimensions, in the target workspace.
/// Calculated from number of input properties and the operations, performed on input workspace;
size_t n_activated_dimensions;
/// conversion mode (see its description below)
int emode;
/// minimal and maximal values for the workspace dimensions:
std::vector<double> dim_min,dim_max;
/// the names for the target workspace dimensions and properties of input MD workspace
std::vector<std::string> dim_names;
/// the units of target workspace dimensions and properties of input MD workspace dimensions
std::vector<std::string> dim_units;
/// the matrix to transform momentums of the workspace into notional target coordinate system
std::vector<double> rotMatrix; // should it be the Quat?
/// helper function checks if min values are less them max values and are consistent between each other
void checkMinMaxNdimConsistent(Mantid::Kernel::Logger& log)const;

};


class IConvertToMDEventMethods
{
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,6 @@ IConvertToMDEventsMethods::fillAddProperties(std::vector<coord_t> &Coord,size_t



/** function verifies the consistency of the min and max dimsnsions values checking if all necessary
* values vere defined and min values are smaller then mav values
*/
void
MDWSDescription::checkMinMaxNdimConsistent(Mantid::Kernel::Logger& g_log)const
{
if(this->dim_min.size()!=this->dim_max.size()||this->dim_min.size()!=this->n_activated_dimensions)
{
g_log.error()<<" number of specified min dimension values: "<<dim_min.size()<<", number of max values: "<<dim_max.size()<<
" and total number of target dimensions: "<<n_activated_dimensions<<" are not consistent\n";
throw(std::invalid_argument("wrong number of dimension limits"));
}

for(size_t i=0; i<this->dim_min.size();i++)
{
if(this->dim_max[i]<=this->dim_min[i])
{
g_log.error()<<" min value "<<dim_min[i]<<" not less then max value"<<dim_max[i]<<" in direction: "<<i<<std::endl;
throw(std::invalid_argument("min limit not smaller then max limit"));
}
}
}

} // endNamespace MDAlgorithms
}
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/MDEvents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set ( SRC_FILES
src/MDBoxIterator.cpp
src/MDEventFactory.cpp
src/MDEventWorkspace.cpp
src/MDWSDescription.cpp
src/MDEventWSWrapper.cpp
src/MDGridBox.cpp
src/MDHistoWorkspace.cpp
Expand Down Expand Up @@ -76,6 +77,7 @@ set ( INC_FILES
inc/MantidMDEvents/MDEvent.h
inc/MantidMDEvents/MDEventFactory.h
inc/MantidMDEvents/MDEventWorkspace.h
inc/MantidMDEvents/MDWSDescription.h
inc/MantidMDEvents/MDEventWSWrapper.h
inc/MantidMDEvents/MDGridBox.h
inc/MantidMDEvents/MDHistoWorkspace.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "MantidMDEvents/MDEvent.h"
#include "MantidMDEvents/MDEventWorkspace.h"
#include "MantidMDEvents/MDWSDescription.h"

namespace Mantid
{
Expand Down Expand Up @@ -52,8 +53,7 @@ class DLLExport MDEventWSWrapper
/// get number of dimensions, for the workspace, currently accessed by the algorithm.
size_t nDimensions()const;
/** function creates empty MD event workspace with given parameters (workspace factory) and stores internal pointer to this workspace for further usage */
API::IMDEventWorkspace_sptr createEmptyMDWS(size_t n_dim, const Strings &targ_dim_names,const Strings &targ_dim_units,
const std::vector<double> &dim_min, const std::vector<double> &dim_max);
API::IMDEventWorkspace_sptr createEmptyMDWS(const MDWSDescription &WSD);
/// add the data to the internal workspace. The workspace has to exist and be initiated
void addMDData(std::vector<float> &sig_err,std::vector<uint16_t> &run_index,std::vector<uint32_t> &det_id,std::vector<coord_t> &Coord,size_t data_size);
/// releases the function pointer of the workspace, stored by the class and makes the class instance undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#ifndef H_MDEVENT_WS_DESCRIPTION
#define H_MDEVENT_WS_DESCRIPTION

#include "MantidMDEvents/MDEvent.h"

namespace Mantid
{
namespace MDEvents
{
/** Lighteweith class wrapping together all parameters, related to MDEventoWorkspace used mainly to reduce number of parameters trasferred between
* an algorithm, creating MD workspace and UI.
*
* Introduced to decrease code bloat in methods and algorithms, which use MDEvents write interface and run-time defined number of dimensions
@date 2011-28-12
Copyright &copy; 2011 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
/// helper class describes the properties of target MD workspace, which should be obtained as the result of conversion algorithm.
struct DLLExport MDWSDescription
{
public:
/// constructor
MDWSDescription():n_dims(0),emode(-1){};
/// mainly test constructor;
MDWSDescription(size_t nDimesnions);
/// the variable which describes the number of the dimensions, in the target workspace.
/// Calculated from number of input properties and the operations, performed on input workspace;
size_t n_dims;
/// conversion mode (see its description below)
int emode;
/// minimal and maximal values for the workspace dimensions:
std::vector<double> dim_min,dim_max;
/// the names for the target workspace dimensions and properties of input MD workspace
std::vector<std::string> dim_names;
/// the units of target workspace dimensions and properties of input MD workspace dimensions
std::vector<std::string> dim_units;
/// the matrix to transform momentums of the workspace into notional target coordinate system
std::vector<double> rotMatrix; // should it be the Quat?
/// helper function checks if min values are less them max values and are consistent between each other
void checkMinMaxNdimConsistent(Mantid::Kernel::Logger& log)const;

};


}
}
#endif
18 changes: 9 additions & 9 deletions Code/Mantid/Framework/MDEvents/src/MDEventWSWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ MDEventWSWrapper::nDimensions()const
}
/** function creates empty MD event workspace with given parameters (workspace factory) and stores internal pointer to this workspace for further usage */
API::IMDEventWorkspace_sptr
MDEventWSWrapper::createEmptyMDWS(size_t n_dim, const Strings &targ_dim_names,const Strings &targ_dim_units,
const std::vector<double> &dim_min, const std::vector<double> &dim_max)
MDEventWSWrapper::createEmptyMDWS(const MDWSDescription &WSD)
{
if(n_dim<1||n_dim>MAX_N_DIM){
g_log.error()<< " Number of requested dimensions: "<<n_dim<<" exceeds the maxumal allowed numed or dimensions: "<<MAX_N_DIM<<std::endl;
if(WSD.n_dims<1||WSD.n_dims>MAX_N_DIM){
g_log.error()<< " Number of requested dimensions: "<<WSD.n_dims<<" exceeds the maxumal allowed numed or dimensions: "<<MAX_N_DIM<<std::endl;
throw(std::invalid_argument(" Numer of requested dimensions exceeds maximal allowed number of dimensions"));
}
this->n_dimensions = (int)n_dim;
this->n_dimensions = (int)WSD.n_dims;
size_t n_dim = WSD.n_dims;

// store input dimensions;
this->dim_min.resize(n_dim);
Expand All @@ -36,10 +36,10 @@ MDEventWSWrapper::createEmptyMDWS(size_t n_dim, const Strings &targ_dim_names,co
this->targ_dim_units.resize(n_dim);

for(size_t i=0;i<n_dim;i++){
this->dim_min[i]=dim_min[i];
this->dim_max[i]=dim_max[i];
this->targ_dim_names[i]= targ_dim_names[i];
this->targ_dim_units[i]= targ_dim_units[i];
this->dim_min[i]=WSD.dim_min[i];
this->dim_max[i]=WSD.dim_max[i];
this->targ_dim_names[i]= WSD.dim_names[i];
this->targ_dim_units[i]= WSD.dim_units[i];
}

wsCreator[n_dimensions]();
Expand Down
39 changes: 39 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDWSDescription.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "MantidMDEvents/MDWSDescription.h"

namespace Mantid
{
namespace MDEvents
{

/** function verifies the consistency of the min and max dimsnsions values checking if all necessary
* values vere defined and min values are smaller then mav values */
void
MDWSDescription::checkMinMaxNdimConsistent(Mantid::Kernel::Logger& g_log)const
{
if(this->dim_min.size()!=this->dim_max.size()||this->dim_min.size()!=this->n_dims)
{
g_log.error()<<" number of specified min dimension values: "<<dim_min.size()<<", number of max values: "<<dim_max.size()<<
" and total number of target dimensions: "<<n_dims<<" are not consistent\n";
throw(std::invalid_argument("wrong number of dimension limits"));
}

for(size_t i=0; i<this->dim_min.size();i++)
{
if(this->dim_max[i]<=this->dim_min[i])
{
g_log.error()<<" min value "<<dim_min[i]<<" not less then max value"<<dim_max[i]<<" in direction: "<<i<<std::endl;
throw(std::invalid_argument("min limit not smaller then max limit"));
}
}
}

MDWSDescription::MDWSDescription(size_t nDimesnions):
n_dims(nDimesnions),
emode(-1),
dim_names(nDimesnions,"mdn"),
dim_units(nDimesnions,"Momentum"),
dim_min(nDimesnions,-1),
dim_max(nDimesnions,1)
{}
}
}
17 changes: 9 additions & 8 deletions Code/Mantid/Framework/MDEvents/test/MDEventWSWrapperTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ class MDEventWSWrapperTest : public CxxTest::TestSuite
void test_buildNewWS()
{
IMDEventWorkspace_sptr pws;
Mantid::MDEvents::Strings targ_dim_names(5,"mdn"),targ_dim_units(5,"Momentum");
std::vector<double> dim_min(5,-1),dim_max(5,1);
MDWSDescription TWS0;
MDWSDescription TWS9(9);
MDWSDescription TWS5(5);


TSM_ASSERT_THROWS("too few dimensions",pws=pWSWrap->createEmptyMDWS(0, targ_dim_names,targ_dim_units,dim_min,dim_max),std::invalid_argument);
TSM_ASSERT_THROWS("too many dimensions",pws=pWSWrap->createEmptyMDWS(9, targ_dim_names,targ_dim_units,dim_min,dim_max),std::invalid_argument);
TSM_ASSERT_THROWS("too few dimensions",pws=pWSWrap->createEmptyMDWS(TWS0),std::invalid_argument);
TSM_ASSERT_THROWS("too many dimensions",pws=pWSWrap->createEmptyMDWS(TWS9),std::invalid_argument);
TSM_ASSERT_THROWS("dimensions have not been defined ",pWSWrap->nDimensions(),std::invalid_argument);

TSM_ASSERT_THROWS_NOTHING("should be fine",pws=pWSWrap->createEmptyMDWS(5, targ_dim_names,targ_dim_units,dim_min,dim_max));
TSM_ASSERT_THROWS_NOTHING("should be fine",pws=pWSWrap->createEmptyMDWS(TWS5));

TSM_ASSERT_EQUALS("should have 5 dimensions",5,pWSWrap->nDimensions());

Expand All @@ -49,10 +51,9 @@ class MDEventWSWrapperTest : public CxxTest::TestSuite

const size_t n_dims(5),n_MDev(2);
Mantid::API::BoxController_sptr bc;
Mantid::MDEvents::Strings targ_dim_names(n_dims,"mdn"),targ_dim_units(n_dims,"Momentum");
std::vector<double> dim_min(n_dims,-1),dim_max(n_dims,1);
MDWSDescription TWSD(5);

TSM_ASSERT_THROWS_NOTHING("should be fine",pWSWrap->createEmptyMDWS(5, targ_dim_names,targ_dim_units,dim_min,dim_max));
TSM_ASSERT_THROWS_NOTHING("should be fine",pWSWrap->createEmptyMDWS(TWSD));

// Build up the box controller
TSM_ASSERT_THROWS_NOTHING("should be fine", bc = pWSWrap->getBoxController());
Expand Down

0 comments on commit 355f75e

Please sign in to comment.