Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make listener properties in StartLiveData dynamic #17926

Merged
merged 10 commits into from
Nov 7, 2016
4 changes: 4 additions & 0 deletions Framework/LiveData/inc/MantidLiveData/StartLiveData.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class DLLExport StartLiveData : public LiveDataAlgorithm {
void init() override;
void exec() override;
void afterPropertySet(const std::string &) override;

void copyListenerProperties(
const boost::shared_ptr<Mantid::API::ILiveListener> &listener);
void removeListenerProperties();
};

} // namespace LiveData
Expand Down
53 changes: 34 additions & 19 deletions Framework/LiveData/src/StartLiveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,43 @@ void StartLiveData::init() {
*/
void StartLiveData::afterPropertySet(const std::string &propName) {
if (propName == "Instrument") {
// Remove old listener's properties
const std::vector<Property *> existingProps = getProperties();
for (auto existingProp : existingProps) {
if (existingProp->getGroup() == listenerPropertyGroup) {
removeProperty(existingProp->name());
}
}
// Properties of old listener, if any, need to be removed
removeListenerProperties();

// Add new listener's properties
// Get of instance of listener for this instrument
auto listener = LiveListenerFactory::Instance().create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be useful to have a comment about this (following) code relating to the transfer of ownership. Or to put this in a separate named method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by refactoring with two helper functions and simplifying code a bit.

getPropertyValue(propName), false);
auto propertyManagerListener =
boost::dynamic_pointer_cast<IPropertyManager>(listener);

if (propertyManagerListener) {
const std::vector<Property *> listenerProps =
propertyManagerListener->getProperties();
for (auto listenerProp : listenerProps) {
auto prop = std::unique_ptr<Property>(listenerProp->clone());
prop->setGroup(listenerPropertyGroup);
declareProperty(std::move(prop));
}

// Copy over properties of new listener to this algorithm
copyListenerProperties(listener);
}
}

/**
* Copies properties from an ILiveListener to this algorithm. This makes them
* appear in the "listener properties" group on the StartLiveData custom dialog.
*
* @param listener ILiveListener from which to copy properties
*/
void StartLiveData::copyListenerProperties(const boost::shared_ptr<ILiveListener> &listener)
{
// Add clones of listener's properties to this algorithm
for (auto listenerProp : listener->getProperties()) {
auto prop = std::unique_ptr<Property>(listenerProp->clone());
prop->setGroup(listenerPropertyGroup);
declareProperty(std::move(prop));
}
}

/**
* Removes previously copied ILiveListener properties.
*/
void StartLiveData::removeListenerProperties()
{
// Remove all properties tagged with the listener property group
for (auto prop : getProperties()) {
if (prop->getGroup() == listenerPropertyGroup) {
removeProperty(prop->name());
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions docs/source/algorithms/StartLiveData-v1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ simply calls :ref:`algm-LoadLiveData` at a fixed interval.
Instructions for setting up a "fake" data stream are found `here
<http://www.mantidproject.org/MBC_Live_Data_Simple_Examples>`__.

Listener Properties
###################

Specific LiveListeners may provide their own properties, in addition to
properties provided by StartLiveData. For convenience and accessibility, these
properties are made available through StartLiveData as well.

In the StartLiveData algorithm dialog, a group box called "Listener Properties"
will appear at the bottom of the sidebar on the left, if the currently selected
listener provides additional properties.

In the Python API, these listener properties may also be set as keyword
arguments when calling StartLiveData. For example, in this code snippet:

.. code-block:: python

StartLiveData(Instrument='ISIS_Histogram', OutputWorkspace='wsOut', UpdateEvery=1,
AccumulationMethod='Replace', PeriodList=[1,3], SpectraList=[2,4,6])

PeriodList and SpectraList are properties of the ISISHistoDataListener. They
are available as arguments in this call because Instrument is set to
'ISIS_Histogram', which uses that listener.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good documentation!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! :)

Live Plots
##########

Expand Down
2 changes: 1 addition & 1 deletion docs/source/release/v3.9.0/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Python Algorithms

- :ref:`MatchPeaks <algm-MatchPeaks>` performs circular shift operation (numpy roll) along the x-axis to align the peaks in the spectra.
- :ref:`FindEPP <algm-FindEPP>` is improved to better determine the initial parameters and range for the fitting.
- :ref:`StartLiveData <algm-StartLiveData>` can now accept LiveListener properties as parameters, based on the Instrument parameter.
- :ref:`StartLiveData <algm-StartLiveData>` can now accept LiveListener properties as parameters, based on the value of the "Instrument" parameter.

Bug Fixes
---------
Expand Down