-
Notifications
You must be signed in to change notification settings - Fork 124
/
RenameLog.cpp
57 lines (45 loc) · 1.92 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
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidDataHandling/RenameLog.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(make_unique<API::WorkspaceProperty<API::MatrixWorkspace>>(
"Workspace", "Anonymous", Direction::InOut),
"Workspace to have logs merged");
declareProperty("OriginalLogName", "",
boost::make_shared<MandatoryValidator<std::string>>(),
"Log's original name.");
declareProperty("NewLogName", "",
boost::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();
Kernel::TimeSeriesProperty<double> *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<Kernel::DateAndTime> newtimes = timeprop->timesAsVector();
// std::cout << "Entries = " << newtimes.size() << '\n';
matrixWS->mutableRun().addProperty(timeprop);
}
} // namespace Mantid
} // namespace DataHandling