From 4a80fcc10db595b40c8a6fe004e83e1be46bb092 Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Wed, 19 Apr 2023 18:08:20 -0400 Subject: [PATCH] cannot get trace, need to review the Digitizer Class using test.cpp --- .gitignore | 2 + ClassData.h | 15 +++---- ClassDigitizer.cpp | 8 ++-- ClassDigitizer.h | 8 +++- CustomThreads.h | 6 +-- FSUDAQ.cpp | 14 +++++- Scope.cpp | 110 ++++++++++++++++++++++++++++++++++++++------- Scope.h | 13 +++--- test.cpp | 13 +++--- 9 files changed, 143 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index 8e86b85..9ac68ee 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ programSettings.txt data +*.txt + *~ *.autosave moc_* diff --git a/ClassData.h b/ClassData.h index 233c9e4..d1d0b07 100644 --- a/ClassData.h +++ b/ClassData.h @@ -34,7 +34,8 @@ class Data{ unsigned short NumEventsDecoded[MaxNChannels]; /// reset at every decode unsigned short NumNonPileUpDecoded[MaxNChannels]; /// reset at every decode - /// store data for event building + /// store data for event building and deduce the trigger rate. + //TODO... make it a circular memory bool IsNotRollOverFakeAgg; unsigned short NumEvents[MaxNChannels]; /// max 65535, reset only clear Data unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit @@ -68,7 +69,7 @@ class Data{ void PrintStat() const; - void PrintData() const; + void PrintAllData() const; //^================= Saving data void OpenSaveFile(std::string fileNamePrefix); @@ -178,6 +179,7 @@ inline void Data::ClearData(){ inline void Data::ClearBuffer(){ delete buffer; + buffer = nullptr; AllocatedSize = 0; nByte = 0; } @@ -245,7 +247,7 @@ inline void Data::PrintBuffer() const{ } } -inline void Data::PrintData() const{ +inline void Data::PrintAllData() const{ printf("============================= Print Data\n"); for( int ch = 0; ch < MaxNChannels ; ch++){ if( NumEvents[ch] == 0 ) continue; @@ -280,12 +282,8 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){ return; } - if( nByte == 0 ) { - return; - } - + if( nByte == 0 ) return; nw = 0; - ClearTriggerRate(); do{ @@ -722,7 +720,6 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe NumEvents[channel] ++; NumEventsDecoded[channel] ++; TotNumEvents[channel] ++; - } if( NumEvents[channel] >= MaxNData ) ClearData(); diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index 10564e2..e666b90 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -288,7 +288,7 @@ int Digitizer::ProgramPHABoard(){ printf("======== program board PHA\n"); ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::RecordLength_G + 0x7000, 62); - ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x0F8915); /// has Extra2 + ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x0F8915); /// has Extra2, dual trace, input and trap-baseline ///ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x0D8115); /// diable Extra2 //TODO change to write register @@ -369,6 +369,7 @@ void Digitizer::StopACQ(){ printf("\n\e[1m\e[33m====== Acquisition STOPPED for Board %d\e[0m\n", boardID); AcqRun = false; data->ClearTriggerRate(); + data->ClearBuffer(); } unsigned int Digitizer::CalByteForBuffer(){ @@ -906,6 +907,7 @@ void Digitizer::SetPreTriggerDuration(unsigned int ns, int ch) void Digitizer::SetDCOffset(float offsetPrecentage, int ch) { WriteRegister( Register::DPP::ChannelDCOffset, uint( 0xFFFF * (1.0-offsetPrecentage)), ch ); ErrorMsg(__func__);} void Digitizer::SetVetoWidth(uint32_t bit, int ch) { WriteRegister( Register::DPP::VetoWidth, bit, ch); ErrorMsg(__func__);} + void Digitizer::SetTriggerPolarity(bool RiseingIsZero, int ch ){ if( !isConnected ) return; if ( DPPType >= 128 ) return; /// do thing for DPP firmware @@ -926,7 +928,7 @@ void Digitizer::SetDPPAlgorithmControl(uint32_t bit, int ch){ if( ret != 0 ) ErrorMsg(__func__); } -unsigned int Digitizer::ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch ){ +unsigned int Digitizer::ReadBits(Register::Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch ){ int tempCh = ch; if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0 uint32_t bit = ReadRegister(address, tempCh); @@ -934,7 +936,7 @@ unsigned int Digitizer::ReadBits(Reg address, unsigned int bitLength, unsigned i return bit; } -void Digitizer::SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch){ +void Digitizer::SetBits(Register::Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch){ ///printf("address : 0x%X, value : 0x%X, len : %d, pos : %d, ch : %d \n", address, bitValue, bitLength, bitSmallestPos, ch); uint32_t bit ; uint32_t bitmask = (uint(pow(2, bitLength)-1) << bitSmallestPos); diff --git a/ClassDigitizer.h b/ClassDigitizer.h index ecfbb73..4ee933b 100644 --- a/ClassDigitizer.h +++ b/ClassDigitizer.h @@ -76,7 +76,7 @@ class Digitizer{ void PrintBoard() ; virtual int ProgramBoard() ; /// program a generic board, no program channel - int ProgramPHABoard() ; /// program a default PHA board + int ProgramPHABoard() ; /// program a default PHA board with dual trace //^================ ACQ control void StopACQ(); @@ -138,6 +138,12 @@ class Digitizer{ void SaveSettingToFile (Register::Reg registerAddress, unsigned int value, unsigned short ch = 0); /// also save to memory unsigned int ReadSettingFromFile (Register::Reg registerAddress, unsigned short ch = 0); /// read from setting binary + //============ old methods, that only manipulate digitizer register, not setting in memory + // void SetTriggerPolarity(bool RiseingIsZero, int ch ); + // void SetDPPAlgorithmControl(uint32_t bit, int ch); + // unsigned int ReadBits(Register::Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch ); + // void SetBits(Register::Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch); + }; diff --git a/CustomThreads.h b/CustomThreads.h index 914d950..47f6963 100644 --- a/CustomThreads.h +++ b/CustomThreads.h @@ -84,7 +84,7 @@ public: } void Stop() { this->stop = true;} void SetWaitTimeinSec(float sec) {waitTime = sec * 10 ;} - unsigned int GetWaitTimeinSec() const {return waitTime/10;} + float GetWaitTimeinSec() const {return waitTime/10.;} void run(){ unsigned int count = 0; stop = false; @@ -92,12 +92,12 @@ public: usleep(100000); count ++; if( count % waitTime == 0){ - emit updataScalar(); + emit timeUp(); } }while(!stop); } signals: - void updataScalar(); + void timeUp(); private: bool stop; unsigned int waitTime; diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index b06fdf2..583eae2 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -183,7 +183,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ lbScalarACQStatus = nullptr; scalarThread = new TimingThread(); - connect(scalarThread, &TimingThread::updataScalar, this, &MainWindow::UpdateScalar); + connect(scalarThread, &TimingThread::timeUp, this, &MainWindow::UpdateScalar); } @@ -370,10 +370,15 @@ void MainWindow::OpenDigitizers(){ readDataThread = new ReadDataThread * [nDigi]; for( unsigned int i = 0; i < nDigi; i++){ digi[i] = new Digitizer(portList[i].first, portList[i].second); + //TODO === load settings + digi[i]->Reset(); + digi[i]->ProgramPHABoard(); readDataThread[i] = new ReadDataThread(digi[i], i); connect(readDataThread[i], &ReadDataThread::sendMsg, this, &MainWindow::LogMsg); } + digi[0]->SaveAllSettingsAsText("setting.txt"); + LogMsg(QString("Done. Opened %1 digitizer(s).").arg(nDigi)); WaitForDigitizersOpen(false); @@ -571,6 +576,9 @@ void MainWindow::StartACQ(){ } lbScalarACQStatus->setText("ACQ On"); + bnStartACQ->setEnabled(false); + bnStopACQ->setEnabled(true); + } void MainWindow::StopACQ(){ @@ -597,6 +605,9 @@ void MainWindow::StopACQ(){ } lbScalarACQStatus->setText("ACQ Off"); + + bnStartACQ->setEnabled(true); + bnStopACQ->setEnabled(false); } void MainWindow::AutoRun(){ @@ -707,6 +718,7 @@ void MainWindow::OpenScope(){ scope->show(); }else{ scope->show(); + scope->activateWindow(); } } diff --git a/Scope.cpp b/Scope.cpp index b8e4cf2..8f0654f 100644 --- a/Scope.cpp +++ b/Scope.cpp @@ -50,8 +50,7 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh updateTraceThread = new TimingThread(); updateTraceThread->SetWaitTimeinSec(0.5); - - //connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &Scope::UpdateScope); + connect(updateTraceThread, &TimingThread::timeUp, this, &Scope::UpdateScope); //*================================== UI int rowID = -1; @@ -86,11 +85,9 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh for( int i = 0; i < digi[ID]->GetNChannels(); i++) cbScopeCh->addItem("Ch-" + QString::number(i)); //---Setup SettingGroup - if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) { - SetUpPHAPanel(); - }else{ - CleanUpSettingsGroupBox(); - } + CleanUpSettingsGroupBox(); + if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) SetUpPHAPanel(); + if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) SetUpPSDPanel(); }); @@ -130,7 +127,6 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh rowID ++; bnScopeStart = new QPushButton("Start", this); layout->addWidget(bnScopeStart, rowID, 0); - bnScopeStart->setEnabled(false); connect(bnScopeStart, &QPushButton::clicked, this, [=](){this->StartScope();}); bnScopeStop = new QPushButton("Stop", this); @@ -150,8 +146,6 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh layout->addWidget(bnClose, rowID, 5); connect(bnClose, &QPushButton::clicked, this, &Scope::close); - - layout->setColumnStretch(0, 1); layout->setColumnStretch(1, 1); layout->setColumnStretch(2, 1); @@ -161,6 +155,9 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh enableSignalSlot = true; + bnScopeStart->setEnabled(true); + bnScopeStop->setEnabled(false); + } @@ -177,11 +174,91 @@ Scope::~Scope(){ //*======================================================= //*======================================================= void Scope::StartScope(){ + if( !digi ) return; + for( unsigned int iDigi = 0; iDigi < nDigi; iDigi ++){ + + digi[iDigi]->GetData()->SetSaveWaveToMemory(true); + + digi[iDigi]->StartACQ(); + + readDataThread[iDigi]->SetScopeMode(true); + readDataThread[iDigi]->SetSaveData(false); + + readDataThread[iDigi]->start(); + + } + + updateTraceThread->start(); + + bnScopeStart->setEnabled(false); + bnScopeStop->setEnabled(true); } void Scope::StopScope(){ + if( !digi ) return; + + updateTraceThread->Stop(); + updateTraceThread->quit(); + updateTraceThread->exit(); + + + for( unsigned int iDigi = 0; iDigi < nDigi; iDigi ++){ + + digi[iDigi]->StopACQ(); + + readDataThread[iDigi]->quit(); + readDataThread[iDigi]->wait(); + } + + bnScopeStart->setEnabled(true); + bnScopeStop->setEnabled(false); + +} + +void Scope::UpdateScope(){ + + printf("---- %s \n", __func__); + + if( !digi ) return; + + int ID = cbScopeDigi->currentIndex(); + int ch = cbScopeCh->currentIndex(); + int ch2ns = digi[ID]->GetCh2ns(); + + Data * data = digi[ID]->GetData(); + + digiMTX[ID].lock(); + leTriggerRate->setText(QString::number(data->TriggerRate[ch])); + + unsigned short index = data->NumEvents[ch]; + unsigned short traceLength = data->Waveform1[ch][index].size(); + + if( data->TriggerRate[ch] > 0 ){ + + printf("--- %d | %d \n", index, traceLength ); + + QVector points; + for( int i = 0; i < (int) (data->Waveform1[ch][index]).size() ; i++ ) points.append(QPointF(ch2ns * i, (data->Waveform1[ch][index])[i])); + dataTrace[0]->replace(points); + + points.clear(); + for( int i = 0; i < (int) (data->Waveform2[ch][index]).size() ; i++ ) points.append(QPointF(ch2ns * i, (data->Waveform2[ch][index])[i])); + dataTrace[1]->replace(points); + + points.clear(); + for( int i = 0; i < (int) (data->DigiWaveform1[ch][index]).size() ; i++ ) points.append(QPointF(ch2ns * i, (data->DigiWaveform1[ch][index])[i] * 1000)); + dataTrace[2]->replace(points); + + points.clear(); + for( int i = 0; i < (int) (data->DigiWaveform2[ch][index]).size() ; i++ ) points.append(QPointF(ch2ns * i, (data->DigiWaveform2[ch][index])[i] * 1000)); + dataTrace[3]->replace(points); + + } + digiMTX[ID].unlock(); + + plot->axes(Qt::Horizontal).first()->setRange(0, ch2ns * traceLength); } @@ -243,8 +320,6 @@ void Scope::SetUpSpinBox(RSpinBox * &sb, QString str, int row, int col, const Re void Scope::CleanUpSettingsGroupBox(){ - printf("-- %s\n", __func__); - QList labelChildren1 = settingGroup->findChildren(); for( int i = 0; i < labelChildren1.size(); i++) delete labelChildren1[i]; @@ -255,12 +330,9 @@ void Scope::CleanUpSettingsGroupBox(){ for( int i = 0; i < labelChildren3.size(); i++) delete labelChildren3[i]; } + void Scope::SetUpPHAPanel(){ - CleanUpSettingsGroupBox(); - - printf("-- %s\n", __func__); - SetUpSpinBox(sbReordLength, "Record Length [ns]", 0, 0, Register::DPP::RecordLength_G); SetUpSpinBox(sbPreTrigger, "Pre Trigger [ns]", 0, 2, Register::DPP::PreTrigger); @@ -275,6 +347,10 @@ void Scope::SetUpPHAPanel(){ SetUpSpinBox(sbDecayTime, "Decay Time [ns]", 2, 4, Register::DPP::PHA::DecayTime); SetUpSpinBox(sbPeakingTime, "Peaking Time [ns]", 2, 6, Register::DPP::PHA::PeakingTime); - } +void Scope::SetUpPSDPanel(){ + + SetUpSpinBox(sbReordLength, "Record Length [ns]", 0, 0, Register::DPP::RecordLength_G); + SetUpSpinBox(sbPreTrigger, "Pre Trigger [ns]", 0, 2, Register::DPP::PreTrigger); +} diff --git a/Scope.h b/Scope.h index e8d6f83..c70effe 100644 --- a/Scope.h +++ b/Scope.h @@ -31,21 +31,22 @@ public: Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataThread, QMainWindow * parent = nullptr); ~Scope(); -public slots: - private slots: void StartScope(); void StopScope(); + void UpdateScope(); + +signals: + +private: + void SetUpComboBox(RComboBox * &cb, QString str, int row, int col, const Register::Reg para); void SetUpSpinBox(RSpinBox * &sb, QString str, int row, int col, const Register::Reg para); void CleanUpSettingsGroupBox(); void SetUpPHAPanel(); - -signals: - -private: + void SetUpPSDPanel(); Digitizer ** digi; unsigned short nDigi; diff --git a/test.cpp b/test.cpp index f915e41..995ae61 100644 --- a/test.cpp +++ b/test.cpp @@ -38,18 +38,19 @@ int main(int argc, char* argv[]){ const float ch2ns = dig[0]->GetCh2ns(); Data * data = dig[0]->GetData(); - data->Allocate80MBMemory(); dig[0]->StartACQ(); - sleep(3); + for( int i = 0; i < 5; i ++ ){ + sleep(1); + dig[0]->ReadData(); + data->DecodeBuffer(false, true); + } - dig[0]->ReadData(); + dig[0]->StopACQ(); - data->SaveBuffer("test"); + data->PrintAllData(); - - /*