Skip to content

Commit

Permalink
refs #4201 Added the inheritance from BoxControllerSettingsAlgorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Dec 8, 2011
1 parent 9846f7f commit 1d3dfaf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "MantidAPI/Progress.h"
#include "MantidMDEvents/MDEventWorkspace.h"
#include "MantidMDEvents/MDEvent.h"
#include "MantidMDEvents/BoxControllerSettingsAlgorithm.h"
#include "MantidKernel/PhysicalConstants.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidMDAlgorithms/ConvertToQ3DdE.h"
Expand Down Expand Up @@ -55,7 +56,7 @@ namespace MDAlgorithms
typedef boost::function<void (ConvertToMDEvents*, API::IMDEventWorkspace *const)> pMethod;
// signature for a fucntion, creating n-dimension workspace
//typedef boost::function<API::IMDEventWorkspace_sptr (ConvertToMDEvents*, const std::vector<std::string> &,const std::vector<std::string> &, size_t ,size_t ,size_t )> pWSCreator;
typedef boost::function<API::IMDEventWorkspace_sptr (ConvertToMDEvents*, size_t ,size_t ,size_t )> pWSCreator;
typedef boost::function<API::IMDEventWorkspace_sptr (ConvertToMDEvents* )> pWSCreator;
// vectors of strings are here everywhere
typedef std::vector<std::string> Strings;
/// known sates for algorithms, caluclating Q-values
Expand Down Expand Up @@ -86,7 +87,7 @@ namespace MDAlgorithms
template<Q_state Q, AnalMode MODE, CnvrtUnits CONV>
struct COORD_TRANSFORMER;

class DLLExport ConvertToMDEvents : public API::Algorithm
class DLLExport ConvertToMDEvents : public MDEvents::BoxControllerSettingsAlgorithm
{
public:
ConvertToMDEvents();
Expand Down Expand Up @@ -198,12 +199,12 @@ namespace MDAlgorithms
friend class LOOP_ND;

/** template to build empty MDevent workspace with box controller and other palavra
* @param split_into -- the number of the bin the grid is split into
* @param split_threshold -- number of events in an intermediate cell?
* @param split_maxDepth -- maximal depth of the split tree;
*
* The box controller parameters are obtained from host class BoxControllerSettingsAlgorithm.
*
*/
template<size_t nd>
API::IMDEventWorkspace_sptr createEmptyEventWS(size_t split_into,size_t split_threshold,size_t split_maxDepth);
API::IMDEventWorkspace_sptr createEmptyEventWS(void);

// known momentum analysis mo des ID-s;
std::vector<std::string> Q_modes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct COORD_TRANSFORMER
*
* has to be specialized
*/
inline bool calculate_ND_coordinatese(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord){
inline bool calcMatrixCoord(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord){
UNUSED_ARG(X); UNUSED_ARG(i); UNUSED_ARG(j); UNUSED_ARG(Coord);throw(Kernel::Exception::NotImplementedError(""));
return false;}

Expand Down Expand Up @@ -110,7 +110,7 @@ struct COORD_TRANSFORMER<NoQ,MODE,CONV>
if(Coord[i]<pHost->dim_min[i]||Coord[i]>=pHost->dim_max[i])return false;
}
}

// set up units conversion defined by the host algorithm.
CONV_UNITS_FROM.setUpConversion(this->pHost);
return true;
}
Expand All @@ -125,7 +125,7 @@ struct COORD_TRANSFORMER<NoQ,MODE,CONV>
return true;
}

inline bool calculate_ND_coordinates(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord)
inline bool calcMatrixCoord(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord)
{
UNUSED_ARG(i);
coord_t X_ev = CONV_UNITS_FROM.getXConverted(X,j);
Expand Down Expand Up @@ -203,7 +203,7 @@ struct COORD_TRANSFORMER<modQ,MODE,CONV>
return true;
}
//
inline bool calculate_ND_coordinates(const MantidVec& X,uint64_t i,size_t j,std::vector<coord_t> &Coord)
inline bool calcMatrixCoord(const MantidVec& X,uint64_t i,size_t j,std::vector<coord_t> &Coord)
{
UNUSED_ARG(i);
// convert X-data into energy transfer (if necessary)
Expand All @@ -217,7 +217,7 @@ struct COORD_TRANSFORMER<modQ,MODE,CONV>
double qx = -ex*k_tr;
double qy = -ey*k_tr;
double qz = ki - ez*k_tr;
// transformation matrix has to be here for "Crystal AS Powder mode, further specialization possible if "powder" switch provided in input interface"
// transformation matrix has to be here for "Crystal AS Powder mode, further specialization possible if "powder" switch provided"
double Qx = (rotMat[0]*qx+rotMat[3]*qy+rotMat[6]*qz);
double Qy = (rotMat[1]*qx+rotMat[4]*qy+rotMat[7]*qz);
double Qz = (rotMat[2]*qx+rotMat[5]*qy+rotMat[8]*qz);
Expand Down Expand Up @@ -277,7 +277,7 @@ struct COORD_TRANSFORMER<modQ,Elastic,CONV>
return true;
}
//
inline bool calculate_ND_coordinates(const MantidVec& X,uint64_t i,size_t j,std::vector<coord_t> &Coord)
inline bool calcMatrixCoord(const MantidVec& X,uint64_t i,size_t j,std::vector<coord_t> &Coord)
{
UNUSED_ARG(i);
// convert X-data into momentum transfer (if necessary)
Expand Down Expand Up @@ -352,7 +352,7 @@ struct COORD_TRANSFORMER<Q3D,MODE,CONV>
return true;
}

inline bool calculate_ND_coordinates(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord){
inline bool calcMatrixCoord(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord){
UNUSED_ARG(i);
// convert X-data into energy transfer (if necessary)
coord_t E_tr = CONV_UNITS_FROM.getXConverted(X,j);
Expand Down Expand Up @@ -423,7 +423,7 @@ struct COORD_TRANSFORMER<Q3D,Elastic,CONV>
return true;
}

inline bool calculate_ND_coordinates(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord){
inline bool calcMatrixCoord(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord){
UNUSED_ARG(i);
//convert X from any units it initally is, into momentum transfer (if necessary)
coord_t k0 = CONV_UNITS_FROM.getXConverted(X,j);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ConvertToMDEvents::processQND(API::IMDEventWorkspace *const piWS)
// drop emtpy events
if(Signal[j]<FLT_EPSILON)continue;

if(!trn.calculate_ND_coordinates(X,i,j,Coord))continue; // skip ND outside the range
if(!trn.calcMatrixCoord(X,i,j,Coord))continue; // skip ND outside the range
// ADD RESULTING EVENTS TO THE WORKSPACE
float ErrSq = float(Error[j]*Error[j]);
pWs->addEvent(MDEvents::MDEvent<nd>(float(Signal[j]),ErrSq,runIndex,det_id,&Coord[0]));
Expand Down Expand Up @@ -119,7 +119,7 @@ ConvertToMDEvents::processQND(API::IMDEventWorkspace *const piWS)
/// helper function to create empty MDEventWorkspace with nd dimensions
template<size_t nd>
API::IMDEventWorkspace_sptr
ConvertToMDEvents::createEmptyEventWS(size_t split_into,size_t split_threshold,size_t split_maxDepth)
ConvertToMDEvents::createEmptyEventWS(void)
{

boost::shared_ptr<MDEvents::MDEventWorkspace<MDEvents::MDEvent<nd>,nd> > ws =
Expand All @@ -128,20 +128,19 @@ ConvertToMDEvents::createEmptyEventWS(size_t split_into,size_t split_threshold,s
// Give all the dimensions
for (size_t d=0; d<nd; d++)
{
Geometry::MDHistoDimension * dim = new Geometry::MDHistoDimension(this->targ_dim_names[d], this->targ_dim_names[d], this->targ_dim_units[d], dim_min[d], dim_max[d], 10);
Geometry::MDHistoDimension * dim = new Geometry::MDHistoDimension(this->targ_dim_names[d], this->targ_dim_names[d], this->targ_dim_units[d],
this->dim_min[d], this->dim_max[d], 10);
ws->addDimension(Geometry::MDHistoDimension_sptr(dim));
}
ws->initialize();

// Build up the box controller
Mantid::API::BoxController_sptr bc = ws->getBoxController();
bc->setSplitInto(split_into);
// bc->setSplitThreshold(1500);
bc->setSplitThreshold(split_threshold);
bc->setMaxDepth(split_maxDepth);
// We always want the box to be split (it will reject bad ones)
ws->splitBox();
return ws;
Mantid::API::BoxController_sptr bc = ws->getBoxController();
// Build up the box controller, using the properties in BoxControllerSettingsAlgorithm
this->setBoxController(bc);
// We always want the box to be split (it will reject bad ones)
ws->splitBox();
return ws;
}


Expand Down
35 changes: 16 additions & 19 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,15 @@ ConvertToMDEvents::init()
"An array of the same size as MinValues array"
" Values higher then the specified by the array will be ignored\n"
" If a maximal output workspace ranges is lower, then one of specified, the workspace range will be used instead)" );



declareProperty(new ArrayProperty<double>("u","1,0,0",new ArrayLengthValidator<double>(3)), "first base vector (in hkl) defining fractional coordinate system for neutron diffraction");
declareProperty(new ArrayProperty<double>("v","0,1,0",new ArrayLengthValidator<double>(3)), "second base vector (in hkl) defining fractional coordinate system for neutron diffraction");

// Box controller properties. These are the defaults
this->initBoxControllerProps("5" /*SplitInto*/, 1500 /*SplitThreshold*/, 20 /*MaxRecursionDepth*/);



}


Expand Down Expand Up @@ -390,13 +393,13 @@ void ConvertToMDEvents::exec(){


if(create_new_ws){
// create the event workspace with proper number of dimensions and specified box controller parameters;
spws = ws_creator[n_activated_dimensions](this,5,10,20);
if(!spws){
g_log.error()<<"can not create target event workspace with :"<<n_activated_dimensions<<" dimensions\n";
throw(std::invalid_argument("can not create target workspace"));
spws = ws_creator[n_activated_dimensions](this);
if(!spws){
g_log.error()<<"can not create target event workspace with :"<<n_activated_dimensions<<" dimensions\n";
throw(std::invalid_argument("can not create target workspace"));
}
}
}


// call selected algorithm
pMethod algo = alg_selector[algo_id];
Expand Down Expand Up @@ -800,6 +803,7 @@ class LOOP_ND{
std::string Key = pH->Q_modes[Q]+pH->dE_modes[MODE]+pH->ConvModes[CONV]+num.str();

pH->alg_selector.insert(std::pair<std::string,pMethod>(Key,&ConvertToMDEvents::processQND<i,Q,MODE,CONV>));
pH->ws_creator.insert(std::pair<size_t,pWSCreator>(i,&ConvertToMDEvents::createEmptyEventWS<i>));
}
};
template< Q_state Q, AnalMode MODE, CnvrtUnits CONV >
Expand All @@ -810,12 +814,14 @@ class LOOP_ND<2,Q,MODE,CONV>{
std::stringstream num;
num << 2;
std::string Key = pH->Q_modes[Q]+pH->dE_modes[MODE]+pH->ConvModes[CONV]+num.str();

pH->alg_selector.insert(std::pair<std::string,pMethod>(Key,
&ConvertToMDEvents::processQND<2,Q,MODE,CONV>));
pH->ws_creator.insert(std::pair<size_t,pWSCreator>(2,&ConvertToMDEvents::createEmptyEventWS<2>));
#ifdef _DEBUG
std::cout<<" Ending group by instansiating algorithm with ID: "<<Key<<std::endl;
#endif

pH->alg_selector.insert(std::pair<std::string,pMethod>(Key,
&ConvertToMDEvents::processQND<2,Q,MODE,CONV>));
}
};
/** Constructor
Expand Down Expand Up @@ -877,15 +883,6 @@ native_inelastic_unitID("DeltaE")
LOOP_ND<MAX_NDIM,Q3D,Elastic,ConvByTOF>::EXEC(this);


// Workspaces:
// TO DO: Loop on MAX_NDIM
ws_creator.insert(std::pair<size_t,pWSCreator>(2,&ConvertToMDEvents::createEmptyEventWS<2>));
ws_creator.insert(std::pair<size_t,pWSCreator>(3,&ConvertToMDEvents::createEmptyEventWS<3>));
ws_creator.insert(std::pair<size_t,pWSCreator>(4,&ConvertToMDEvents::createEmptyEventWS<4>));
ws_creator.insert(std::pair<size_t,pWSCreator>(5,&ConvertToMDEvents::createEmptyEventWS<5>));
ws_creator.insert(std::pair<size_t,pWSCreator>(6,&ConvertToMDEvents::createEmptyEventWS<6>));
ws_creator.insert(std::pair<size_t,pWSCreator>(7,&ConvertToMDEvents::createEmptyEventWS<7>));
ws_creator.insert(std::pair<size_t,pWSCreator>(8,&ConvertToMDEvents::createEmptyEventWS<8>));
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void testInit(){
TS_ASSERT_THROWS_NOTHING( pAlg->initialize() )
TS_ASSERT( pAlg->isInitialized() )

TSM_ASSERT_EQUALS("algortithm should have 10 propeties",10,(size_t)(pAlg->getProperties().size()));
TSM_ASSERT_EQUALS("algortithm should have 13 propeties",13,(size_t)(pAlg->getProperties().size()));
}
// TEST QMode
void testParseQMode_WrongThrows()
Expand Down

0 comments on commit 1d3dfaf

Please sign in to comment.