/** * Validate the transmission workspace inputs when a second transmission run is provided. * Throws if any of the property values do not make sense. * @param firstTransmissionInWavelength: Indicates that the first transmission run is in units of wavlength. */ void ReflectometryWorkflowBase::validateSecondTransmissionInputs( const bool firstTransmissionInWavelength) const { // Verify that all the required inputs for the second transmission run are now given. //Check if the first transmission run has been set bool ftrDefault = isPropertyDefault("FirstTransmissionRun"); MatrixWorkspace_sptr ws = this->getProperty("FirstTransmissionRun"); if(ws) ftrDefault = false; if(ftrDefault) { if (firstTransmissionInWavelength) { this->g_log.warning( "The first transmission run is in wavelength so is assumed to be correctly stitched in wavelength. " "The second transmission run and associated inputs will be ignored." "Run CreateTransmissionWorkspace to create a transmission workspace from TOF runs."); } else { throw std::invalid_argument( "A SecondTransmissionRun is only valid if a FirstTransmissionRun is provided."); } } else { if (!isPropertyDefault("StartOverlap") && !isPropertyDefault("EndOverlap")) { const double startOverlap = this->getProperty("StartOverlap"); const double endOverlap = this->getProperty("EndOverlap"); if (startOverlap >= endOverlap) { throw std::invalid_argument("EndOverlap must be > StartOverlap"); } } if (!isPropertyDefault("SecondTransmissionRun")) { MatrixWorkspace_sptr trans1 = this->getProperty("FirstTransmissionRun"); MatrixWorkspace_sptr trans2 = this->getProperty("SecondTransmissionRun"); auto firstMap = trans1->getSpectrumToWorkspaceIndexMap(); auto secondMap = trans2->getSpectrumToWorkspaceIndexMap(); if (firstMap != secondMap) { throw std::invalid_argument( "Spectrum maps differ between the transmission runs. They must be the same."); } } } }
/** * Fetch min, max inputs as a vector (int) if they are non-default and set them to the optionalUpperLower object. * Performs checks to verify that invalid indexes have not been passed in. * @param propertyName : Property name to fetch * @param isPointDetector : Flag indicates that the execution is in point detector mode. * @param optionalUpperLower : Object to set min and max on. */ void ReflectometryWorkflowBase::fetchOptionalLowerUpperPropertyValue(const std::string& propertyName, bool isPointDetector, OptionalWorkspaceIndexes& optionalUpperLower) const { if (!isPropertyDefault(propertyName)) { // Validation of property inputs. if (isPointDetector) { throw std::invalid_argument( "Cannot have a region of interest property in point detector mode."); } std::vector<int> temp = this->getProperty(propertyName); if (temp.size() != 2) { const std::string message = propertyName + " requires a lower and upper boundary"; throw std::invalid_argument(message); } if (temp[0] > temp[1]) { throw std::invalid_argument("Min must be <= Max index"); } if (std::find_if(temp.begin(), temp.end(), checkNotPositive) != temp.end()) { const std::string message = propertyName + " contains negative indexes"; throw std::invalid_argument(message); } // Assignment optionalUpperLower = temp; } }
/** * Get the detector component. Use the name provided as a property as the basis *for the lookup as a priority. * * Throws if the name is invalid. * @param workspace : Workspace from instrument with detectors * @param isPointDetector : True if this is a point detector. Used to guess a *name. * @return The component : The component object found. */ boost::shared_ptr<const Mantid::Geometry::IComponent> SpecularReflectionAlgorithm::getDetectorComponent( MatrixWorkspace_sptr workspace, const bool isPointDetector) const { boost::shared_ptr<const IComponent> searchResult; if (!isPropertyDefault("SpectrumNumbersOfDetectors")) { const std::vector<int> spectrumNumbers = this->getProperty("SpectrumNumbersOfDetectors"); const bool strictSpectrumChecking = this->getProperty("StrictSpectrumChecking"); checkSpectrumNumbers(spectrumNumbers, strictSpectrumChecking, g_log); auto specToWorkspaceIndex = workspace->getSpectrumToWorkspaceIndexMap(); DetectorGroup_sptr allDetectors = boost::make_shared<DetectorGroup>(); const auto &spectrumInfo = workspace->spectrumInfo(); for (auto index : spectrumNumbers) { const size_t spectrumNumber{static_cast<size_t>(index)}; auto it = specToWorkspaceIndex.find(index); if (it == specToWorkspaceIndex.end()) { std::stringstream message; message << "Spectrum number " << spectrumNumber << " does not exist in the InputWorkspace"; throw std::invalid_argument(message.str()); } const size_t workspaceIndex = it->second; auto detector = workspace->getDetector(workspaceIndex); if (spectrumInfo.isMasked(workspaceIndex)) g_log.warning() << "Adding a detector (ID:" << detector->getID() << ") that is flagged as masked.\n"; allDetectors->addDetector(detector); } searchResult = allDetectors; } else { Mantid::Geometry::Instrument_const_sptr inst = workspace->getInstrument(); std::string componentToCorrect = isPointDetector ? "point-detector" : "linedetector"; if (!isPropertyDefault("DetectorComponentName")) { componentToCorrect = this->getPropertyValue("DetectorComponentName"); } searchResult = inst->getComponentByName(componentToCorrect); if (searchResult == nullptr) { throw std::invalid_argument(componentToCorrect + " does not exist. Check input properties."); } } return searchResult; }
/** * Get the sample component. Use the name provided as a property as the basis *for the lookup as a priority. * * Throws if the name is invalid. * @param inst : Instrument to search through * @return : The component : The component object found. */ Mantid::Geometry::IComponent_const_sptr SpecularReflectionAlgorithm::getSurfaceSampleComponent( Mantid::Geometry::Instrument_const_sptr inst) const { std::string sampleComponent = "some-surface-holder"; if (!isPropertyDefault("SampleComponentName")) { sampleComponent = this->getPropertyValue("SampleComponentName"); } auto searchResult = inst->getComponentByName(sampleComponent); if (searchResult == nullptr) { throw std::invalid_argument(sampleComponent + " does not exist. Check input properties."); } return searchResult; }
bool BoxedValueType::isDefaultValue() const { return isPropertyDefault("value"); }