Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/7822_carry_log_state_to_…
Browse files Browse the repository at this point in the history
…new_live_chunk'
  • Loading branch information
AndreiSavici committed Oct 18, 2013
2 parents 2184a87 + 26d78b5 commit fc3f1b4
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 14 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ITimeSeriesProperty
virtual int realSize() const = 0;
/// Deletes the series of values in the property
virtual void clear() = 0;
/// Deletes all but the 'last entry' in the property
virtual void clearOutdated() = 0;

/// Virtual destructor
virtual ~ITimeSeriesProperty() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ namespace Mantid

/// Deletes the series of values in the property
void clear();
/// Deletes all but the 'last entry' in the property
void clearOutdated();
/// Clears and creates a TimeSeriesProperty from these parameters
void create(const Kernel::DateAndTime &start_time, const std::vector<double> & time_sec, const std::vector<TYPE> & new_values);
/// Clears and creates a TimeSeriesProperty from these parameters
Expand Down
17 changes: 17 additions & 0 deletions Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,23 @@ namespace Mantid
m_filterApplied = false;
}

/** Clears out all but the last value in the property.
* The last value is the last entry in the m_values vector - no sorting is
* done or checked for to ensure that the last value is the most recent in time.
* It is up to the client to call sort() first if this is a requirement.
*/
template<typename TYPE>
void TimeSeriesProperty<TYPE>::clearOutdated()
{
if ( realSize() > 1 )
{
auto lastValue = m_values.back();
clear();
m_values.push_back(lastValue);
m_size = 1;
}
}

/**
* Clears and creates a TimeSeriesProperty from these parameters:
* @param start_time :: The reference time as a boost::posix_time::ptime value
Expand Down
35 changes: 33 additions & 2 deletions Code/Mantid/Framework/Kernel/test/TimeSeriesPropertyTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <boost/math/special_functions/fpclassify.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <boost/scoped_ptr.hpp>

using namespace Mantid::Kernel;

Expand Down Expand Up @@ -966,19 +967,49 @@ class TimeSeriesPropertyTest : public CxxTest::TestSuite

void test_clear()
{
TimeSeriesProperty<int> * p = new TimeSeriesProperty<int>("aProp");
boost::scoped_ptr<TimeSeriesProperty<int>> p(new TimeSeriesProperty<int>("aProp"));
p->addValue("2007-11-30T16:17:00",1);

TS_ASSERT_EQUALS( p->size(), 1);
TS_ASSERT_EQUALS( p->realSize(), 1);

ITimeSeriesProperty * pi = p;
ITimeSeriesProperty * pi = p.get();
TS_ASSERT_THROWS_NOTHING( pi->clear() );

TS_ASSERT_EQUALS( p->size(), 0);
TS_ASSERT_EQUALS( p->realSize(), 0);
}

void test_clearOutdated()
{
boost::scoped_ptr<TimeSeriesProperty<int>> p(new TimeSeriesProperty<int>("aProp"));
p->addValue("2007-11-30T16:17:00",99);

ITimeSeriesProperty * pi = p.get();
TS_ASSERT_THROWS_NOTHING( pi->clearOutdated() );
// No change
TS_ASSERT_EQUALS( p->size(), 1);
TS_ASSERT_EQUALS( p->realSize(), 1);
TS_ASSERT_EQUALS( p->lastValue(), 99);

DateAndTime t("2007-11-30T15:17:00");
p->addValue(t,88);
TS_ASSERT_EQUALS( p->size(), 2);

TS_ASSERT_THROWS_NOTHING( pi->clearOutdated() );
TS_ASSERT_EQUALS( p->size(), 1);
TS_ASSERT_EQUALS( p->realSize(), 1);
// Note that it kept the last-added entry even though its time is earlier
TS_ASSERT_EQUALS( p->lastTime(), t);
TS_ASSERT_EQUALS( p->firstValue(), 88);

TimeSeriesProperty<double> pp("empty");
TS_ASSERT_THROWS_NOTHING( pp.clearOutdated() );
// No change
TS_ASSERT_EQUALS( pp.size(), 0);
TS_ASSERT_EQUALS( pp.realSize(), 0);
}

/*
* Test 2 create() functions by creating 3 properties in different approaches.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,8 @@ namespace LiveData
//Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(m_eventBuffer, temp, false);

// Clear out the old logs
temp->mutableRun().clearTimeSeriesLogs();
// Clear out the old logs, except for the most recent entry
temp->mutableRun().clearOutdatedTimeSeriesLogValues();

// Lock the mutex and swap the workspaces
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,7 @@ def to_live_script(self):

script = """StartLiveData(UpdateEvery='10',Instrument='"""
script += self.instrument_name
script += """',ProcessingScript='"""

# Have to jump through this hoop because chunks after the first have an empty EnergyRequest property
script += """if mtd.doesExist(\""""
script += output_workspace_name
script += """\"): input.run().addProperty("EnergyRequest",mtd[\""""
script += output_workspace_name
script += """\"].getRun()["EnergyRequest"],True)\\n"""
script += """',ProcessingScript='"""
script += DgsReductionScripter.TOPLEVEL_WORKFLOWALG + '('
script += options
script += ")"
Expand All @@ -124,7 +117,6 @@ def to_live_script(self):
script += output_workspace
script += ")\n"

print script
return script

def to_batch(self):
Expand Down

0 comments on commit fc3f1b4

Please sign in to comment.