12#define DATA_BUFFER_SIZE 8192
14template <
class T>
inline bool isNaN(T val) {
31 bool ignoreZeros,
bool useLogTimes) {
38 throw(std::logic_error(
"ConvToDataObjectsHisto should work with defined "
39 "histrogram workspace"));
51 size_t nAddedEvents(0), nBufEvents(0);
55 const size_t specSize = this->
m_InWS2D->blocksize();
63 std::vector<coord_t> locCoord(
m_Coord);
72 size_t n_coordinates = 0;
75 if (nSpectraToProcess > nValidSpectra)
76 nSpectraToProcess = nValidSpectra;
79 for (
size_t i = startSpectra; i < nSpectraToProcess; ++i) {
84 const auto &Signal =
m_InWS2D->y(iSpctr);
85 const auto &Error =
m_InWS2D->e(iSpctr);
92 if (
X.size() == Signal.size())
97 std::vector<double> XtargetUnits;
98 XtargetUnits.resize(
X.size());
102 for (
size_t j = 1; j < XtargetUnits.size(); j++) {
104 XtargetUnits[j - 1] = 0.5 * (xm + xm1);
107 XtargetUnits.back() = xm1;
109 for (
size_t j = 0; j < XtargetUnits.size(); j++)
113 for (
size_t j = 0; j < specSize; ++j) {
114 double signal = Signal[j];
119 if (ignoreZeros && (signal == 0.))
121 double errorSq = Error[j] * Error[j];
123 if (!
m_QConverter->calcMatrixCoord(XtargetUnits[j], locCoord, signal, errorSq))
127 sig_err[2 * nBufEvents + 0] = float(signal);
128 sig_err[2 * nBufEvents + 1] = float(errorSq);
130 goniometer_index[nBufEvents] = 0;
131 det_ids[nBufEvents] = det_id;
133 for (
size_t ii = 0; ii <
m_NDims; ii++)
134 allCoord[n_coordinates++] = locCoord[ii];
139 m_OutWSWrapper->addMDData(sig_err, expInfoIndex, goniometer_index, det_ids, allCoord, nBufEvents);
140 nAddedEvents += nBufEvents;
148 if (nBufEvents > 0) {
149 m_OutWSWrapper->addMDData(sig_err, expInfoIndex, goniometer_index, det_ids, allCoord, nBufEvents);
150 nAddedEvents += nBufEvents;
160 size_t nAddedEvents(0);
163 size_t lastNumBoxes = bc->getTotalNumMDBoxes();
167 const size_t specSize =
m_InWS2D->blocksize();
182 bool runMultithreaded =
false;
184 runMultithreaded =
true;
195 if (runMultithreaded)
196 nThreads =
static_cast<int>(
tp.getNumPhysicalCores());
202 size_t eventsChunkNum = bc->getSignificantEventsNumber();
208 nAddedEvents += nThreadEv;
209 nEventsInWS += nThreadEv;
211 if (bc->shouldSplitBoxes(nEventsInWS, nAddedEvents, lastNumBoxes)) {
212 if (runMultithreaded) {
225 lastNumBoxes = bc->getTotalNumMDBoxes();
227 pProgress->
report(i,
"Adding Events");
245 if (runMultithreaded) {
275 size_t nSpectras = nPointsToProcess / specSize + 1;
276 m_spectraChunk = std::max(nSpectras / nThreads,
static_cast<size_t>(1));
static std::unique_ptr< QThreadPool > tp
Helper class for reporting progress from algorithms.
void resetNumSteps(int64_t nsteps, double start, double end)
Change the number of steps between start/end.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
A Thread Pool implementation that keeps a certain number of threads running (normally,...
A First-In-First-Out Thread Scheduler.
size_t size() override
Returns the size of the queue.
Class describes the interface to the methods, which perform conversion from usual workspaces to MDEve...
API::MatrixWorkspace_const_sptr m_InWS2D
std::vector< size_t > m_detIDMap
virtual size_t initialize(const MDWSDescription &WSD, std::shared_ptr< MDEventWSWrapper > inWSWrapper, bool ignoreZeros, bool useLogTimes=false)
method which initiates all main class variables
std::vector< int32_t > m_detID
Mantid::Kernel::SpecialCoordinateSystem m_coordinateSystem
Any special coordinate system used.
MDTransf_sptr m_QConverter
std::vector< coord_t > m_Coord
size_t m_NDims
number of target ws dimensions
std::shared_ptr< MDEventWSWrapper > m_OutWSWrapper
UnitsConversionHelper m_UnitConversion
void runConversion(API::Progress *pProgress) override
run conversion as multithread job
size_t initialize(const MDWSDescription &WSD, std::shared_ptr< MDEventWSWrapper > inWSWrapper, bool ignoreZeros, bool useLogTimes) override
method sets up all internal variables necessary to convert from Matrix2D workspace to MDEvent workspa...
ConvToMDHistoWS()
Default constructor.
size_t conversionChunk(size_t startSpectra) override
convert range of spectra starting from initial spectra startSpectra into MD events
void estimateThreadWork(size_t nThreads, size_t specSize, size_t nPointsToProcess)
function calculates the size of temporary memory used to keep convertTo MD data before these data sho...
helper class describes the properties of target MD workspace, which should be obtained as the result ...
void updateConversion(size_t i)
Method updates unit conversion given the index of detector parameters in the array of detectors.
double convertUnits(double val) const
do actual unit conversion from input to oputput data
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
std::shared_ptr< const Workspace2D > Workspace2D_const_sptr
shared pointer to Mantid::DataObjects::Workspace2D (const version)
bool isNaN(T val)
Template to check if a variable equal to NaN.