Skip to content

Commit

Permalink
refs #4401 explicitly extracted interfaces on biggest subalg classes
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 27, 2012
1 parent 2a88e49 commit 25244bf
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 97 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 @@ -63,6 +63,7 @@ set ( INC_FILES
inc/MantidMDAlgorithms/CompositeImplicitFunctionParser.h
inc/MantidMDAlgorithms/ConvertToDetectorFaceMD.h
inc/MantidMDAlgorithms/ConvertToMDEvents.h
inc/MantidMDAlgorithms/ConvertToMDEventsWSInterface.h
inc/MantidMDAlgorithms/ConvertToMDEventsEventWS.h
inc/MantidMDAlgorithms/ConvertToMDEventsHistoWS.h
inc/MantidMDAlgorithms/ConvertToMDEventsParams.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#include "MantidMDEvents/MDEventWSWrapper.h"
#include "MantidMDEvents/MDEvent.h"

#include "MantidMDAlgorithms/IConvertToMDEventsWS.h"
#include "MantidMDAlgorithms/ConvertToMDEventsWSInterface.h"
#include "MantidMDAlgorithms/ConvToMDPreprocDetectors.h"
//#include "MantidMDAlgorithms/ConvertToMDEventsTransfInterface.h"
// coordinate transformation
#include "MantidMDAlgorithms/ConvertToMDEventsTransfInterface.h"
#include "MantidMDAlgorithms/ConvertToMDEventsTransfNoQ.h"
#include "MantidMDAlgorithms/ConvertToMDEventsTransfModQ.h"
#include "MantidMDAlgorithms/ConvertToMDEventsTransfQ3D.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
#include "MantidMDEvents/MDEventWSWrapper.h"
#include "MantidMDEvents/MDEvent.h"

#include "MantidMDAlgorithms/IConvertToMDEventsWS.h"
#include "MantidMDAlgorithms/ConvertToMDEventsWSInterface.h"

#include "MantidMDAlgorithms/ConvToMDPreprocDetectors.h"
//#include "MantidMDAlgorithms/ConvertToMDEventsTransfInterface.h"
// coordinate transformation
#include "MantidMDAlgorithms/ConvertToMDEventsTransfInterface.h"
#include "MantidMDAlgorithms/ConvertToMDEventsTransfNoQ.h"
#include "MantidMDAlgorithms/ConvertToMDEventsTransfModQ.h"
#include "MantidMDAlgorithms/ConvertToMDEventsTransfQ3D.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


#include "MantidMDAlgorithms/ConvertToMDEventsParams.h"
//#include "MantidMDAlgorithms/IConvertToMDEventsWS.h"
#include "MantidMDAlgorithms/ConvertToMDEventsWSInterface.h"
#include "MantidMDAlgorithms/ConvertToMDEventsHistoWS.h"
#include "MantidMDAlgorithms/ConvertToMDEventsEventWS.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
//
#include "MantidMDAlgorithms/ConvertToMDEventsParams.h"
#include "MantidMDAlgorithms/ConvertToMDEventsUnitsConv.h"


#undef EXCLUDE_TRANSFORMATION_INTERFACE // define interface
#undef EXCLUDE_Q_TRANSFORMATION_NOQ
#undef EXCLUDE_Q_TRANSFORMATION_MODQ
#undef EXCLUDE_Q_TRANSFORMATION_Q3D

// turn different parts of coordinate transformation code on and off.
#define EXCLUDE_TRANSFORMATION_INTERFACE
//#define EXCLUDE_Q_TRANSFORMATION_MODQ
//#define EXCLUDE_Q_TRANSFORMATION_NOQ
//#define EXCLUDE_Q_TRANSFORMATION_Q3D
//
namespace Mantid
{
Expand All @@ -11,7 +23,7 @@ namespace MDAlgorithms
/** Interface to set of internal classes used by ConvertToMDEvents algorithm and responsible for conversion of input workspace
* data into from 1 to 4 output dimensions as function of input parameters;
*
* The class itself should never be instanciated (and this is actually impossible)
* The class itself should never be instantiated (and this is actually impossible unless in debug mode, when adding new code)
*
** The template below describes general ingerface to coordinate transformation:
*
Expand Down Expand Up @@ -46,7 +58,28 @@ 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>
*/
////----------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------
// the module for the momentum transfer wavevector of the scattered neutrons
template<ConvertToMD::AnalMode MODE>
inline double k_trans(double Ei, double E_tr){
UNUSED_ARG(Ei);UNUSED_ARG(E_tr);
throw(Kernel::Exception::NotImplementedError("Generic K_tr should not be implemented"));
}
// Direct Inelastic analysis
template<>
inline double k_trans<ConvertToMD::Direct>(double Ei, double E_tr)
{
return sqrt((Ei-E_tr)/PhysicalConstants::E_mev_toNeutronWavenumberSq);
}
// Indirect Inelastic analysis
template<>
inline double k_trans<ConvertToMD::Indir>(double Ei, double E_tr)
{
return sqrt((Ei+E_tr)/PhysicalConstants::E_mev_toNeutronWavenumberSq);
}

#ifndef EXCLUDE_TRANSFORMATION_INTERFACE
template<ConvertToMD::QMode Q,ConvertToMD::AnalMode MODE,ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType TYPE,ConvertToMD::SampleType Sample>
struct CoordTransformer
{
Expand All @@ -63,10 +96,12 @@ struct CoordTransformer
*
* has to be specialized
*/
bool calcGenericVariables(std::vector<coord_t> &Coord, size_t n_ws_variabes);
//{
// return false;
//}

bool calcGenericVariables(std::vector<coord_t> &Coord, size_t n_ws_variabes)
{
throw(std::logic_error("CoordTransformer::This part of code should not be deployed"));
return false;
}

/** template generalizes the code to calculate Y-variables within the detector's loop of processQND workspace
* @param Coord -- current Y coordinate, placed in the position of the Coordinate vector, specific for particular subalgorithm.
Expand All @@ -76,11 +111,13 @@ struct CoordTransformer
*
* some default implementations possible (e.g mode Q3D,ragged Any_Mode( Direct, indirect,elastic),
*/
//calcYDepCoordinates
bool calcYDepCoordinates(std::vector<coord_t> &Coord,size_t i);
//{
// return false;
// }

bool calcYDepCoordinates(std::vector<coord_t> &Coord,size_t i)
{
throw(std::logic_error("CoordTransformer::This part of code should not be deployed"));
return false;
}

/** template generalizes the code to calculate all remaining coordinates, defined within the inner loop
* @param X -- vector of X workspace values
* @param i -- index of external loop, identifying generic y-coordinate
Expand All @@ -92,10 +129,12 @@ struct CoordTransformer
* has to be specialized
*/
//calcMatrixCoord(X,i,j,Coord)
bool calcMatrixCoord(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord)const;
//{
// return false;
//}

bool calcMatrixCoord(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord)const
{
throw(std::logic_error("CoordTransformer::This part of code should not be deployed"));
return false;
}

/** template generalizes the code to calculate all remaining coordinates, defined within the inner loop
* given that the input described by sinble value only
Expand All @@ -105,48 +144,45 @@ struct CoordTransformer
* @return true -- if all Coord are within the range requested by algorithm. false otherwise
*
* has to be specialized */
bool calc1MatrixCoord(const double & X,std::vector<coord_t> &Coord)const;
//{
// return false;
// }
bool calc1MatrixCoord(const double & X,std::vector<coord_t> &Coord)const
{
throw(std::logic_error("CoordTransformer::This part of code should not be deployed"));
return false;
}
/** template generalizes the conversion of single x-variable using unit conversion as the first step
* @param X -- X workspace value
*
* @param Coord -- subalgorithm specific number of coordinates, placed in the proper position of the Coordinate vector
* @return true -- if all Coord are within the range requested by algorithm. false otherwise
*
* has to be specialized */
bool convertAndCalcMatrixCoord(const double & X,std::vector<coord_t> &Coord)const;
//{
// return false;
// }
bool convertAndCalcMatrixCoord(const double & X,std::vector<coord_t> &Coord)const
{
throw(std::logic_error("CoordTransformer::This part of code should not be generated or deployed"));
return false;
}
/** set up transformation and retrieve the pointer to the incorporating class, which runs the transformation and provides
* necessary variables */
void setUpTransf(IConvertToMDEventsWS *);
//{};

private:

void setUpTransf(IConvertToMDEventsWS *)
{
throw(std::logic_error("CoordTransformer::This part of code should not be deployed"));
}

}; // end CoordTransformer structure:
#else
template<ConvertToMD::QMode Q,ConvertToMD::AnalMode MODE,ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType TYPE,ConvertToMD::SampleType Sample>
struct CoordTransformer
{
bool calcGenericVariables(std::vector<coord_t> &Coord, size_t n_ws_variabes);
bool calcYDepCoordinates(std::vector<coord_t> &Coord,size_t i);
bool calcMatrixCoord(const MantidVec& X,size_t i,size_t j,std::vector<coord_t> &Coord)const;
bool calc1MatrixCoord(const double & X,std::vector<coord_t> &Coord)const;
bool convertAndCalcMatrixCoord(const double & X,std::vector<coord_t> &Coord)const;
void setUpTransf(IConvertToMDEventsWS *);
}; // end CoordTransformer structure:

////----------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------
// the module for the momentum transfer wavevector of the scattered neutrons
template<ConvertToMD::AnalMode MODE>
inline double k_trans(double Ei, double E_tr){
UNUSED_ARG(Ei);UNUSED_ARG(E_tr);
throw(Kernel::Exception::NotImplementedError("Generic K_tr should not be implemented"));
}
// Direct Inelastic analysis
template<>
inline double k_trans<ConvertToMD::Direct>(double Ei, double E_tr){
return sqrt((Ei-E_tr)/PhysicalConstants::E_mev_toNeutronWavenumberSq);
}
// Indirect Inelastic analysis
template<>
inline double k_trans<ConvertToMD::Indir>(double Ei, double E_tr){
return sqrt((Ei+E_tr)/PhysicalConstants::E_mev_toNeutronWavenumberSq);
}
#endif

} // End MDAlgorighms namespace
} // End Mantid namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace Mantid
{
namespace MDAlgorithms
{
//namespace ConvertToMD
//{


/** Set of internal classes used by ConvertToMDEvents algorithm and responsible for conversion of input workspace
* data into from 1 to 4 output dimensions as function of input parameters
Expand Down Expand Up @@ -38,7 +37,7 @@ namespace MDAlgorithms
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/


#ifndef EXCLUDE_Q_TRANSFORMATION_MODQ
// ModQ,Inelastic
template<ConvertToMD::AnalMode MODE, ConvertToMD::CnvrtUnits CONV, ConvertToMD::XCoordType TYPE, ConvertToMD::SampleType SAMPLE>
struct CoordTransformer<ConvertToMD::ModQ,MODE,CONV,TYPE,SAMPLE>
Expand Down Expand Up @@ -233,8 +232,8 @@ struct CoordTransformer<ConvertToMD::ModQ, ConvertToMD::Elastic,CONV,TYPE,SAMPLE
UnitsConverter<CONV,TYPE> CONV_UNITS_FROM;

};
#endif

//}
} // End MDAlgorighms namespace
} // End Mantid namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace MDAlgorithms
// ----> NoQ
// NoQ,ANY_Mode -- no units conversion. This templates just copies the data into MD events and not doing any momentum transformations
//
#ifndef EXCLUDE_Q_TRANSFORMATION_NOQ
template<ConvertToMD::AnalMode MODE,ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType TYPE,ConvertToMD::SampleType SAMPLE>
struct CoordTransformer<ConvertToMD::NoQ,MODE,CONV,TYPE,SAMPLE>
{
Expand Down Expand Up @@ -113,9 +114,9 @@ struct CoordTransformer<ConvertToMD::NoQ,MODE,CONV,TYPE,SAMPLE>
// class which would convert units
UnitsConverter<CONV,TYPE> CONV_UNITS_FROM;
};
#endif
//
//} // namespace ConvertToMD
} // End MDAlgorighms namespace
} // End Mantid namespace

#endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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>
*/

#ifndef EXCLUDE_Q_TRANSFORMATION_Q3D
template<ConvertToMD::AnalMode MODE,ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType TYPE,ConvertToMD::SampleType SAMPLE>
struct CoordTransformer<ConvertToMD::Q3D,MODE,CONV,TYPE,SAMPLE>
{
Expand Down Expand Up @@ -207,7 +207,7 @@ struct CoordTransformer<ConvertToMD::Q3D,ConvertToMD::Elastic,CONV,TYPE,SAMPLE>
UnitsConverter<CONV,TYPE> CONV_UNITS_FROM;

};

#endif
//} // namespace ConvertToMD
} // End MDAlgorighms namespace
} // End Mantid namespace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#ifndef H_CONVERT_TO_MDEVENTS_WSTYPE_INTERFACE
#define H_CONVERT_TO_MDEVENTS_WSTYPE_INTERFACE

#include "MantidMDAlgorithms/ConvertToMDEventsParams.h"
#include "MantidMDAlgorithms/IConvertToMDEventsWS.h"
/** class describes templated inteface to the methods, dealing with workspaces while performing conversion from usual workspaces to MDEventWorkspace
the template below should never be instantiated and us used for debug purposes only
(instantiating it is actually impossible unless in debug mode, when adding new code)
TEMPLATES INSTANSIATION: Users are welcome to specialize its own specific algorithm
*e.g.
template<> class ConvertToMDEventsWS<ModQ,Elastic,ConvertNo,Centered,CrystalType>::public IConvertToMDEventsMethods
{
User specific code for workspace processed to obtain ModQ in elastic mode, without unit conversion,
implementing something user defined for calculating x-coord and coord transformation, which will be invoked
on ws with oriented lattice by writing the templated class and
Overloading the methods:
public:
size_t setUPConversion(Mantid::API::MatrixWorkspace_sptr , const PreprocessedDetectors &,const MDEvents::MDWSDescription &, boost::shared_ptr<MDEvents::MDEventWSWrapper> );
void runConversion(API::Progress *);
private:
virtual size_t conversionChunk(size_t job_ID);
}
*
* @date 26-04-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>
*/
#undef EXCLUDE_CONVERT_WORKSPACE_INTERFACE
#define EXCLUDE_CONVERT_WORKSPACE_INTERFACE

namespace Mantid
{
namespace MDAlgorithms
{

/// Templated interface to the workspace conversion algorithm. Every template parameter refers to different conversion possibilities
#ifndef EXCLUDE_CONVERT_WORKSPACE_INTERFACE

template<ConvertToMD::InputWSType WS,ConvertToMD::QMode Q, ConvertToMD::AnalMode MODE, ConvertToMD::CnvrtUnits CONV,ConvertToMD::SampleType Sample>
class ConvertToMDEventsWS: public IConvertToMDEventsWS
{
public:
ConvertToMDEventsWS(){};
/**templated virtual function to set up conversion*/
size_t setUPConversion(Mantid::API::MatrixWorkspace_sptr , ConvToMDPreprocDetectors &,const MDEvents::MDWSDescription &, boost::shared_ptr<MDEvents::MDEventWSWrapper> )
{return 0;}
/**templated virtual function to run conversion itself*/
void runConversion(API::Progress *){};
private:
/**templated virtual function to run conversion chunk */
virtual size_t conversionChunk(size_t job_ID)
{return 0;}
};

#else
template<ConvertToMD::InputWSType WS,ConvertToMD::QMode Q, ConvertToMD::AnalMode MODE, ConvertToMD::CnvrtUnits CONV,ConvertToMD::SampleType Sample>
class ConvertToMDEventsWS: public IConvertToMDEventsWS
{
public:
ConvertToMDEventsWS(){};
/**templated virtual function to set up conversion*/
size_t setUPConversion(Mantid::API::MatrixWorkspace_sptr , ConvToMDPreprocDetectors &,const MDEvents::MDWSDescription &, boost::shared_ptr<MDEvents::MDEventWSWrapper> );
/**templated virtual function to run conversion itself*/
void runConversion(API::Progress *);
private:
/**templated virtual function to run conversion chunk */
virtual size_t conversionChunk(size_t job_ID);
};
#endif

} // end namespace MDAlgorithms
} // end namespace Mantid
#endif

0 comments on commit 25244bf

Please sign in to comment.