Mantid
Loading...
Searching...
No Matches
DefaultEventLoader.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2017 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "MantidAPI/Axis.h"
10#include "MantidDataHandling/DllConfig.h"
12
13class BankPulseTimes;
14
15namespace Mantid {
16namespace DataHandling {
17class LoadEventNexus;
18
23class MANTID_DATAHANDLING_DLL DefaultEventLoader {
24public:
25 static void load(LoadEventNexus *alg, EventWorkspaceCollection &ws, bool haveWeights, bool event_id_is_spec,
26 std::vector<std::string> bankNames, const std::vector<int> &periodLog, const std::string &classType,
27 std::vector<std::size_t> bankNumEvents, const bool oldNeXusFileNames, const bool precount,
28 const int chunk, const int totalChunks);
29
32
35
38
41
44
46 int32_t eventid_max{0};
47
49 int chunk;
56
59
62 std::vector<std::vector<std::vector<Mantid::Types::Event::TofEvent> *>> eventVectors;
63
66 std::vector<std::vector<std::vector<Mantid::DataObjects::WeightedEvent> *>> weightedEventVectors;
67
70 std::vector<std::vector<std::vector<Mantid::DataObjects::WeightedEventNoTime> *>> weightedNoTimeEventVectors;
71
74 std::vector<size_t> pixelID_to_wi_vector;
75
77 std::vector<std::shared_ptr<BankPulseTimes>> m_bankPulseTimes;
78
79private:
80 DefaultEventLoader(LoadEventNexus *alg, EventWorkspaceCollection &ws, bool haveWeights, bool event_id_is_spec,
81 const size_t numBanks, const bool precount, const int chunk, const int totalChunks);
82 std::pair<size_t, size_t> setupChunking(std::vector<std::string> &bankNames, std::vector<std::size_t> &bankNumEvents);
84 template <class T> void makeMapToEventLists(std::vector<std::vector<T>> &vectors);
85};
86
91template <class T> void DefaultEventLoader::makeMapToEventLists(std::vector<std::vector<T>> &vectors) {
92 vectors.resize(m_ws.nPeriods());
93 if (event_id_is_spec) {
94 // Find max spectrum no
95 const auto *ax1 = m_ws.getAxis(1);
96 specnum_t maxSpecNo = -std::numeric_limits<specnum_t>::max(); // So that any number will be
97 // greater than this
98 for (size_t i = 0; i < ax1->length(); i++) {
99 specnum_t spec = ax1->spectraNo(i);
100 if (spec > maxSpecNo)
101 maxSpecNo = spec;
102 }
103
104 // These are used by the bank loader to figure out where to put the events
105 // The index of eventVectors is a spectrum number so it is simply resized to
106 // the maximum
107 // possible spectrum number
108 eventid_max = maxSpecNo;
109 for (size_t i = 0; i < vectors.size(); ++i) {
110 vectors[i].resize(maxSpecNo + 1, nullptr);
111 }
112 for (size_t period = 0; period < m_ws.nPeriods(); ++period) {
113 for (size_t i = 0; i < m_ws.getNumberHistograms(); ++i) {
114 const auto &spec = m_ws.getSpectrum(i);
115 getEventsFrom(m_ws.getSpectrum(i, period), vectors[period][spec.getSpectrumNo()]);
116 }
117 }
118 } else {
119 // To avoid going out of range in the vector, this is the MAX INDEX that can
120 // go into it
121 eventid_max = static_cast<int32_t>(pixelID_to_wi_vector.size() - 1 - pixelID_to_wi_offset);
122
123 // Make an array where index = pixel ID
124 // Set the value to NULL by default
125 for (size_t i = 0; i < vectors.size(); ++i) {
126 vectors[i].resize(eventid_max + 1, nullptr);
127 }
128
129 for (size_t j = 0; j < pixelID_to_wi_vector.size(); j++) {
130 size_t wi = pixelID_to_wi_vector[j];
131 // Save a POINTER to the vector
132 if (wi < m_ws.getNumberHistograms()) {
133 for (size_t period = 0; period < m_ws.nPeriods(); ++period) {
134 getEventsFrom(m_ws.getSpectrum(wi, period), vectors[period][j - pixelID_to_wi_offset]);
135 }
136 }
137 }
138 }
139}
140
141} // namespace DataHandling
142} // namespace Mantid
Helper class for LoadEventNexus that is specific to the current default loading code for NXevent_data...
int32_t eventid_max
Maximum (inclusive) event ID possible for this instrument.
std::vector< std::vector< std::vector< Mantid::DataObjects::WeightedEventNoTime > * > > weightedNoTimeEventVectors
Vector where index = event_id; value = ptr to std::vector<WeightedEventNoTime> in the event list.
std::vector< std::vector< std::vector< Mantid::Types::Event::TofEvent > * > > eventVectors
Vector where index = event_id; value = ptr to std::vector<TofEvent> in the event list.
std::vector< std::shared_ptr< BankPulseTimes > > m_bankPulseTimes
One entry of pulse times for each preprocessor.
bool precount
Do we pre-count the # of events in each pixel ID?
std::vector< size_t > pixelID_to_wi_vector
Vector where (index = pixel ID+pixelID_to_wi_offset), value = workspace index)
std::vector< std::vector< std::vector< Mantid::DataObjects::WeightedEvent > * > > weightedEventVectors
Vector where index = event_id; value = ptr to std::vector<WeightedEvent> in the event list.
detid_t pixelID_to_wi_offset
Offset in the pixelID_to_wi_vector to use.
bool splitProcessing
whether or not to launch multiple ProcessBankData jobs per bank
size_t eventsPerChunk
number of chunks per bank
bool event_id_is_spec
True if the event_id is spectrum no not pixel ID.
int firstChunkForBank
for multiple chunks per bank
bool m_haveWeights
Flag for dealing with a simulated file.
void makeMapToEventLists(std::vector< std::vector< T > > &vectors)
Map detector IDs to event lists.
EventWorkspaceCollection : Collection of EventWorspaces to give backward-forward compatibility around...
Mantid::API::Axis * getAxis(const size_t &i) const
const DataObjects::EventList & getSpectrum(const size_t workspace_index, const size_t periodNumber) const
DLLExport void getEventsFrom(EventList &el, std::vector< Types::Event::TofEvent > *&events)
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14