Commit 685d1474 authored by Russell Taylor's avatar Russell Taylor
Browse files

Re #7822. A method to clear all log values except the current one.

Takes all TimeSeriesProperty logs and clears out all entries
except the last one. Single value logs are left unchanged.
parent 769ff9f7
......@@ -143,6 +143,8 @@ namespace Mantid
/// Empty the values out of all TimeSeriesProperty logs
void clearTimeSeriesLogs();
/// Empty all but the last value out of all TimeSeriesProperty logs
void clearOutdatedTimeSeriesLogValues();
/// Save the run to a NeXus file with a given group name
virtual void saveNexus(::NeXus::File * file, const std::string & group,bool keepOpen=false) const;
......
......@@ -378,7 +378,22 @@ Kernel::Logger& LogManager::g_log = Kernel::Logger::get("LogManager");
}
}
/** Clears out all but the last entry of all logs of type TimeSeriesProperty
* Check the documentation/definition of TimeSeriesProperty::clearOutdated for
* the definition of 'last entry'.
*/
void LogManager::clearOutdatedTimeSeriesLogValues()
{
auto & props = getProperties();
for ( auto it = props.begin(); it != props.end(); ++it)
{
if ( auto tsp = dynamic_cast<ITimeSeriesProperty*>(*it) )
{
tsp->clearOutdated();
}
}
}
//--------------------------------------------------------------------------------------------
/** Save the object to an open NeXus file.
* @param file :: open NeXus file
......
......@@ -259,7 +259,37 @@ public:
TS_ASSERT_EQUALS( runInfo.getPropertyValueAsType<int>(intProp), 99 );
}
void clearOutdatedTimeSeriesLogValues()
{
// Set up a Run object with 3 properties in it (1 time series, 2 single value)
LogManager runInfo;
const std::string stringProp("aStringProp");
const std::string stringVal("testing");
runInfo.addProperty(stringProp,stringVal);
const std::string intProp("anIntProp");
runInfo.addProperty(intProp,99);
const std::string tspProp("tsp");
addTestTimeSeries(runInfo,"tsp");
// Check it's set up right
TS_ASSERT_EQUALS( runInfo.getProperties().size(), 3 );
auto tsp = runInfo.getTimeSeriesProperty<double>(tspProp);
TS_ASSERT_EQUALS( tsp->realSize(), 10 );
auto lastTime = tsp->lastTime();
auto lastValue = tsp->lastValue();
// Do the clearing work
TS_ASSERT_THROWS_NOTHING( runInfo.clearOutdatedTimeSeriesLogValues() );
// Check the time-series property has 1 entry, & the others are unchanged
TS_ASSERT_EQUALS( runInfo.getProperties().size(), 3 );
TS_ASSERT_EQUALS( tsp->realSize(), 1 );
TS_ASSERT_EQUALS( tsp->firstTime(), lastTime );
TS_ASSERT_EQUALS( tsp->firstValue(), lastValue );
TS_ASSERT_EQUALS( runInfo.getPropertyValueAsType<std::string>(stringProp), stringVal );
TS_ASSERT_EQUALS( runInfo.getPropertyValueAsType<int>(intProp), 99 );
}
/** Save and load to NXS file */
void test_nexus()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment