TInt CSensorBackendSym::SetDataRate()
    {
    //Get available datarates
    qrangelist availableDataRates = sensor()->availableDataRates();
    if ( availableDataRates.count() != 0 )
        {
        //Check if discret values or range value is used
        if( availableDataRates[0].first == availableDataRates[0].second )
            {
            //In descrete ranges if only one available, no need to set that range
            if(availableDataRates.length() <= 1)
                {
                return KErrNone;
                }
            TInt err = KErrNone;
            TSensrvPropertyType type = propertyType(KSensrvPropIdDataRate, err);
            if(err != KErrNone)
                {
                return err;
                }
            if(type == ESensrvIntProperty)
                {
                return SetProperty(KSensrvPropIdDataRate, ESensrvIntProperty, ESensrvArrayPropertyInfo,
                            availableDataRates.indexOf(qrange(sensor()->dataRate(),sensor()->dataRate())));
                }
            else if(type == ESensrvRealProperty)
                {
                return SetProperty(KSensrvPropIdDataRate, ESensrvRealProperty, ESensrvArrayPropertyInfo,
                            availableDataRates.indexOf(qrange(sensor()->dataRate(),sensor()->dataRate())));
                }
            }
        else
            {
            TInt err = KErrNone;
            TSensrvPropertyType type = propertyType(KSensrvPropIdDataRate, err);
            if(err != KErrNone)
                {
                return err;
                }
            if(type == ESensrvIntProperty)
                {
                // Uses range value
                return SetProperty(KSensrvPropIdDataRate, ESensrvIntProperty, ESensrvSingleProperty, sensor()->dataRate());
                }
            else if(type == ESensrvRealProperty)
                {
                // Uses range value
                return SetProperty(KSensrvPropIdDataRate, ESensrvIntProperty, ESensrvSingleProperty, sensor()->dataRate());
                }
            }
        }
    // No data rates available
    return KErrNone;
    }
Beispiel #2
0
template<int N> template<class dtype> void LogPhaseProb<N>::get_phi_fom( datatypes::Phi_fom<dtype>& phifom ) const
{
  Range<ftype64> qrange( -700.0, 700.0 );
  ftype s, a, b, q0, pq;
  s = a = b = q0 = 0.0;
  for ( int p = 0; p < q.size(); p++ ) q0 += q[p];
  q0 /= double( q.size() );
  for ( int p = 0; p < q.size(); p++ ) {
    pq = exp( qrange.truncate(q[p] - q0) );
    s += pq;
    a += pq * cos( phase(p) );
    b += pq * sin( phase(p) );
  }
  std::complex<ftype64> pw( a/s, b/s );
  phifom.phi() = std::arg( pw );
  phifom.fom() = std::abs( pw );
}
Beispiel #3
0
    /**
     * A map detector ID and Q ranges
     * This method looks unnecessary as it could be calculated on the fly but
     * the parallelization means that lazy instantation slows it down due to the 
     * necessary CRITICAL sections required to update the cache. The Q range 
     * values are required very frequently so the total time is more than
     * offset by this precaching step
     */
    void SofQW2::initQCache(API::MatrixWorkspace_const_sptr workspace)
    {
      Mantid::Kernel::Timer clock;
      const size_t nhist(workspace->getNumberHistograms());
      const size_t nxpoints = workspace->blocksize();
      const MantidVec & X = workspace->readX(0);
      m_qcached.clear();

      PARALLEL_FOR1(workspace)
      for(int64_t i = 0 ; i < (int64_t)nhist; ++i)
      {
        PARALLEL_START_INTERUPT_REGION

        IDetector_const_sptr det;
        try
        {
           det = workspace->getDetector(i);
           if( det->isMonitor() ) det.reset();
        }
        catch(Kernel::Exception::NotFoundError&)
        {
          // Catch if no detector. Next line tests whether this happened - test placed
          // outside here because Mac Intel compiler doesn't like 'continue' in a catch
          // in an openmp block.
        }
        // If no detector found, skip onto the next spectrum
        if ( !det ) continue;

        std::vector<QValues> qvalues(nxpoints);
        DetectorGroup_const_sptr detGroup = boost::dynamic_pointer_cast<const DetectorGroup>(det);
        if( detGroup )
        {
          std::vector<IDetector_const_sptr> dets = detGroup->getDetectors();
          const size_t ndets(dets.size());
          for( size_t j = 0; j < ndets; ++j )
          {
            IDetector_const_sptr det_j = dets[j];
            QRangeCache qrange(static_cast<size_t>(i), 1.0/(double)ndets);
            for( size_t k = 0; k < nxpoints; ++k)
            {
              qvalues[k] = calculateQValues(det_j, X[k], X[k+1]);
            }
            qrange.qValues = qvalues;
            PARALLEL_CRITICAL(qcache_a)
            {
              m_qcached.insert(m_qcached.end(), qrange);
            }
          }
        }
        else
        {
          QRangeCache qrange(static_cast<size_t>(i), 1.0);
          for( size_t k = 0; k < nxpoints; ++k)
          {
            qvalues[k] = calculateQValues(det, X[k], X[k+1]);
          }
          qrange.qValues = qvalues;
          PARALLEL_CRITICAL(qcache_b)
          {
            m_qcached.insert(m_qcached.end(), qrange);
          }
        }

        PARALLEL_END_INTERUPT_REGION
      }
/*!
    Add a data rate (consisting of \a min and \a max values) for the sensor.

    Note that this function should be called from the constructor so that the information
    is available immediately.

    \sa QSensor::availableDataRates
*/
void QSensorBackend::addDataRate(qreal min, qreal max)
{
    Q_D(QSensorBackend);
    QSensorPrivate *sensorPrivate = d->m_sensor->d_func();
    sensorPrivate->availableDataRates << qrange(min, max);
}
/*!
    Add a data rate (consisting of \a min and \a max values) for the sensor.

    Note that this function should be called from the constructor so that the information
    is available immediately.

    \sa QSensor::availableDataRates
*/
void QSensorBackend::addDataRate(qreal min, qreal max)
{
    QSensorPrivate *d = m_sensor->d_func();
    d->availableDataRates << qrange(min, max);
}