Commit 012a3df0 authored by Russell Taylor's avatar Russell Taylor
Browse files

Re #5751. Add a method to run to clear out all time-series logs.

This is needed for live-data work.
parent cd5eb149
......@@ -5,14 +5,20 @@
#include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidKernel/Cache.h"
#include "MantidKernel/PropertyManager.h"
#include "MantidKernel/Statistics.h"
#include "MantidKernel/TimeSplitter.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/Matrix.h"
#include "MantidNexusCPP/NeXusFile.hpp"
#include <vector>
namespace Mantid
{
namespace Kernel
{
template<typename TYPE>
class TimeSeriesProperty;
}
namespace API
{
......@@ -48,8 +54,8 @@ namespace Mantid
public:
/// Default constructor
Run();
/// Virtual destructor
virtual ~Run();
/// Destructor. Doesn't need to be virtual as long as nothing inherits from this class.
~Run();
/// Copy constructor
Run(const Run& copy);
/// Assignment operator
......@@ -155,6 +161,9 @@ namespace Mantid
*/
double getLogAsSingleValue(const std::string & name, Kernel::Math::StatisticType statistic = Kernel::Math::Mean) const { return getPropertyAsSingleValue(name, statistic); }
/// Empty the values out of all TimeSeriesProperty logs
void clearTimeSeriesLogs();
/// Save the run to a NeXus file with a given group name
void saveNexus(::NeXus::File * file, const std::string & group) const;
/// Load the run from a NeXus file with a given group name
......@@ -189,7 +198,7 @@ namespace Mantid
* @param overwrite :: If true, a current value is overwritten. (Default: False)
*/
template<class TYPE>
void Run::addProperty(const std::string & name, const TYPE & value, bool overwrite)
void Run::addProperty(const std::string & name, const TYPE & value, bool overwrite)
{
addProperty(new Kernel::PropertyWithValue<TYPE>(name, value), overwrite);
}
......@@ -203,7 +212,7 @@ namespace Mantid
* @param overwrite :: If true, a current value is overwritten. (Default: False)
*/
template<class TYPE>
void Run::addProperty(const std::string & name, const TYPE & value, const std::string& units, bool overwrite)
void Run::addProperty(const std::string & name, const TYPE & value, const std::string& units, bool overwrite)
{
Kernel::Property * newProp = new Kernel::PropertyWithValue<TYPE>(name, value);
newProp->setUnits(units);
......
......@@ -511,8 +511,28 @@ Kernel::Logger& Run::g_log = Kernel::Logger::get("Run");
*/
Kernel::Property * Run::getProperty(const std::string & name) const
{
Kernel::Property *p = m_manager.getProperty(name);
return p;
return m_manager.getProperty(name);
}
/** Clear out the contents of all logs of type TimeSeriesProperty.
* Single-value properties will be left unchanged.
*
* The method has been fully implemented here instead of as a pass-through to
* PropertyManager to limit its visibility to Run clients.
*/
void Run::clearTimeSeriesLogs()
{
auto & props = getProperties();
// Loop over the set of properties, identifying those that are time-series properties
// and then clearing them out.
for ( auto it = props.begin(); it != props.end(); ++it)
{
if ( auto tsp = dynamic_cast<ITimeSeriesProperty*>(*it) )
{
tsp->clear();
}
}
}
//-----------------------------------------------------------------------------------------------
......
......@@ -396,6 +396,33 @@ public:
runInfo.addProperty(tsp);
}
void test_clear()
{
// Set up a Run object with 3 properties in it (1 time series, 2 single value)
Run 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 )
// Do the clearing work
TS_ASSERT_THROWS_NOTHING( runInfo.clearTimeSeriesLogs() );
// Check the time-series property is empty, but not the others
TS_ASSERT_EQUALS( runInfo.getProperties().size(), 3 );
TS_ASSERT_EQUALS( tsp->realSize(), 0 )
TS_ASSERT_EQUALS( runInfo.getPropertyValueAsType<std::string>(stringProp), stringVal );
TS_ASSERT_EQUALS( runInfo.getPropertyValueAsType<int>(intProp), 99 );
}
/** Setting up a goniometer and the angles to feed it
* using sample logs, then getting the right rotation matrix out.
*/
......
#include "MantidDataHandling/RenameLog.h"
#include "MantidKernel/MandatoryValidator.h"
#include "MantidKernel/TimeSeriesProperty.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
......
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