12#define DATA_BUFFER_SIZE 8192
14template <
class T>
inline bool isNaN(T val) {
37 throw(std::logic_error(
"ConvToDataObjectsHisto should work with defined "
38 "histrogram workspace"));
50 size_t nAddedEvents(0), nBufEvents(0);
54 const size_t specSize = this->
m_InWS2D->blocksize();
62 std::vector<coord_t> locCoord(
m_Coord);
71 size_t n_coordinates = 0;
74 if (nSpectraToProcess > nValidSpectra)
75 nSpectraToProcess = nValidSpectra;
78 for (
size_t i = startSpectra; i < nSpectraToProcess; ++i) {
83 const auto &Signal =
m_InWS2D->y(iSpctr);
84 const auto &Error =
m_InWS2D->e(iSpctr);
91 if (
X.size() == Signal.size())
96 std::vector<double> XtargetUnits;
97 XtargetUnits.resize(
X.size());
101 for (
size_t j = 1; j < XtargetUnits.size(); j++) {
103 XtargetUnits[j - 1] = 0.5 * (xm + xm1);
106 XtargetUnits.back() = xm1;
108 for (
size_t j = 0; j < XtargetUnits.size(); j++)
112 for (
size_t j = 0; j < specSize; ++j) {
113 double signal = Signal[j];
118 if (ignoreZeros && (signal == 0.))
120 double errorSq = Error[j] * Error[j];
122 if (!
m_QConverter->calcMatrixCoord(XtargetUnits[j], locCoord, signal, errorSq))
126 sig_err[2 * nBufEvents + 0] = float(signal);
127 sig_err[2 * nBufEvents + 1] = float(errorSq);
129 goniometer_index[nBufEvents] = 0;
130 det_ids[nBufEvents] = det_id;
132 for (
size_t ii = 0; ii <
m_NDims; ii++)
133 allCoord[n_coordinates++] = locCoord[ii];
138 m_OutWSWrapper->addMDData(sig_err, expInfoIndex, goniometer_index, det_ids, allCoord, nBufEvents);
139 nAddedEvents += nBufEvents;
147 if (nBufEvents > 0) {
148 m_OutWSWrapper->addMDData(sig_err, expInfoIndex, goniometer_index, det_ids, allCoord, nBufEvents);
149 nAddedEvents += nBufEvents;
159 size_t nAddedEvents(0);
162 size_t lastNumBoxes = bc->getTotalNumMDBoxes();
166 const size_t specSize =
m_InWS2D->blocksize();
181 bool runMultithreaded =
false;
183 runMultithreaded =
true;
194 if (runMultithreaded)
195 nThreads =
static_cast<int>(
tp.getNumPhysicalCores());
201 size_t eventsChunkNum = bc->getSignificantEventsNumber();
207 nAddedEvents += nThreadEv;
208 nEventsInWS += nThreadEv;
210 if (bc->shouldSplitBoxes(nEventsInWS, nAddedEvents, lastNumBoxes)) {
211 if (runMultithreaded) {
224 lastNumBoxes = bc->getTotalNumMDBoxes();
226 pProgress->
report(i,
"Adding Events");
244 if (runMultithreaded) {
274 size_t nSpectras = nPointsToProcess / specSize + 1;
275 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
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
virtual size_t initialize(const MDWSDescription &WSD, std::shared_ptr< MDEventWSWrapper > inWSWrapper, bool ignoreZeros)
method which initiates all main class variables
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) 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.