Mantid
Loading...
Searching...
No Matches
RenameLog.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 +
9#include "MantidAPI/Run.h"
12
13using namespace Mantid::Kernel;
14using namespace Mantid::API;
15
16namespace Mantid::DataHandling {
17
19
20void RenameLog::init() {
21
22 declareProperty(
23 std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>("Workspace", "Anonymous", Direction::InOut),
24 "Workspace to have logs merged");
25 declareProperty("OriginalLogName", "", std::make_shared<MandatoryValidator<std::string>>(), "Log's original name.");
26 declareProperty("NewLogName", "", std::make_shared<MandatoryValidator<std::string>>(), "Log's new name.");
27}
28
30
31 // 1. Get value
32 matrixWS = this->getProperty("Workspace");
33 std::string origlogname = this->getProperty("OriginalLogName");
34 std::string newlogname = this->getProperty("NewLogName");
35
36 Kernel::Property *property = matrixWS->run().getLogData(origlogname)->clone();
37 auto *timeprop = dynamic_cast<Kernel::TimeSeriesProperty<double> *>(property);
38
39 if (!timeprop) {
40 // g_log.error() << "After Log data is removed, TimeSeriesProperty " <<
41 // origlogname << " is deleted from memory\n";
42 throw std::runtime_error("Not a TimeSeriesProperty!");
43 }
44
45 // std::cout << "Remove log" << origlogname << '\n';
46 matrixWS->mutableRun().removeLogData(origlogname);
47
48 // std::cout << "Change log name\n";
49 timeprop->setName(newlogname);
50 // std::cout << "Add log" << timeprop->name() << '\n';
51 // std::vector<Types::Core::DateAndTime> newtimes = timeprop->timesAsVector();
52 // std::cout << "Entries = " << newtimes.size() << '\n';
53 matrixWS->mutableRun().addProperty(timeprop);
54}
55
56} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
RenameLog : TODO: DESCRIPTION.
Definition: RenameLog.h:19
API::MatrixWorkspace_sptr matrixWS
Definition: RenameLog.h:37
void exec() override
Virtual method - must be overridden by concrete algorithm.
Definition: RenameLog.cpp:29
Validator to check that a property is not left empty.
Base class for properties.
Definition: Property.h:94
A specialised Property class for holding a series of time-value pairs.
@ InOut
Both an input & output workspace.
Definition: Property.h:55