// read the monitors list from the workspace and try to do it once for any // particular ws; bool MonIDPropChanger::monitorIdReader( API::MatrixWorkspace_const_sptr inputWS) const { // no workspace if (!inputWS) return false; // no instrument Geometry::Instrument_const_sptr pInstr = inputWS->getInstrument(); if (!pInstr) return false; std::vector<detid_t> mon = pInstr->getMonitors(); if (mon.empty()) { if (iExistingAllowedValues.empty()) { return false; } else { iExistingAllowedValues.clear(); return true; } } // are these monitors really there? // got the index of correspondent spectra. std::vector<size_t> indexList = inputWS->getIndicesFromDetectorIDs(mon); if (indexList.empty()) { if (iExistingAllowedValues.empty()) { return false; } else { iExistingAllowedValues.clear(); return true; } } // index list can be less or equal to the mon list size (some monitors do not // have spectra) size_t mon_count = (mon.size() < indexList.size()) ? mon.size() : indexList.size(); std::vector<int> allowed_values(mon_count); for (size_t i = 0; i < mon_count; i++) { allowed_values[i] = mon[i]; } // are known values the same as the values we have just identified? if (iExistingAllowedValues.size() != mon_count) { iExistingAllowedValues.clear(); iExistingAllowedValues.assign(allowed_values.begin(), allowed_values.end()); return true; } // the monitor list has the same size as before. Is it equivalent to the // existing one? bool values_redefined = false; for (size_t i = 0; i < mon_count; i++) { if (iExistingAllowedValues[i] != allowed_values[i]) { values_redefined = true; iExistingAllowedValues[i] = allowed_values[i]; } } return values_redefined; }
/** Make a map containing spectra indexes to group, the indexes could have come from * file, or an array, spectra numbers ... * @param workspace :: the user selected input workspace * @param unUsedSpec :: spectra indexes that are not members of any group */ void GroupDetectors2::getGroups(API::MatrixWorkspace_const_sptr workspace, std::vector<int64_t> &unUsedSpec) { // this is the map that we are going to fill m_GroupSpecInds.clear(); // There are several properties that may contain the user data go through them in order of precedence const std::string filename = getProperty("MapFile"); if ( ! filename.empty() ) {// The file property has been set so try to load the file try { // check if XML file and if yes assume it is a XML grouping file std::string filenameCopy(filename); std::transform(filenameCopy.begin(), filenameCopy.end(), filenameCopy.begin(), tolower); if ( (filenameCopy.find(".xml")) != std::string::npos ) { processXMLFile(filename, workspace, unUsedSpec); } else { // the format of this input file format is described in "GroupDetectors2.h" processFile(filename, workspace, unUsedSpec); } } catch ( std::exception & ) { g_log.error() << name() << ": Error reading input file " << filename << std::endl; throw; } return; } const std::vector<specid_t> spectraList = getProperty("SpectraList"); const std::vector<detid_t> detectorList = getProperty("DetectorList"); const std::vector<size_t> indexList = getProperty("WorkspaceIndexList"); // only look at these other parameters if the file wasn't set if ( ! spectraList.empty() ) { workspace->getIndicesFromSpectra( spectraList, m_GroupSpecInds[0]); g_log.debug() << "Converted " << spectraList.size() << " spectra numbers into spectra indices to be combined\n"; } else {// go through the rest of the properties in order of decreasing presidence, abort when we get the data we need ignore the rest if ( ! detectorList.empty() ) { // we are going to group on the basis of detector IDs, convert from detectors to workspace indices workspace->getIndicesFromDetectorIDs( detectorList, m_GroupSpecInds[0]); g_log.debug() << "Found " << m_GroupSpecInds[0].size() << " spectra indices from the list of " << detectorList.size() << " detectors\n"; } else if ( ! indexList.empty() ) { m_GroupSpecInds[0] = indexList; g_log.debug() << "Read in " << m_GroupSpecInds[0].size() << " spectra indices to be combined\n"; } //check we don't have an index that is too high for the workspace size_t maxIn = static_cast<size_t>(workspace->getNumberHistograms() - 1); std::vector<size_t>::const_iterator it = m_GroupSpecInds[0].begin(); for( ; it != m_GroupSpecInds[0].end() ; ++it ) { if ( *it > maxIn ) { g_log.error() << "Spectra index " << *it << " doesn't exist in the input workspace, the highest possible index is " << maxIn << std::endl; throw std::out_of_range("One of the spectra requested to group does not exist in the input workspace"); } } } if ( m_GroupSpecInds[0].empty() ) { g_log.information() << name() << ": File, WorkspaceIndexList, SpectraList, and DetectorList properties are all empty\n"; throw std::invalid_argument("All list properties are empty, nothing to group"); } // up date unUsedSpec, this is used to find duplicates and when the user has set KeepUngroupedSpectra std::vector<size_t>::const_iterator index = m_GroupSpecInds[0].begin(); for ( ; index != m_GroupSpecInds[0].end(); ++index ) {// the vector<int> m_GroupSpecInds[0] must not index contain numbers that don't exist in the workspaace if ( unUsedSpec[*index] != USED ) { unUsedSpec[*index] = USED; } else g_log.warning() << "Duplicate index, " << *index << ", found\n"; } }