Skip to content

Commit

Permalink
Refs #10223 Add getRunNumber method
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Jeffery committed Sep 24, 2014
1 parent 0ff5278 commit 8494e11
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Expand Up @@ -57,6 +57,8 @@ namespace MantidQt
Mantid::API::Workspace_sptr fetchRun(const std::string& run, const std::string& instrument);
//make a transmission workspace name
std::string makeTransWSName(const std::string& transString) const;
//get the run number of a TOF workspace
std::string getRunNumber(const Mantid::API::Workspace_sptr& ws);
//make a transmission workspace
Mantid::API::MatrixWorkspace_sptr makeTransWS(const std::string& transString);
//Validate a row
Expand Down
Expand Up @@ -2,7 +2,12 @@
#include "MantidAPI/ITableWorkspace.h"
#include "MantidQtCustomInterfaces/ReflMainView.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidKernel/PropertyWithValue.h"

#include <boost/regex.hpp>

using namespace Mantid::API;
using namespace Mantid::Kernel;

namespace MantidQt
{
Expand Down Expand Up @@ -132,6 +137,47 @@ namespace MantidQt
throw std::invalid_argument("Qmax column may not be empty.");
}

/**
Extracts the run number of a workspace
@param ws : The workspace to fetch the run number from
@returns The run number of the workspace
*/
std::string ReflMainViewPresenter::getRunNumber(const Workspace_sptr& ws)
{
//If we can, use the run number from the workspace's sample log
MatrixWorkspace_sptr mws = boost::dynamic_pointer_cast<MatrixWorkspace>(ws);
if(mws)
{
const Property* runProperty = mws->mutableRun().getLogData("run_number");
auto runNumber = dynamic_cast<const PropertyWithValue<std::string>*>(runProperty);
if(runNumber)
return *runNumber;
}

//Okay, let's see what we can get from the workspace's name
const std::string wsName = ws->name();

//Matches TOF_13460 -> 13460
boost::regex outputRegex("(TOF|IvsQ|IvsLam)_([0-9]+)");

//Matches INTER13460 -> 13460
boost::regex instrumentRegex("[a-zA-Z]+([0-9]+)");

boost::smatch matches;

if(boost::regex_match(wsName, matches, outputRegex))
{
return matches[2].str();
}
else if(boost::regex_match(wsName, matches, instrumentRegex))
{
return matches[1].str();
}

//Resort to using the workspace name
return wsName;
}

/**
Fetches a run from disk or the AnalysisDataService
@param run : The name of the run
Expand Down

0 comments on commit 8494e11

Please sign in to comment.