Mantid
Loading...
Searching...
No Matches
RemoveLogs.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
14#include "MantidKernel/Glob.h"
18
19#include <Poco/DateTimeFormat.h>
20#include <Poco/DateTimeParser.h>
21#include <Poco/DirectoryIterator.h>
22#include <boost/algorithm/string.hpp>
23
24#include <algorithm>
25#include <fstream> // used to get ifstream
26#include <sstream>
27
28namespace Mantid::DataHandling {
29
30// Register the algorithm into the algorithm factory
31DECLARE_ALGORITHM(RemoveLogs)
32
33using namespace Kernel;
34using namespace API;
36
38RemoveLogs::RemoveLogs() = default;
39
42 // When used as a Child Algorithm the workspace name is not used - hence the
43 // "Anonymous" to satisfy the validator
44 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("Workspace", "Anonymous", Direction::InOut),
45 "The name of the workspace to which the log data will be removed");
46 declareProperty(std::make_unique<ArrayProperty<std::string>>("KeepLogs", Direction::Input),
47 "List(comma separated) of logs to be kept");
48}
49
57 // Get the input workspace and retrieve run from workspace.
58 // the log file(s) will be loaded into the run object of the workspace
59 const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
60 const std::vector<Mantid::Kernel::Property *> &logData = localWorkspace->run().getLogData();
61 std::vector<std::string> keepLogs = getProperty("KeepLogs");
62 std::vector<std::string> logNames;
63 logNames.reserve(logData.size());
64 std::transform(logData.cbegin(), logData.cend(), std::back_inserter(logNames),
65 [](const auto &property) { return property->name(); });
66 for (const auto &logName : logNames) {
67 auto location = std::find(keepLogs.cbegin(), keepLogs.cend(), logName);
68 if (location == keepLogs.cend()) {
69 localWorkspace->mutableRun().removeLogData(logName);
70 }
71 }
72
73 // operation was a success and ended normally
74 return;
75}
76
77} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
void exec() override
Overwrites Algorithm method.
void init() override
Overwrites Algorithm method.
RemoveLogs()
Default constructor.
Support for a property that holds an array of values.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
@ InOut
Both an input & output workspace.
Definition Property.h:55
@ Input
An input workspace.
Definition Property.h:53