Mantid
Loading...
Searching...
No Matches
SortEvents.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
14
15namespace Mantid::Algorithms {
16
17// Register the class into the algorithm factory
18DECLARE_ALGORITHM(SortEvents)
19
20using namespace Kernel;
21using namespace API;
22using DataObjects::EventWorkspace;
25
30 declareProperty(std::make_unique<WorkspaceProperty<EventWorkspace>>("InputWorkspace", "", Direction::InOut),
31 "EventWorkspace to be sorted.");
32
33 std::vector<std::string> propOptions{"X Value", "Pulse Time", "Pulse Time + TOF"};
34 declareProperty("SortBy", "X Value", std::make_shared<StringListValidator>(propOptions),
35 "How to sort the events:\n"
36 " X Value: the x-position of the event in each pixel "
37 "(typically Time of Flight).\n"
38 " Pulse Time: the wall-clock time of the pulse that "
39 "produced the event.");
40}
41
48 // Get the input workspace
49 EventWorkspace_sptr eventW = getProperty("InputWorkspace");
50 // And other properties
51 std::string sortoption = getPropertyValue("SortBy");
52
53 //------- EventWorkspace ---------------------------
54 const size_t histnumber = eventW->getNumberHistograms();
55
56 // Initialize progress reporting.
57 Progress prog(this, 0.0, 1.0, histnumber);
58
60 if (sortoption == "Pulse Time")
62 else if (sortoption == "Pulse Time + TOF")
64
65 // This runs the SortEvents algorithm in parallel
66 eventW->sortAll(sortType, &prog);
67}
68
69} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
A property class for workspaces.
void exec() override
Executes the rebin algorithm.
Definition: SortEvents.cpp:47
void init() override
Initialisation method.
Definition: SortEvents.cpp:29
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
EventSortType
How the event list is sorted.
Definition: EventList.h:31
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
@ InOut
Both an input & output workspace.
Definition: Property.h:55