Mantid
Loading...
Searching...
No Matches
LoadEventNexus.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 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
14#include "MantidDataHandling/DllConfig.h"
26
28
30#include "MantidNexus/NexusFile.h"
31
32#include <algorithm>
33#include <boost/lexical_cast.hpp>
34#include <boost/scoped_array.hpp>
35#include <cstdint>
36#include <filesystem>
37#include <functional>
38#include <memory>
39#include <mutex>
40#include <numeric>
41#include <random>
42#include <string>
43
44namespace Mantid {
45namespace DataHandling {
46
53class InvalidLogPeriods : public std::invalid_argument {
54public:
55 InvalidLogPeriods(const std::string &msg) : std::invalid_argument(msg) {}
56};
57
58bool exists(Nexus::File &file, const std::string &name);
59
60bool exists(const std::map<std::string, std::string> &entries, const std::string &name);
61
74class MANTID_DATAHANDLING_DLL LoadEventNexus : public API::NexusFileLoader {
75
76public:
78
79 const std::string name() const override { return "LoadEventNexus"; };
80
82 const std::string summary() const override {
83 return "Loads an Event NeXus file and stores as an "
84 "EventWorkspace. Optionally, you can filter out events falling "
85 "outside a range of times-of-flight and/or a time interval.";
86 }
87
89 int version() const override { return 1; };
90 const std::vector<std::string> seeAlso() const override { return {"LoadISISNexus", "LoadEventAndCompress"}; }
91
93 const std::string category() const override { return "DataHandling\\Nexus"; }
94
95 int confidence(Nexus::NexusDescriptor &descriptor) const override;
96
97 template <typename T>
98 static std::shared_ptr<BankPulseTimes>
99 runLoadNexusLogs(const std::string &nexusfilename, T localWorkspace, Algorithm &alg, bool returnpulsetimes,
100 int &nPeriods, std::unique_ptr<const Kernel::TimeSeriesProperty<int>> &periodLog);
101
102 template <typename T>
103 static std::shared_ptr<BankPulseTimes>
104 runLoadNexusLogs(const std::string &nexusfilename, T localWorkspace, Algorithm &alg, bool returnpulsetimes,
105 int &nPeriods, std::unique_ptr<const Kernel::TimeSeriesProperty<int>> &periodLog,
106 const std::vector<std::string> &allow_list, const std::vector<std::string> &block_list);
107
108 static int checkForCorruptedPeriods(std::unique_ptr<Kernel::TimeSeriesProperty<int>> tempPeriodLog,
109 std::unique_ptr<const Kernel::TimeSeriesProperty<int>> &periodLog,
110 const int &nPeriods, const std::string &nexusfilename, std::string &status);
111
112 template <typename T>
113 static void loadEntryMetadata(const std::string &nexusfilename, T WS, const std::string &entry_name,
114 const Nexus::NexusDescriptor &descriptor);
115
117 template <typename T>
118 static bool loadInstrument(const std::string &nexusfilename, T localWorkspace, const std::string &top_entry_name,
119 Algorithm *alg, const Nexus::NexusDescriptor *descriptor = nullptr);
120
122 template <typename T>
123 static bool runLoadIDFFromNexus(const std::string &nexusfilename, T localWorkspace, const std::string &top_entry_name,
124 Algorithm *alg);
125
127 template <typename T>
128 static bool runLoadInstrument(const std::string &nexusfilename, T localWorkspace, const std::string &top_entry_name,
129 Algorithm *alg, const Nexus::NexusDescriptor *descriptor = nullptr);
130
131 static void loadSampleDataISIScompatibility(Nexus::File &file, EventWorkspaceCollection &WS);
132
135 static std::string readInstrumentFromISIS_VMSCompat(Nexus::File &hFile);
136
137public:
139 std::string m_filename;
140
142 std::shared_ptr<EventWorkspaceCollection> m_ws;
143
150
152 int32_t m_specMin;
154 int32_t m_specMax;
155
157 Mantid::Types::Core::DateAndTime filter_time_start;
159 Mantid::Types::Core::DateAndTime filter_time_stop;
161 bool m_is_time_filtered{false};
162
163 bool filter_bad_pulses{false};
164 std::shared_ptr<Mantid::Kernel::TimeROI> bad_pulses_timeroi;
165
167 std::mutex m_tofMutex;
168
175 size_t bad_tofs;
179
183
185 std::shared_ptr<BankPulseTimes> m_allBanksPulseTimes;
186
188 std::string m_top_entry_name;
189 std::unique_ptr<Nexus::File> m_file;
190
191private:
193 void init() override;
194
196 void execLoader() override;
197
198 std::map<std::string, std::string> validateInputs() override;
199
201
202 void loadEvents(API::Progress *const prog, const bool monitors);
203 void createSpectraMapping(const std::string &nxsfile, const bool monitorsOnly,
204 const std::vector<std::string> &bankNames = std::vector<std::string>());
205 void deleteBanks(const EventWorkspaceCollection_sptr &workspace, const std::vector<std::string> &bankNames);
206 void runLoadMonitors();
208 void setTimeFilters(const bool monitors);
209 template <typename T>
210 T filterEventsByTime(T workspace, Mantid::Types::Core::DateAndTime &startTime,
211 Mantid::Types::Core::DateAndTime &stopTime);
212
214 std::unique_ptr<std::pair<std::vector<int32_t>, std::vector<int32_t>>>
215 loadISISVMSSpectraMapping(const std::string &entry_name);
216
217 template <typename T> void filterDuringPause(T workspace);
218
220 void setTopEntryName();
221
223 void safeOpenFile(const std::string &fname);
224
227
232};
233
234//-----------------------------------------------------------------------------
235// ISIS event corrections
236//-----------------------------------------------------------------------------
237
267template <typename T>
268void makeTimeOfFlightDataFuzzy(Nexus::File &file, T localWorkspace, const std::string &binsName, size_t start_wi = 0,
269 size_t end_wi = 0) {
270 const std::string EVENT_TIME_SHIFT_TAG("event_time_offset_shift");
271 // first check if the data is already randomized
272 const auto entries = file.getEntries();
273 if (entries.find(EVENT_TIME_SHIFT_TAG) != entries.end()) {
274 std::string event_shift_type;
275 file.readData(EVENT_TIME_SHIFT_TAG, event_shift_type);
276 if (event_shift_type == "random") {
277 return;
278 }
279 }
280
281 // if the data is not randomized randomize it uniformly within each bin
282 file.openData(binsName);
283 // time of flights of events
284 std::vector<float> tofsFile;
285 file.getData(tofsFile);
286 file.closeData();
287
288 // todo: try to find if tof can be reduced to just 3 numbers: start, end and
289 // dt
290 if (end_wi <= start_wi) {
291 end_wi = localWorkspace->getNumberHistograms();
292 }
293
294 // random number generator
295 std::mt19937 rng;
296
297 // loop over spectra
298 for (size_t wi = start_wi; wi < end_wi; ++wi) {
299 DataObjects::EventList &event_list = dynamic_cast<DataObjects::EventList &>(localWorkspace->getSpectrum(wi));
300 if (event_list.empty())
301 continue;
302 // sort the events
303 event_list.sortTof();
304 auto tofsEventList = event_list.getTofs();
305
306 size_t n = tofsFile.size();
307 // iterate over the events and time bins
308 auto ev = tofsEventList.begin();
309 auto ev_end = tofsEventList.end();
310 for (size_t i = 1; i < n; ++i) {
311 double right = double(tofsFile[i]);
312 // find the right boundary for the current event
313 if ((ev != ev_end) && (right < *ev)) {
314 continue;
315 }
316 // count events which have the same right boundary
317 size_t m = 0;
318 while ((ev != ev_end) && (*ev < right)) {
319 ++ev;
320 ++m; // count events in the i-th bin
321 }
322
323 if (m > 0) { // m events in this bin
324 double left = double(tofsFile[i - 1]);
325 // spread the events uniformly inside the bin
326 std::uniform_real_distribution<double> flat(left, right);
327 std::vector<double> random_numbers(m);
328 std::generate(random_numbers.begin(), random_numbers.end(), [&flat, &rng]() { return flat(rng); });
329 std::sort(random_numbers.begin(), random_numbers.end());
330 auto it = random_numbers.begin();
331 for (auto ev1 = ev - m; ev1 != ev; ++ev1, ++it) {
332 *ev1 = *it;
333 }
334 }
335
336 } // for i
337 event_list.setTofs(tofsEventList);
338
339 event_list.sortTof();
340 } // for wi
341}
342
356template <typename T>
357void adjustTimeOfFlightISISLegacy(Nexus::File &file, T localWorkspace, const std::string &entry_name,
358 const std::string &classType, const Nexus::NexusDescriptor *descriptor = nullptr) {
359 bool done = false;
360 // Go to the root, and then top entry
361 file.openAddress("/");
362 file.openGroup(entry_name, "NXentry");
363
364 // NexusDescriptor
365 if (descriptor != nullptr) {
366 // not an ISIS file
367 if (!descriptor->isEntry("/" + entry_name + "/detector_1_events")) {
368 return;
369 }
370 }
371
372 using string_map_t = std::map<std::string, std::string>;
373 string_map_t entries = file.getEntries();
374
375 if (entries.find("detector_1_events") == entries.end()) { // not an ISIS file
376 return;
377 }
378
379 // try if monitors have their own bins
380 if (classType == "NXmonitor") {
381 std::vector<std::string> bankNames;
382 for (string_map_t::const_iterator it = entries.begin(); it != entries.end(); ++it) {
383 const std::string entry_class(it->second);
384 if (entry_class == classType) {
385 const std::string entryName(it->first);
386 bankNames.emplace_back(entryName);
387 }
388 }
389 for (size_t i = 0; i < bankNames.size(); ++i) {
390 const std::string &mon = bankNames[i];
391 file.openGroup(mon, classType);
392 entries = file.getEntries();
393 if (entries.find("event_time_bins") == entries.end()) {
394 // bins = entries.find("time_of_flight"); // I think time_of_flight
395 // doesn't work here
396 // if (bins == entries.end())
397 //{
398 done = false;
399 file.closeGroup();
400 break; // done == false => use bins from the detectors
401 //}
402 }
403 done = true;
404 makeTimeOfFlightDataFuzzy(file, localWorkspace, "event_time_bins", i, i + 1);
405 file.closeGroup();
406 }
407 }
408
409 if (!done) {
410 // first check detector_1_events
411 file.openGroup("detector_1_events", "NXevent_data");
412 entries = file.getEntries();
413 for (string_map_t::const_iterator it = entries.begin(); it != entries.end(); ++it) {
414 if (it->first == "time_of_flight" || it->first == "event_time_bins") {
415 makeTimeOfFlightDataFuzzy(file, localWorkspace, it->first);
416 done = true;
417 }
418 }
419 file.closeGroup(); // detector_1_events
420
421 if (!done) { // if time_of_flight was not found try
422 // instrument/dae/time_channels_#
423 file.openGroup("instrument", "NXinstrument");
424 file.openGroup("dae", "IXdae");
425 entries = file.getEntries();
426 size_t time_channels_number = 0;
427 for (string_map_t::const_iterator it = entries.begin(); it != entries.end(); ++it) {
428 // check if there are groups with names "time_channels_#" and select the
429 // one with the highest number
430 if (it->first.size() > 14 && it->first.substr(0, 14) == "time_channels_") {
431 size_t n = boost::lexical_cast<size_t>(it->first.substr(14));
432 if (n > time_channels_number) {
433 time_channels_number = n;
434 }
435 }
436 }
437 if (time_channels_number > 0) // the numbers start with 1
438 {
439 file.openGroup("time_channels_" + std::to_string(time_channels_number), "IXtime_channels");
440 entries = file.getEntries();
441 for (string_map_t::const_iterator it = entries.begin(); it != entries.end(); ++it) {
442 if (it->first == "time_of_flight" || it->first == "event_time_bins") {
443 makeTimeOfFlightDataFuzzy(file, localWorkspace, it->first);
444 }
445 }
446 file.closeGroup();
447 }
448 file.closeGroup(); // dae
449 file.closeGroup(); // instrument
450 }
451 }
452
453 // close top entry (or entry given in entry_name)
454 file.closeGroup();
455}
456
457//-----------------------------------------------------------------------------
468template <typename T>
469bool LoadEventNexus::runLoadInstrument(const std::string &nexusfilename, T localWorkspace,
470 const std::string &top_entry_name, Algorithm *alg,
471 const Nexus::NexusDescriptor *descriptor) {
472 std::string instrument;
473 std::string instFilename;
474
475 const bool isNexus = (descriptor == nullptr) ? LoadGeometry::isNexus(nexusfilename)
476 : LoadGeometry::isNexus(descriptor->getAllEntries());
477
478 // Check if the geometry can be loaded directly from the Nexus file
479 if (isNexus) {
480 instFilename = nexusfilename;
481 } else {
482 // Get the instrument name
483 Nexus::File nxfile(nexusfilename);
484 // Start with the base entry
485 nxfile.openGroup(top_entry_name, "NXentry");
486 // Open the instrument
487 nxfile.openGroup("instrument", "NXinstrument");
488 try {
489 nxfile.openData("name");
490 instrument = nxfile.getStrData();
491 alg->getLogger().debug() << "Instrument name read from NeXus file is " << instrument << '\n';
492 } catch (Nexus::Exception const &) {
493 // Try to fall back to isis compatibility options
494 nxfile.closeGroup();
495 instrument = readInstrumentFromISIS_VMSCompat(nxfile);
496 if (instrument.empty()) {
497 // Get the instrument name from the file instead
498 size_t n = nexusfilename.rfind('/');
499 if (n != std::string::npos) {
500 std::string temp = nexusfilename.substr(n + 1, nexusfilename.size() - n - 1);
501 n = temp.find('_');
502 if (n != std::string::npos && n > 0) {
503 instrument = temp.substr(0, n);
504 }
505 }
506 }
507 }
508 if (instrument == "POWGEN3") // hack for powgen b/c of bad long name
509 instrument = "POWGEN";
510 if (instrument == "NOM") // hack for nomad
511 instrument = "NOMAD";
512
513 if (instrument.empty())
514 throw std::runtime_error("Could not find the instrument name in the NXS "
515 "file or using the filename. Cannot load "
516 "instrument!");
517
518 // Now let's close the file as we don't need it anymore to load the
519 // instrument.
520 nxfile.close();
521 }
522
523 if (instFilename.empty()) {
524 try {
525 instFilename =
526 API::InstrumentFileFinder::getInstrumentFilename(instrument, localWorkspace->getWorkspaceStartDate());
528 if (instFilename.empty()) {
529 std::filesystem::path directory(Kernel::ConfigService::Instance().getInstrumentDirectory());
530 std::filesystem::path file(instrument + "_Definition.xml");
531 std::filesystem::path fullPath = directory / file;
532 instFilename = fullPath.string();
533 }
534 }
535 }
536
537 // do the actual work
538 auto loadInst = alg->createChildAlgorithm("LoadInstrument");
539
540 // Now execute the Child Algorithm. Catch and log any error, but don't stop.
541 bool executionSuccessful(true);
542 try {
543 loadInst->setPropertyValue("Filename", instFilename);
544 loadInst->setPropertyValue("InstrumentName", instrument);
545 loadInst->setProperty<Mantid::API::MatrixWorkspace_sptr>("Workspace", localWorkspace);
546 loadInst->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false));
547 loadInst->execute();
548
549 // Populate the instrument parameters in this workspace - this works around
550 // a bug
551 localWorkspace->populateInstrumentParameters();
552 } catch (std::invalid_argument &e) {
553 alg->getLogger().information() << "Invalid argument to LoadInstrument Child Algorithm : " << e.what() << '\n';
554 executionSuccessful = false;
555 } catch (std::runtime_error &e) {
556 alg->getLogger().information("Unable to successfully run LoadInstrument Child Algorithm");
557 alg->getLogger().information(e.what());
558 executionSuccessful = false;
559 }
560
561 // If loading instrument definition file fails
562 if (!executionSuccessful) {
563 alg->getLogger().error() << "Error loading Instrument definition file\n";
564 return false;
565 }
566
567 // Ticket #2049: Cleanup all loadinstrument members to a single instance
568 // If requested update the instrument to positions in the data file
569 const auto &pmap = localWorkspace->constInstrumentParameters();
570 if (!pmap.contains(localWorkspace->getInstrument()->getComponentID(), "det-pos-source"))
571 return executionSuccessful;
572
573 std::shared_ptr<Geometry::Parameter> updateDets =
574 pmap.get(localWorkspace->getInstrument()->getComponentID(), "det-pos-source");
575 std::string value = updateDets->value<std::string>();
576 if (value.substr(0, 8) == "datafile") {
577 auto updateInst = alg->createChildAlgorithm("UpdateInstrumentFromFile");
578 updateInst->setProperty<Mantid::API::MatrixWorkspace_sptr>("Workspace", localWorkspace);
579 updateInst->setPropertyValue("Filename", nexusfilename);
580 if (value == "datafile-ignore-phi") {
581 updateInst->setProperty("IgnorePhi", true);
582 alg->getLogger().information("Detector positions in IDF updated with "
583 "positions in the data file except for the "
584 "phi values");
585 } else {
586 alg->getLogger().information("Detector positions in IDF updated with positions in the data file");
587 }
588 // We want this to throw if it fails to warn the user that the information
589 // is not correct.
590 updateInst->execute();
591 }
592
593 return executionSuccessful;
594}
595
596//-----------------------------------------------------------------------------
598template <typename T>
599void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, const std::string &entry_name,
600 const Nexus::NexusDescriptor &descriptor) {
601 // Open the file
602 Nexus::File file(nexusfilename);
603 file.openGroup(entry_name, "NXentry");
604
605 // get the title
606 if (descriptor.isEntry("/" + entry_name + "/title", "SDS")) {
607 file.openData("title");
608 if (file.getInfo().type == NXnumtype::CHAR) {
609 std::string title = file.getStrData();
610 if (!title.empty())
611 WS->setTitle(title);
612 }
613 file.closeData();
614 }
615
616 // get the notes
617 if (descriptor.isEntry("/" + entry_name + "/notes", "SDS")) {
618 file.openData("notes");
619 if (file.getInfo().type == NXnumtype::CHAR) {
620 std::string notes = file.getStrData();
621 if (!notes.empty())
622 WS->mutableRun().addProperty("file_notes", notes, true);
623 }
624 file.closeData();
625 }
626
627 // Get the run number
628 if (descriptor.isEntry("/" + entry_name + "/run_number", "SDS")) {
629 file.openData("run_number");
630 std::string run;
631 if (file.getInfo().type == NXnumtype::CHAR) {
632 run = file.getStrData();
633 } else if (file.isDataInt()) {
634 // inside ISIS the run_number type is int32
635 std::vector<int> value;
636 file.getData(value);
637 if (!value.empty())
638 run = std::to_string(value[0]);
639 }
640 if (!run.empty()) {
641 WS->mutableRun().addProperty("run_number", run, true);
642 }
643 file.closeData();
644 }
645
646 // get the experiment identifier
647 if (descriptor.isEntry("/" + entry_name + "/experiment_identifier", "SDS")) {
648 file.openData("experiment_identifier");
649 std::string expId;
650 if (file.getInfo().type == NXnumtype::CHAR) {
651 expId = file.getStrData();
652 }
653 if (!expId.empty()) {
654 WS->mutableRun().addProperty("experiment_identifier", expId, true);
655 }
656 file.closeData();
657 }
658
659 // get the sample name - nested try/catch to leave the handle in an
660 // appropriate state
661 if (descriptor.isEntry("/" + entry_name + "/sample", "NXsample")) {
662 file.openGroup("sample", "NXsample");
663 try {
664 if (descriptor.isEntry("/" + entry_name + "/sample/name", "SDS")) {
665 file.openData("name");
666 const auto info = file.getInfo();
667 std::string sampleName;
668 if (info.type == NXnumtype::CHAR) {
669 if (info.dims.size() == 1) {
670 sampleName = file.getStrData();
671 } else { // something special for 2-d array
672 const int64_t total_length = std::accumulate(info.dims.begin(), info.dims.end(), static_cast<int64_t>(1),
673 std::multiplies<int64_t>());
674 boost::scoped_array<char> val_array(new char[total_length]);
675 file.getData(val_array.get());
676 sampleName = std::string(val_array.get(), total_length);
677 }
678 }
679 file.closeData();
680 if (!sampleName.empty()) {
681 WS->mutableSample().setName(sampleName);
682 }
683 }
684 } catch (Nexus::Exception const &) {
685 // let it drop on floor if an exception occurs while reading sample
686 }
687 file.closeGroup();
688 }
689
690 // get the duration
691 if (descriptor.isEntry("/" + entry_name + "/duration", "SDS")) {
692 file.openData("duration");
693 std::vector<double> duration;
694 file.getDataCoerce(duration);
695 if (duration.size() == 1) {
696 // get the units
697 std::string units;
698 if (file.hasAttr("units")) {
699 file.getAttr<std::string>("units", units);
700 }
701
702 // set the property
703 WS->mutableRun().addProperty("duration", duration[0], units, true);
704 }
705 file.closeData();
706 }
707
708 // close the file
709 file.close();
710}
711
712//-----------------------------------------------------------------------------
725template <typename T>
726bool LoadEventNexus::loadInstrument(const std::string &nexusfilename, T localWorkspace,
727 const std::string &top_entry_name, Algorithm *alg,
728 const Nexus::NexusDescriptor *descriptor) {
729
730 bool loadNexusInstrumentXML = true;
731 if (alg->existsProperty("LoadNexusInstrumentXML"))
732 loadNexusInstrumentXML = alg->getProperty("LoadNexusInstrumentXML");
733
734 bool foundInstrument = false;
735 if (loadNexusInstrumentXML)
736 foundInstrument = runLoadIDFFromNexus<T>(nexusfilename, localWorkspace, top_entry_name, alg);
737 if (!foundInstrument)
738 foundInstrument = runLoadInstrument<T>(nexusfilename, std::move(localWorkspace), top_entry_name, alg, descriptor);
739 return foundInstrument;
740}
741
742//-----------------------------------------------------------------------------
752template <typename T>
753bool LoadEventNexus::runLoadIDFFromNexus(const std::string &nexusfilename, T localWorkspace,
754 const std::string &top_entry_name, Algorithm *alg) {
755 // Test if IDF exists in file, move on quickly if not
756 try {
757 Nexus::File nxsfile(nexusfilename);
758 nxsfile.openAddress(top_entry_name + "/instrument/instrument_xml");
759 } catch (Nexus::Exception const &) {
760 alg->getLogger().information("No instrument XML definition found in " + nexusfilename + " at " + top_entry_name +
761 "/instrument");
762 return false;
763 }
764
765 auto loadInst = alg->createChildAlgorithm("LoadIDFFromNexus");
766
767 // Now execute the Child Algorithm. Catch and log any error, but don't stop.
768 try {
769 loadInst->setPropertyValue("Filename", nexusfilename);
770 loadInst->setProperty<Mantid::API::MatrixWorkspace_sptr>("Workspace", localWorkspace);
771 loadInst->setPropertyValue("InstrumentParentPath", top_entry_name);
772 loadInst->execute();
773 } catch (std::invalid_argument &) {
774 alg->getLogger().error("Invalid argument to LoadIDFFromNexus Child Algorithm ");
775 } catch (std::runtime_error &) {
776 alg->getLogger().debug("No instrument definition found by LoadIDFFromNexus in " + nexusfilename + " at " +
777 top_entry_name + "/instrument");
778 }
779
780 if (!loadInst->isExecuted())
781 alg->getLogger().information("No IDF loaded from Nexus file.");
782 return loadInst->isExecuted();
783}
784} // namespace DataHandling
785} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
IPeaksWorkspace_sptr workspace
double left
double right
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Kernel::Logger & getLogger() const
Returns a reference to the logger.
static std::string getInstrumentFilename(const std::string &instrumentName, const std::string &date="")
Get the IDF using the instrument name and date.
Helper class for reporting progress from algorithms.
Definition Progress.h:25
EventWorkspaceCollection : Collection of EventWorspaces to give backward-forward compatibility around...
Custom exception extending std::invalid_argument Thrown when nperiods does not match period_log Custo...
InvalidLogPeriods(const std::string &msg)
std::shared_ptr< Mantid::Kernel::TimeROI > bad_pulses_timeroi
double longest_tof
Limits found to tof.
Mantid::Types::Core::DateAndTime filter_time_start
Filter by start time.
double filter_tof_max
Filter by a maximum time-of-flight.
bool loadlogs
Do we load the sample logs?
bool event_id_is_spec
True if the event_id is spectrum no not pixel ID.
size_t discarded_events
A count of events discarded because they came from a pixel that's not in the IDF.
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.
Mantid::Types::Core::DateAndTime filter_time_stop
Filter by stop time.
static bool runLoadInstrument(const std::string &nexusfilename, T localWorkspace, const std::string &top_entry_name, Algorithm *alg, const Nexus::NexusDescriptor *descriptor=nullptr)
Load instrument from IDF file specified by Nexus file.
const std::string summary() const override
Summary of algorithms purpose.
int32_t m_specMax
Maximum spectrum to load.
double compressTolerance
Tolerance for CompressEvents; use -1 to mean don't compress.
const std::string category() const override
Category.
std::string m_filename
The name and path of the input file.
std::shared_ptr< BankPulseTimes > m_allBanksPulseTimes
Pulse times for ALL banks, taken from proton_charge log.
static bool loadInstrument(const std::string &nexusfilename, T localWorkspace, const std::string &top_entry_name, Algorithm *alg, const Nexus::NexusDescriptor *descriptor=nullptr)
Load instrument from Nexus file if possible, else from IDF spacified by Nexus file.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
double shortest_tof
Limits found to tof.
std::mutex m_tofMutex
Mutex protecting tof limits.
bool filter_tof_range
Tof range is being filtered.
static std::string readInstrumentFromISIS_VMSCompat(Nexus::File &hFile)
method used to return instrument name for some old ISIS files where it is not written properly within...
DataObjects::EventWorkspace_sptr createEmptyEventWorkspace()
const std::string name() const override
function to return a name of the algorithm, must be overridden in all algorithms
std::unique_ptr< Nexus::File > m_file
std::shared_ptr< EventWorkspaceCollection > m_ws
The workspace being filled out.
static bool runLoadIDFFromNexus(const std::string &nexusfilename, T localWorkspace, const std::string &top_entry_name, Algorithm *alg)
Load instrument for Nexus file.
bool m_instrument_loaded_correctly
Was the instrument loaded?
size_t bad_tofs
Count of all the "bad" tofs found.
int32_t m_specMin
Minimum spectrum to load.
int version() const override
Version.
double filter_tof_min
Filter by a minimum time-of-flight.
std::string m_top_entry_name
name of top level NXentry to use
A class for holding :
Definition EventList.h:57
void setTofs(const MantidVec &tofs) override
Set a list of TOFs to the current event list.
void sortTof() const
Sort events by TOF in one thread.
bool empty() const
Much like stl containers, returns true if there is nothing in the event list.
void getTofs(std::vector< double > &tofs) const override
Fill a vector with the list of TOFs.
Exception for when an item is not found in a collection.
Definition Exception.h:145
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
OptionalBool : Tri-state bool.
A specialised Property class for holding a series of time-value pairs.
Class that provides for a standard Nexus exception.
const std::map< std::string, std::set< std::string > > & getAllEntries() const noexcept
Returns a const reference of the internal map holding all entries in the Nexus HDF5 file.
bool isEntry(const std::string &entryName, const std::string &groupClass) const noexcept
Checks if a full-address entry exists for a particular groupClass in a Nexus dataset.
static unsigned short constexpr CHAR
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
bool isNexus(const std::string &filename)
Determine if the Geometry file type is Nexus.
void adjustTimeOfFlightISISLegacy(Nexus::File &file, T localWorkspace, const std::string &entry_name, const std::string &classType, const Nexus::NexusDescriptor *descriptor=nullptr)
ISIS specific method for dealing with wide events.
void makeTimeOfFlightDataFuzzy(Nexus::File &file, T localWorkspace, const std::string &binsName, size_t start_wi=0, size_t end_wi=0)
Load the time of flight data.
std::shared_ptr< EventWorkspaceCollection > EventWorkspaceCollection_sptr
bool exists(Nexus::File &file, const std::string &name)
void loadEvents(API::Progress &prog, const char *progMsg, EP &eventProcessor, const Nexus::NXEntry &entry, uint64_t start_nsec, uint64_t end_nsec)
Definition LoadBBY2.cpp:120
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
Helper class which provides the Collimation Length for SANS instruments.
Generate a tableworkspace to store the calibration results.
STL namespace.
std::string to_string(const wide_integer< Bits, Signed > &n)