-
Notifications
You must be signed in to change notification settings - Fork 122
/
RemoveLogs.cpp
82 lines (72 loc) · 2.92 KB
/
RemoveLogs.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// 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 +
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidDataHandling/RemoveLogs.h"
#include "MantidAPI/FileProperty.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/Glob.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include <Poco/DateTimeFormat.h>
#include <Poco/DateTimeParser.h>
#include <Poco/DirectoryIterator.h>
#include <Poco/File.h>
#include <Poco/Path.h>
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <fstream> // used to get ifstream
#include <sstream>
namespace Mantid {
namespace DataHandling {
// Register the algorithm into the algorithm factory
DECLARE_ALGORITHM(RemoveLogs)
using namespace Kernel;
using namespace API;
using DataObjects::Workspace2D_sptr;
/// Empty default constructor
RemoveLogs::RemoveLogs() {}
/// Initialisation method.
void RemoveLogs::init() {
// When used as a Child Algorithm the workspace name is not used - hence the
// "Anonymous" to satisfy the validator
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("Workspace", "Anonymous", Direction::InOut),
"The name of the workspace to which the log data will be removed");
declareProperty(std::make_unique<ArrayProperty<std::string>>("KeepLogs", Direction::Input),
"List(comma separated) of logs to be kept");
}
/** Executes the algorithm. Reading in log file(s)
*
* @throw Mantid::Kernel::Exception::FileError Thrown if file is not
*recognised to be a raw datafile or log file
* @throw std::runtime_error Thrown with Workspace problems
*/
void RemoveLogs::exec() {
// Get the input workspace and retrieve run from workspace.
// the log file(s) will be loaded into the run object of the workspace
const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
const std::vector<Mantid::Kernel::Property *> &logData = localWorkspace->run().getLogData();
std::vector<std::string> keepLogs = getProperty("KeepLogs");
std::vector<std::string> logNames;
logNames.reserve(logData.size());
for (const auto property : logData) {
logNames.emplace_back(property->name());
}
for (const auto &name : logNames) {
auto location = std::find(keepLogs.cbegin(), keepLogs.cend(), name);
if (location == keepLogs.cend()) {
localWorkspace->mutableRun().removeLogData(name);
}
}
// operation was a success and ended normally
return;
}
} // namespace DataHandling
} // namespace Mantid