Skip to content

Commit

Permalink
refs #9048 nasty conflict with develop
Browse files Browse the repository at this point in the history
Merge branch 'bugfix/9048_smallWinBugs' into develop

Conflicts:
	Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/UnitsConversionHelper.h
	Code/Mantid/Framework/MDEvents/src/MDTransfModQ.cpp
	Code/Mantid/Framework/MDEvents/src/UnitsConversionHelper.cpp
  • Loading branch information
abuts committed Feb 20, 2014
2 parents 7c959d6 + bcb02d5 commit 4399e00
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 83 deletions.
Expand Up @@ -104,7 +104,15 @@ namespace MDAlgorithms
//----------------------------------------------------------------------------------------------
/** Constructor
*/
ConvertToDiffractionMDWorkspace::ConvertToDiffractionMDWorkspace()
ConvertToDiffractionMDWorkspace::ConvertToDiffractionMDWorkspace():
ClearInputWorkspace(false), // imput workspace should be left untouched
OneEventPerBin(false), // it is very expensive otherwise
Append(true), // append data to existing target MD workspace if one exist
LorentzCorrection(false), // not doing Lorents
l1(1.),
beamline_norm(1.),
failedDetectorLookupCount(0),
m_extentsMin(NULL),m_extentsMax(NULL) // will be allocated in exec using nDims
{
}

Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/src/LoadMD.cpp
Expand Up @@ -61,7 +61,9 @@ namespace Mantid
//----------------------------------------------------------------------------------------------
/** Constructor
*/
LoadMD::LoadMD()
LoadMD::LoadMD():
m_numDims(0), // uninitialized incorrect value
m_BoxStructureAndMethadata(true) // this is faster but rarely needed.
{
}

Expand Down
Expand Up @@ -50,7 +50,7 @@ class DLLExport MDTransfModQ: public MDTransfInterface
const std::string transfID()const; // {return "ModQ"; }
/** energy conversion modes supported by this class;
* The class supports three standard energy conversion modes */
std::vector<std::string> getEmodes()const{ return Kernel::DeltaEMode().availableTypes();}
std::vector<std::string> getEmodes()const;

bool calcGenericVariables(std::vector<coord_t> &Coord, size_t nd);
bool calcYDepCoordinates(std::vector<coord_t> &Coord,size_t i);
Expand Down
Expand Up @@ -72,9 +72,15 @@ class DLLExport UnitsConversionHelper
float *m_pEfixedArray;

public:
<<<<<<< HEAD
UnitsConversionHelper():m_pTwoThetas(NULL),m_pL2s(NULL){};
void initialize(const MDWSDescription &targetWSDescr,const std::string &units_to,bool forceViaTOF=false);
void initialize(const std::string &unitsFrom,const std::string &unitsTo,const DataObjects::TableWorkspace_const_sptr &DetWS,int Emode,bool forceViaTOF=false);
=======
UnitsConversionHelper();
void initialize(const MDWSDescription &targetWSDescr,const std::string &units_to);
void initialize(const std::string &unitsFrom,const std::string &unitsTo,const DataObjects::TableWorkspace_const_sptr &DetWS,int Emode);
>>>>>>> bugfix/9048_smallWinBugs
void updateConversion(size_t i);
double convertUnits(double val)const;

Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/MDTransfModQ.cpp
Expand Up @@ -361,8 +361,18 @@ namespace Mantid

/// constructor;
MDTransfModQ::MDTransfModQ():
m_DetDirecton(NULL)//,m_NMatrixDim(-1)
m_Det(NULL),
m_ex(0),m_ey(0),m_ez(1),
m_NMatrixDim(0), //uninitialized
m_Emode(Kernel::DeltaEMode::Undefined), // uninitialized
m_Ki(1.),m_Ei(1.),
m_pEfixedArray(NULL),
m_pDetMasks(NULL)
{}

std::vector<std::string> MDTransfModQ::getEmodes()const
{
return Kernel::DeltaEMode().availableTypes();
}
} // End MDAlgorighms namespace
} // End Mantid namespace
158 changes: 79 additions & 79 deletions Code/Mantid/Framework/MDEvents/src/UnitsConversionHelper.cpp
@@ -1,26 +1,19 @@
#include "MantidMDEvents/UnitsConversionHelper.h"
#include "MantidAPI/NumericAxis.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/Strings.h"
#include <boost/math/special_functions/fpclassify.hpp>



namespace Mantid
{
namespace MDEvents
{

/** establish and initialize proper units conversion from input to output units
@param UnitsFrom -- the ID of the units, which have to be converted from
@param UnitsTo -- the ID of the units to converted to
@param forceViaTOF -- force to perform unit conversion via TOF even if quick conversion exist (by default, false)
@param UnitsFrom -- the ID of the units, which have to be converted from
@param UnitsTo -- the ID of the units to converted to
@param forceViaTOF -- force to perform unit conversion via TOF even if quick conversion exist (by default, false)
@return kind of the initiated conversion, e.g. no conversion (unitsFrom == UnitsTo, fastConversion, convFromTOF or convViaTOF.
See ConvertUnits for the details of this transformations
@return kind of the initiated conversion, e.g. no conversion (unitsFrom == UnitsTo, fastConversion, convFromTOF or convViaTOF.
See ConvertUnits for the details of this transformations
if necessary, also sets up the proper units convertor pointers which do the actual conversion.
*/
if necessary, also sets up the proper units convertor pointers which do the actual conversion.
*/
CnvrtToMD::ConvertUnits UnitsConversionHelper::analyzeUnitsConversion(const std::string &UnitsFrom,const std::string &UnitsTo,bool forceViaTOF)
{
// if units are equal, no conversion is necessary;
Expand Down Expand Up @@ -52,25 +45,25 @@ namespace Mantid
return CnvrtToMD::ConvertFromTOF;
}
else
{ // convert using TOF
m_TargetUnit =Kernel::UnitFactory::Instance().create(UnitsTo);
{ // convert using TOF
m_TargetUnit =Kernel::UnitFactory::Instance().create(UnitsTo);
return CnvrtToMD::ConvertByTOF;
}
}

}
/** Initialize unit conversion helper
* This method is interface to internal initialize method, which actually takes all parameters UnitConversion helper needs from
* targetWSDescr class
* @param targetWSDescr -- the class which contains all information about target workspace
including energy transfer mode, number of dimensions, input workspace etc.
* @param unitsTo -- the ID of the units conversion helper would help to convert to
* @param forceViaTOF -- force to perform unit conversion via TOF even if quick conversion exist (by default, false)
*
*/
* This method is interface to internal initialize method, which actually takes all parameters UnitConversion helper needs from
* targetWSDescr class
* @param targetWSDescr -- the class which contains all information about target workspace
including energy transfer mode, number of dimensions, input workspace etc.
* @param unitsTo -- the ID of the units conversion helper would help to convert to
* @param forceViaTOF -- force to perform unit conversion via TOF even if quick conversion exist (by default, false)
*
*/
void UnitsConversionHelper::initialize(const MDWSDescription &targetWSDescr, const std::string &unitsTo,bool forceViaTOF)
{
{
// obtain input workspace units
API::MatrixWorkspace_const_sptr inWS2D = targetWSDescr.getInWS();
if(!inWS2D)throw(std::runtime_error("UnitsConversionHelper::initialize Should not be able to call this function when workpsace is undefined"));
Expand All @@ -85,7 +78,7 @@ namespace Mantid
if(!(targetWSDescr.m_PreprDetTable))
throw std::runtime_error("MDWSDescription does not have a detector table");

int Emode = (int)targetWSDescr.getEMode();
int Emode = (int)targetWSDescr.getEMode();

this->initialize(unitsFrom,unitsTo,targetWSDescr.m_PreprDetTable,Emode,forceViaTOF);

Expand All @@ -111,12 +104,12 @@ namespace Mantid


/** Method verify if the Units transformation is well defined in the range provided and if not
returns the range where the transformation is well defined.
returns the range where the transformation is well defined.
It is assumed that the points beyond of this range will be filtered in some other way
@param x1 -- the initial point of the units conversion range to verify
@param x2 -- the final point of the units conversion range to verify
*/
It is assumed that the points beyond of this range will be filtered in some other way
@param x1 -- the initial point of the units conversion range to verify
@param x2 -- the final point of the units conversion range to verify
*/
std::pair<double,double> UnitsConversionHelper::getConversionRange(double x1,double x2)const
{
std::pair<double,double> range;
Expand All @@ -125,7 +118,7 @@ namespace Mantid

switch(m_UnitCnvrsn)
{
case(CnvrtToMD::ConvertNo):
case(CnvrtToMD::ConvertNo):
{
return range;
}
Expand All @@ -135,7 +128,7 @@ namespace Mantid
double u1 = this->convertUnits(x1);
double u2 = this->convertUnits(x2);

if (!inRange(trRange,u1) || !inRange(trRange,u2)) // hopefully it is a rare event
if (!inRange(trRange,u1) || !inRange(trRange,u2)) // hopefully it is a rare event
{
double uMin=std::min(u1,u2);
double uMax=std::max(u1,u2);
Expand Down Expand Up @@ -187,7 +180,7 @@ namespace Mantid
if(range.first<source_range.first)range.first=source_range.first;
if(range.second>source_range.second)range.second=source_range.second;
tof1=m_SourceWSUnit->singleToTOF(range.first);
tof2=m_SourceWSUnit->singleToTOF(range.second);
tof2=m_SourceWSUnit->singleToTOF(range.second);
}


Expand Down Expand Up @@ -219,18 +212,18 @@ namespace Mantid

/** Initialize unit conversion helper
* @param unitsFrom -- the ID of the unit, which should be converted from
* @param unitsTo -- the ID of the units conversion helper helps to convert to
* @param DetWS -- table workspace with preprocessed detectors information.
See MDAlgorithms::PreprocessDetectorsToMD for the info what this workspace contains
* @param Emode -- energy transfer mode (integer value used by Kernel::ConvertUnits to indetify energy transfer mode
* @param forceViaTOF -- force to perform unit conversion via TOF even if quick conversion exist (by default, false)
*
*/
* @param unitsFrom -- the ID of the unit, which should be converted from
* @param unitsTo -- the ID of the units conversion helper helps to convert to
* @param DetWS -- table workspace with preprocessed detectors information.
See MDAlgorithms::PreprocessDetectorsToMD for the info what this workspace contains
* @param Emode -- energy transfer mode (integer value used by Kernel::ConvertUnits to indetify energy transfer mode
* @param forceViaTOF -- force to perform unit conversion via TOF even if quick conversion exist (by default, false)
*
*/

void UnitsConversionHelper::initialize(const std::string &unitsFrom,const std::string &unitsTo,const DataObjects::TableWorkspace_const_sptr &DetWS,int Emode,bool forceViaTOF)
{
m_Emode = Emode;
m_Emode = Emode;

if(!DetWS)throw std::runtime_error("UnitsConversionHelper::initialize called with empty preprocessed detectors table");

Expand All @@ -241,21 +234,21 @@ namespace Mantid
m_TargetUnit = Kernel::UnitFactory::Instance().create(unitsTo);
if(!m_TargetUnit)throw(std::runtime_error(" Cannot retrieve target unit from the units factory"));

// get access to all values used by unit conversion.
m_pTwoThetas = &(DetWS->getColVector<double>("TwoTheta"));
m_pL2s = &(DetWS->getColVector<double>("L2"));
// get access to all values used by unit conversion.
m_pTwoThetas = &(DetWS->getColVector<double>("TwoTheta"));
m_pL2s = &(DetWS->getColVector<double>("L2"));

m_L1 = DetWS->getLogs()->getPropertyValueAsType<double>("L1");
m_L1 = DetWS->getLogs()->getPropertyValueAsType<double>("L1");

// get efix
m_Efix = DetWS->getLogs()->getPropertyValueAsType<double>("Ei");
m_Efix = DetWS->getLogs()->getPropertyValueAsType<double>("Ei");
m_pEfixedArray=NULL;
if(m_Emode==(int)Kernel::DeltaEMode::Indirect) m_pEfixedArray = DetWS->getColDataArray<float>("eFixed");

// set up conversion to working state -- in some tests it can be used straight from the beginning.
// set up conversion to working state -- in some tests it can be used straight from the beginning.
m_TwoTheta = (*m_pTwoThetas)[0];
m_L2 = (*m_pL2s)[0];
double Efix = m_Efix;
m_L2 = (*m_pL2s)[0];
double Efix = m_Efix;
if(m_pEfixedArray)Efix=(double)(*(m_pEfixedArray+0));


Expand All @@ -270,25 +263,25 @@ namespace Mantid
{
switch(m_UnitCnvrsn)
{
case(CnvrtToMD::ConvertNo): return;
case(CnvrtToMD::ConvertFast): return;
case(CnvrtToMD::ConvertNo): return;
case(CnvrtToMD::ConvertFast): return;
case(CnvrtToMD::ConvertFromTOF):
{
double delta;
double delta(std::numeric_limits<double>::quiet_NaN());
m_TwoTheta = (*m_pTwoThetas)[i];
m_L2 = (*m_pL2s)[i];
double Efix = m_Efix;
m_L2 = (*m_pL2s)[i];
double Efix = m_Efix;
if(m_pEfixedArray)Efix=(double)(*(m_pEfixedArray+i));

m_TargetUnit->initialize(m_L1,m_L2,m_TwoTheta,m_Emode,Efix,delta);
return;
}
case(CnvrtToMD::ConvertByTOF):
{
double delta;
double delta(std::numeric_limits<double>::quiet_NaN());
m_TwoTheta = (*m_pTwoThetas)[i];
m_L2 = (*m_pL2s)[i];
double Efix = m_Efix;
m_L2 = (*m_pL2s)[i];
double Efix = m_Efix;
if(m_pEfixedArray)Efix=(double)(*(m_pEfixedArray+i));

m_TargetUnit->initialize(m_L1,m_L2,m_TwoTheta,m_Emode,Efix,delta);
Expand All @@ -300,15 +293,15 @@ namespace Mantid

}
}
/** do actual unit conversion from input to oputput data
@param val -- the input value which has to be converted
@return the input value converted into the units requested.
*/
/** do actual unit conversion from input to oputput data
@param val -- the input value which has to be converted
@return the input value converted into the units requested.
*/
double UnitsConversionHelper::convertUnits(double val)const
{
switch(m_UnitCnvrsn)
{
case(CnvrtToMD::ConvertNo):
case(CnvrtToMD::ConvertNo):
{
return val;
}
Expand All @@ -317,13 +310,13 @@ namespace Mantid
return m_Factor*std::pow(val,m_Power);
}
case(CnvrtToMD::ConvertFromTOF):
{
{
return m_TargetUnit->singleFromTOF(val);
}
case(CnvrtToMD::ConvertByTOF):
{
double tof = m_SourceWSUnit->singleToTOF(val);
return m_TargetUnit->singleFromTOF(tof);
return m_TargetUnit->singleFromTOF(tof);
}
default:
throw std::runtime_error("updateConversion: unknown type of conversion requested");
Expand All @@ -334,22 +327,29 @@ namespace Mantid
UnitsConversionHelper::UnitsConversionHelper(const UnitsConversionHelper &another)
{
m_UnitCnvrsn = another.m_UnitCnvrsn;
m_Factor = another.m_Factor;
m_Power = another.m_Power;

m_Emode = another.m_Emode;
m_L1 = another.m_L1;
m_Efix = another.m_Efix;
m_TwoTheta = another.m_TwoTheta;
m_L2 = another.m_L2;
m_Factor = another.m_Factor;
m_Power = another.m_Power;

m_Emode = another.m_Emode;
m_L1 = another.m_L1;
m_Efix = another.m_Efix;
m_TwoTheta = another.m_TwoTheta;
m_L2 = another.m_L2;
m_pTwoThetas = another.m_pTwoThetas;
m_pL2s = another.m_pL2s;
m_pL2s = another.m_pL2s;
m_pEfixedArray=another.m_pEfixedArray;

if(another.m_SourceWSUnit)m_SourceWSUnit = Kernel::Unit_sptr(another.m_SourceWSUnit->clone());
if(another.m_TargetUnit) m_TargetUnit = Kernel::Unit_sptr(another.m_TargetUnit->clone());
if(another.m_SourceWSUnit)m_SourceWSUnit = Kernel::Unit_sptr(another.m_SourceWSUnit->clone());
if(another.m_TargetUnit) m_TargetUnit = Kernel::Unit_sptr(another.m_TargetUnit->clone());
}

UnitsConversionHelper::UnitsConversionHelper():
m_UnitCnvrsn(CnvrtToMD::ConvertNo),
m_Factor(1),m_Power(1),
m_Emode(-1), // undefined
m_L1(1),m_Efix(1),m_TwoTheta(0),m_L2(1),
m_pTwoThetas(NULL),m_pL2s(NULL),m_pEfixedArray(NULL)
{};

} // endNamespace MDEvents
} // endNamespace Mantid

4 changes: 4 additions & 0 deletions Code/Mantid/Framework/TestHelpers/src/MDEventsTestHelper.cpp
Expand Up @@ -255,6 +255,10 @@ namespace MDEventsTestHelper
MDHistoDimension_sptr(new MDHistoDimension("t","t","m", 0.0, max, numBins))
);
}

if (!ws)
throw std::runtime_error(" invalid or unsupported number of dimensions given");

Mantid::MDEvents::MDHistoWorkspace_sptr ws_sptr(ws);
ws_sptr->setTo(signal, errorSquared, numEvents);
ws_sptr->addExperimentInfo(ExperimentInfo_sptr(new ExperimentInfo()));
Expand Down

0 comments on commit 4399e00

Please sign in to comment.