Skip to content

Commit

Permalink
Refs #8547. Use the returned label, create and store a group for it.
Browse files Browse the repository at this point in the history
Instead of getting group name and retrieving it on every plot, we can
just store a pointer to the group.
  • Loading branch information
arturbekasov committed Feb 27, 2014
1 parent 1028041 commit a7a05f1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 32 deletions.
Expand Up @@ -503,6 +503,9 @@ private slots:
/// When data loaded set various buttons etc to active
void nowDataAvailable();

/// Updates m_currentGroup given the new loaded label
void updateCurrentGroup(const std::string& newGroupName);

/// handles option tab work
MantidQt::CustomInterfaces::Muon::MuonAnalysisOptionTab* m_optionTab;
/// handles fit data work
Expand All @@ -516,6 +519,9 @@ private slots:
/// First Good Data time as loaded from Data file
double m_dataFirstGoodData;

/// The group we should add new plot workspaces to
WorkspaceGroup_sptr m_currentGroup;

static const QString NOT_AVAILABLE;

//A reference to a logger
Expand Down
81 changes: 49 additions & 32 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MuonAnalysis.cpp
Expand Up @@ -364,28 +364,26 @@ void MuonAnalysis::plotItem(ItemType itemType, int tableRow, PlotType plotType)

try
{
// Name of the group currently used to store plot workspaces. Depends on loaded data.
const std::string groupName = getGroupName().toStdString();

// Create workspace and a raw (unbinned) version of it
MatrixWorkspace_sptr ws = createAnalysisWorkspace(itemType, tableRow, plotType);
MatrixWorkspace_sptr wsRaw = createAnalysisWorkspace(itemType, tableRow, plotType, true);

// Make sure they are in the current group
if ( ! m_currentGroup->contains(ws) )
{
m_currentGroup->addWorkspace(ws);
m_currentGroup->addWorkspace(wsRaw);
}

// Find names for new workspaces
const std::string wsName = getNewAnalysisWSName(groupName, itemType, tableRow, plotType);
const std::string wsName = getNewAnalysisWSName(m_currentGroup->getName(), itemType, tableRow,
plotType);
const std::string wsRawName = wsName + "_Raw";

// Make sure they end up in the ADS
ads.addOrReplace(wsName, ws);
ads.addOrReplace(wsRawName, wsRaw);

// Make sure they are in the right group
if ( ! ads.retrieveWS<WorkspaceGroup>(groupName)->contains(wsName) )
{
ads.addToGroup(groupName, wsName);
ads.addToGroup(groupName, wsRawName);
}

QString wsNameQ = QString::fromStdString(wsName);

// Hide all the previous plot windows, if requested by user
Expand Down Expand Up @@ -1583,28 +1581,25 @@ void MuonAnalysis::inputFileChanged(const QStringList& files)

std::ostringstream infoStr;

// Populate run information with the run number
QString run(getGroupName());
if (m_previousFilenames.size() > 1)
infoStr << "Runs: ";
else
infoStr << "Run: ";
std::string label = loadResult->label;

// Remove instrument and leading zeros
// TODO: this should be moved to a separate method
int zeroCount(0);
for (int i=0; i<run.size(); ++i)
for (auto it = label.begin(); it != label.end(); ++it)
{
if ( (run[i] == '0') || (run[i].isLetter() ) )
++zeroCount;
else
if ( !(isalpha(*it) || *it == '0') )
{
run = run.right(run.size() - zeroCount);
// When non-letter and non-zero met - delete everything up to it
label.erase(label.begin(), it);
break;
}
}

infoStr << run.toStdString();
if (files.size() > 1)
infoStr << "Runs: ";
else
infoStr << "Run: ";

infoStr << label;

// Add other information about the run
printRunInfo(matrix_workspace, infoStr);
Expand Down Expand Up @@ -1633,12 +1628,8 @@ void MuonAnalysis::inputFileChanged(const QStringList& files)
// Make the options available
nowDataAvailable();

// Create a group for new data, if it doesn't exist
const std::string groupName = getGroupName().toStdString();
if ( ! AnalysisDataService::Instance().doesExist(groupName) )
{
AnalysisDataService::Instance().add( groupName, boost::make_shared<WorkspaceGroup>() );
}
// Use label as a name for the group we will place plots to
updateCurrentGroup(loadResult->label);

if(m_uiForm.frontPlotButton->isEnabled())
plotSelectedItem();
Expand Down Expand Up @@ -2707,7 +2698,7 @@ void MuonAnalysis::changeRun(int amountToChange)
if (currentFile.contains("auto") || currentFile.contains("argus0000000"))
{
separateMuonFile(filePath, currentFile, run, runSize);
currentFile = filePath + getGroupName() + ".nxs";
currentFile = filePath + QString::fromStdString(m_currentGroup->getName()) + ".nxs";
}

separateMuonFile(filePath, currentFile, run, runSize);
Expand Down Expand Up @@ -3488,6 +3479,32 @@ void MuonAnalysis::nowDataAvailable()
m_uiForm.guessAlphaButton->setEnabled(true);
}

/**
* Updates the m_currentGroup given the name of the new group we want to store plot workspace to.
* @param newGroupName :: Name of the group m_currentGroup should have
*/
void MuonAnalysis::updateCurrentGroup(const std::string& newGroupName)
{
if ( AnalysisDataService::Instance().doesExist(newGroupName) )
{
auto existingGroup = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(newGroupName);

if (existingGroup)
{
m_currentGroup = existingGroup;
return;
}
else
{
g_log.warning() << "Workspace with name '" << newGroupName << "' ";
g_log.warning() << "was replaced with the group used by MuonAnalysis.";
}
}

m_currentGroup = boost::make_shared<WorkspaceGroup>();
AnalysisDataService::Instance().addOrReplace(newGroupName, m_currentGroup);
}


void MuonAnalysis::openDirectoryDialog()
{
Expand Down

0 comments on commit a7a05f1

Please sign in to comment.