20using namespace Kernel;
22using DataObjects::EventList;
23using DataObjects::EventWorkspace;
26using Types::Core::DateAndTime;
29 std::string commonHelp(
"\nYou can only specify the relative or absolute "
30 "start/stop times, not both.");
33 "An input event workspace");
36 "The name to use for the output workspace");
38 auto min = std::make_shared<BoundedValidator<double>>();
41 "The start time, in seconds, since the start of the run. "
42 "Events before this time are filtered out. \nThe time of the "
43 "first pulse (i.e. the first entry in the ProtonCharge "
44 "sample log) is used as the zero. " +
48 "The stop time, in seconds, since the start of the run. "
49 "Events at or after this time are filtered out. \nThe time "
50 "of the first pulse (i.e. the first entry in the "
51 "ProtonCharge sample log) is used as the zero. " +
54 std::string absoluteHelp(
"Specify date and UTC time in ISO8601 format, e.g. 2010-09-14T04:20:12." + commonHelp);
56 "Absolute start time; events before this time are filtered out. " + absoluteHelp);
59 "Absolute stop time; events at of after this time are filtered out. " + absoluteHelp);
68 DateAndTime start, stop;
70 double start_dbl, stop_dbl;
74 std::string start_str, stop_str;
78 if ((start_str !=
"") && (stop_str !=
"") && (start_dbl <= 0.0) && (stop_dbl <= 0.0)) {
80 start = DateAndTime(start_str);
81 stop = DateAndTime(stop_str);
82 }
else if ((start_str ==
"") && (stop_str ==
"") && ((start_dbl > 0.0) || (stop_dbl > 0.0))) {
84 DateAndTime first = inputWS->getFirstPulseTime();
85 DateAndTime last = inputWS->getLastPulseTime();
86 start = first + start_dbl;
88 stop = first + stop_dbl;
90 this->
getLogger().
debug() <<
"No end filter time specified - assuming last pulse\n";
91 stop = last + 10000.0;
95 throw std::invalid_argument(
"You need to specify either the StartTime or "
96 "StopTime parameters; or both the "
97 "AbsoluteStartTime and AbsoluteStopTime "
98 "parameters; but not other combinations.");
102 throw std::invalid_argument(
"The stop time should be larger than the start time.");
104 auto outputWS = DataObjects::create<EventWorkspace>(*inputWS);
106 size_t numberOfSpectra = inputWS->getNumberHistograms();
109 Progress prog(
this, 0.0, 1.0, numberOfSpectra);
113 for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i) {
117 EventList &output_el = outputWS->getSpectrum(i);
119 const EventList &input_el = inputWS->getSpectrum(i);
130 outputWS->mutableRun().filterByTime(start, stop);
131 setProperty(
"OutputWorkspace", std::move(outputWS));
#define DECLARE_ALGORITHM(classname)
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
#define PARALLEL_FOR_NO_WSP_CHECK()
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Kernel::Logger & getLogger() const
Returns a reference to the logger.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Executes the algorithm.
void init() override
Virtual method - must be overridden by concrete algorithm.
void filterByPulseTime(Types::Core::DateAndTime start, Types::Core::DateAndTime stop, EventList &output) const
Filter this EventList into an output EventList, using keeping only events within the >= start and < e...
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
@ Input
An input workspace.
@ Output
An output workspace.