20namespace MDAlgorithms {
33 bool ignoreZeros)
override;
38 template <
typename T>
static bool isSplitValid(
const std::vector<T> &split_into) {
39 bool validSplitInfo = !split_into.empty();
41 const T &
n = split_into[0];
42 validSplitInfo &= (
n > 1 && ((
n & (
n - 1)) == 0));
44 validSplitInfo &= all_of(split_into.begin(), split_into.end(), [&
n](T i) { return i == n; });
46 return validSplitInfo;
59 template <
typename EventType,
size_t ND,
template <
size_t>
class MDEventType>
63 template <
size_t ND,
template <
size_t>
class MDEventType>
69 template <
typename EventType,
size_t ND,
template <
size_t>
class MDEventType>
72 template <
size_t ND,
template <
size_t>
class MDEventType>
struct MDEventMaker {
73 static MDEventType<ND>
makeMDEvent(
const double &sig,
const double &err,
const uint16_t &expInfoIndex,
74 const uint16_t &goniometer_index,
const uint32_t &det_id,
coord_t *coord) {
75 return MDEventType<ND>(sig, err, expInfoIndex, goniometer_index, det_id, coord);
82template <
typename EventType,
size_t ND,
template <
size_t>
class MDEventType>
84 std::vector<MDEventType<ND>> mdEvents;
85 mdEvents.reserve(
m_EventWS->getNumberEvents());
88 std::array<std::pair<coord_t, coord_t>, ND> bounds;
89 for (
size_t ax = 0; ax < ND; ++ax) {
90 bounds[ax] = std::make_pair(pws->getDimension(ax)->getMinimum(), pws->getDimension(ax)->getMaximum());
93 std::vector<MDTransf_sptr> qConverters;
96#pragma omp parallel for num_threads(numWorkers())
97 for (
int workspaceIndex = 0; workspaceIndex < static_cast<int>(
m_NSpectra); ++workspaceIndex) {
108 int32_t detID =
m_detID[workspaceIndex];
110 uint16_t goniometerIndex(0);
112 std::vector<coord_t> locCoord(ND);
115 if (!localQConverter->calcYDepCoordinates(locCoord, workspaceIndex))
120 typename std::vector<EventType>
const *events_ptr;
122 const typename std::vector<EventType> &events = *events_ptr;
123 std::vector<MDEventType<ND>> mdEventsForSpectrum;
125 for (
const auto &event : events) {
127 double signal =
event.weight();
128 double errorSq =
event.errorSquared();
130 if (!localQConverter->calcMatrixCoord(val, locCoord, signal, errorSq))
134 signal, errorSq, expInfoIndexLoc, goniometerIndex, detID, &locCoord[0]));
138 bool isInOutWSBox =
true;
139 for (
size_t ax = 0; ax < ND; ++ax) {
140 const coord_t &coord{mdEventsForSpectrum.back().getCenter(ax)};
141 if (coord < bounds[ax].first || coord > bounds[ax].second)
142 isInOutWSBox =
false;
146 mdEventsForSpectrum.pop_back();
152 mdEvents.insert(mdEvents.cend(), mdEventsForSpectrum.begin(), mdEventsForSpectrum.end());
158template <
typename EventType,
size_t ND,
template <
size_t>
class MDEventType>
160 bc->clearBoxesCounter(1);
161 bc->clearGridBoxesCounter(0);
164 std::vector<MDEventType<ND>> mdEvents = convertEvents<EventType, ND, MDEventType>();
168 for (
size_t ax = 0; ax < ND; ++ax) {
169 space(ax, 0) = pws->getDimension(ax)->getMinimum();
170 space(ax, 1) = pws->getDimension(ax)->getMaximum();
177 EventDistributor distributor(nThreads, mdEvents.size() / nThreads / 10, bc, space);
179 auto rootAndErr = distributor.distribute(mdEvents);
181 rootAndErr.root->calculateGridCaches();
183 std::stringstream ss;
184 ss << rootAndErr.err;
190template <
size_t ND,
template <
size_t>
class MDEventType>
192 switch (
m_EventWS->getSpectrum(0).getEventType()) {
194 appendEvents<Mantid::Types::Event::TofEvent, ND, MDEventType>(pProgress, bc);
197 appendEvents<Mantid::DataObjects::WeightedEvent, ND, MDEventType>(pProgress, bc);
200 appendEvents<Mantid::DataObjects::WeightedEventNoTime, ND, MDEventType>(pProgress, bc);
203 throw std::runtime_error(
"Events in event workspace had an unexpected data type!");
210 switch (mdEventType<ND>()) {
212 appendEvents<ND, DataObjects::MDLeanEvent>(pProgress, bc);
215 appendEvents<ND, DataObjects::MDEvent>(pProgress, bc);
218 throw std::runtime_error(
"MD events in md event workspace had an unexpected data type!");
223template <
size_t maxDim>
227 throw std::runtime_error(
"Can't convert to MD workspace with dims " +
std::to_string(ndim) +
"less than 2");
230 if (ndim == maxDim) {
231 appendEvents<maxDim>(pProgress, bc);
239 const uint16_t,
const uint32_t,
coord_t *coord) {
#define PARALLEL_THREAD_NUMBER
#define PARALLEL_GET_MAX_THREADS
Helper class for reporting progress from algorithms.
std::size_t getNumberEvents() const override
Return the number of events in the list.
Templated class for the multi-dimensional event workspace.
Templated class holding data about a neutron detection event in N-dimensions (for example,...
void information(const std::string &msg)
Logs at information level.
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.
static Mantid::Kernel::Logger g_Log
std::vector< int32_t > m_detID
MDTransf_sptr m_QConverter
std::shared_ptr< MDEventWSWrapper > m_OutWSWrapper
UnitsConversionHelper m_UnitConversion
This class creates the MDWorkspace from the collection of ToF events: converts to the MD events with ...
size_t initialize(const MDWSDescription &WSD, std::shared_ptr< MDEventWSWrapper > inWSWrapper, bool ignoreZeros) override
method sets up all internal variables necessary to convert from Event Workspace to MDEvent workspace
void appendEvents(API::Progress *pProgress, const API::BoxController_sptr &bc)
std::vector< MDEventType< ND > > convertEvents()
void appendEventsFromInputWS(API::Progress *pProgress, const API::BoxController_sptr &bc) override
MD_EVENT_TYPE mdEventType()
static bool isSplitValid(const std::vector< T > &split_into)
The class specializes ConvToDataObjectsBase for the case when the conversion occurs from Events WS to...
DataObjects::EventWorkspace_const_sptr m_EventWS
Class to create the box structure of MDWorkspace.
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::size_t numEvents(::NeXus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const NexusHDF5Descriptor &descriptor)
Get the number of events in the currently opened group.
DLLExport void getEventsFrom(EventList &el, std::vector< Types::Event::TofEvent > *&events)
std::shared_ptr< MDTransfInterface > MDTransf_sptr
Helper class which provides the Collimation Length for SANS instruments.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
Eigen::Array< float, static_cast< int >(ND), 2 > MDSpaceBounds
std::string to_string(const wide_integer< Bits, Signed > &n)
static Mantid::DataObjects::MDLeanEvent< ND > makeMDEvent(const double &sig, const double &err, const uint16_t, const uint16_t, const uint32_t, coord_t *coord)
static MDEventType< ND > makeMDEvent(const double &sig, const double &err, const uint16_t &expInfoIndex, const uint16_t &goniometer_index, const uint32_t &det_id, coord_t *coord)