Skip to content

Commit

Permalink
Merge remote branch 'origin/feature/9106_RemoveLogsWhiteList'
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Mar 3, 2014
2 parents d523676 + 35f2bcb commit 7d5da4e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
14 changes: 11 additions & 3 deletions Code/Mantid/Framework/DataHandling/src/RemoveLogs.cpp
@@ -1,7 +1,7 @@
/*WIKI*
===Removes all logs from workspace===
Removes all logs from workspace, except those that are specified
Expand All @@ -27,6 +27,7 @@

#include <fstream> // used to get ifstream
#include <sstream>
#include <algorithm>

namespace Mantid
{
Expand All @@ -39,7 +40,7 @@ DECLARE_ALGORITHM(RemoveLogs)
/// Sets documentation strings for this algorithm
void RemoveLogs::initDocs()
{
this->setWikiSummary("Remove log file(s) from a [[workspace]]. ");
this->setWikiSummary("Remove logs from a [[workspace]]. ");
this->setOptionalMessage("Remove logs from a workspace.");
}

Expand All @@ -60,6 +61,8 @@ void RemoveLogs::init()
declareProperty(
new WorkspaceProperty<MatrixWorkspace>("Workspace","Anonymous",Direction::InOut),
"The name of the workspace to which the log data will be removed");
declareProperty(new ArrayProperty<std::string>("KeepLogs",Direction::Input),
"List(comma separated) of logs to be kept");

}

Expand All @@ -75,6 +78,7 @@ void RemoveLogs::exec()
// 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;
auto pEnd = logData.end();
for(auto pItr = logData.begin();
Expand All @@ -84,7 +88,11 @@ void RemoveLogs::exec()
}
for (std::vector<std::string>::const_iterator it = logNames.begin(); it != logNames.end(); ++it)
{
localWorkspace->mutableRun().removeLogData(*it);
auto location=std::find(keepLogs.begin(), keepLogs.end(), (*it));
if (location==keepLogs.end())
{
localWorkspace->mutableRun().removeLogData(*it);
}
}

// operation was a success and ended normally
Expand Down
55 changes: 54 additions & 1 deletion Code/Mantid/Framework/DataHandling/test/RemoveLogsTest.h
Expand Up @@ -16,7 +16,7 @@
#include "MantidGeometry/Instrument/Component.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include <vector>

#include "MantidTestHelpers/WorkspaceCreationHelper.h"
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataHandling;
Expand Down Expand Up @@ -172,6 +172,59 @@ class RemoveLogsTest : public CxxTest::TestSuite
do_test_SNSTextFile("Temp1,Temp2,Temp3,Yadda", "C,K,F,Fortnights", false, false);
}

void test_KeepLogs()
{
// Create an empty workspace and put it in the AnalysisDataService
EventWorkspace_sptr ws = WorkspaceCreationHelper::CreateEventWorkspace(1000,1,10000);
outputSpace = "PartiallyRemoveLogs";

// Add a bunch of logs
std::vector<DateAndTime> times;
std::vector<int> index;
std::vector<double> dbl1, dbl2;
DateAndTime startTime("2010-01-01T00:00:00");
for (int i = 0; i < 100; ++i)
{
times.push_back(startTime + i*10.0);
index.push_back(i);
dbl1.push_back(i*0.1);
dbl2.push_back(6.0);
}

auto scan_index = new TimeSeriesProperty<int>("scan_index");
scan_index->addValues(times,index);
ws->mutableRun().addProperty(scan_index);
auto dbl_prop1 = new TimeSeriesProperty<double>("some_prop");
auto dbl_prop2 = new TimeSeriesProperty<double>("some_other_prop");
dbl_prop1->addValues(times,dbl1);
dbl_prop2->addValues(times,dbl2);
ws->mutableRun().addProperty(dbl_prop1);
ws->mutableRun().addProperty(dbl_prop2);
ws->mutableRun().addProperty("Ei", 42.);
ws->mutableRun().addProperty("T0", 42.);
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));


// Get back the saved workspace
MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputSpace));

if ( !remover.isInitialized() ) remover.initialize();
TS_ASSERT_THROWS_NOTHING(remover.setPropertyValue("Workspace", outputSpace));
TS_ASSERT_THROWS_NOTHING(remover.setPropertyValue("KeepLogs", "Ei, scan_index"));
TS_ASSERT_THROWS_NOTHING(remover.execute());


TS_ASSERT( remover.isExecuted() );

// log should have been removed
TS_ASSERT_THROWS( output->run().getLogData("some_other_prop"), std::runtime_error);
TS_ASSERT_THROWS( output->run().getLogData("some_prop"), std::runtime_error);
TS_ASSERT_THROWS( output->run().getLogData("T0"), std::runtime_error);
TS_ASSERT_THROWS_NOTHING( output->run().getLogData("Ei"));
TS_ASSERT_THROWS_NOTHING( output->run().getLogData("scan_index"));
AnalysisDataService::Instance().remove(outputSpace);
}

private:
LoadLog loader;
Expand Down

0 comments on commit 7d5da4e

Please sign in to comment.