diff --git a/ClassData.h b/ClassData.h index b71c6e5..7278478 100644 --- a/ClassData.h +++ b/ClassData.h @@ -70,7 +70,7 @@ class Data{ void PrintStat() const; - void PrintAllData(bool tableMode = true) const; + void PrintAllData(bool tableMode = true, unsigned int maxRowDisplay = 0) const; //^================= Saving data bool OpenSaveFile(std::string fileNamePrefix); // return false when fail @@ -268,7 +268,7 @@ inline void Data::PrintStat() const{ printf("---+--------+-----------+-----------+----------\n"); } -inline void Data::PrintAllData(bool tableMode) const{ +inline void Data::PrintAllData(bool tableMode, unsigned int maxRowDisplay) const{ printf("============================= Print Data\n"); if( tableMode ){ @@ -296,6 +296,8 @@ inline void Data::PrintAllData(bool tableMode) const{ } printf("\n"); entry ++; + + if( maxRowDisplay > 0 && (unsigned int) entry >= maxRowDisplay ) break; }while(entry <= MaxEntry); }else{ @@ -305,6 +307,7 @@ inline void Data::PrintAllData(bool tableMode) const{ for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){ if( DPPType == V1730_DPP_PHA_CODE ) printf("%4d, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); if( DPPType == V1730_DPP_PSD_CODE ) printf("%4d, %5u, %5u, %15llu, %5u \n", ev, Energy[ch][ev], Energy2[ch][ev], Timestamp[ch][ev], fineTime[ch][ev]); + if( maxRowDisplay > 0 && (unsigned int) ev > maxRowDisplay ) break; } } } diff --git a/ClassDigitizer.cpp b/ClassDigitizer.cpp index 8b39dc5..9ee70fa 100644 --- a/ClassDigitizer.cpp +++ b/ClassDigitizer.cpp @@ -408,6 +408,24 @@ void Digitizer::StartACQ(){ printf("\e[1m\e[33m======= Acquisition Started for %d | Board %d, Port %d\e[0m\n", BoardInfo.SerialNumber, boardID, portID); AcqRun = true; data->ClearTriggerRate(); + + unsigned int acqID = ExtractBits(GetSettingFromMemory(DPP::AcquisitionControl), DPP::Bit_AcquistionControl::StartStopMode); + unsigned int trgOutID = ExtractBits(GetSettingFromMemory(DPP::FrontPanelIOControl), DPP::Bit_FrontPanelIOControl::TRGOUTConfig); + + std::string acqStr = ""; + for( int i = 0; i < (int) DPP::Bit_AcquistionControl::ListStartStopMode.size(); i++){ + if( DPP::Bit_AcquistionControl::ListStartStopMode[i].second == acqID ){ + acqStr = DPP::Bit_AcquistionControl::ListStartStopMode[i].first; + } + } + std::string trgOutStr = ""; + for( int i = 0; i < (int) DPP::Bit_FrontPanelIOControl::ListTRGOUTConfig.size(); i++){ + if( DPP::Bit_FrontPanelIOControl::ListTRGOUTConfig[i].second == (trgOutID << 14) ){ + trgOutStr = DPP::Bit_FrontPanelIOControl::ListTRGOUTConfig[i].first; + } + } + + printf(" ACQ mode : %s (%d), TRG-OUT mode : %s (%d) \n", acqStr.c_str(), acqID, trgOutStr.c_str(), trgOutID); } void Digitizer::StopACQ(){ diff --git a/CustomThreads.h b/CustomThreads.h index 285b777..1d99159 100644 --- a/CustomThreads.h +++ b/CustomThreads.h @@ -3,6 +3,7 @@ #include #include +#include #include "macro.h" #include "ClassDigitizer.h" @@ -24,11 +25,30 @@ public: void Stop() { this->stop = true;} void SetSaveData(bool onOff) {this->isSaveData = onOff;} void SetScopeMode(bool onOff) {this->isScope = onOff;} + + void go(){ + mutex.lock(); + condition.wakeAll(); + mutex.unlock(); + } + void run(){ + + stop = false; + + mutex.lock(); + condition.wait(&mutex); + mutex.unlock(); + clock_gettime(CLOCK_REALTIME, &t0); + printf("--- %d, %ld nsec \n", ID, t0.tv_nsec); ta = t0; // clock_gettime(CLOCK_REALTIME, &t1); - stop = false; + + digi->StartACQ(); + + usleep(1000); // wait for some data; + do{ if( stop) break; @@ -84,7 +104,10 @@ private: timespec ta, tb, t1, t2, t0; bool isSaveData; bool isScope; - unsigned long readCount; + unsigned long readCount; + + QMutex mutex; + QWaitCondition condition; }; //^#======================================================= Timing Thread diff --git a/DataReaderScript.cpp b/DataReaderScript.cpp index 567aa73..18fe1b2 100644 --- a/DataReaderScript.cpp +++ b/DataReaderScript.cpp @@ -7,7 +7,7 @@ void DataReaderScript(){ Data * data = new Data(); data->DPPType = V1730_DPP_PSD_CODE; - std::string fileName = "data/temp_043_089_PSD_000.fsu"; + std::string fileName = "data/temp_046_325_PHA_000.fsu"; FILE * haha = fopen(fileName.c_str(), "r"); fseek(haha, 0L, SEEK_END); @@ -49,16 +49,17 @@ void DataReaderScript(){ //if( countBdAgg % 100 == 0) data->PrintStat(); //data->ClearData(); - if( countBdAgg > 500 ){ - data->PrintAllData(); - mb->BuildEventsBackWard(false); - break; - } + //if( countBdAgg > 500 ){ + // data->PrintAllData(); + // mb->BuildEventsBackWard(false); + // break; + //} }while(!feof(haha) && ftell(haha) < inFileSize); data->PrintStat(); + data->PrintAllData(); fclose(haha); diff --git a/DigiSettingsPanel.cpp b/DigiSettingsPanel.cpp index bc8ed46..49805b4 100644 --- a/DigiSettingsPanel.cpp +++ b/DigiSettingsPanel.cpp @@ -2476,7 +2476,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ chkEnableExternalTrigger[ID]->setChecked( ! ( digi[ID]->GetSettingFromMemory(DPP::DisableExternalTrigger) & 0x1) ); - sbRunDelay[ID]->setValue(digi[ID]->GetSettingFromMemory(DPP::RunStartStopDelay)); + sbRunDelay[ID]->setValue(digi[ID]->GetSettingFromMemory(DPP::RunStartStopDelay) * DPP::RunStartStopDelay.GetPartialStep() * digi[ID]->GetTick2ns()); //*======================================== uint32_t anaMonitor = digi[ID]->GetSettingFromMemory(DPP::AnalogMonitorMode); @@ -2496,6 +2496,13 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ sbBufferGain[ID]->setValue(digi[ID]->GetSettingFromMemory(DPP::BufferOccupancyGain)); sbVoltageLevel[ID]->setValue(digi[ID]->GetSettingFromMemory(DPP::VoltageLevelModeConfig)); + //*======================================== + uint32_t acqCtrl = digi[ID]->GetSettingFromMemory(DPP::AcquisitionControl); + + cbStartStopMode[ID]->setCurrentIndex( Digitizer::ExtractBits(acqCtrl, DPP::Bit_AcquistionControl::StartStopMode) ); + cbAcqStartArm[ID]->setCurrentIndex( Digitizer::ExtractBits(acqCtrl, DPP::Bit_AcquistionControl::ACQStartArm) ); + cbPLLRefClock[ID]->setCurrentIndex( Digitizer::ExtractBits(acqCtrl, DPP::Bit_AcquistionControl::PLLRef) ); + //*======================================== uint32_t frontPanel = digi[ID]->GetSettingFromMemory(DPP::FrontPanelIOControl); cbLEMOMode[ID]->setCurrentIndex( ( frontPanel & 0x1 )); @@ -2503,8 +2510,7 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){ if( (frontPanel >> 1 ) & 0x1 ) { // bit-1, TRIG-OUT high impedance, i.e. disable cbTRGOUTMode[ID]->setCurrentIndex(0); }else{ - unsigned short trgOutBit = ((frontPanel >> 14 ) & 0x3F ) << 14 ; - + unsigned int trgOutBit = ((frontPanel >> 14 ) & 0x3F ) << 14 ; for( int i = 0; i < cbTRGOUTMode[ID]->count() ; i++ ){ if( cbTRGOUTMode[ID]->itemData(i).toUInt() == trgOutBit ){ cbTRGOUTMode[ID]->setCurrentIndex(i); @@ -3076,6 +3082,8 @@ void DigiSettingsPanel::LoadSetting(){ digi[ID]->ProgramSettingsToBoard(); UpdatePanelFromMemory(); + UpdateOtherPanels(); + }else{ SendLogMsg("Fail to Loaded settings file " + fileName + " for Digi-" + QString::number(digi[ID]->GetSerialNumber())); } diff --git a/FSUDAQ.cpp b/FSUDAQ.cpp index 70d4c3c..037e7df 100644 --- a/FSUDAQ.cpp +++ b/FSUDAQ.cpp @@ -64,9 +64,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){ layout->addWidget(bnCanvas, 1, 2); connect(bnCanvas, &QPushButton::clicked, this, &MainWindow::OpenCanvas); - QPushButton * bnSync = new QPushButton("Sync Boards", this); + bnSync = new QPushButton("Sync Boards", this); layout->addWidget(bnSync); - bnSync->setEnabled(false); + connect(bnSync, &QPushButton::clicked, this, &MainWindow::SetSyncMode); } @@ -561,6 +561,8 @@ void MainWindow::OpenDigitizers(){ bnStopACQ->setEnabled(false); bnStopACQ->setStyleSheet(""); + bnSync->setEnabled( nDigi >= 1 ); + if( rawDataPath == "" ) { chkSaveData->setChecked(false); chkSaveData->setEnabled(false); @@ -635,6 +637,8 @@ void MainWindow::WaitForDigitizersOpen(bool onOff){ bnCanvas->setEnabled(!onOff); bnAnalyzer->setEnabled(!onOff); + bnSync->setEnabled(false); + } //*************************************************************** @@ -786,6 +790,8 @@ void MainWindow::UpdateScalar(){ for( unsigned int iDigi = 0; iDigi < nDigi; iDigi++){ digiMTX[iDigi].lock(); + printf("### %d ", iDigi); + digi[iDigi]->GetData()->PrintAllData(true, 10); if( chkSaveData->isChecked() ) totalFileSize += digi[iDigi]->GetData()->GetTotalFileSize(); for( int i = 0; i < digi[iDigi]->GetNChannels(); i++){ if( digi[iDigi]->GetChannelOnOff(i) == true ) { @@ -828,7 +834,6 @@ void MainWindow::StartACQ(){ LogMsg("===================== Start a non-save Run"); } - for( unsigned int i = 0; i < nDigi ; i++){ if( chkSaveData->isChecked() ) { if( digi[i]->GetData()->OpenSaveFile((rawDataPath + "/" + prefix + "_" + QString::number(runID).rightJustified(3, '0')).toStdString()) == false ) { @@ -841,11 +846,15 @@ void MainWindow::StartACQ(){ digi[i]->WriteRegister(DPP::SoftwareClear_W, 1); digi[i]->GetData()->ClearData(); - digi[i]->StartACQ(); readDataThread[i]->start(); } if( chkSaveData->isChecked() ) SaveLastRunFile(); - + + printf("------------ wait for 2 sec \n"); + usleep(2000*1000); + printf("------------ Go! \n"); + for( unsigned int i = 0; i < nDigi; i++) readDataThread[i]->go(); + scalarThread->start(); if( !scalar->isVisible() ) { @@ -960,6 +969,19 @@ void MainWindow::StopACQ(){ void MainWindow::AutoRun(){ //TODO +} + +void MainWindow::SetSyncMode(){ + + // No sync + + // using external start ( TRG-OUT (S-IN) --> S-IN ) + + // using SW ( TRG-OUT(RUN) --> S-IN) + + // using external Clock ( TRG-OUT(RUN) --> S-IN ) + + } bool MainWindow::CommentDialog(bool isStartRun){ diff --git a/FSUDAQ.h b/FSUDAQ.h index e9091d0..6615dfc 100644 --- a/FSUDAQ.h +++ b/FSUDAQ.h @@ -74,6 +74,8 @@ private slots: void WriteElog(QString htmlText, QString subject, QString category, int runNumber); void AppendElog(QString appendHtmlText); + void SetSyncMode(); + private: @@ -95,6 +97,7 @@ private: QPushButton * bnOpenScaler; QPushButton * bnStartACQ; QPushButton * bnStopACQ; + QPushButton * bnSync; QPushButton * bnCanvas;