65 if (!descriptor.
isEntry(
"/entry/bank_error_events"))
66 throw std::runtime_error(
"entry bank_error_events does not exist");
70 auto periodLog = std::make_unique<const TimeSeriesProperty<int>>(
"period_log");
71 LoadEventNexus::runLoadNexusLogs<MatrixWorkspace_sptr>(filename, outWS, *
this,
false, nPeriods, periodLog);
74 g_log.
warning(
"This algorithm does not correctly handle period data");
77 LoadEventNexus::loadInstrument<MatrixWorkspace_sptr>(filename, outWS,
"entry",
this, &descriptor);
82 }
catch (std::exception &e) {
83 g_log.
warning() <<
"Error while loading meta data: " << e.what() <<
'\n';
87 Nexus::File file(filename);
89 file.openAddress(
"/");
90 file.openGroup(
"entry",
"NXentry");
91 file.openGroup(
"bank_error_events",
"NXevent_data");
93 const auto event_times = Nexus::IOHelper::readNexusVector<float>(file,
"event_time_offset");
94 const auto event_index =
95 std::make_shared<std::vector<uint64_t>>(Nexus::IOHelper::readNexusVector<uint64_t>(file,
"event_index"));
96 const auto bankPulseTimes = std::make_shared<BankPulseTimes>(boost::ref(file), periodLog->valuesAsVector());
104 const auto numEvents = event_times.size();
107 if (!std::is_sorted(event_index->cbegin(), event_index->cend()))
108 throw std::runtime_error(
"Event index is not sorted");
110 auto eventWS = std::dynamic_pointer_cast<Mantid::DataObjects::EventWorkspace>(outWS);
111 auto &ev = eventWS->getSpectrum(0);
113 auto min_tof = std::numeric_limits<double>::max();
114 auto max_tof = std::numeric_limits<double>::lowest();
117 std::vector<size_t>());
119 for (
const auto &pulseIter : pulseIndexer) {
121 const auto &pulsetime = bankPulseTimes->pulseTime(pulseIter.pulseIndex);
124 for (std::size_t eventIndex = pulseIter.eventIndexStart; eventIndex < pulseIter.eventIndexStop; ++eventIndex) {
125 const auto tof =
static_cast<double>(event_times[eventIndex]);
126 ev.addEventQuickly(Mantid::Types::Event::TofEvent(tof, pulsetime));
127 min_tof = std::min(min_tof, tof);
128 max_tof = std::max(max_tof, tof);
135 if (min_tof < max_tof)
136 eventWS->setAllX(HistogramData::BinEdges{min_tof, max_tof});
138 eventWS->setAllX(HistogramData::BinEdges{0, 16666.7});
140 outWS->getAxis(0)->setUnit(
"TOF");
141 outWS->setYUnit(
"Counts");
142 outWS->mutableRun().addProperty(
"Filename", filename);
static void loadEntryMetadata(const std::string &nexusfilename, T WS, const std::string &entry_name, const Nexus::NexusDescriptor &descriptor)
Load the run number and other meta data from the given bank.
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const Nexus::NexusDescriptor &descriptor)
Get the number of events in the currently opened group.