/** Make dimensions from the currently selected input workspace. Also fills the inputs with default values. @param propertyPrefix: The prefix for the property in the algorithm, i.e. AxisAligned. @param owningLayout: The layout that will take ownership of the widgets once generated. @param format: function pointer to the formatting function @param history : Whether to remember of forget property history. */ void SlicingAlgorithmDialog::makeDimensionInputs( const QString &propertyPrefix, QLayout *owningLayout, QString (*format)(IMDDimension_const_sptr), History history) { // Remove excess dimensions from the tied properties and the stored property // values size_t indexRemoved = 0; QString propertyNameRemoved = propertyPrefix; propertyNameRemoved.append(QString().number(indexRemoved)); Mantid::Kernel::Property *propertyRemoved = getAlgorithmProperty(propertyNameRemoved); while (propertyRemoved) { untie(propertyNameRemoved); removePropertyValue(propertyNameRemoved); indexRemoved++; propertyNameRemoved = propertyPrefix; propertyNameRemoved.append(QString().number(indexRemoved)); propertyRemoved = getAlgorithmProperty(propertyNameRemoved); } const QString &txt = getCurrentInputWorkspaceName(); if (!txt.isEmpty()) { IMDWorkspace_sptr ws = boost::dynamic_pointer_cast<IMDWorkspace>( AnalysisDataService::Instance().retrieve(txt.toStdString())); size_t nDimensions = ws->getNumDims(); for (size_t index = 0; index < nDimensions; ++index) { Mantid::Geometry::IMDDimension_const_sptr dim = ws->getDimension(index); // Configure the label QString propertyName = propertyPrefix; propertyName.append(QString().number(index)); QLabel *dimensionLabel = new QLabel(propertyName); // Configure the default input. const QString dimensionInfo = format(dim); QLineEdit *txtDimension = new QLineEdit(dimensionInfo); // Create a widget to contain the dimension components. QHBoxLayout *layout = new QHBoxLayout; QWidget *w = new QWidget; w->setLayout(layout); tie(txtDimension, propertyName, layout, (history == Remember)); // Add components to the layout. layout->addWidget(dimensionLabel); layout->addWidget(txtDimension); owningLayout->addWidget(w); } } }
//---------------------------------------------------------------------------------------------- /// Run the algorithm void QueryMDWorkspace::exec() { // Extract the required normalisation. std::string strNormalisation = getPropertyValue("Normalisation"); MDNormalization requestedNormalisation = whichNormalisation(strNormalisation); IMDWorkspace_sptr input = getProperty("InputWorkspace"); const bool transformCoordsToOriginal = getProperty("TransformCoordsToOriginal"); // Define a table workspace with a specific column schema. ITableWorkspace_sptr output = WorkspaceFactory::Instance().createTable(); const std::string signalColumnName = "Signal/" + strNormalisation; const std::string errorColumnName = "Error/" + strNormalisation; output->addColumn("double", signalColumnName); output->addColumn("double", errorColumnName); output->addColumn("int", "Number of Events"); const size_t ndims = input->getNumDims(); for (size_t index = 0; index < ndims; ++index) { Mantid::Geometry::IMDDimension_const_sptr dim = input->getDimension(index); std::string dimInUnit = dim->getName() + "/" + dim->getUnits().ascii(); output->addColumn("double", dimInUnit); // Magic numbers required to configure the X axis. output->getColumn(dimInUnit)->setPlotType(1); } // Magic numbers required to configure the Y axis. output->getColumn(signalColumnName)->setPlotType(2); output->getColumn(errorColumnName)->setPlotType(5); IMDIterator *it = input->createIterator(); it->setNormalization(requestedNormalisation); bool bLimitRows = getProperty("LimitRows"); int maxRows = 0; if (bLimitRows) { maxRows = getProperty("MaximumRows"); } // Use the iterator to loop through each MDBoxBase and create a row for each // entry. int rowCounter = 0; Progress progress(this, 0, 1, int64_t(input->getNPoints())); while (true) { size_t cellIndex = 0; output->appendRow(); output->cell<double>(rowCounter, cellIndex++) = it->getNormalizedSignal(); output->cell<double>(rowCounter, cellIndex++) = it->getNormalizedError(); output->cell<int>(rowCounter, cellIndex++) = int(it->getNumEvents()); VMD center = it->getCenter(); const size_t numberOriginal = input->getNumberTransformsToOriginal(); if (transformCoordsToOriginal && numberOriginal > 0) { const size_t index = numberOriginal - 1; CoordTransform const *transform = input->getTransformToOriginal(index); VMD temp = transform->applyVMD(center); center = temp; } for (size_t index = 0; index < ndims; ++index) { output->cell<double>(rowCounter, cellIndex++) = center[index]; } progress.report(); if (!it->next() || (bLimitRows && ((rowCounter + 1) >= maxRows))) { break; } rowCounter++; } setProperty("OutputWorkspace", output); delete it; // IMDEventWorkspace_sptr mdew; CALL_MDEVENT_FUNCTION(this->getBoxData, input); }