Skip to content

Commit

Permalink
refs #4201 Code fully transformed
Browse files Browse the repository at this point in the history
to separate the Mantid algorithm and the data conversion subalgorithms.
  • Loading branch information
abuts committed Jan 8, 2012
1 parent 355f75e commit 55a8ecd
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 233 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set ( SRC_FILES
src/CompositeImplicitFunction.cpp
src/CompositeImplicitFunctionParser.cpp
src/ConvertToMDEvents.cpp
src/IConvertToMDEventsMethods.cpp
src/DivideMD.cpp
src/EqualToMD.cpp
src/ExponentialMD.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef MANTID_MD_CONVERT2_MDEVENTS
#define MANTID_MD_CONVERT2_MDEVENTS

#include "MantidMDAlgorithms/ConvertToMDEventsMethods.h"
#include "MantidMDAlgorithms/IConvertToMDEventsMethods.h"
#include "MantidMDEvents/MDWSDescription.h"
#include "MantidMDEvents/BoxControllerSettingsAlgorithm.h"

namespace Mantid
Expand Down Expand Up @@ -40,7 +41,6 @@ namespace MDAlgorithms

// vectors of strings are here everywhere
typedef std::vector<std::string> Strings;


/// Convert to MD Events class itself:
class DLLExport ConvertToMDEvents : public MDEvents::BoxControllerSettingsAlgorithm
Expand All @@ -55,13 +55,9 @@ namespace MDAlgorithms
virtual int version() const { return 1;};
/// Algorithm's category for identification
virtual const std::string category() const { return "MDAlgorithms";}

//**> helper functions: To assist with units conversion done by separate class and get access to some important internal states of the algorithm
static std::string getNativeUnitsID(ConvertToMDEvents const *const pHost);
static Kernel::Unit_sptr getAxisUnits(ConvertToMDEvents const *const pHost);
static preprocessed_detectors & getPrepDetectors(ConvertToMDEvents const *const pHost);
static double getEi(ConvertToMDEvents const *const pHost);
static int getEMode(ConvertToMDEvents const *const pHost);
// helper function to obtain some characteristics of the workspace and invoked algorithm
static double getEi(ConvertToMDEvents const *const pHost);
static int getEMode(ConvertToMDEvents const *const pHost);
//**<
private:
void init();
Expand All @@ -75,19 +71,19 @@ namespace MDAlgorithms
Mantid::API::MatrixWorkspace_sptr inWS2D;

/// the variable which keeps preprocessed positions of the detectors if any availible (TODO: should it be a table ws and separate algorithm?);
static preprocessed_detectors det_loc;
static PreprocessedDetectors det_loc;
/// the properties of the requested target MD workpsace:
MDWSDescription TWS;
MDEvents::MDWSDescription TWS;
/// the pointer to class which is responsible for adding data to N-dimensional workspace;
boost::shared_ptr<MDEvents::MDEventWSWrapper> pWSWrapper;
protected: //for testing

//>---> Parts of the identifyTheAlg;
/** function returns the list of the property names, which can be treated as additional dimensions present in current matrix workspace */
void getAddDimensionNames(API::MatrixWorkspace_const_sptr inMatrixWS,std::vector<std::string> &add_dim_names,std::vector<std::string> &add_dim_units)const;
void getAddDimensionNames(API::MatrixWorkspace_const_sptr inMatrixWS,Strings &add_dim_names,Strings &add_dim_units)const;
/** function parses arguments entered by user, and identifies, which subalgorithm should be deployed on WS as function of the input artuments and the WS format */
std::string identifyMatrixAlg(API::MatrixWorkspace_const_sptr inMatrixWS,const std::string &Q_mode_req, const std::string &dE_mode_req,
std::vector<std::string> &out_dim_names,std::vector<std::string> &out_dim_units);
Strings &out_dim_names,Strings &out_dim_units);
//>---> Parts of the identifyMatrixAlg, separated for unit testing:
// identify Q - mode
std::string parseQMode(const std::string &Q_mode_req,const Strings &ws_dim_names,const Strings &ws_dim_units,Strings &out_dim_names,Strings &out_dim_units, int &nQdims);
Expand All @@ -101,7 +97,7 @@ namespace MDAlgorithms
//<---< Parts of the identifyMatrixAlg;
/** identifies the ID of the conversion subalgorithm to run on a workspace */
std::string identifyTheAlg(API::MatrixWorkspace_const_sptr inMatrixWS,const std::string &Q_mode_req, const std::string &dE_mode_req,
const std::vector<std::string> &other_dim_names,MDWSDescription &TargWSDescription);
const Strings &other_dim_names,MDEvents::MDWSDescription &TargWSDescription);
//<---< Parts of the identifyTheAlg;


Expand All @@ -111,7 +107,7 @@ namespace MDAlgorithms
bool is_powder=false)const;

/// map to select an algorithm as function of the key, which describes it
std::map<std::string, IConvertToMDEventMethods *> alg_selector;
std::map<std::string, IConvertToMDEventsMethods *> alg_selector;


// strictly for testing!!!
Expand All @@ -129,20 +125,9 @@ namespace MDAlgorithms
}
private:
//--------------------------------------------------------------------------------------------------
///** generic template to convert to any Dimensions workspace from a histohram workspace */
// template<Q_state Q, AnalMode MODE, CnvrtUnits CONV>
// void processQNDHWS();
///** generic template to convert to any Dimensions workspace from an Event workspace */
// template<Q_state Q, AnalMode MODE, CnvrtUnits CONV>
// void processQNDEWS();

// temporary
template<Q_state Q, AnalMode MODE, CnvrtUnits CONV>
friend class ProcessHistoWS;
template<Q_state Q, AnalMode MODE, CnvrtUnits CONV,XCoordType XTYPE>
friend struct COORD_TRANSFORMER;
/// progress reporter
std::auto_ptr<API::Progress > pProg;


/// helper class to orginize metaloop on various algorithm options
template<Q_state Q,size_t N_ALGORITHMS >
friend class LOOP_ND;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef H_CONVERT_TO_MDEVENTS_COORD_TRANSF
#define H_CONVERT_TO_MDEVENTS_COORD_TRANSF
//
#include "MantidMDAlgorithms/ConvertToMDEvents.h"
#include "MantidMDAlgorithms/IConvertToMDEventsMethods.h"
#include "MantidMDAlgorithms/ConvertToMDEventsUnitsConv.h"
//
namespace Mantid
Expand Down Expand Up @@ -47,7 +47,7 @@ namespace MDAlgorithms
template<Q_state Q,AnalMode MODE,CnvrtUnits CONV,XCoordType Type>
struct COORD_TRANSFORMER
{
COORD_TRANSFORMER(ConvertToMDEvents *){}

/**Template defines common interface to common part of the algorithm, where all variables
* needed within the loop calculated before the loop starts.
*
Expand Down Expand Up @@ -90,7 +90,7 @@ struct COORD_TRANSFORMER
UNUSED_ARG(X); UNUSED_ARG(i); UNUSED_ARG(j); UNUSED_ARG(Coord);throw(Kernel::Exception::NotImplementedError(""));
return false;}

void setUP(ConvertToMDEvents *){};
inline void setUP(IConvertToMDEventsMethods *){};

private:

Expand All @@ -111,14 +111,14 @@ struct COORD_TRANSFORMER<NoQ,MODE,CONV,Type>
inline bool calcGenericVariables(std::vector<coord_t> &Coord, size_t nd)
{
// get optional Y axis which can be used in NoQ-kind of algorithms
pYAxis = dynamic_cast<API::NumericAxis *>(pHost->inWS2D->getAxis(1));
pYAxis = pHost->getPAxis(1);
if(pYAxis){ // two inital properties came from workspace. All are independant; All other dimensions are obtained from properties
if(!pHost->fillAddProperties(Coord,nd,2))return false;
}else{ // only one workspace property availible;
if(!pHost->fillAddProperties(Coord,nd,1))return false;
}
// set up units conversion defined by the host algorithm.
CONV_UNITS_FROM.setUpConversion(this->pHost);
CONV_UNITS_FROM.setUpConversion(this->pHost,"");
return true;
}

Expand All @@ -144,15 +144,16 @@ struct COORD_TRANSFORMER<NoQ,MODE,CONV,Type>
}
// constructor;
COORD_TRANSFORMER(){}
void setUP(ConvertToMDEvents *pConv){

inline void setUP(IConvertToMDEventsMethods *pConv){
pHost = pConv;
}
private:
// the variables used for exchange data between different specific parts of the generic ND algorithm:
// pointer to Y axis of MD workspace
API::NumericAxis *pYAxis;
// pointer to MD workspace convertor
ConvertToMDEvents *pHost;
IConvertToMDEventsMethods *pHost;
// class which would convert units
UNITS_CONVERSION<CONV,Type> CONV_UNITS_FROM;
};
Expand Down Expand Up @@ -187,16 +188,17 @@ struct COORD_TRANSFORMER<modQ,MODE,CONV,Type>
if(!pHost->fillAddProperties(Coord,nd,2))return false;

// energy
Ei = ConvertToMDEvents::getEi(pHost);
Ei = pHost->getEi();
// the wave vector of incident neutrons;
ki=sqrt(Ei/PhysicalConstants::E_mev_toNeutronWavenumberSq);
// get transformation matrix (needed for CrystalAsPoder mode)
rotMat = pHost->getTransfMatrix();
//
CONV_UNITS_FROM.setUpConversion(this->pHost);
CONV_UNITS_FROM.setUpConversion(this->pHost,"DeltaE");

// get pointer to the positions of the detectors
pDet = &(ConvertToMDEvents::getPrepDetectors(pHost).det_dir[0]);
std::vector<Kernel::V3D> const & DetDir = pHost->pPrepDetectors()->getDetDir();
pDet = &DetDir[0];
//
return true;
}
Expand Down Expand Up @@ -238,7 +240,7 @@ struct COORD_TRANSFORMER<modQ,MODE,CONV,Type>
}
// constructor;
COORD_TRANSFORMER(){}
void setUP(ConvertToMDEvents *pConv){
void setUP(IConvertToMDEventsMethods *pConv){
pHost = pConv;
}
private:
Expand All @@ -251,9 +253,9 @@ struct COORD_TRANSFORMER<modQ,MODE,CONV,Type>
// the matrix which transforms the neutron momentums from lablratory to crystall coordinate system.
std::vector<double> rotMat;
//
Kernel::V3D *pDet;
Kernel::V3D const *pDet;
// Calling Mantid algorithm
ConvertToMDEvents *pHost;
IConvertToMDEventsMethods *pHost;
// class that performs untis conversion;
UNITS_CONVERSION<CONV,Type> CONV_UNITS_FROM;
};
Expand All @@ -269,10 +271,11 @@ struct COORD_TRANSFORMER<modQ,Elastic,CONV,Type>
// get transformation matrix (needed for CrystalAsPoder mode)
rotMat = pHost->getTransfMatrix();
//
CONV_UNITS_FROM.setUpConversion(this->pHost);
CONV_UNITS_FROM.setUpConversion(this->pHost,"Momentum");

// get pointer to the positions of the detectors
pDet = ConvertToMDEvents::getPrepDetectors(pHost).pDetDir();
//
std::vector<Kernel::V3D> const & DetDir = pHost->pPrepDetectors()->getDetDir();
pDet = &DetDir[0]; //
return true;
}
//
Expand Down Expand Up @@ -308,7 +311,7 @@ struct COORD_TRANSFORMER<modQ,Elastic,CONV,Type>
}
// constructor;
COORD_TRANSFORMER(){}
void setUP(ConvertToMDEvents *pConv){
void setUP(IConvertToMDEventsMethods *pConv){
pHost = pConv;
}
private:
Expand All @@ -321,9 +324,9 @@ struct COORD_TRANSFORMER<modQ,Elastic,CONV,Type>
// the matrix which transforms the neutron momentums from lablratory to crystall coordinate system.
std::vector<double> rotMat;
//
Kernel::V3D *pDet;
Kernel::V3D const * pDet;
// Calling Mantid algorithm
ConvertToMDEvents *pHost;
IConvertToMDEventsMethods *pHost;
// class that performs untis conversion;
UNITS_CONVERSION<CONV,Type> CONV_UNITS_FROM;
};
Expand All @@ -338,17 +341,17 @@ struct COORD_TRANSFORMER<Q3D,MODE,CONV,Type>
// four inital properties came from workspace and all are interconnnected all additional defined by properties:
if(!pHost->fillAddProperties(Coord,nd,4))return false;
// energy
Ei = ConvertToMDEvents::getEi(pHost);
Ei = pHost->getEi();
// the wave vector of incident neutrons;
ki=sqrt(Ei/PhysicalConstants::E_mev_toNeutronWavenumberSq);
//
rotMat = pHost->getTransfMatrix();
CONV_UNITS_FROM.setUpConversion(this->pHost);
CONV_UNITS_FROM.setUpConversion(this->pHost,"DeltaE");

// get pointer to the positions of the detectors
pDet = &(ConvertToMDEvents::getPrepDetectors(pHost).det_dir[0]);
//
return true;
// get pointer to the positions of the detectors
std::vector<Kernel::V3D> const & DetDir = pHost->pPrepDetectors()->getDetDir();
pDet = &DetDir[0];
return true;
}
//
inline bool calcYDepCoordinates(std::vector<coord_t> &Coord,uint64_t i)
Expand Down Expand Up @@ -382,7 +385,7 @@ struct COORD_TRANSFORMER<Q3D,MODE,CONV,Type>
return true;
}
COORD_TRANSFORMER(){}
void setUP(ConvertToMDEvents *pConv){
void setUP(IConvertToMDEventsMethods *pConv){
pHost = pConv;
}
private:
Expand All @@ -395,9 +398,9 @@ struct COORD_TRANSFORMER<Q3D,MODE,CONV,Type>
// the matrix which transforms the neutron momentums from lablratory to orthogonal crystall coordinate system.
std::vector<double> rotMat;
// pointer to the detectors directions
Kernel::V3D *pDet;
Kernel::V3D const *pDet;
// Calling Mantid algorithm
ConvertToMDEvents *pHost;
IConvertToMDEventsMethods *pHost;
// class that performs untis conversion;
UNITS_CONVERSION<CONV,Type> CONV_UNITS_FROM;
};
Expand All @@ -413,9 +416,9 @@ struct COORD_TRANSFORMER<Q3D,Elastic,CONV,Type>
//
rotMat = pHost->getTransfMatrix();
//
CONV_UNITS_FROM.setUpConversion(this->pHost);
CONV_UNITS_FROM.setUpConversion(this->pHost,"Momentum");
// get pointer to the positions of the detectors
pDet = &(ConvertToMDEvents::getPrepDetectors(pHost).det_dir[0]);
pDet = &(pHost->pPrepDetectors()->det_dir[0]);

return true;
}
Expand Down Expand Up @@ -447,7 +450,7 @@ struct COORD_TRANSFORMER<Q3D,Elastic,CONV,Type>
return true;
}
COORD_TRANSFORMER(){}
void setUP(ConvertToMDEvents *pConv){
void setUP(IConvertToMDEventsMethods *pConv){
pHost = pConv;
}
private:
Expand All @@ -456,9 +459,9 @@ struct COORD_TRANSFORMER<Q3D,Elastic,CONV,Type>
// the matrix which transforms the neutron momentums from lablratory to crystall coordinate system.
std::vector<double> rotMat;
// pointer to the beginning of the array with
Kernel::V3D *pDet;
Kernel::V3D const *pDet;
// pointer to the algoritm, which calls all these transformations
ConvertToMDEvents *pHost;
IConvertToMDEventsMethods *pHost;
// class that performs untis conversion;
UNITS_CONVERSION<CONV,Type> CONV_UNITS_FROM;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Mantid
namespace MDAlgorithms
{

struct preprocessed_detectors{
struct PreprocessedDetectors{
double L1;
Kernel::V3D minDetPosition; // minimal and
Kernel::V3D maxDetPosition; // maxinal position for the detectors
Expand All @@ -51,15 +51,15 @@ struct preprocessed_detectors{
//
bool is_defined(void)const{return det_dir.size()>0;}
bool is_defined(size_t new_size)const{return det_dir.size()==new_size;}
double * pL2(){return &L2[0];}
double * pTwoTheta(){return &TwoTheta[0];}
size_t * iDetIDMap(){return &detIDMap[0];}
Kernel::V3D * pDetDir(){return &det_dir[0];}
std::vector<double>const & getL2()const{return L2;}
std::vector<double>const & getTwoTheta()const{return TwoTheta;}
std::vector<size_t>const & getDetIDMap()const{return detIDMap;}
std::vector<Kernel::V3D>const & getDetDir()const{return det_dir;}
};

/** helper function, does preliminary calculations of the detectors positions to convert results into k-dE space ;
and places the resutls into static cash to be used in subsequent calls to this algorithm */
void DLLExport processDetectorsPositions(const API::MatrixWorkspace_sptr inputWS,preprocessed_detectors &det,Kernel::Logger& convert_log);
void DLLExport processDetectorsPositions(const API::MatrixWorkspace_sptr inputWS,PreprocessedDetectors &det,Kernel::Logger& convert_log);
} // end MDAlgorithms
}
#endif

0 comments on commit 55a8ecd

Please sign in to comment.