Skip to content

Commit

Permalink
Refs #4897 up/down button to choose which experiment info
Browse files Browse the repository at this point in the history
to view in sample logs
  • Loading branch information
Janik Zikovsky committed Mar 22, 2012
1 parent b16e371 commit f917a56
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/API/src/MultipleExperimentInfos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace API
ExperimentInfo_sptr MultipleExperimentInfos::getExperimentInfo(const uint16_t runIndex)
{
if (size_t(runIndex) >= m_expInfos.size())
throw std::invalid_argument("MDEventWorkspace::getExperimentInfo(): runIndex is out of range.");
throw std::invalid_argument("MDWorkspace::getExperimentInfo(): runIndex is out of range.");
return m_expInfos[runIndex];
}

Expand All @@ -58,7 +58,7 @@ namespace API
ExperimentInfo_const_sptr MultipleExperimentInfos::getExperimentInfo(const uint16_t runIndex) const
{
if (size_t(runIndex) >= m_expInfos.size())
throw std::invalid_argument("MDEventWorkspace::getExperimentInfo(): runIndex is out of range.");
throw std::invalid_argument("MDWorkspace::getExperimentInfo() const: runIndex is out of range.");
return m_expInfos[runIndex];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
if (!ws) return;
size_t npoints = ws->getNPoints();
TS_ASSERT_LESS_THAN( 100000, npoints); // Some points are left
TS_ASSERT_EQUALS( ws->getNumExperimentInfo(), 1);
TSM_ASSERT("ExperimentInfo object is valid", ws->getExperimentInfo(0) );

// Add to an existing MDEW
for (size_t i=1; i < numTimesToAdd; i++)
Expand All @@ -136,6 +138,8 @@ class ConvertToDiffractionMDWorkspaceTest : public CxxTest::TestSuite
if (!ws) return;

TS_ASSERT_EQUALS( npoints*(i+1), ws->getNPoints()); // There are now twice as many points as before
TS_ASSERT_EQUALS( ws->getNumExperimentInfo(), (i+1));
TSM_ASSERT("ExperimentInfo object is valid", ws->getExperimentInfo(i) );
}


Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ void MantidDockWidget::addMDEventWorkspaceMenuItems(QMenu *menu, Mantid::API::IM
menu->addAction(m_showSliceViewer); // The 2D slice viewer
menu->addAction(m_showHist); // Algorithm history
menu->addAction(m_showListData); // Show data in table
menu->addAction(m_showLogs);
}

void MantidDockWidget::addMDHistoWorkspaceMenuItems(QMenu *menu, Mantid::API::IMDWorkspace_const_sptr WS) const
Expand All @@ -892,6 +893,7 @@ void MantidDockWidget::addMDHistoWorkspaceMenuItems(QMenu *menu, Mantid::API::IM
menu->addAction(m_showSliceViewer); // The 2D slice viewer
menu->addAction(m_showMDPlot); // A plot of intensity vs bins
menu->addAction(m_showListData); // Show data in table
menu->addAction(m_showLogs);
}


Expand Down
82 changes: 61 additions & 21 deletions Code/Mantid/MantidPlot/src/Mantid/MantidSampleLogDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using namespace Mantid::Kernel;
MantidSampleLogDialog::MantidSampleLogDialog(const QString & wsname, MantidUI* mui, Qt::WFlags flags, size_t experimentInfoIndex) :
QDialog(mui->appWindow(), flags), m_wsname(wsname), m_experimentInfoIndex(experimentInfoIndex), m_mantidUI(mui)
{
setWindowTitle(tr("MantidPlot - " + wsname + " sample logs " + QString::number(m_experimentInfoIndex)));
setWindowTitle(tr("MantidPlot - " + wsname + " sample logs"));

m_tree = new QTreeWidget;
QStringList titles;
Expand Down Expand Up @@ -86,24 +86,49 @@ MantidSampleLogDialog::MantidSampleLogDialog(const QString & wsname, MantidUI* m
}
statsBox->setLayout(statsBoxLayout);


QHBoxLayout *bottomButtons = new QHBoxLayout;
// -------------- The Import/Close buttons ------------------------
QHBoxLayout *topButtons = new QHBoxLayout;
buttonPlot = new QPushButton(tr("&Import selected log"));
buttonPlot->setAutoDefault(true);
buttonPlot->setToolTip("Import log file as a table and construct a 1D graph if appropriate");
bottomButtons->addWidget(buttonPlot);
topButtons->addWidget(buttonPlot);

buttonClose = new QPushButton(tr("Close"));
buttonClose->setToolTip("Close dialog");
bottomButtons->addWidget(buttonClose);
topButtons->addWidget(buttonClose);


QVBoxLayout *hbox = new QVBoxLayout;
hbox->addLayout(bottomButtons);

// -------------- The ExperimentInfo selector------------------------
boost::shared_ptr<MultipleExperimentInfos> mei = AnalysisDataService::Instance().retrieveWS<MultipleExperimentInfos>(m_wsname);
if (mei)
{
if (mei->getNumExperimentInfo() > 0)
{
QHBoxLayout * numSelectorLayout = new QHBoxLayout;
QLabel * lbl = new QLabel("Experiment Info #");
m_spinNumber = new QSpinBox;
m_spinNumber->setMinValue(0);
m_spinNumber->setMaxValue(int(mei->getNumExperimentInfo())-1);
m_spinNumber->setValue(int(m_experimentInfoIndex));
numSelectorLayout->addWidget(lbl);
numSelectorLayout->addWidget(m_spinNumber);
//Double-click imports a log file
connect(m_spinNumber, SIGNAL(valueChanged(int)),
this, SLOT(selectExpInfoNumber(int)));
hbox->addLayout(numSelectorLayout);
}
}

// Finish laying out the right side
hbox->addLayout(topButtons);
hbox->addWidget(groupBox);
hbox->addWidget(statsBox);
hbox->addStretch(1);



//--- Main layout With 2 sides -----
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->addLayout(uiLayout, 1); // the tree
Expand Down Expand Up @@ -191,11 +216,11 @@ void MantidSampleLogDialog::showLogStatisticsOfItem(QTreeWidgetItem * item)
case numTSeries :
// Calculate the stats
// Get the workspace
if (!m_ws) return;
if (!m_ei) return;

// Now the log
Mantid::Kernel::TimeSeriesPropertyStatistics stats;
Mantid::Kernel::Property * logData = m_ws->run().getLogData(item->text(0).toStdString());
Mantid::Kernel::Property * logData = m_ei->run().getLogData(item->text(0).toStdString());
// Get the stas if its a series of int or double; fail otherwise
Mantid::Kernel::TimeSeriesProperty<double> * tspd = dynamic_cast<TimeSeriesProperty<double> *>(logData);
Mantid::Kernel::TimeSeriesProperty<int> * tspi = dynamic_cast<TimeSeriesProperty<int> *>(logData);
Expand Down Expand Up @@ -241,7 +266,7 @@ void MantidSampleLogDialog::importItem(QTreeWidgetItem * item)
if (filterStatus->isChecked()) filter = 1;
if (filterPeriod->isChecked()) filter = 2;
if (filterStatusPeriod->isChecked()) filter = 3;
m_mantidUI->importNumSeriesLog(m_wsname, item->text(0), filter);
m_mantidUI->importNumSeriesLog(QString::fromStdString(m_wsname), item->text(0), filter);
break;
case stringTSeries :
m_mantidUI->importStrSeriesLog(item->text(0),
Expand Down Expand Up @@ -279,31 +304,35 @@ void MantidSampleLogDialog::popupMenu(const QPoint & pos)

//------------------------------------------------------------------------------------------------
/**
* Initialize everything
* Initialize everything ub tge tree.
*/
void MantidSampleLogDialog::init()
{
m_tree->clear();

// ------------------- Retrieve the proper ExperimentInfo workspace -------------------------------
IMDWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(m_wsname.toStdString());
IMDWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(m_wsname);
if (!ws)
throw std::runtime_error("Wrong type of a Workspace");
throw std::runtime_error("Wrong type of a workspace (" + m_wsname + " is not an IMDWorkspace)");
// Is it MatrixWorkspace, which itself is ExperimentInfo?
m_ws = boost::dynamic_pointer_cast<const ExperimentInfo>(ws);;
if (!m_ws)
m_ei = boost::dynamic_pointer_cast<const ExperimentInfo>(ws);;
if (!m_ei)
{
boost::shared_ptr<const MultipleExperimentInfos> mei = boost::dynamic_pointer_cast<const MultipleExperimentInfos>(m_ws);
boost::shared_ptr<MultipleExperimentInfos> mei = boost::dynamic_pointer_cast<MultipleExperimentInfos>(ws);
if (mei)
m_ws = mei->getExperimentInfo(static_cast<uint16_t>(m_experimentInfoIndex) );
{
if (m_experimentInfoIndex >= mei->getNumExperimentInfo())
throw std::runtime_error("ExperimentInfo requested (#" + Strings::toString(m_experimentInfoIndex) + ") is not available. There are " + Strings::toString(mei->getNumExperimentInfo()) + " in the workspace");
m_ei = mei->getExperimentInfo(static_cast<uint16_t>(m_experimentInfoIndex) );
}
}
if (!m_ws)
throw std::runtime_error("Wrong type of a Workspace");
if (!m_ei)
throw std::runtime_error("Wrong type of a workspace (no ExperimentInfo)");

const std::vector< Mantid::Kernel::Property * > & logData = m_ws->run().getLogData();
std::vector< Mantid::Kernel::Property * >::const_iterator pEnd = logData.end();
const std::vector< Mantid::Kernel::Property * > & logData = m_ei->run().getLogData();
auto pEnd = logData.end();
int max_length(0);
for( std::vector< Mantid::Kernel::Property * >::const_iterator pItr = logData.begin();
for(auto pItr = logData.begin();
pItr != pEnd; ++pItr )
{
//name() contains the full path, so strip to file name
Expand Down Expand Up @@ -399,3 +428,14 @@ void MantidSampleLogDialog::init()
m_tree->header()->setMovable(false);
m_tree->setSortingEnabled(true);
}


/** Slot called when selecting a different experiment info number */
void MantidSampleLogDialog::selectExpInfoNumber(int num)
{
m_experimentInfoIndex=size_t(num);
m_tree->blockSignals(true);
this->init();
m_tree->blockSignals(false);
}

9 changes: 7 additions & 2 deletions Code/Mantid/MantidPlot/src/Mantid/MantidSampleLogDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QTextEdit>
#include <QLineEdit>
#include "MantidAPI/ExperimentInfo.h"
#include <QDoubleSpinBox>

//----------------------------------
// Forward declarations
Expand Down Expand Up @@ -69,6 +70,8 @@ private slots:
//Import a single item
void importItem(QTreeWidgetItem *item);

void selectExpInfoNumber(int num);

private:
//Initialize the layout
void init();
Expand All @@ -77,13 +80,13 @@ private slots:
QTreeWidget *m_tree;

//The workspace name
QString m_wsname;
std::string m_wsname;

/// Index into the ExperimentInfo list.
size_t m_experimentInfoIndex;

/// The actual experiment info being looked at.
Mantid::API::ExperimentInfo_const_sptr m_ws;
Mantid::API::ExperimentInfo_const_sptr m_ei;

//Buttons to do things
QPushButton *buttonPlot, *buttonClose;
Expand All @@ -97,6 +100,8 @@ private slots:
// Testboxes with stats data
QLineEdit * statValues[5];

/// Widget to select the # of the experiment info to look at.
QSpinBox * m_spinNumber;

//A pointer to the MantidUI object
MantidUI* m_mantidUI;
Expand Down

0 comments on commit f917a56

Please sign in to comment.