qavrg 0.0.28
qavrgacquisitiondata.cpp
Go to the documentation of this file.
00001 #include "qavrgacquisitiondata.h"
00002 
00003 #include "qavrgsettings.h"
00004 #include "qavrgfitter.h"
00005 
00006 #include <QFile>
00007 #include <stdio.h>
00008 
00009 QavrgAcquisitionData::QavrgAcquisitionData(QavrgAcquisitionThread */*acq*/, QavrgApplication */*app*/, QObject *parent)
00010   : QavrgAcquisitionParms(parent),
00011     m_AcquireCancel(0)
00012 {
00013 }
00014 
00015 QavrgAcquisitionData::~QavrgAcquisitionData()
00016 {
00017 }
00018 
00019 //QVector< QVector<double> > QavrgAcquisitionData::get_RawData()
00020 //{
00021 //  QMutexLocker lock(&m_RawDataMutex);
00022 //
00023 //  return m_RawData;
00024 //}
00025 //
00026 QVector<double> QavrgAcquisitionData::get_RawData(int chan, int start, int nbins)
00027 {
00028   QMutexLocker lock(&m_AcquisitionDataMutex);
00029 //
00030 //  return m_RawData.value(chan).mid(start,nbins);
00031 
00032   return fitter(chan) -> get_RawData(start, nbins);
00033 }
00034 
00035 QVector<double> QavrgAcquisitionData::get_RawData(int chan)
00036 {
00037   QMutexLocker lock(&m_AcquisitionDataMutex);
00038 //
00039 //  return m_RawData.value(chan);
00040 
00041   return fitter(chan) -> get_RawData();
00042 }
00043 
00044 double QavrgAcquisitionData::get_RawData(int chan, int bin)
00045 {
00046   QMutexLocker lock(&m_AcquisitionDataMutex);
00047 
00048   return fitter(chan) -> get_RawData(bin);
00049 }
00050 
00051 void QavrgAcquisitionData::setReferenceData()
00052 {
00053   int nchan = get_NChannels();
00054 
00055   for (int i=0; i<nchan; i++) {
00056     fitter(i) -> setReferenceData();
00057   }
00058 
00059   saveReferenceData();
00060 
00061   emit new_ReferenceData();
00062 }
00063 
00064 void QavrgAcquisitionData::setDarkData()
00065 {
00066   int nchan = get_NChannels();
00067 
00068   for (int i=0; i<nchan; i++) {
00069     fitter(i) -> setDarkData();
00070   }
00071 
00072   saveDarkData();
00073 
00074   emit new_DarkData();
00075 }
00076 
00077 //int QavrgAcquisitionData::referenceAvailable() const
00078 //{
00079 //  return m_ReferenceAvailable;
00080 //}
00081 //
00082 //int QavrgAcquisitionData::darkAvailable() const
00083 //{
00084 //  return m_DarkAvailable;
00085 //}
00086 
00087 //QVector< QVector<double> > QavrgAcquisitionData::get_ReferenceData()
00088 //{
00089 //  QMutexLocker lock(&m_ReferenceDataMutex);
00090 //
00091 //  return m_ReferenceData;
00092 //}
00093 //
00094 QVector<double> QavrgAcquisitionData::get_ReferenceData(int chan, int start, int nbins)
00095 {
00096   QMutexLocker lock(&m_AcquisitionDataMutex);
00097 
00098   return fitter(chan) -> get_ReferenceData(start,nbins);
00099 }
00100 
00101 QVector<double> QavrgAcquisitionData::get_ReferenceData(int chan)
00102 {
00103   QMutexLocker lock(&m_AcquisitionDataMutex);
00104 
00105   return fitter(chan) -> get_ReferenceData();
00106 }
00107 
00108 double QavrgAcquisitionData::get_ReferenceData(int chan, int bin)
00109 {
00110   QMutexLocker lock(&m_AcquisitionDataMutex);
00111 
00112   return fitter(chan) -> get_ReferenceData(bin);
00113 }
00114 
00115 //QVector< QVector<double> > QavrgAcquisitionData::get_DarkData()
00116 //{
00117 //  QMutexLocker lock(&m_AcquisitionDataMutex);
00118 //
00119 //  return m_DarkData;
00120 //}
00121 
00122 QVector<double> QavrgAcquisitionData::get_DarkData(int chan, int start, int nbins)
00123 {
00124   QMutexLocker lock(&m_AcquisitionDataMutex);
00125 
00126   return fitter(chan) -> get_DarkData(start,nbins);
00127 }
00128 
00129 QVector<double> QavrgAcquisitionData::get_DarkData(int chan)
00130 {
00131   QMutexLocker lock(&m_AcquisitionDataMutex);
00132 
00133   return fitter(chan) -> get_DarkData();
00134 }
00135 
00136 double QavrgAcquisitionData::get_DarkData(int chan, int bin)
00137 {
00138   QMutexLocker lock(&m_AcquisitionDataMutex);
00139 
00140   return fitter(chan) -> get_DarkData(bin);
00141 }
00142 
00143 //QVector< QVector<double> > QavrgAcquisitionData::get_FitData()
00144 //{
00145 //  QMutexLocker lock(&m_FitDataMutex);
00146 //
00147 //  return m_FitData;
00148 //}
00149 
00150 QVector<double> QavrgAcquisitionData::get_FitData(int chan, int start, int nbins)
00151 {
00152   QMutexLocker lock(&m_AcquisitionDataMutex);
00153 
00154   return fitter(chan) -> get_FitData(start,nbins);
00155 }
00156 
00157 QVector<double> QavrgAcquisitionData::get_FitData(int chan)
00158 {
00159   QMutexLocker lock(&m_AcquisitionDataMutex);
00160 
00161   return fitter(chan) -> get_FitData();
00162 }
00163 
00164 double QavrgAcquisitionData::get_FitData(int chan, int bin)
00165 {
00166   QMutexLocker lock(&m_AcquisitionDataMutex);
00167 
00168   return fitter(chan) -> get_FitData(bin);
00169 }
00170 
00171 //void QavrgAcquisitionData::set_FitData(int chan, int bin, double value)
00172 //{
00173 //  QMutexLocker lock(&m_AcquisitionDataMutex);
00174 //
00175 //  fitter(chan) -> set_FitData(bin, value);
00176 //}
00177 //
00178 //void QavrgAcquisitionData::set_FitData(int chan, QVector<double> value)
00179 //{
00180 //  QMutexLocker lock(&m_AcquisitionDataMutex);
00181 //
00182 //  fitter(chan) -> set_FitData(value);
00183 //}
00184 
00185 //QString QavrgAcquisitionData::referenceDataPath(int chan)
00186 //{
00187 //  return QavrgSettings::settingsDirectory().filePath(tr("ref%1").arg(chan));
00188 //}
00189 
00190 void QavrgAcquisitionData::loadReferenceData()
00191 {
00192   int nchan = get_NChannels();
00193 
00194   for (int i = 0; i<nchan; i++) {
00195     fitter(i) -> loadReferenceData();
00196   }
00197 }
00198 
00199 void QavrgAcquisitionData::saveReferenceData()
00200 {
00201   int nchan = get_NChannels();
00202 
00203   for (int i = 0; i<nchan; i++) {
00204     fitter(i) -> saveReferenceData();
00205   }
00206 }
00207 
00208 
00209 void QavrgAcquisitionData::loadDarkData()
00210 {
00211   int nchan = get_NChannels();
00212 
00213   for (int i = 0; i<nchan; i++) {
00214     fitter(i) -> loadDarkData();
00215   }
00216 }
00217 
00218 void QavrgAcquisitionData::saveDarkData()
00219 {
00220   int nchan = get_NChannels();
00221 
00222   for (int i = 0; i<nchan; i++) {
00223     fitter(i) -> saveDarkData();
00224   }
00225 }
00226 
00227 //void QavrgAcquisitionData::setReferenceAvailable(int t)
00228 //{
00229 //  m_ReferenceAvailable = t;
00230 //}
00231 //
00232 //void QavrgAcquisitionData::setDarkAvailable(int t)
00233 //{
00234 //  m_DarkAvailable = t;
00235 //}
00236 
00237 //void QavrgAcquisitionData::readData(QString loadName)
00238 //{
00239 //  QMutexLocker lock(&m_RawDataMutex);
00240 //
00241 //  if (!loadName.isNull()) {
00242 //    double val;
00243 //    long n;
00244 //
00245 //    QFile file(loadName);
00246 //    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) return;
00247 //
00248 //    int ncols=0, nrows=0;
00249 //
00250 //    QByteArray buffer(20000, 0);
00251 //
00252 //    while (!file.atEnd()) {
00253 //      n = file.readLine(buffer.data(), buffer.count());
00254 //
00255 //      char* p=buffer.data();
00256 //      int nf = 0;
00257 //      while(1) {
00258 //        char *endp;
00259 //        val = strtod(p, &endp);
00260 //        if (p != endp) {
00261 //          nf++;
00262 //          p = endp;
00263 //        } else {
00264 //          break;
00265 //        }
00266 //      }
00267 //
00268 //      if (nf) {
00269 //        nrows ++;
00270 //      }
00271 //
00272 //      if (nf>ncols) {
00273 //        ncols = nf;
00274 //      }
00275 //    }
00276 //
00277 //    printf("%d rows, %d cols\n", nrows, ncols);
00278 //
00279 //    file.seek(0);
00280 //
00281 //    m_RawData.resize(ncols);
00282 //    for (int i=0; i<ncols; i++) { // skip column 0
00283 //      m_RawData[i].resize(nrows);
00284 //    }
00285 //
00286 //    for (int r=0; r<nrows; r++) {
00287 //      n = file.readLine(buffer.data(), buffer.count());
00288 //
00289 //      char* p=buffer.data();
00290 //
00291 //      for (int c=0; c<ncols; c++) {
00292 //        char *endp;
00293 //        val = strtod(p, &endp);
00294 //        if (p != endp) {
00295 //          m_RawData[c][r] = val;
00296 //          p = endp;
00297 //        } else {
00298 //          break;
00299 //        }
00300 //      }
00301 //    }
00302 //
00303 //    emit new_RawData();
00304 //  }
00305 //}
00306 //
00307 //void QavrgAcquisitionData::writeData(QString &saveName)
00308 //{
00309 //  QMutexLocker lock(&m_RawDataMutex);
00310 //
00311 //  if (!saveName.isNull()) {
00312 //    FILE *f = fopen(qPrintable(saveName),"w");
00313 //
00314 //    int nacq = m_RawData.count();
00315 //    int n    = m_RawData[0].count();
00316 //
00317 //    for (int r=0; r<n; r++) {
00318 //      fprintf(f, "%d\t", r);
00319 //
00320 //      for (int i=0; i<nacq*2; i++) {
00321 //        fprintf(f, "%g\t", m_RawData[i][r]);
00322 //      }
00323 //      fprintf(f,"\n");
00324 //    }
00325 //
00326 //    fclose(f);
00327 //  }
00328 //}
00329 //
00330 //QVector< QFuture<void> >   QavrgAcquisitionData::futures() const
00331 //{
00332 //  QMutexLocker lock(&m_Mutex);
00333 //
00334 //  return m_Futures;
00335 //}