Skip to content

Commit

Permalink
refs #4401 Code refactored to separate different parts
Browse files Browse the repository at this point in the history
of the code into different pieces, which are much less connected with each other.
  • Loading branch information
abuts committed Mar 14, 2012
1 parent 1fa3c13 commit 4bd322c
Show file tree
Hide file tree
Showing 11 changed files with 1,229 additions and 1,081 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set ( SRC_FILES
src/CompositeImplicitFunctionParser.cpp
src/ConvertToDetectorFaceMD.cpp
src/ConvertToMDEvents.cpp
src/ConvertToMDEventsParams.cpp
src/DivideMD.cpp
src/EqualToMD.cpp
src/ExponentialMD.cpp
Expand Down Expand Up @@ -61,6 +62,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/CompositeImplicitFunctionParser.h
inc/MantidMDAlgorithms/ConvertToDetectorFaceMD.h
inc/MantidMDAlgorithms/ConvertToMDEvents.h
inc/MantidMDAlgorithms/ConvertToMDEventsParams.h
inc/MantidMDAlgorithms/ConvertToMDEventsCoordTransf.h
inc/MantidMDAlgorithms/ConvertToMDEventsDetInfo.h
inc/MantidMDAlgorithms/ConvertToMDEventsEventWS.h
Expand Down Expand Up @@ -114,6 +116,7 @@ set ( TEST_FILES
test/ConvertToMDEventsCoordTransfTest.h
test/ConvertToMDEventsMethodsTest.h
test/ConvertToMDEventsTest.h
test/ConvertToMDEventsParamsTest.h
test/ConvertToMDEventsUnitsConvTest.h
test/ConvertToQ3DdETest.h
test/DivideMDTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MANTID_MD_CONVERT2_MDEVENTS
#define MANTID_MD_CONVERT2_MDEVENTS


#include "MantidMDAlgorithms/ConvertToMDEventsParams.h"
#include "MantidMDAlgorithms/IConvertToMDEventsMethods.h"
#include "MantidMDEvents/MDWSDescription.h"
#include "MantidMDEvents/BoxControllerSettingsAlgorithm.h"
Expand Down Expand Up @@ -39,8 +40,6 @@ namespace MDAlgorithms
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

// 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 @@ -64,69 +63,28 @@ namespace MDAlgorithms
void exec();
/// Sets documentation strings for this algorithm
virtual void initDocs();
/// pointer to the input workspace;
/// pointer to the input workspace;
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 PreprocessedDetectors det_loc;
static PreprocessedDetectors det_loc;
/// the pointer to class which is responsible for adding data to N-dimensional workspace;
boost::shared_ptr<MDEvents::MDEventWSWrapper> pWSWrapper;
boost::shared_ptr<MDEvents::MDEventWSWrapper> pWSWrapper;
/// progress reporter
std::auto_ptr<API::Progress > pProg;
/// logger -> to provide logging, for MD dataset file operations
static Mantid::Kernel::Logger& convert_log;
//------------------------------------------------------------------------------------------------------------------------------------------
// Internal helper variables
//
/// known momentum analysis mode ID-s (symbolic representation of correspondent enum);
std::vector<std::string> Q_modes;
/// known energy transfer modes ID-s (symbolic representation of correspondent enum)
std::vector<std::string> dE_modes;
/// known conversion modes ID-s (symbolic representation of correspondent enum)
std::vector<std::string> ConvModes;
/// supported input workspace types (names of supported workspace types )
std::vector<std::string> SupportedWS;

/// the ID of the unit, which is used in the expression to converty to QND. All other related elastic units should be converted to this one.
std::string native_elastic_unitID; // currently it is Q
/// the ID of the unit, which is used in the expression to converty to QND. All other related inelastic units should be converted to this one.
std::string native_inelastic_unitID; // currently it is energy transfer (DeltaE)

/** The Units (different for different Q and dE mode), for input workspace, for the selected sub algorihm to work with.
* Any other input workspace units have to be converted into these, and these have to correspond to actual units, defined in workspace */
std::string subalgorithm_units;
ConvertToMDEventsParams ParamParser;
/// string -Key to identify the algorithm -- rather for testing and debugging, though may be reliet upon somewhere by bad practice
std::string algo_id;
// the vector describes default dimension names, specified along the axis if nothing explicitly requested;
std::vector<std::string> default_dim_ID;


/// the properties of the requested target MD workpsace:
MDEvents::MDWSDescription TWS;

protected: //for testing
static Mantid::Kernel::Logger & getLogger();
//>---> 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,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,
Strings &out_dim_IDs,Strings &out_dim_units, bool &is_detector_information_lost);
//>---> 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);
// identify energy transfer mode
std::string parseDEMode(const std::string &Q_MODE_ID,const std::string &dE_mode_req,const Strings &ws_dim_units,Strings &out_dim_names,
Strings &out_dim_units, int &ndE_dims,std::string &natural_units);
// indentify input units conversion mode
std::string parseConvMode(const std::string &Q_MODE_ID,const std::string &natural_units,const Strings &ws_dim_units);
// identify what kind of input workspace is there:
std::string parseWSType(API::MatrixWorkspace_const_sptr inMatrixWS)const;
//<---< 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 Strings &other_dim_names,bool convert_to_hkl,MDEvents::MDWSDescription &TargWSDescription);
//<---< Parts of the identifyTheAlg;



/** function provides the linear representation for the transformation matrix, which translate momentums from laboratory to crystal cartezian
(C)- Busing, Levi 1967 coordinate system */
Expand All @@ -143,20 +101,6 @@ namespace MDAlgorithms

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

// strictly for testing!!!
void setAlgoID(const std::string &newID){
this->algo_id=newID;
}
// strictly for testing!!!
void setAlgoUnits(int emode){
if(emode==0){
this->subalgorithm_units=native_elastic_unitID;
}
if(emode==1||emode==2){
this->subalgorithm_units=native_inelastic_unitID;
}
}
private:
//--------------------------------------------------------------------------------------------------
/// helper class to orginize metaloop instantiating various subalgorithms
Expand All @@ -168,7 +112,7 @@ namespace MDAlgorithms
* sets default values u and v to [1,0,0] and [0,1,0] if not present or any error. */
void checkUVsettings(const std::vector<double> &ut,const std::vector<double> &vt,MDEvents::MDWSDescription &TargWSDescription)const;
};

} // namespace Mantid
} // namespace MDAlgorithms

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#ifndef H_CONVERT2MDEVENTS_PARAMS
#define H_CONVERT2MDEVENTS_PARAMS
#include <vector>
#include <string>
#include "MantidKernel/System.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidMDEvents/MDWSDescription.h"

namespace Mantid
{
namespace MDAlgorithms
{
/** Helper class describes the possible properties of the algorithm, which converts a workspace to MDEventWorkspace
*
* It is used to convert user input and input data into the key, which is responsible for calling appropriate
* subalgorithm, performing actual conversion.
*
* @date 14-03-2012
Copyright &copy; 2010 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>
*/

/// known sates for algorithms, caluclating momentums
enum Q_state{
modQ, //< calculate mod Q
Q3D, //< calculate 3 component of Q in fractional coordinate system.
NoQ, //< no Q transformatiom, just copying values along X axis (may be with units transformation)
NQStates // number of various recognized Q-analysis modes used to terminate Q-state algorithms metalooop.
};
/** known analysis modes, arranged according to emodes
* It is importent to assign enums proper numbers, as direct correspondence between enums and their emodes
* used by the external units conversion algorithms and this algorithm, so the agreement should be the stame */
enum AnalMode{
Elastic = 0, //< int emode = 0; Elastic analysis
Direct = 1, //< emode=1; Direct inelastic analysis mode
Indir = 2, //< emode=2; InDirect inelastic analysis mode
ANY_Mode //< couples with NoQ, means just copying existing data (may be doing units conversion), also used to terminate AnalMode algorithms initiation metaloop
};
/** enum describes if there is need to convert workspace units and different unit conversion modes
* this modes are identified by algorithm from workpace parameters and user input. */
enum CnvrtUnits // here the numbers are specified to enable proper metaloop on conversion
{
ConvertNo, //< no, input workspace has the same units as output workspace or in units used by Q-dE algorithms naturally
ConvFast , //< the input workspace has different units from the requested and fast conversion is possible
ConvByTOF, //< conversion possible via TOF
ConvFromTOF, //< Input workspace units are the TOF
NConvUintsStates // number of various recognized unit conversion modes used to terminate CnvrtUnits algorithms initiation metalooop.
};
enum InputWSType // Algorithm recognizes 2 input workspace types with different interface.
{
Workspace2DType, //< 2D matirix workspace
EventWSType, //< Event worskapce
NInWSTypes
};
// way to treat the X-coorinate in the workspace:
enum XCoordType
{
Histohram, // typical for Matrix workspace -- deploys central average 0.5(X[i]+X[i+1]); other types of averaging are possible if needed
Centered // typical for events
};

/** describes default dimensions ID currently used by multidimensional workspace
*
* DimensionID is the short name which used to retrieve this dimesnion from MD workspace.
* The names themself are defined in constructor
*/
enum defaultDimID
{
modQ_ID, //< the defauld |Q| id for mod Q or powder mode
Q1_ID, //< 1 of 3 dimID in Q3D mode
Q2_ID, //< 2 of 3 dimID in Q3D mode
Q3_ID, //< 3 of 3 dimID in Q3D mode
dE_ID, //< energy transfer ID
nDefaultID //< ID conunter
};

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

/** the structure, which provides helper variables and varions text parameters for the algorithm */
class DLLExport ConvertToMDEventsParams
{

//
/// known momentum analysis mode ID-s (symbolic representation of correspondent enum);
Strings Q_modes;
/// known energy transfer modes ID-s (symbolic representation of correspondent enum)
Strings dE_modes;
/// known conversion modes ID-s (symbolic representation of correspondent enum)
Strings ConvModes;
/// supported input workspace types (names of supported workspace types )
Strings SupportedWS;

/// the ID of the unit, which is used in the expression to converty to QND. All other related elastic units should be converted to this one.
std::string native_elastic_unitID; // currently it is Q
/// the ID of the unit, which is used in the expression to converty to QND. All other related inelastic units should be converted to this one.
std::string native_inelastic_unitID; // currently it is energy transfer (DeltaE)
/** The Units (different for different Q and dE mode), for input workspace, for the selected sub algorihm to work with.
* Any other input workspace units have to be converted into these, and these have to correspond to actual units, defined in workspace */
std::string natural_units;
// the vector describes default dimension names, specified along the axis if no names are explicitly requested;
Strings default_dim_ID;
public:
Strings getQModes()const{return Q_modes;}
Strings getDEModes()const{return dE_modes;}
// constructor
ConvertToMDEventsParams();
//// get the identifier of the correspondent algorithm as function of integer ws ID-s
std::string getAlgoID(Q_state Q,AnalMode Mode,CnvrtUnits Conv,InputWSType WS)const;

//>---> Parts of the identifyMatrixAlg, separated for unit testing:
// indentify input units conversion mode
std::string parseConvMode(const std::string &Q_MODE_ID,const std::string &UnitsToConvert2,const Strings &ws_dim_unit)const;
// 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)const;
// identify energy transfer mode
std::string parseDEMode(const std::string &Q_MODE_ID,const std::string &dE_mode_req,const Strings &ws_dim_units,
Strings &out_dim_IDs,Strings &out_dim_units,int &ndE_dims,std::string &natural_units)const;
// identify what kind of input workspace is there:
std::string parseWSType(API::MatrixWorkspace_const_sptr inMatrixWS)const;
/** 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,Strings &add_dim_names,Strings &add_dim_units)const;
//<---< Parts of the identifyMatrixAlg;
/** 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,
Strings &out_dim_IDs,Strings &out_dim_units, bool &is_detector_information_lost);
/** 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 Strings &other_dim_names,bool convert_to_hkl,size_t maxNdim,MDEvents::MDWSDescription &TargWSDescription);

/// helper function to obtain the eMode from existing algorithm ID;
int getEMode(const std::string &AlgID)const;
/// helper function to obtain energy from input workspace
double getEi(API::MatrixWorkspace_const_sptr inMatrixWS)const;

private:
static Mantid::Kernel::Logger& convert_log;

};

} // end namespace
}

#endif
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef H_ICONVERT_TO_MDEVENTS_METHODS
#define H_ICONVERT_TO_MDEVENTS_METHODS

#include <vector>
#include "MantidKernel/Logger.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidMDAlgorithms/ConvertToMDEventsParams.h"

#include "MantidAPI/NumericAxis.h"
#include "MantidAPI/Progress.h"
Expand Down Expand Up @@ -40,47 +40,6 @@ namespace MDAlgorithms
File/ change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

/// known sates for algorithms, caluclating momentums
enum Q_state{
modQ, //< calculate mod Q
Q3D, //< calculate 3 component of Q in fractional coordinate system.
NoQ, //< no Q transformatiom, just copying values along X axis (may be with units transformation)
NQStates // number of various recognized Q-analysis modes used to terminate Q-state algorithms metalooop.
};
/** known analysis modes, arranged according to emodes
* It is importent to assign enums proper numbers, as direct correspondence between enums and their emodes
* used by the external units conversion algorithms and this algorithm, so the agreement should be the stame */
enum AnalMode{
Elastic = 0, //< int emode = 0; Elastic analysis
Direct = 1, //< emode=1; Direct inelastic analysis mode
Indir = 2, //< emode=2; InDirect inelastic analysis mode
ANY_Mode //< couples with NoQ, means just copying existing data (may be doing units conversion), also used to terminate AnalMode algorithms initiation metaloop
};
/** enum describes if there is need to convert workspace units and different unit conversion modes
* this modes are identified by algorithm from workpace parameters and user input. */
enum CnvrtUnits // here the numbers are specified to enable proper metaloop on conversion
{
ConvertNo, //< no, input workspace has the same units as output workspace or in units used by Q-dE algorithms naturally
ConvFast , //< the input workspace has different units from the requested and fast conversion is possible
ConvByTOF, //< conversion possible via TOF
ConvFromTOF, //< Input workspace units are the TOF
NConvUintsStates // number of various recognized unit conversion modes used to terminate CnvrtUnits algorithms initiation metalooop.
};
enum InputWSType // Algorithm recognizes 2 input workspace types with different interface.
{
Workspace2DType, //< 2D matirix workspace
EventWSType, //< Event worskapce
NInWSTypes
};
// way to treat the X-coorinate in the workspace:
enum XCoordType
{
Histohram, // typical for Matrix workspace -- deploys central average 0.5(X[i]+X[i+1]); other types of averaging are possible if needed
Centered // typical for events
};


class DLLExport IConvertToMDEventsMethods
{
template<Q_state Q,AnalMode MODE,CnvrtUnits CONV,XCoordType Type>
Expand Down

0 comments on commit 4bd322c

Please sign in to comment.