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<size_t> pixelID_to_wi_vector;
71
73 std::vector<std::shared_ptr<BankPulseTimes>> m_bankPulseTimes;
74
75private:
76 DefaultEventLoader(LoadEventNexus *alg, EventWorkspaceCollection &ws, bool haveWeights, bool event_id_is_spec,
77 const size_t numBanks, const bool precount, const int chunk, const int totalChunks);
78 std::pair<size_t, size_t> setupChunking(std::vector<std::string> &bankNames, std::vector<std::size_t> &bankNumEvents);
80 template <class T> void makeMapToEventLists(std::vector<std::vector<T>> &vectors);
81};
82
87template <class T> void DefaultEventLoader::makeMapToEventLists(std::vector<std::vector<T>> &vectors) {
88 vectors.resize(m_ws.nPeriods());
89 if (event_id_is_spec) {
90 // Find max spectrum no
91 auto *ax1 = m_ws.getAxis(1);
92 specnum_t maxSpecNo = -std::numeric_limits<specnum_t>::max(); // So that any number will be
93 // greater than this
94 for (size_t i = 0; i < ax1->length(); i++) {
95 specnum_t spec = ax1->spectraNo(i);
96 if (spec > maxSpecNo)
97 maxSpecNo = spec;
98 }
99
100 // These are used by the bank loader to figure out where to put the events
101 // The index of eventVectors is a spectrum number so it is simply resized to
102 // the maximum
103 // possible spectrum number
104 eventid_max = maxSpecNo;
105 for (size_t i = 0; i < vectors.size(); ++i) {
106 vectors[i].resize(maxSpecNo + 1, nullptr);
107 }
108 for (size_t period = 0; period < m_ws.nPeriods(); ++period) {
109 for (size_t i = 0; i < m_ws.getNumberHistograms(); ++i) {
110 const auto &spec = m_ws.getSpectrum(i);
111 getEventsFrom(m_ws.getSpectrum(i, period), vectors[period][spec.getSpectrumNo()]);
112 }
113 }
114 } else {
115 // To avoid going out of range in the vector, this is the MAX INDEX that can
116 // go into it
117 eventid_max = static_cast<int32_t>(pixelID_to_wi_vector.size() - 1 - pixelID_to_wi_offset);
118
119 // Make an array where index = pixel ID
120 // Set the value to NULL by default
121 for (size_t i = 0; i < vectors.size(); ++i) {
122 vectors[i].resize(eventid_max + 1, nullptr);
123 }
124
125 for (size_t j = 0; j < pixelID_to_wi_vector.size(); j++) {
126 size_t wi = pixelID_to_wi_vector[j];
127 // Save a POINTER to the vector
128 if (wi < m_ws.getNumberHistograms()) {
129 for (size_t period = 0; period < m_ws.nPeriods(); ++period) {
130 getEventsFrom(m_ws.getSpectrum(wi, period), vectors[period][j - pixelID_to_wi_offset]);
131 }
132 }
133 }
134 }
135}
136
137} // namespace DataHandling
138} // namespace Mantid
This class defines the pulse times for a specific bank.
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::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.
Definition: SpectrumInfo.h:21
int32_t specnum_t
Typedef for a spectrum Number.
Definition: IDTypes.h:16