qavrg 0.0.28
Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes
QavrgAcquisitionSimulated Class Reference

#include <qavrgacquisitionsimulated.h>

Inheritance diagram for QavrgAcquisitionSimulated:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 QavrgAcquisitionSimulated (QavrgAcquisitionThread *acq, QavrgApplication *app, QObject *parent)

Protected Member Functions

void simulatedConfigureAverager (AcquisitionMode mode)
void simulatedStartAcquisition (int rep, int nrep)
void simulatedWaitAcquisition (int rep, int nrep)
void simulatedReadoutAcquisition (int rep, int nrep)

Private Slots

void calculateSimulatedAcquisition (int rep, int nrep)

Private Member Functions

double randomPoisson (double val) const

Private Attributes

QavrgAcquisitionThreadm_AcquisitionThread

Detailed Description

Definition at line 7 of file qavrgacquisitionsimulated.h.


Constructor & Destructor Documentation

QavrgAcquisitionSimulated::QavrgAcquisitionSimulated ( QavrgAcquisitionThread acq,
QavrgApplication app,
QObject *  parent 
)

Definition at line 10 of file qavrgacquisitionsimulated.cpp.

  : QavrgAcquisitionData(acq, app, parent),
    m_AcquisitionThread(acq)
{
}

Member Function Documentation

void QavrgAcquisitionSimulated::calculateSimulatedAcquisition ( int  rep,
int  nrep 
) [private, slot]

Definition at line 79 of file qavrgacquisitionsimulated.cpp.

References QavrgAcquisitionParms::AcquireDark, QavrgAcquisitionParms::AcquireData, QavrgAcquisitionParms::AcquireDone, QavrgAcquisitionParms::AcquireOnce, QavrgAcquisitionParms::AcquireReference, QavrgAcquisitionParms::AcquireScope, QavrgFitter::darkDataPtr(), QavrgAcquisitionParms::fitter(), QavrgAcquisitionParms::get_AcquisitionMode(), QavrgAcquisitionParms::incr_NQueuedResults(), QavrgAcquisitionData::m_Accumulator, QavrgAcquisitionData::m_AccumulatorMutex, QavrgAcquisitionData::new_DarkData(), QavrgAcquisitionData::new_FitData(), QavrgAcquisitionData::new_FittingResults(), QavrgAcquisitionData::new_RawData(), QavrgAcquisitionData::new_ReferenceData(), QavrgFitter::performCalculation(), QavrgAcquisitionParms::printMessage(), randomPoisson(), QavrgFitter::rawDataPtr(), QavrgFitter::referenceDataPtr(), and QavrgAcquisitionParms::samplesPerOrbit.

Referenced by simulatedReadoutAcquisition().

{
//  printf("Calculating simulated acquisition rep %d nrep %d\n", rep, nrep);

  int nchan = get_NChannels();
  int nsamp = get_NSamples();

  for (int chan=0; chan<nchan; chan++) {
    QMutexLocker lock(&m_AccumulatorMutex);

    double samplesPerOrbit = get_SamplesPerOrbit();
    double bunchesPerOrbit = 24;
    double samplesPerBunch = samplesPerOrbit / bunchesPerOrbit;
    double amplitude = 1.0;
    double width     = 10.0;
    double integ     = get_AcquireIntegrationTime();

//    printf("NS: %d, SPO: %g, BPO: %g, SPB: %g\n", nsamp, samplesPerOrbit, bunchesPerOrbit, samplesPerBunch);

    if (get_AcquisitionMode() != AcquireDark) {
      for (double bunch = 0; bunch < nsamp; bunch += samplesPerBunch) {
        double amp = randomPoisson(amplitude*integ*10.0)/(10.0*integ);

        for (double i = 0; (i < (8*width)) && (((bunch+i) < nsamp)); i++) {
          double val = randomPoisson(amp*exp(-(i)/width)*100.0)/(amp*100.0);
          m_Accumulator[chan][bunch+i] += val;
        }
      }
    }

    for (int i = 0; i<nsamp; i++) {
      double val = randomPoisson(0.3*integ*100.0)/(100.0*integ);
      m_Accumulator[chan][i] += val;
    }
  }

  if (rep >= (nrep-1)) {
    switch (get_AcquisitionMode()) {

    case AcquireDone:
      printf("Invalid acquisition mode in QavrgAcquisitionSimulated::calculateSimulatedAcquisition\n");
      return;

    case AcquireData:
    case AcquireScope:
    case AcquireOnce:
      for (int chan=0; chan<nchan; chan++) {
        fitter(chan) -> resize(nsamp);
        QMutexLocker lock(&m_AccumulatorMutex);
        QMutexLocker lock1(fitter(chan)->mutex());

        double *rawData = fitter(chan)->rawDataPtr();
        double *accum   = m_Accumulator[chan].data();

        for (int i = 0; i<nsamp; i++) {
          rawData[i] = accum[i]/nrep;
        }
      }

      if (get_AcquisitionMode() == AcquireScope) {
        incr_NQueuedResults();

        emit new_RawData();
      }

      break;

    case AcquireDark:
      for (int chan=0; chan<nchan; chan++) {
        fitter(chan) -> resize(nsamp);
        QMutexLocker lock(&m_AccumulatorMutex);
        QMutexLocker lock1(fitter(chan)->mutex());

        double *darkData = fitter(chan)->darkDataPtr();
        double *accum   = m_Accumulator[chan].data();

        for (int i = 0; i<nsamp; i++) {
          darkData[i] = accum[i]/nrep;
        }

        fitter(chan) -> set_DarkAvailable(true);
      }

      incr_NQueuedResults();

      emit new_DarkData();

      break;

    case AcquireReference:
      for (int chan=0; chan<nchan; chan++) {
        fitter(chan) -> resize(nsamp);
        QMutexLocker lock(&m_AccumulatorMutex);
        QMutexLocker lock1(fitter(chan)->mutex());

        double *refData = fitter(chan)->referenceDataPtr();
        double *accum   = m_Accumulator[chan].data();

        for (int i = 0; i<nsamp; i++) {
          refData[i] = accum[i]/nrep;
        }

        fitter(chan) -> set_ReferenceAvailable(true);
      }

      incr_NQueuedResults();

      emit new_ReferenceData();

      break;
    }

    if (get_AcquisitionMode() == AcquireData  || get_AcquisitionMode() == AcquireOnce) {
      QList< QFuture<void> > futures;

      QTime timer;
      timer.start();

      for (int chan=0; chan<nchan; chan++) {
        if (fitter(chan) -> get_ReferenceAvailable()) {
          //        printf("concurrent fitting, max Threads = %d\n", QThreadPool::globalInstance()->maxThreadCount());
          futures.append(QtConcurrent::run(fitter(chan), &QavrgFitter::performCalculation));
        }
      }

      foreach(QFuture<void> f, futures) {
        f.waitForFinished();
      }

      incr_NQueuedResults();

      emit new_FitData();  /* implies new_RawData(), also */

      emit new_FittingResults();

      emit printMessage(tr("Fitting took %1 msec").arg(timer.restart()));
    }

//    printf("Simulated Readout complete...\n");
  }
}
double QavrgAcquisitionSimulated::randomPoisson ( double  val) const [private]

Definition at line 74 of file qavrgacquisitionsimulated.cpp.

Referenced by calculateSimulatedAcquisition().

{
  return val+sqrt(val)*(((double)qrand()/(double)RAND_MAX)-0.5);
}
void QavrgAcquisitionSimulated::simulatedConfigureAverager ( AcquisitionMode  mode) [protected]
void QavrgAcquisitionSimulated::simulatedReadoutAcquisition ( int  rep,
int  nrep 
) [protected]
void QavrgAcquisitionSimulated::simulatedStartAcquisition ( int  rep,
int  nrep 
) [protected]

Definition at line 21 of file qavrgacquisitionsimulated.cpp.

References QavrgAcquisitionData::m_Accumulator, and QavrgAcquisitionData::m_AccumulatorMutex.

Referenced by QavrgAcquisition::startAcquisition().

{
  QMutexLocker lock(&m_AccumulatorMutex);

//  printf("Starting simulated acquisition %d of %d\n", rep, nrep);

  if (rep == 0) {
    int nchan = get_NChannels();
    int nsamp = get_NSamples();

    m_Accumulator.resize(nchan);

    for (int chan=0; chan<nchan; chan++) {
      m_Accumulator[chan].resize(nsamp);
      m_Accumulator[chan].fill(0);
    }

//    m_Futures.resize(nchan);
  }
}
void QavrgAcquisitionSimulated::simulatedWaitAcquisition ( int  rep,
int  nrep 
) [protected]

Definition at line 42 of file qavrgacquisitionsimulated.cpp.

References QavrgAcquisitionData::m_AcquireCancel, m_AcquisitionThread, and QavrgAcquisitionThread::sleepFor().

Referenced by QavrgAcquisition::waitAcquisition().

{
//  QMutexLocker lock(&m_Mutex);
//
//  QFuture<void> result = QtConcurrent::run(
//      this, &QavrgAcquisitionSimulated::calculateSimulatedAcquisition, rep, nrep);
//  QTime timer;
//
//  timer.start();

  double extraTime = get_AcquireIntegrationTime()/* - timer.restart()/1000.0*/;

//  printf("Sleep for %g sec\n", extraTime);

  while (extraTime > 0.1) {
    if (m_AcquireCancel) break;

    m_AcquisitionThread->sleepFor(0.1);
    extraTime -= 0.1;
  }

  if (extraTime >= 0) {
    m_AcquisitionThread->sleepFor(extraTime);
  }
//  result.waitForFinished();
}

Member Data Documentation

Reimplemented in QavrgAcquisition.

Definition at line 28 of file qavrgacquisitionsimulated.h.

Referenced by simulatedWaitAcquisition().


The documentation for this class was generated from the following files: