Beispiel #1
0
// 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;
}
Beispiel #2
0
// read the monitors list from the workspace and try to do it once for any
// particular ws;
bool MonIDPropChanger::monitorIdReader(
    MatrixWorkspace_const_sptr inputWS) const {
  // no workspace
  if (!inputWS)
    return false;

  // no instrument
  Geometry::Instrument_const_sptr pInstr = inputWS->getInstrument();
  if (!pInstr)
    return false;

  // are these monitors really there?
  std::vector<detid_t> monitorIDList = pInstr->getMonitors();
  {
    const auto &specInfo = inputWS->spectrumInfo();
    std::set<detid_t> idsInWorkspace;
    size_t i = 0;
    // Loop over spectra, but finish early if we find everything
    while (i < specInfo.size() &&
           idsInWorkspace.size() < monitorIDList.size()) {
      if (specInfo.isMonitor(i))
        idsInWorkspace.insert(specInfo.detector(i).getID());
      ++i;
    }
    monitorIDList =
        std::vector<detid_t>(idsInWorkspace.begin(), idsInWorkspace.end());
  }

  if (monitorIDList.empty()) {
    if (iExistingAllowedValues.empty()) {
      return false;
    } else {
      iExistingAllowedValues.clear();
      return true;
    }
  }

  // are known values the same as the values we have just identified?
  if (iExistingAllowedValues.size() != monitorIDList.size()) {
    iExistingAllowedValues.clear();
    iExistingAllowedValues.assign(monitorIDList.begin(), monitorIDList.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 < monitorIDList.size(); i++) {
    if (iExistingAllowedValues[i] != monitorIDList[i]) {
      values_redefined = true;
      iExistingAllowedValues[i] = monitorIDList[i];
    }
  }
  return values_redefined;
}