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 <Poco/File.h>
23#include <Poco/Path.h>
24#include <boost/algorithm/string.hpp>
25
26#include <algorithm>
27#include <fstream> // used to get ifstream
28#include <sstream>
29
30namespace Mantid::DataHandling {
31
32// Register the algorithm into the algorithm factory
33DECLARE_ALGORITHM(RemoveLogs)
34
35using namespace Kernel;
36using namespace API;
38
40RemoveLogs::RemoveLogs() = default;
41
44 // When used as a Child Algorithm the workspace name is not used - hence the
45 // "Anonymous" to satisfy the validator
46 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("Workspace", "Anonymous", Direction::InOut),
47 "The name of the workspace to which the log data will be removed");
48 declareProperty(std::make_unique<ArrayProperty<std::string>>("KeepLogs", Direction::Input),
49 "List(comma separated) of logs to be kept");
50}
51
59 // Get the input workspace and retrieve run from workspace.
60 // the log file(s) will be loaded into the run object of the workspace
61 const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
62 const std::vector<Mantid::Kernel::Property *> &logData = localWorkspace->run().getLogData();
63 std::vector<std::string> keepLogs = getProperty("KeepLogs");
64 std::vector<std::string> logNames;
65 logNames.reserve(logData.size());
66 std::transform(logData.cbegin(), logData.cend(), std::back_inserter(logNames),
67 [](const auto &property) { return property->name(); });
68 for (const auto &name : logNames) {
69 auto location = std::find(keepLogs.cbegin(), keepLogs.cend(), name);
70 if (location == keepLogs.cend()) {
71 localWorkspace->mutableRun().removeLogData(name);
72 }
73 }
74
75 // operation was a success and ended normally
76 return;
77}
78
79} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition: RemoveLogs.h:65
void exec() override
Overwrites Algorithm method.
Definition: RemoveLogs.cpp:58
void init() override
Overwrites Algorithm method.
Definition: RemoveLogs.cpp:43
RemoveLogs()
Default constructor.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
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