-
Notifications
You must be signed in to change notification settings - Fork 122
/
RenameLog.cpp
63 lines (51 loc) · 2.19 KB
/
RenameLog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidDataHandling/RenameLog.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidKernel/MandatoryValidator.h"
#include "MantidKernel/TimeSeriesProperty.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
namespace Mantid {
namespace DataHandling {
DECLARE_ALGORITHM(RenameLog)
void RenameLog::init() {
declareProperty(
std::make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(
"Workspace", "Anonymous", Direction::InOut),
"Workspace to have logs merged");
declareProperty("OriginalLogName", "",
std::make_shared<MandatoryValidator<std::string>>(),
"Log's original name.");
declareProperty("NewLogName", "",
std::make_shared<MandatoryValidator<std::string>>(),
"Log's new name.");
}
void RenameLog::exec() {
// 1. Get value
matrixWS = this->getProperty("Workspace");
std::string origlogname = this->getProperty("OriginalLogName");
std::string newlogname = this->getProperty("NewLogName");
Kernel::Property *property = matrixWS->run().getLogData(origlogname)->clone();
auto *timeprop = dynamic_cast<Kernel::TimeSeriesProperty<double> *>(property);
if (!timeprop) {
// g_log.error() << "After Log data is removed, TimeSeriesProperty " <<
// origlogname << " is deleted from memory\n";
throw std::runtime_error("Not a TimeSeriesProperty!");
}
// std::cout << "Remove log" << origlogname << '\n';
matrixWS->mutableRun().removeLogData(origlogname);
// std::cout << "Change log name\n";
timeprop->setName(newlogname);
// std::cout << "Add log" << timeprop->name() << '\n';
// std::vector<Types::Core::DateAndTime> newtimes = timeprop->timesAsVector();
// std::cout << "Entries = " << newtimes.size() << '\n';
matrixWS->mutableRun().addProperty(timeprop);
}
} // namespace DataHandling
} // namespace Mantid