Skip to content

Commit

Permalink
refs #4401 enabling part of the code
Browse files Browse the repository at this point in the history
in hope that should be no errors on Unix
  • Loading branch information
abuts committed Apr 25, 2012
1 parent 2dc8c40 commit cbf50c4
Show file tree
Hide file tree
Showing 10 changed files with 967 additions and 912 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set ( SRC_FILES
src/CompositeImplicitFunctionParser.cpp
src/ConvertToDetectorFaceMD.cpp
# src/ConvertToMDEvents.cpp
# src/ConvertToMDEventsParams.cpp
src/ConvertToMDEventsParams.cpp
# src/ConvertToMDEventsSubalgFactory.cpp
src/IConvertToMDEventsMethods.cpp
src/ConvToMDPreprocDetectors.cpp
Expand Down Expand Up @@ -65,7 +65,7 @@ set ( INC_FILES
# inc/MantidMDAlgorithms/ConvertToMDEvents.h
# inc/MantidMDAlgorithms/ConvertToMDEventsEventWS.h
# inc/MantidMDAlgorithms/ConvertToMDEventsHistoWS.h
# inc/MantidMDAlgorithms/ConvertToMDEventsParams.h
inc/MantidMDAlgorithms/ConvertToMDEventsParams.h
# inc/MantidMDAlgorithms/ConvertToMDEventsSubalgFactory.h
# inc/MantidMDAlgorithms/ConvertToMDEventsTransfInterface.h
# inc/MantidMDAlgorithms/ConvertToMDEventsTransfModQ.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace Mantid
namespace MDAlgorithms
{

struct ConvToMDPreprocDetectors{
double L1; //< source-sample distance;
class DLLExport ConvToMDPreprocDetectors{
public: // temporary
Kernel::V3D minDetPosition; //< minimal and
Kernel::V3D maxDetPosition; //< maxinal position for the detectors
/** shared pointer to the base instrument, which was source of the detector's information. If the instrument changed,
Expand All @@ -56,6 +56,7 @@ struct ConvToMDPreprocDetectors{
std::vector<size_t> detIDMap; //< stores spectra index which corresponds to a valid detector index;
std::vector<size_t> spec2detMap; //< stores detector index which corresponds to the workspace index;
//
public:
bool isDefined(const API::MatrixWorkspace_const_sptr &inputWS)const;
bool isDefined(size_t new_size)const{return det_dir.size()==new_size;}
size_t nDetectors()const{return TwoTheta.size();}
Expand All @@ -64,8 +65,23 @@ struct ConvToMDPreprocDetectors{
std::vector<size_t>const & getDetIDMap()const{return detIDMap;}
std::vector<size_t>const & getSpec2DetMap()const{return spec2detMap;}
std::vector<Kernel::V3D>const & getDetDir()const{return det_dir;}

// function allocates the class detectors memory
void allocDetMemory(size_t nSpectra);
int getEmode()const{return emode;}
double getEfix()const{return efix;}
double getL1()const{return L1;}

void setEmode(int mode);
void setEfix(double Ei);
void setL1(double Dist);
private:
// parameter which describes the conversion mode, used to convert uints using TOF and detector's positions
int emode;
// parameter wjocj describes the energy used to convert uints using TOF and detector's positions
double efix;
// source-sample distance used to convert uints using TOF and detector's positions
double L1;
};

/** helper function, does preliminary calculations of the detectors positions to convert results into k-dE space ;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef H_CONVERT_TO_MDEVENTS_UNITS
#define H_CONVERT_TO_MDEVENTS_UNITS
#include "MantidMDAlgorithms/IConvertToMDEventsMethods.h"
#include "MantidMDAlgorithms/ConvertToMDEventsParams.h"
#include "MantidMDAlgorithms/ConvToMDPreprocDetectors.h"
#include "MantidKernel/Unit.h"
#include "MantidKernel/UnitFactory.h"
/** Set of internal classes used by ConvertToMDEvents algorithm and responsible for Units conversion
Expand Down Expand Up @@ -43,22 +44,22 @@ inline double XValue<ConvertToMD::Centered>(const MantidVec& X,size_t j){return


// general procedure does nothing (non-converts units)
template<ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType Type>
template<ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType TYPE>
struct UnitsConverter
{
/** Set up all variables necessary for units conversion at the beginning of the conversion loop
* @param pHost -- pointer to the Mantid algorithm, which calls this function to obtain the variables,
* relevant to the units conversion
*@param targ_units -- the units we want to convert to
*/
inline void setUpConversion(IConvertToMDEventsMethods const * const pHost,const std::string &targ_units )
{UNUSED_ARG(pHost);UNUSED_ARG(targ_units);}
inline void setUpConversion(const ConvToMDPreprocDetectors &det, const std::string &units_from,const std::string &units_to )
{UNUSED_ARG(det);UNUSED_ARG(units_from);UNUSED_ARG(units_to);}
/// Update all spectra dependednt variables, relevant to conversion in the loop over spectra (detectors)
inline void updateConversion(size_t i){UNUSED_ARG(i);}
/// Convert current X variable into the units requested;
inline double getXConverted(const MantidVec& X,size_t j)const
{
return XValue<Type>(X,j);
return XValue<TYPE>(X,j);
}
/// Convert current X variable into the units requested;
inline double getXConverted(const double& X)const
Expand All @@ -70,15 +71,16 @@ struct UnitsConverter
};

// Fast conversion:
template<ConvertToMD::XCoordType Type>
struct UnitsConverter<ConvertToMD::ConvFast,Type>
template<ConvertToMD::XCoordType TYPE>
struct UnitsConverter<ConvertToMD::ConvFast,TYPE>
{

void setUpConversion(IConvertToMDEventsMethods const *const pHost,const std::string &targ_units)
void setUpConversion(const ConvToMDPreprocDetectors &det, const std::string &units_from,const std::string &units_to)
{
const Kernel::Unit_sptr pThisUnit= pHost->getAxisUnits();
//const Kernel::Unit_sptr pThisUnit= pHost->getAxisUnits();
const Kernel::Unit_sptr pThisUnit= Kernel::UnitFactory::Instance().create(units_from);

if(!pThisUnit->quickConversion(targ_units,factor,power)){
if(!pThisUnit->quickConversion(units_to,factor,power)){
throw(std::logic_error(" should be able to convert units quickly and catch the case of non-conversions before invoking this template"));
}

Expand All @@ -88,7 +90,7 @@ struct UnitsConverter<ConvertToMD::ConvFast,Type>
// convert X coordinate using power series
inline double getXConverted(const MantidVec& X,size_t j)const
{
double x = XValue<Type>(X,j);
double x = XValue<TYPE>(X,j);
return getXConverted(x);
}
// convert X coordinate using power series
Expand All @@ -103,30 +105,30 @@ struct UnitsConverter<ConvertToMD::ConvFast,Type>
};

// Convert from TOF:
template<ConvertToMD::XCoordType Type>
struct UnitsConverter<ConvertToMD::ConvFromTOF,Type>
template<ConvertToMD::XCoordType TYPE>
struct UnitsConverter<ConvertToMD::ConvFromTOF,TYPE>
{

void setUpConversion(IConvertToMDEventsMethods const *const pHost,const std::string &targ_units)
void setUpConversion(const ConvToMDPreprocDetectors &det, const std::string &units_from,const std::string &units_to)
{
// check if axis units are TOF
const Kernel::Unit_sptr pThisUnit= pHost->getAxisUnits();
if(std::string("TOF").compare(pThisUnit->unitID())!=0){
//const Kernel::Unit_sptr pThisUnit= pHost->getAxisUnits();
if(std::string("TOF").compare(units_from)!=0){
throw(std::logic_error(" it whould be only TOF here"));
}
// create units for this subalgorith to convert to
pWSUnit = Kernel::UnitFactory::Instance().create(targ_units);
pWSUnit = Kernel::UnitFactory::Instance().create(units_to);
if(!pWSUnit){
throw(std::logic_error(" can not retrieve workspace unit from the units factory"));
}

// get detectors positions and other data needed for units conversion:
pTwoTheta = &(pHost->pPrepDetectors()->getTwoTheta());
pL2 = &(pHost->pPrepDetectors()->getL2());
L1 = pHost->pPrepDetectors()->L1;
pTwoTheta = &(det.getTwoTheta());
pL2 = &(det.getL2());
L1 = det.getL1();
// get efix
efix = pHost->getEi();
emode = pHost->getEMode();
efix = det.getEfix();
emode = det.getEmode();

};
inline void updateConversion(size_t i)
Expand All @@ -136,7 +138,7 @@ struct UnitsConverter<ConvertToMD::ConvFromTOF,Type>
}
inline double getXConverted(const MantidVec& X,size_t j)const
{
double x = XValue<Type>(X,j);
double x = XValue<TYPE>(X,j);
return getXConverted(x);
}

Expand All @@ -162,31 +164,34 @@ struct UnitsConverter<ConvertToMD::ConvFromTOF,Type>
};

// Convert By TOF:
template<ConvertToMD::XCoordType Type>
struct UnitsConverter<ConvertToMD::ConvByTOF,Type>
template<ConvertToMD::XCoordType TYPE>
struct UnitsConverter<ConvertToMD::ConvByTOF,TYPE>
{

void setUpConversion(IConvertToMDEventsMethods const *const pHost,const std::string &targ_units)
void setUpConversion(const ConvToMDPreprocDetectors &det, const std::string &units_from,const std::string &units_to)
{

pSourceWSUnit= pHost->getAxisUnits();
pSourceWSUnit= Kernel::UnitFactory::Instance().create(units_from);
//pSourceWSUnit= pHost->getAxisUnits();
if(!pSourceWSUnit){
throw(std::logic_error(" can not retrieve source workspace units from the input workspacee"));
}

// get units class, requested by subalgorithm
pWSUnit = Kernel::UnitFactory::Instance().create(targ_units);
pWSUnit = Kernel::UnitFactory::Instance().create(units_to);
if(!pWSUnit){
throw(std::logic_error(" can not retrieve target workspace unit from the units factory"));
}

// get detectors positions and other data needed for units conversion:
pTwoTheta = &(pHost->pPrepDetectors()->getTwoTheta());
pL2 = &(pHost->pPrepDetectors()->getL2());
L1 = pHost->pPrepDetectors()->L1;
pTwoTheta = &(det.getTwoTheta());
pL2 = &(det.getL2());

L1 = det.getL1();
// get efix
efix = pHost->getEi();
emode = pHost->getEMode();
efix = det.getEfix();
emode = det.getEmode();

};

inline void updateConversion(size_t i)
Expand All @@ -198,7 +203,7 @@ struct UnitsConverter<ConvertToMD::ConvByTOF,Type>
//
inline double getXConverted(const MantidVec& X,size_t j)const
{
double x = XValue<Type>(X,j);
double x = XValue<TYPE>(X,j);
return getXConverted(x);
}
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef H_ICONVERT_TO_MDEVENTS_METHODS
#define H_ICONVERT_TO_MDEVENTS_METHODS

#define NO_CONVERSION

#include "MantidKernel/Logger.h"
#include "MantidKernel/TimeSeriesProperty.h"

Expand All @@ -11,13 +9,13 @@
#include "MantidAPI/Progress.h"

#include "MantidAPI/MatrixWorkspace.h"

#include "MantidMDEvents/MDWSDescription.h"
#include "MantidMDEvents/MDEventWSWrapper.h"
#include "MantidMDAlgorithms/ConvToMDPreprocDetectors.h"

#ifdef NO_CONVERSION
#include "MantidMDAlgorithms/ConvToMDPreprocDetectors.h"
#include "MantidMDAlgorithms/ConvertToMDEventsParams.h"
#endif


namespace Mantid
{
Expand Down Expand Up @@ -70,10 +68,10 @@ namespace MDAlgorithms
protected:
/// shalow class which is invoked from processQND procedure and describes the transformation from workspace coordinates to target coordinates
/// presumably will be completely inlined
#ifdef NO_CONVERSION
template<ConvertToMD::QMode Q,ConvertToMD::AnalMode MODE,ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType Type,ConvertToMD::SampleType Sample>
friend struct CoordTransformer;
#endif

// template<ConvertToMD::QMode Q,ConvertToMD::AnalMode MODE,ConvertToMD::CnvrtUnits CONV,ConvertToMD::XCoordType Type,ConvertToMD::SampleType Sample>
// friend struct CoordTransformer;

public:
// constructor;
IConvertToMDEventsMethods();
Expand Down Expand Up @@ -126,23 +124,23 @@ namespace MDAlgorithms

};

#ifdef NO_CONVERSION
/// Templated interface to the workspace conversion algorithm. Every template parameter refers to different conversion possibilities
template<ConvertToMD::InputWSType WS,ConvertToMD::QMode Q, ConvertToMD::AnalMode MODE, ConvertToMD::CnvrtUnits CONV,ConvertToMD::SampleType Sample>
class ConvertToMDEventsWS: public IConvertToMDEventsMethods
{
public:
ConvertToMDEventsWS();
/**templated virtual function to set up conversion*/
size_t setUPConversion(Mantid::API::MatrixWorkspace_sptr , const PreprocessedDetectors &,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;}
};
#endif
//
///// Templated interface to the workspace conversion algorithm. Every template parameter refers to different conversion possibilities
//template<ConvertToMD::InputWSType WS,ConvertToMD::QMode Q, ConvertToMD::AnalMode MODE, ConvertToMD::CnvrtUnits CONV,ConvertToMD::SampleType Sample>
//class ConvertToMDEventsWS: public IConvertToMDEventsMethods
//{
//public:
// ConvertToMDEventsWS();
// /**templated virtual function to set up conversion*/
// size_t setUPConversion(Mantid::API::MatrixWorkspace_sptr , const PreprocessedDetectors &,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;}
//};


} // end namespace MDAlgorithms
} // end namespace Mantid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,34 @@ namespace Mantid
{
namespace MDAlgorithms
{

/// function sets appropriate energy conversion mode to work with detectors and unit conversion
void ConvToMDPreprocDetectors::setEmode(int mode)
{
if(mode<-1||mode>2){
std::string Err="Energy conversion mode has to be between -1 and 2 but trying to set: "+boost::lexical_cast<std::string>(mode);
throw(std::invalid_argument(Err));
}
emode = mode;
}
/// function sets appropriate energy to work with detectors and unit conversion
void ConvToMDPreprocDetectors::setEfix(double Ei)
{
if(Ei<=0){
std::string Err="Input neutron's energy can not be negative but equal: "+boost::lexical_cast<std::string>(Ei);
throw(std::invalid_argument(Err));
}
efix = Ei;
}
/// function sets source-sample distance to work with detectors and unit conversion
void ConvToMDPreprocDetectors::setL1(double Dist)
{
if(Dist<0){
std::string Err="Source-sample distance has to be positive but equal: "+boost::lexical_cast<std::string>(Dist);
throw(std::invalid_argument(Err));
}
L1 = Dist;
}
/// function checks if preprocessed detectors are already calculated
bool ConvToMDPreprocDetectors::isDefined(const API::MatrixWorkspace_const_sptr &inputWS)const
{
if(det_dir.empty())return false;
Expand Down Expand Up @@ -48,8 +75,9 @@ void DLLExport processDetectorsPositions(const API::MatrixWorkspace_sptr inputWS

// L1
try{
det_loc.L1 = source->getDistance(*sample);
convert_log.debug() << "Source-sample distance: " << det_loc.L1 << std::endl;
double L1 = source->getDistance(*sample);
det_loc.setL1(L1);
convert_log.debug() << "Source-sample distance: " << L1 << std::endl;
}catch (Exception::NotFoundError &) {
convert_log.error("Unable to calculate source-sample distance");
throw Exception::InstrumentDefinitionError("Unable to calculate source-sample distance", inputWS->getTitle());
Expand Down Expand Up @@ -114,8 +142,8 @@ void DLLExport processDetectorsPositions(const API::MatrixWorkspace_sptr inputWS
void DLLExport buildFakeDetectorsPositions(const API::MatrixWorkspace_sptr inputWS,ConvToMDPreprocDetectors &det_loc)
{

det_loc.L1 = 1;
double polar(0);
det_loc.setL1(1);
double polar(0);
//
const size_t nHist = inputWS->getNumberHistograms();
det_loc.allocDetMemory(nHist);
Expand Down

0 comments on commit cbf50c4

Please sign in to comment.