21using namespace Kernel;
23using DataObjects::EventList;
24using DataObjects::EventWorkspace;
27using Types::Core::DateAndTime;
33const std::string START_TIME(
"StartTime");
34const std::string STOP_TIME(
"StopTime");
35const std::string ABS_START(
"AbsoluteStartTime");
36const std::string ABS_STOP(
"AbsoluteStopTime");
41 std::string commonHelp(
"\nYou can only specify the relative or absolute "
42 "start/stop times, not both.");
45 "An input event workspace");
49 "The name to use for the output workspace");
51 auto min = std::make_shared<BoundedValidator<double>>();
54 "The start time since the start of the run. "
55 "Use an integer value for time in nanoseconds. "
56 "Use a floating-point value for time in seconds. "
57 "Events before this time are filtered out. \nThe time of the "
58 "first pulse (i.e. the first entry in the \"proton_charge\" "
59 "sample log) is used as the zero. " +
63 "The stop time since the start of the run. "
64 "Use an integer value for time in nanoseconds. "
65 "Use a floating-point value for time in seconds. "
66 "Events at or after this time are filtered out. \nThe AbsoluteStartTime "
67 "or the time of the first pulse (i.e. the first entry in the "
68 "\"proton_charge\" sample log) is used as the zero. " +
71 auto dateTime = std::make_shared<DateTimeValidator>();
72 dateTime->allowEmpty(
true);
73 std::string absoluteHelp(
"Specify date and UTC time in ISO8601 format, e.g. 2010-09-14T04:20:12." + commonHelp);
75 "Absolute start time; events before this time are filtered out. " + absoluteHelp);
78 "Absolute stop time; events at of after this time are filtered out. " + absoluteHelp);
82 std::map<std::string, std::string> errors;
84 const std::string msg_double_spec(
"You need to specify either the relative or absolute parameter, but not both");
86 if ((!
isDefault(PropertyNames::START_TIME)) && (!
isDefault(PropertyNames::ABS_START))) {
87 errors[PropertyNames::START_TIME] = msg_double_spec;
88 errors[PropertyNames::ABS_START] = msg_double_spec;
92 errors[PropertyNames::STOP_TIME] = msg_double_spec;
93 errors[PropertyNames::ABS_STOP] = msg_double_spec;
106 const double startRelative =
getProperty(PropertyNames::START_TIME);
107 if (!
isDefault(PropertyNames::ABS_START)) {
112 const auto startOfRun = inputWS->run().getFirstPulseTime();
113 start = startOfRun + startRelative;
118 if (!
isDefault(PropertyNames::ABS_STOP)) {
121 }
else if (!
isDefault(PropertyNames::STOP_TIME)) {
123 const double stopRelative =
getProperty(PropertyNames::STOP_TIME);
124 stop = start - startRelative + stopRelative;
126 this->
getLogger().
debug(
"No end filter time specified - assuming last pulse");
127 stop = inputWS->run().getLastPulseTime();
133 std::stringstream msg;
134 msg <<
"The stop time (" << stop <<
") should be larger than the start time (" << start <<
")";
135 throw std::invalid_argument(msg.str());
138 auto outputWS = DataObjects::create<EventWorkspace>(*inputWS);
140 size_t numberOfSpectra = inputWS->getNumberHistograms();
143 Progress prog(
this, 0.0, 1.0, numberOfSpectra);
147 for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i) {
151 EventList &output_el = outputWS->getSpectrum(i);
153 const EventList &input_el = inputWS->getSpectrum(i);
164 auto timeroi = outputWS->mutableRun().getTimeROI();
165 if (timeroi.useAll()) {
167 timeroi.addROI(start, stop);
170 timeroi.update_intersection(
TimeROI(start, stop));
172 outputWS->mutableRun().setTimeROI(timeroi);
173 outputWS->mutableRun().removeDataOutsideTimeROI();
#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.
bool isDefault(const std::string &name) const
Kernel::Logger & getLogger() const
Returns a reference to the logger.
Helper class for reporting progress from algorithms.
A property class for workspaces.
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
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.
TimeROI : Object that holds information about when the time measurement was active.
std::string const OUTPUT_WKSP("OutputWorkspace")
std::string const INPUT_WKSP("InputWorkspace")
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
const std::string OUTPUT_WKSP("OutputWorkspace")
const std::string INPUT_WKSP("InputWorkspace")
@ Input
An input workspace.
@ Output
An output workspace.