Skip to content

Commit

Permalink
Re #7822. A method to clear all log values except the current one.
Browse files Browse the repository at this point in the history
Takes all TimeSeriesProperty logs and clears out all entries
except the last one. Single value logs are left unchanged.
  • Loading branch information
RussellTaylor committed Oct 1, 2013
1 parent 769ff9f commit 685d147
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/LogManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion Code/Mantid/Framework/API/src/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions Code/Mantid/Framework/API/test/LogManagerTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,37 @@ class LogManagerTest : public CxxTest::TestSuite
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()
Expand Down

0 comments on commit 685d147

Please sign in to comment.