Newer
Older
// 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 "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/Glob.h"
#include "MantidKernel/PropertyWithValue.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 <fstream> // used to get ifstream
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
void RemoveLogs::init() {
// When used as a Child Algorithm the workspace name is not used - hence the
// "Anonymous" to satisfy the validator
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
*/
// 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");
logNames.reserve(logData.size());
logNames.emplace_back(property->name());
auto location = std::find(keepLogs.cbegin(), keepLogs.cend(), name);
if (location == keepLogs.cend()) {
localWorkspace->mutableRun().removeLogData(name);
// operation was a success and ended normally
}
} // namespace DataHandling
} // namespace Mantid