Mantid
Loading...
Searching...
No Matches
ChangePulsetime.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 +
10#include "MantidKernel/System.h"
11
12namespace Mantid::Algorithms {
13
14// Register the algorithm into the AlgorithmFactory
15DECLARE_ALGORITHM(ChangePulsetime)
16
17using namespace Mantid::Kernel;
18using namespace Mantid::API;
19using namespace Mantid::DataObjects;
20using std::size_t;
21
22//----------------------------------------------------------------------------------------------
26 declareProperty(std::make_unique<WorkspaceProperty<EventWorkspace>>("InputWorkspace", "", Direction::Input),
27 "An input event workspace.");
28 declareProperty(std::make_unique<PropertyWithValue<double>>("TimeOffset", Direction::Input),
29 "Number of seconds (a float) to add to each event's pulse "
30 "time. Required.");
31 declareProperty(std::make_unique<ArrayProperty<int>>("WorkspaceIndexList", ""),
32 "An optional list of workspace indices to change. If blank, "
33 "all spectra in the workspace are modified.");
34 declareProperty(std::make_unique<WorkspaceProperty<EventWorkspace>>("OutputWorkspace", "", Direction::Output),
35 "An output event workspace.");
36}
37
38//----------------------------------------------------------------------------------------------
42 EventWorkspace_const_sptr in_ws = getProperty("InputWorkspace");
43 EventWorkspace_sptr out_ws = getProperty("OutputWorkspace");
44 if (!out_ws) {
45 out_ws = in_ws->clone();
46 }
47
48 // Either use the given list or use all spectra
49 std::vector<int> workspaceIndices = getProperty("WorkspaceIndexList");
50 auto num_to_do = static_cast<int64_t>(workspaceIndices.size());
51 bool doAll = false;
52 if (workspaceIndices.empty()) {
53 doAll = true;
54 num_to_do = in_ws->getNumberHistograms();
55 }
56
57 double timeOffset = getProperty("TimeOffset");
58
59 Progress prog(this, 0.0, 1.0, num_to_do);
61 for (int64_t i = 0; i < num_to_do; i++) {
62 // What workspace index?
63 int64_t wi;
64 if (doAll)
65 wi = i;
66 else
67 wi = workspaceIndices[i];
68
69 // Call the method on the event list
70 out_ws->getSpectrum(wi).addPulsetime(timeOffset);
71
72 prog.report(name());
73 }
74
75 setProperty("OutputWorkspace", out_ws);
76}
77
78} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
#define PARALLEL_FOR_NO_WSP_CHECK()
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
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.
const std::string name() const override
Algorithm's name for identification.
void init() override
Initialise the properties.
void exec() override
Run the algorithm.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Definition: ProgressBase.h:51
The concrete, templated class for properties.
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.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54