Skip to content

Commit

Permalink
Refs #8020. Move utility functions to MuonAnalysisHelper.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Feb 25, 2014
1 parent 7e4722f commit 35d3b1d
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 138 deletions.
Expand Up @@ -523,17 +523,6 @@ private slots:
//A reference to a logger
static Mantid::Kernel::Logger & g_log;

/// Returns a first period MatrixWorkspace in a run workspace
/// TODO: Move to MuonAnalysisHelper
static MatrixWorkspace_sptr firstPeriod(Workspace_sptr ws);

/// Returns a number of periods in a run workspace
/// TODO: Move to MuonAnalysisHelper
static size_t numPeriods(Workspace_sptr ws);

/// Print various information about the run
/// TODO: Move to MuonAnalysisHelper
static void printRunInfo(MatrixWorkspace_sptr runWs, std::ostringstream& out);
};

}
Expand Down
Expand Up @@ -2,6 +2,7 @@
#define MANTID_CUSTOMINTERFACES_MUONANALYSISHELPER_H_

#include "MantidKernel/System.h"
#include "MantidAPI/MatrixWorkspace.h"

#include <QSettings>
#include <QVector>
Expand All @@ -15,9 +16,20 @@ namespace CustomInterfaces
namespace MuonAnalysisHelper
{

using namespace Mantid::API;

/// Sets double validator for specified field
DLLExport void setDoubleValidator(QLineEdit* field);

/// Returns a first period MatrixWorkspace in a run workspace
DLLExport MatrixWorkspace_sptr firstPeriod(Workspace_sptr ws);

/// Returns a number of periods in a run workspace
DLLExport size_t numPeriods(Workspace_sptr ws);

/// Print various information about the run
DLLExport void printRunInfo(MatrixWorkspace_sptr runWs, std::ostringstream& out);

/**
* A class which deals with auto-saving the widget values. Widgets are registered and then on any
* change, their value is stored using QSettings.
Expand Down
128 changes: 1 addition & 127 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp
Expand Up @@ -1623,7 +1623,7 @@ void MuonAnalysis::inputFileChanged(const QStringList& files)
m_uiForm.infoBrowser->setText( QString::fromStdString(infoStr.str()) );

// If instrument or number of periods has changed -> update period widgets
size_t numPeriods = MuonAnalysis::numPeriods(loadResult->loadedWorkspace);
size_t numPeriods = MuonAnalysisHelper::numPeriods(loadResult->loadedWorkspace);
if(instrumentChanged || static_cast<int>(numPeriods) != m_uiForm.homePeriodBox1->count())
{
updatePeriodWidgets(numPeriods);
Expand Down Expand Up @@ -3503,132 +3503,6 @@ Algorithm_sptr MuonAnalysis::createLoadAlgorithm()
return loadAlg;
}

/**
* Return a first period MatrixWorkspace in a run workspace. If the run workspace has one period
* only - it is returned.
* @param ws :: Run workspace
*/
MatrixWorkspace_sptr MuonAnalysis::firstPeriod(Workspace_sptr ws)
{
if ( auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(ws) )
{
return boost::dynamic_pointer_cast<MatrixWorkspace>( group->getItem(0) );
}
else
{
return boost::dynamic_pointer_cast<MatrixWorkspace>(ws);
}
}

/**
* Returns a number of periods in a run workspace
* @param ws :: Run wokspace
* @return Number of periods
*/
size_t MuonAnalysis::numPeriods(Workspace_sptr ws)
{
if ( auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(ws) )
{
return group->size();
}
else
{
return 1;
}
}

/**
* Print various informaion about the run
* @param runWs :: Run workspace to retrieve information from
* @param out :: Stream to print to
*/
void MuonAnalysis::printRunInfo(MatrixWorkspace_sptr runWs, std::ostringstream& out)
{
// Set display style for floating point values
out << std::fixed << std::setprecision(12);

out << "\nTitle: " << runWs->getTitle();
out << "\nComment: " << runWs->getComment();

const Run& run = runWs->run();

Mantid::Kernel::DateAndTime start, end;

// Add the start time for the run
out << "\nStart: ";
if ( run.hasProperty("run_start") )
{
start = run.getProperty("run_start")->value();
out << start.toSimpleString();
}

// Add the end time for the run
out << "\nEnd: ";
if ( run.hasProperty("run_end") )
{
end = run.getProperty("run_end")->value();
out << end.toSimpleString();
}

// Add counts to run information
out << "\nCounts: ";
double counts(0.0);
for (size_t i=0; i<runWs->getNumberHistograms(); ++i)
{
for (size_t j=0; j<runWs->blocksize(); ++j)
{
counts += runWs->dataY(i)[j];
}
}
out << counts/1000000 << " MEv";

// Add average temperature.
out << "\nAverage Temperature: ";
if ( run.hasProperty("Temp_Sample") )
{
// Filter the temperatures by the start and end times for the run.
run.getProperty("Temp_Sample")->filterByTime(start, end);

// Get average of the values
double average = run.getPropertyAsSingleValue("Temp_Sample");

if (average != 0.0)
{
out << average;
}
else
{
out << "Not set";
}
}
else
{
out << "Not found";
}

// Add sample temperature
out << "\nSample Temperature: ";
if ( run.hasProperty("sample_temp") )
{
out << run.getPropertyValueAsType<double>("sample_temp");
}
else
{
out << "Not found";
}

// Add sample magnetic field
out << "\nSample Magnetic Field: ";
if ( run.hasProperty("sample_magn_field") )
{
out << run.getPropertyValueAsType<double>("sample_magn_field");
}
else
{
out << "Not found";
}
}

/**
* When no data loaded set various buttons etc to inactive
*/
Expand Down
132 changes: 132 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysisHelper.cpp
@@ -1,5 +1,8 @@
#include "MantidQtCustomInterfaces/MuonAnalysisHelper.h"

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceGroup.h"

#include <QLineEdit>
#include <QCheckBox>
#include <QComboBox>
Expand All @@ -13,6 +16,8 @@ namespace CustomInterfaces
namespace MuonAnalysisHelper
{

using namespace Mantid::API;

/**
* Sets double validator for specified field.
* @param field :: Field to set validator for
Expand All @@ -24,6 +29,133 @@ void setDoubleValidator(QLineEdit* field)
field->setValidator(newValidator);
}


/**
* Return a first period MatrixWorkspace in a run workspace. If the run workspace has one period
* only - it is returned.
* @param ws :: Run workspace
*/
MatrixWorkspace_sptr firstPeriod(Workspace_sptr ws)
{
if ( auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(ws) )
{
return boost::dynamic_pointer_cast<MatrixWorkspace>( group->getItem(0) );
}
else
{
return boost::dynamic_pointer_cast<MatrixWorkspace>(ws);
}
}

/**
* Returns a number of periods in a run workspace
* @param ws :: Run wokspace
* @return Number of periods
*/
size_t numPeriods(Workspace_sptr ws)
{
if ( auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(ws) )
{
return group->size();
}
else
{
return 1;
}
}

/**
* Print various informaion about the run
* @param runWs :: Run workspace to retrieve information from
* @param out :: Stream to print to
*/
void printRunInfo(MatrixWorkspace_sptr runWs, std::ostringstream& out)
{
// Set display style for floating point values
out << std::fixed << std::setprecision(12);

out << "\nTitle: " << runWs->getTitle();
out << "\nComment: " << runWs->getComment();

const Run& run = runWs->run();

Mantid::Kernel::DateAndTime start, end;

// Add the start time for the run
out << "\nStart: ";
if ( run.hasProperty("run_start") )
{
start = run.getProperty("run_start")->value();
out << start.toSimpleString();
}

// Add the end time for the run
out << "\nEnd: ";
if ( run.hasProperty("run_end") )
{
end = run.getProperty("run_end")->value();
out << end.toSimpleString();
}

// Add counts to run information
out << "\nCounts: ";
double counts(0.0);
for (size_t i=0; i<runWs->getNumberHistograms(); ++i)
{
for (size_t j=0; j<runWs->blocksize(); ++j)
{
counts += runWs->dataY(i)[j];
}
}
out << counts/1000000 << " MEv";

// Add average temperature.
out << "\nAverage Temperature: ";
if ( run.hasProperty("Temp_Sample") )
{
// Filter the temperatures by the start and end times for the run.
run.getProperty("Temp_Sample")->filterByTime(start, end);

// Get average of the values
double average = run.getPropertyAsSingleValue("Temp_Sample");

if (average != 0.0)
{
out << average;
}
else
{
out << "Not set";
}
}
else
{
out << "Not found";
}

// Add sample temperature
out << "\nSample Temperature: ";
if ( run.hasProperty("sample_temp") )
{
out << run.getPropertyValueAsType<double>("sample_temp");
}
else
{
out << "Not found";
}

// Add sample magnetic field
out << "\nSample Magnetic Field: ";
if ( run.hasProperty("sample_magn_field") )
{
out << run.getPropertyValueAsType<double>("sample_magn_field");
}
else
{
out << "Not found";
}
}

/**
* Constructor
* @param groupName :: The top-level group to use for all the widgets
Expand Down

0 comments on commit 35d3b1d

Please sign in to comment.