Skip to content

Commit

Permalink
Add option to keep some logs in RemoveLogs. Refs #9106
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed Feb 28, 2014
1 parent 2e7138a commit c9fe52a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 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
34 changes: 34 additions & 0 deletions Code/Mantid/Framework/DataHandling/test/RemoveLogsTest.h
Expand Up @@ -5,6 +5,7 @@

#include "MantidDataHandling/RemoveLogs.h"
#include "MantidDataHandling/LoadLog.h"
#include "MantidDataHandling/LoadNexusLogs.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidGeometry/Instrument.h"
#include "MantidDataObjects/Workspace2D.h"
Expand Down Expand Up @@ -172,6 +173,39 @@ 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
Workspace_sptr ws = WorkspaceFactory::Instance().create("Workspace2D",1,1,1);
outputSpace = "PartiallyRemoveLogs";
TS_ASSERT_THROWS_NOTHING(AnalysisDataService::Instance().add(outputSpace, ws));

LoadNexusLogs lnl;
if ( !lnl.isInitialized() ) lnl.initialize();

TS_ASSERT_THROWS_NOTHING(lnl.setPropertyValue("Filename", "CNCS_7860") );
TS_ASSERT_THROWS_NOTHING(lnl.setPropertyValue("Workspace",outputSpace) );
TS_ASSERT_THROWS_NOTHING(lnl.execute());
TS_ASSERT( lnl.isExecuted() );

// 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", "Speed5, gd_prtn_chrg"));
TS_ASSERT_THROWS_NOTHING(remover.execute());


TS_ASSERT( remover.isExecuted() );

// log should have been removed
TS_ASSERT_THROWS( output->run().getLogData("Speed4"), std::runtime_error);
TS_ASSERT_THROWS_NOTHING( output->run().getLogData("Speed5"));
TS_ASSERT_THROWS_NOTHING( output->run().getLogData("gd_prtn_chrg"));
AnalysisDataService::Instance().remove(outputSpace);
}

private:
LoadLog loader;
Expand Down

0 comments on commit c9fe52a

Please sign in to comment.