Example #1
0
/**
 * Determines if a given workspace is currently shown in the UI.
 *
 * @param ws Pointer to the workspace
 */
bool DataComparison::containsWorkspace(MatrixWorkspace_const_sptr ws) {
  QString testWsName = QString::fromStdString(ws->getName());

  int numRows = m_uiForm.twCurrentData->rowCount();
  for (int row = 0; row < numRows; row++) {
    QString workspaceName =
        m_uiForm.twCurrentData->item(row, WORKSPACE_NAME)->text();
    if (workspaceName == testWsName)
      return true;
  }

  return false;
}
/**
 * Validate the multiperiods workspace groups. Gives the opportunity to exit
 * processing if things don't look right.
 * @param vecMultiPeriodGroups : vector of multiperiod groups.
 */
void MultiPeriodGroupWorker::validateMultiPeriodGroupInputs(
    const VecWSGroupType &vecMultiPeriodGroups) const {
  const size_t multiPeriodGroupsSize = vecMultiPeriodGroups.size();

  if (multiPeriodGroupsSize > 0) {
    const size_t benchMarkGroupSize = vecMultiPeriodGroups[0]->size();
    for (size_t i = 0; i < multiPeriodGroupsSize; ++i) {
      WorkspaceGroup_sptr currentGroup = vecMultiPeriodGroups[i];
      if (currentGroup->size() != benchMarkGroupSize) {
        throw std::runtime_error("Not all the input Multi-period-group input "
                                 "workspaces are the same size.");
      }
      for (size_t j = 0; j < currentGroup->size(); ++j) {
        MatrixWorkspace_const_sptr currentNestedWS =
            boost::dynamic_pointer_cast<const MatrixWorkspace>(
                currentGroup->getItem(j));
        Property *nPeriodsProperty =
            currentNestedWS->run().getLogData("nperiods");
        size_t nPeriods = std::stoul(nPeriodsProperty->value());
        if (nPeriods != benchMarkGroupSize) {
          throw std::runtime_error("Missmatch between nperiods log and the "
                                   "number of workspaces in the input group: " +
                                   vecMultiPeriodGroups[i]->getName());
        }
        Property *currentPeriodProperty =
            currentNestedWS->run().getLogData("current_period");
        size_t currentPeriod = std::stoul(currentPeriodProperty->value());
        if (currentPeriod != (j + 1)) {
          throw std::runtime_error("Multiperiod group workspaces must be "
                                   "ordered by current_period. Correct: " +
                                   currentNestedWS->getName());
        }
      }
    }
  }
}
Example #3
0
/**
 * Adds a MatrixWorkspace by name to the data table.
 *
 * @param ws Pointer to workspace to add.
 */
void DataComparison::addDataItem(Workspace_const_sptr ws) {
  // Check that the workspace is the correct type
  MatrixWorkspace_const_sptr matrixWs =
      boost::dynamic_pointer_cast<const MatrixWorkspace>(ws);
  if (!matrixWs) {
    g_log.error() << "Workspace " << ws->getName() << "is of incorrect type!\n";
    return;
  }

  // Check that the workspace does not already exist in the comparison
  if (containsWorkspace(matrixWs)) {
    g_log.information() << "Workspace " << matrixWs->getName()
                        << " already shown in comparison.\n";
    return;
  }

  std::string wsName = matrixWs->getName();

  // Append a new row to the data table
  int currentRows = m_uiForm.twCurrentData->rowCount();
  m_uiForm.twCurrentData->insertRow(currentRows);

  // Insert the colour selector
  QComboBox *colourCombo = new QComboBox();
  // Add colours
  colourCombo->addItem("Black", QVariant(Qt::black));
  colourCombo->addItem("Red", QVariant(Qt::red));
  colourCombo->addItem("Green", QVariant(Qt::green));
  colourCombo->addItem("Blue", QVariant(Qt::blue));
  colourCombo->addItem("Cyan", QVariant(Qt::cyan));
  colourCombo->addItem("Magenta", QVariant(Qt::magenta));
  colourCombo->addItem("Yellow", QVariant(Qt::yellow));
  colourCombo->addItem("Light Gray", QVariant(Qt::lightGray));
  colourCombo->addItem("Gray", QVariant(Qt::gray));
  colourCombo->addItem("Dark Red", QVariant(Qt::darkRed));
  colourCombo->addItem("Dark Green", QVariant(Qt::darkGreen));
  colourCombo->addItem("Dark Blue", QVariant(Qt::darkBlue));
  colourCombo->addItem("Dark Cyan", QVariant(Qt::darkCyan));
  colourCombo->addItem("Dark Magenta", QVariant(Qt::darkMagenta));
  colourCombo->addItem("Dark Yellow", QVariant(Qt::darkYellow));
  colourCombo->addItem("Dark Gray", QVariant(Qt::darkGray));
  // Set the initial colour
  colourCombo->setCurrentIndex(getInitialColourIndex());
  // Update plots when colour changed
  connect(colourCombo, SIGNAL(currentIndexChanged(int)), this,
          SLOT(plotWorkspaces()));
  // Add widget to table
  m_uiForm.twCurrentData->setCellWidget(currentRows, COLOUR, colourCombo);

  // Insert the workspace name
  QTableWidgetItem *wsNameItem = new QTableWidgetItem(tr(wsName.c_str()));
  wsNameItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  m_uiForm.twCurrentData->setItem(currentRows, WORKSPACE_NAME, wsNameItem);

  // Insert the spectra offset
  QSpinBox *offsetSpin = new QSpinBox();
  offsetSpin->setMinimum(0);
  offsetSpin->setMaximum(INT_MAX);
  connect(offsetSpin, SIGNAL(valueChanged(int)), this,
          SLOT(spectrumIndexChanged()));
  m_uiForm.twCurrentData->setCellWidget(currentRows, SPEC_OFFSET, offsetSpin);

  // Insert the current displayed spectra
  QTableWidgetItem *currentSpecItem = new QTableWidgetItem(tr("n/a"));
  currentSpecItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
  m_uiForm.twCurrentData->setItem(currentRows, CURRENT_SPEC, currentSpecItem);
}