Skip to content

Commit

Permalink
Refs #11724 more changes for thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
VickieLynch committed May 13, 2015
1 parent e62a0ea commit 8e5d4a8
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 60 deletions.
Expand Up @@ -32,11 +32,12 @@ class DLLExport IntegrateEllipsoids : public API::Algorithm {
void exec();
void qListFromEventWS(Integrate3DEvents &integrator, API::Progress &prog,
DataObjects::EventWorkspace_sptr &wksp,
Kernel::DblMatrix const &UBinv, bool hkl_integ);
UnitsConversionHelper &unitConverter,
MDTransf_sptr &qConverter, Kernel::DblMatrix const &UBinv, bool hkl_integ);
void qListFromHistoWS(Integrate3DEvents &integrator, API::Progress &prog,
DataObjects::Workspace2D_sptr &wksp,
Kernel::DblMatrix const &UBinv, bool hkl_integ);

UnitsConversionHelper &unitConverter,
MDTransf_sptr &qConverter, Kernel::DblMatrix const &UBinv, bool hkl_integ);
MDWSDescription m_targWSDescr;

void initTargetWSDescr(API::MatrixWorkspace_sptr &wksp);
Expand Down
Expand Up @@ -9,6 +9,7 @@
#include "MantidKernel/DeltaEMode.h"

#include "MantidMDAlgorithms/MDWSDescription.h"
#include "MantidDataObjects/Events.h"

namespace Mantid {
namespace MDAlgorithms {
Expand Down Expand Up @@ -161,6 +162,8 @@ class MDTransfInterface {
* */
virtual bool calcMatrixCoord(const double &X, std::vector<coord_t> &Coord,
double &signal, double &errSq) const = 0;
virtual std::vector<std::pair<double, Kernel::V3D>> calcMatrixCoordLoop(Kernel::DblMatrix const &UBinv,
std::vector<DataObjects::WeightedEventNoTime> &raw_events, size_t i, const std::vector<double> &x) = 0;

/* clone method allowing to provide the copy of the particular class */
virtual MDTransfInterface *clone() const = 0;
Expand Down
Expand Up @@ -3,6 +3,7 @@
//
#include "MantidMDAlgorithms/MDTransfInterface.h"
#include "MantidMDAlgorithms/MDTransfFactory.h"
#include "MantidDataObjects/Events.h"
//
namespace Mantid {
namespace MDAlgorithms {
Expand Down Expand Up @@ -57,6 +58,9 @@ class DLLExport MDTransfModQ : public MDTransfInterface {
bool calcYDepCoordinates(std::vector<coord_t> &Coord, size_t i);
bool calcMatrixCoord(const double &k0, std::vector<coord_t> &Coord, double &s,
double &err) const;
std::vector<std::pair<double, Kernel::V3D>> calcMatrixCoordLoop(Kernel::DblMatrix const &UBinv,
std::vector<DataObjects::WeightedEventNoTime> &raw_events, size_t i, const std::vector<double> &x);

// constructor;
MDTransfModQ();
/* clone method allowing to provide the copy of the particular class */
Expand Down
Expand Up @@ -4,6 +4,7 @@
#include "MantidAPI/NumericAxis.h"
#include "MantidMDAlgorithms/MDTransfInterface.h"
#include "MantidMDAlgorithms/MDTransfFactory.h"
#include "MantidDataObjects/Events.h"

namespace Mantid {
namespace MDAlgorithms {
Expand Down Expand Up @@ -52,6 +53,9 @@ class DLLExport MDTransfNoQ : public MDTransfInterface {
bool calcYDepCoordinates(std::vector<coord_t> &Coord, size_t i);
bool calcMatrixCoord(const double &k0, std::vector<coord_t> &Coord, double &s,
double &err) const;
std::vector<std::pair<double, Kernel::V3D>> calcMatrixCoordLoop(Kernel::DblMatrix const &UBinv,
std::vector<DataObjects::WeightedEventNoTime> &raw_events, size_t i, const std::vector<double> &x);

// constructor;
MDTransfNoQ();
/* clone method allowing to provide the copy of the particular class */
Expand Down
Expand Up @@ -4,6 +4,7 @@
#include "MantidMDAlgorithms/MDTransfInterface.h"
#include "MantidMDAlgorithms/MDTransfFactory.h"
#include "MantidMDAlgorithms/MDTransfModQ.h"
#include "MantidDataObjects/Events.h"
//
namespace Mantid {
namespace MDAlgorithms {
Expand Down Expand Up @@ -53,6 +54,8 @@ class DLLExport MDTransfQ3D : public MDTransfModQ {
bool calcYDepCoordinates(std::vector<coord_t> &Coord, size_t i);
bool calcMatrixCoord(const double &X, std::vector<coord_t> &Coord, double &s,
double &err) const;
std::vector<std::pair<double, Kernel::V3D>> calcMatrixCoordLoop(Kernel::DblMatrix const &UBinv,
std::vector<DataObjects::WeightedEventNoTime> &raw_events, size_t i, const std::vector<double> &x);
// constructor;
MDTransfQ3D();
/* clone method allowing to provide the copy of the particular class */
Expand Down
Expand Up @@ -7,6 +7,7 @@
#include "MantidKernel/Unit.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidMDAlgorithms/MDWSDescription.h"
#include "MantidDataObjects/Events.h"

namespace Mantid {
namespace MDAlgorithms {
Expand Down Expand Up @@ -80,6 +81,7 @@ class DLLExport UnitsConversionHelper {
int Emode, bool forceViaTOF = false);
void updateConversion(size_t i);
double convertUnits(double val) const;
std::vector<double> convertUnitsLoop(const std::string &unitsTo, size_t i, std::vector<DataObjects::WeightedEventNoTime> &raw_events) const;

bool isUnitConverted() const;
std::pair<double, double> getConversionRange(double x1, double x2) const;
Expand Down
117 changes: 62 additions & 55 deletions Code/Mantid/Framework/MDAlgorithms/src/IntegrateEllipsoids.cpp
Expand Up @@ -41,28 +41,23 @@ const std::size_t DIMS(3);
* @param integrator : itegrator object on which qlists are accumulated
* @param prog : progress object
* @param wksp : input EventWorkspace
* @param unitConverter : Unit converter
* @param qConverter : Q converter
* @param UBinv : inverse of UB matrix
* @param hkl_integ ; boolean for integrating in HKL space
*/
void IntegrateEllipsoids::qListFromEventWS(Integrate3DEvents &integrator, Progress &prog,
EventWorkspace_sptr &wksp,
DblMatrix const &UBinv, bool hkl_integ) {
UnitsConversionHelper &unitConverter,
MDTransf_sptr &qConverter, DblMatrix const &UBinv, bool hkl_integ) {
// loop through the eventlists

int numSpectra = static_cast<int>(wksp->getNumberHistograms());
PARALLEL_FOR1(wksp)
//PARALLEL_FOR1(wksp)
for (int i = 0; i < numSpectra; ++i) {
PARALLEL_START_INTERUPT_REGION
//PARALLEL_START_INTERUPT_REGION

// units conversion helper
UnitsConversionHelper unitConverter;
unitConverter.initialize(m_targWSDescr, "Momentum");

// initialize the MD coordinates conversion class
MDTransfQ3D qConverter;
qConverter.initialize(m_targWSDescr);

std::vector<double> buffer(DIMS);
//std::vector<double> buffer(DIMS);
// get a reference to the event list
EventList &events = wksp->getEventList(i);

Expand All @@ -75,34 +70,38 @@ void IntegrateEllipsoids::qListFromEventWS(Integrate3DEvents &integrator, Progre
}

// update which pixel is being converted
std::vector<Mantid::coord_t> locCoord(DIMS, 0.);
unitConverter.updateConversion(i);
qConverter.calcYDepCoordinates(locCoord, i);
//std::vector<Mantid::coord_t> locCoord(DIMS, 0.);
//unitConverter.updateConversion(i);
//qConverter->calcYDepCoordinates(locCoord, i);

// loop over the events
double signal(1.); // ignorable garbage
double errorSq(1.); // ignorable garbage
const std::vector<WeightedEventNoTime> &raw_events =
//double signal(1.); // ignorable garbage
//double errorSq(1.); // ignorable garbage
std::vector<WeightedEventNoTime> &raw_events =
events.getWeightedEventsNoTime();
std::vector<std::pair<double, V3D>> qList;
for (auto event = raw_events.begin(); event != raw_events.end(); ++event) {
double val = unitConverter.convertUnits(event->tof());
qConverter.calcMatrixCoord(val, locCoord, signal, errorSq);
for (size_t dim = 0; dim < DIMS; ++dim) {
buffer[dim] = locCoord[dim];
}
V3D qVec(buffer[0], buffer[1], buffer[2]);
if (hkl_integ) qVec = UBinv * qVec;
qList.push_back(std::make_pair(event->m_weight, qVec));
} // end of loop over events in list
PARALLEL_CRITICAL(addEvents){
std::vector<double> momentum = unitConverter.convertUnitsLoop("Momentum", i, raw_events);
std::vector<std::pair<double, V3D>> qList = qConverter->calcMatrixCoordLoop(UBinv, raw_events, i, momentum);
//std::vector<std::pair<double, V3D>> qList;
//int i=0;
//for (auto event = raw_events.begin(); event != raw_events.end(); ++event) {
//double val = unitConverter.convertUnits(event->tof());
//qConverter->calcMatrixCoord(momentum[i], locCoord, signal, errorSq);
//i++;
//for (size_t dim = 0; dim < DIMS; ++dim) {
//buffer[dim] = locCoord[dim];
//}
//V3D qVec(buffer[0], buffer[1], buffer[2]);
//if (hkl_integ) qVec = UBinv * qVec;
//qList.push_back(std::make_pair(event->m_weight, qVec));
//} // end of loop over events in list
//PARALLEL_CRITICAL(addEvents){
integrator.addEvents(qList, hkl_integ);
}
//}

prog.report();
PARALLEL_END_INTERUPT_REGION
//PARALLEL_END_INTERUPT_REGION
} // end of loop over spectra
PARALLEL_CHECK_INTERUPT_REGION
//PARALLEL_CHECK_INTERUPT_REGION
}

/**
Expand All @@ -111,28 +110,23 @@ void IntegrateEllipsoids::qListFromEventWS(Integrate3DEvents &integrator, Progre
* @param integrator : itegrator object on which qlists are accumulated
* @param prog : progress object
* @param wksp : input Workspace2D
* @param unitConverter : Unit converter
* @param qConverter : Q converter
* @param UBinv : inverse of UB matrix
* @param hkl_integ ; boolean for integrating in HKL space
*/
void IntegrateEllipsoids::qListFromHistoWS(Integrate3DEvents &integrator, Progress &prog,
Workspace2D_sptr &wksp,
DblMatrix const &UBinv, bool hkl_integ) {
UnitsConversionHelper &unitConverter,
MDTransf_sptr &qConverter, DblMatrix const &UBinv, bool hkl_integ) {

// loop through the eventlists

int numSpectra = static_cast<int>(wksp->getNumberHistograms());
const bool histogramForm = wksp->isHistogramData();
PARALLEL_FOR1(wksp)
//PARALLEL_FOR1(wksp)
for (int i = 0; i < numSpectra; ++i) {
PARALLEL_START_INTERUPT_REGION

// units conversion helper
UnitsConversionHelper unitConverter;
unitConverter.initialize(m_targWSDescr, "Momentum");

// initialize the MD coordinates conversion class
MDTransfQ3D qConverter;
qConverter.initialize(m_targWSDescr);
//PARALLEL_START_INTERUPT_REGION

std::vector<double> buffer(DIMS);
// get tof and counts
Expand All @@ -142,7 +136,7 @@ void IntegrateEllipsoids::qListFromHistoWS(Integrate3DEvents &integrator, Progre
// update which pixel is being converted
std::vector<Mantid::coord_t> locCoord(DIMS, 0.);
unitConverter.updateConversion(i);
qConverter.calcYDepCoordinates(locCoord, i);
qConverter->calcYDepCoordinates(locCoord, i);

// loop over the events
double signal(1.); // ignorable garbage
Expand All @@ -162,7 +156,7 @@ void IntegrateEllipsoids::qListFromHistoWS(Integrate3DEvents &integrator, Progre
}

double val = unitConverter.convertUnits(tof);
qConverter.calcMatrixCoord(val, locCoord, signal, errorSq);
qConverter->calcMatrixCoord(val, locCoord, signal, errorSq);
for (size_t dim = 0; dim < DIMS; ++dim) {
buffer[dim] = locCoord[dim]; // TODO. Looks un-necessary to me. Can't
// we just add localCoord directly to
Expand All @@ -176,13 +170,13 @@ void IntegrateEllipsoids::qListFromHistoWS(Integrate3DEvents &integrator, Progre
qList.push_back(std::make_pair(yVal, qVec));
}
}
PARALLEL_CRITICAL(addHisto) {
//PARALLEL_CRITICAL(addHisto) {
integrator.addEvents(qList, hkl_integ);
}
//}
prog.report();
PARALLEL_END_INTERUPT_REGION
//PARALLEL_END_INTERUPT_REGION
} // end of loop over spectra
PARALLEL_CHECK_INTERUPT_REGION
//PARALLEL_CHECK_INTERUPT_REGION
}

/** NOTE: This has been adapted from the SaveIsawQvector algorithm.
Expand Down Expand Up @@ -348,9 +342,13 @@ void IntegrateEllipsoids::exec() {
// lab-Q vectors
Matrix<double> UB(3, 3, false);
Geometry::IndexingUtils::Optimize_UB(UB, hkl_vectors, peak_q_list);
Matrix<double> UBinv(UB);
UBinv.Invert();
UBinv *= (1.0 / (2.0 * M_PI));
DblMatrix UBinv(3,3,true); //Identity
if(hkl_integ)
{
UBinv = UB;
UBinv.Invert();
UBinv *= (1.0 / (2.0 * M_PI));
}

std::vector<double> PeakRadiusVector(n_peaks, peak_radius);
std::vector<double> BackgroundInnerRadiusVector(n_peaks, back_inner_radius);
Expand All @@ -377,16 +375,25 @@ void IntegrateEllipsoids::exec() {
// set up a descripter of where we are going
this->initTargetWSDescr(wksp);

// units conversion helper
UnitsConversionHelper unitConv;
unitConv.initialize(m_targWSDescr, "Momentum");

// initialize the MD coordinates conversion class
MDTransf_sptr qConverter =
MDTransfFactory::Instance().create(m_targWSDescr.AlgID);
qConverter->initialize(m_targWSDescr);

// set up the progress bar
const size_t numSpectra = wksp->getNumberHistograms();
Progress prog(this, 0.5, 1.0, numSpectra);

if (eventWS) {
// process as EventWorkspace
qListFromEventWS(integrator, prog, eventWS, UBinv, hkl_integ);
qListFromEventWS(integrator, prog, eventWS, unitConv, qConverter, UBinv, hkl_integ);
} else {
// process as Workspace2D
qListFromHistoWS(integrator, prog, histoWS, UBinv, hkl_integ);
qListFromHistoWS(integrator, prog, histoWS, unitConv, qConverter, UBinv, hkl_integ);
}

double inti;
Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/src/MDTransfModQ.cpp
Expand Up @@ -81,7 +81,11 @@ bool MDTransfModQ::calcMatrixCoord(const double &x, std::vector<coord_t> &Coord,
return calcMatrixCoordInelastic(x, Coord);
}
}

std::vector<std::pair<double, Kernel::V3D>> MDTransfModQ::calcMatrixCoordLoop(Kernel::DblMatrix const &UBinv,
std::vector<DataObjects::WeightedEventNoTime> &raw_events, size_t i, const std::vector<double> &x) {
std::vector<std::pair<double, Kernel::V3D>> qList;
return qList;
}
/** Method fills-in all additional properties requested by user and not defined
*by matrix workspace itself.
* it fills in [nd - (1 or 2 -- depending on emode)] values into Coord vector;
Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/MDAlgorithms/src/MDTransfNoQ.cpp
Expand Up @@ -81,7 +81,11 @@ bool MDTransfNoQ::calcMatrixCoord(const double &X, std::vector<coord_t> &Coord,
Coord[0] = (coord_t)X;
return true;
}

std::vector<std::pair<double, Kernel::V3D>> MDTransfNoQ::calcMatrixCoordLoop(Kernel::DblMatrix const &UBinv,
std::vector<DataObjects::WeightedEventNoTime> &raw_events, size_t i, const std::vector<double> &x) {
std::vector<std::pair<double, Kernel::V3D>> qList;
return qList;
}
std::vector<double> MDTransfNoQ::getExtremumPoints(const double xMin,
const double xMax,
size_t det_num) const {
Expand Down

0 comments on commit 8e5d4a8

Please sign in to comment.