コード例 #1
0
ファイル: MSDataCache.cpp プロジェクト: pombredanne/BICEPS
PWIZ_API_DECL
void MSDataCache::update(const DataInfo& dataInfo,
                         const Spectrum& spectrum)
{
    if (!dataInfo.msd.run.spectrumListPtr.get() ||
        size()!=dataInfo.msd.run.spectrumListPtr->size())
        throw runtime_error("[MSDataCache::update()] Usage error."); 

    SpectrumInfo& info = at(spectrum.index);
    info.update(spectrum);

    // MRU binary data caching
    if (impl_->config.binaryDataCacheSize>0 && !info.data.empty())
    {
        // find and erase if we're already on the list
        Impl::MRU::iterator it = find(impl_->mru.begin(), impl_->mru.end(), &info);
        if (it!=impl_->mru.end()) 
            impl_->mru.erase(it);

        // put us at the front of the list
        impl_->mru.push_front(&info);

        // free binary data from the least recently used SpectrumInfo (back of list)
        if (impl_->mru.size() > impl_->config.binaryDataCacheSize)
        {
            SpectrumInfo* lru = impl_->mru.back();
            lru->clearBinaryData();
            impl_->mru.pop_back();
        }
    }
}
コード例 #2
0
void MSDataCache::Impl::updateMRU(SpectrumInfo* info)
{
    if (!info)
        throw runtime_error("[MSDataCache::updateMRU()] Null pointer.");

    // MRU binary data caching
    if (config.binaryDataCacheSize>0 && !info->data.empty())
    {
        // find and erase if we're already on the list
        MRU::iterator it = find(mru.begin(), mru.end(), info);
        if (it!=mru.end()) 
            mru.erase(it);

        // put us at the front of the list
        mru.push_front(info);

        // free binary data from the least recently used SpectrumInfo (back of list)
        if (mru.size() > config.binaryDataCacheSize)
        {
            SpectrumInfo* lru = mru.back();
            lru->clearBinaryData();
            mru.pop_back();
        }
    }
}
コード例 #3
0
ファイル: BinaryOperation.cpp プロジェクト: DanNixon/mantid
/**
 * Checks if the spectra at the given index of either input workspace is masked.
 * If so then the output spectra has zeroed data
 * and is also masked.
 * @param lhsSpectrumInfo :: The LHS spectrum info object
 * @param rhsSpectrumInfo :: The RHS spectrum info object
 * @param index :: The workspace index to check
 * @param out :: A pointer to the output workspace
 * @param outSpectrumInfo :: The spectrum info object of `out`
 * @returns True if further processing is not required on the spectra, false if
 * the binary operation should be performed.
 */
bool BinaryOperation::propagateSpectraMask(const SpectrumInfo &lhsSpectrumInfo,
                                           const SpectrumInfo &rhsSpectrumInfo,
                                           const int64_t index,
                                           MatrixWorkspace &out,
                                           SpectrumInfo &outSpectrumInfo) {
  bool continueOp(true);

  if ((lhsSpectrumInfo.hasDetectors(index) &&
       lhsSpectrumInfo.isMasked(index)) ||
      (rhsSpectrumInfo.hasDetectors(index) &&
       rhsSpectrumInfo.isMasked(index))) {
    continueOp = false;
    out.getSpectrum(index).clearData();
    PARALLEL_CRITICAL(setMasked) { outSpectrumInfo.setMasked(index, true); }
  }
コード例 #4
0
// calculate time from sample to detector
void ModeratorTzeroLinear::calculateTfLi(const SpectrumInfo &spectrumInfo,
                                         size_t i, double &t_f, double &L_i) {
  static const double convFact = 1.0e-6 * sqrt(2 * PhysicalConstants::meV /
                                               PhysicalConstants::NeutronMass);
  static const double TfError = -1.0; // signal error when calculating final
                                      // time

  if (!spectrumInfo.hasDetectors(i)) {
    t_f = TfError;
    return;
  }

  if (spectrumInfo.isMonitor(i)) {
    L_i = spectrumInfo.sourcePosition().distance(spectrumInfo.position(i));
    t_f = 0.0; // t_f=0.0 since there is no sample to detector path
  } else {
    L_i = spectrumInfo.l1();
    // Get final energy E_f, final velocity v_f
    auto wsProp = spectrumInfo.detector(i).getNumberParameter("Efixed");
    if (!wsProp.empty()) {
      double E_f = wsProp.at(0);         //[E_f]=meV
      double v_f = convFact * sqrt(E_f); //[v_f]=meter/microsec
      t_f = spectrumInfo.l2(i) / v_f;
    } else {
      g_log.debug() << "Efixed not found for detector " << i << '\n';
      t_f = TfError;
    }
  }
}
コード例 #5
0
ファイル: RemoveLowResTOF.cpp プロジェクト: mganeva/mantid
double RemoveLowResTOF::calcTofMin(const std::size_t workspaceIndex,
                                   const SpectrumInfo &spectrumInfo) {

  const double l1 = spectrumInfo.l1();

  // Get a vector of detector IDs
  std::vector<detid_t> detNumbers;
  const auto &detSet = m_inputWS->getSpectrum(workspaceIndex).getDetectorIDs();
  detNumbers.assign(detSet.begin(), detSet.end());

  double tmin = 0.;
  if (isEmpty(m_wavelengthMin)) {
    std::map<detid_t, double> offsets; // just an empty offsets map
    Geometry::Instrument_const_sptr instrument = m_inputWS->getInstrument();
    double dspmap = Conversion::tofToDSpacingFactor(
        l1, spectrumInfo.l2(workspaceIndex),
        spectrumInfo.twoTheta(workspaceIndex), detNumbers, offsets);

    // this is related to the reference tof
    double sqrtdmin =
        sqrt(m_Tmin / m_DIFCref) + m_K * log10(dspmap * m_DIFCref);
    if (sqrtdmin <= 0.)
      return 0.;
    tmin = sqrtdmin * sqrtdmin / dspmap;
    if (tmin != tmin) {
      g_log.warning() << "tmin is nan because dspmap = " << dspmap << ".\n";
    }
  } else {
    const double l2 = spectrumInfo.l2(workspaceIndex);

    Kernel::Unit_sptr wavelength = UnitFactory::Instance().create("Wavelength");
    // unfortunately there isn't a good way to convert a single value
    std::vector<double> X(1), temp(1);
    X[0] = m_wavelengthMin;
    wavelength->toTOF(X, temp, l1, l2, 0., 0, 0., 0.);
    tmin = X[0];
  }

  g_log.debug() << "tmin[" << workspaceIndex << "] " << tmin << "\n";

  return tmin;
}