Compare commits

..

No commits in common. "0000be1d4432cf43afaf7ac424b7a5dd960c1bb8" and "fecb77a105d1c263a2d4f8d411eb19db98e27cdb" have entirely different histories.

6 changed files with 75 additions and 167 deletions

View File

@ -29,14 +29,12 @@ class Data{
uint32_t AllocatedSize;
double TriggerRate[MaxNChannels]; /// Hz
double NonPileUpRate[MaxNChannels]; /// Hz
unsigned long TotNumEvents[MaxNChannels];
unsigned short NumEventsDecoded[MaxNChannels]; /// reset at every decode
unsigned short NumNonPileUpDecoded[MaxNChannels]; /// reset at every decode
unsigned short NumEventsDecoded[MaxNChannels];
/// store data for event building
/// store a single Raw event
bool IsNotRollOverFakeAgg;
unsigned short NumEvents[MaxNChannels]; /// max 65535, reset only clear Data
unsigned short NumEvents[MaxNChannels];
unsigned long long Timestamp[MaxNChannels][MaxNData]; /// 47 bit
unsigned short fineTime[MaxNChannels][MaxNData]; /// 10 bits, in unit of ch2ns / 1000 = ps
unsigned short Energy[MaxNChannels][MaxNData]; /// 15 bit
@ -146,9 +144,7 @@ inline void Data::Allocate80MBMemory(){
inline void Data::ClearTriggerRate(){
for( int i = 0 ; i < MaxNChannels; i++) {
TriggerRate[i] = 0.0;
NonPileUpRate[i] = 0.0;
NumEventsDecoded[i] = 0;
NumNonPileUpDecoded[i] = 0;
}
}
@ -344,7 +340,6 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
double sec = dTime * ch2ns / 1e9;
if( sec != 0 && NumEventsDecoded[ch] > 1 ){
TriggerRate[ch] = NumEventsDecoded[ch]/sec;
NonPileUpRate[ch] = NumNonPileUpDecoded[ch]/sec;
}
}
@ -537,21 +532,14 @@ inline int Data::DecodePHADualChannelBlock(unsigned int ChannelMask, bool fastDe
printf(" trapezoid sat. : %d \n", ((extra >> 10) & 0x1) );
}
if( rollOver == 0 ) { // non-time roll over fake event
if( rollOver == 0 ) {
Energy[channel][NumEvents[channel]] = energy;
Timestamp[channel][NumEvents[channel]] = timeStamp;
if(extra2Option == 0 || extra2Option == 2 ) fineTime[channel][NumEvents[channel]] = (extra2 & 0x07FF );
NumEvents[channel] ++;
NumEventsDecoded[channel] ++;
TotNumEvents[channel] ++;
if( !pileUp ) {
NumNonPileUpDecoded[channel] ++;
}
}
if( NumEvents[channel] >= MaxNData ) ClearData();
if( verbose >= 1 ) printf("%4d | ch : %2d, PileUp : %d , energy : %5d, rollOver: %d, timestamp : %10llu, triggerAt : %d, nSample : %d, %f sec\n",
NumEvents[channel], channel, pileUp, energy, rollOver, timeStamp, triggerAtSample, nSample , timeStamp * 4. / 1e9);
@ -722,11 +710,8 @@ inline int Data::DecodePSDDualChannelBlock(unsigned int ChannelMask, bool fastDe
NumEvents[channel] ++;
NumEventsDecoded[channel] ++;
TotNumEvents[channel] ++;
}
if( NumEvents[channel] >= MaxNData ) ClearData();
if( verbose >= 2 ) printf("extra : 0x%08x, Qshort : %d, Qlong : %d \n", extra, Qshort, Qlong);
if( verbose >= 1 ) printf("ch : %2d, Qshort : %d, Qlong : %d, timestamp : %llu\n",

View File

@ -17,10 +17,8 @@ public:
this->digi = dig;
this->ID = digiID;
isSaveData = false;
isScope = false;
}
void SetSaveData(bool onOff) {this->isSaveData = onOff;}
void SetScopeMode(bool onOff) {this->isScope = onOff;}
void run(){
clock_gettime(CLOCK_REALTIME, &ta);
while(true){
@ -30,12 +28,15 @@ public:
if( ret == CAEN_DGTZ_Success ){
digiMTX[ID].lock();
digi->GetData()->DecodeBuffer(!isScope);
if( isSaveData ) digi->GetData()->SaveData();
if( isSaveData ) {
digi->GetData()->SaveData();
}else{
digi->GetData()->DecodeBuffer(false);
}
digiMTX[ID].unlock();
}else{
printf("ReadDataThread::%s------------ ret : %d \n", __func__, ret);
printf("%s------------ ret : %d \n", __func__, ret);
if( ret == CAEN_DGTZ_WrongAcqMode) break;
}
@ -71,19 +72,47 @@ private:
int ID;
timespec ta, tb;
bool isSaveData;
bool isScope;
};
//^#======================================================= Timing Thread
class TimingThread : public QThread {
//^#===================================================== UpdateTrace Thread
class UpdateTraceThread : public QThread {
Q_OBJECT
public:
TimingThread(QObject * parent = 0 ) : QThread(parent){
UpdateTraceThread(QObject * parent = 0) : QThread(parent){
waitTime = 2;
stop = false;
}
unsigned int GetWaitTimeSec() const {return waitTime;}
void SetWaitTimeSec(unsigned sec) {waitTime = sec;}
void Stop() {this->stop = true;}
void run(){
unsigned int count = 0;
stop = false;
do{
usleep(100000);
count ++;
if( count % waitTime == 0){
emit updateTrace();
}
}while(!stop);
}
signals:
void updateTrace();
private:
bool stop;
unsigned int waitTime; //100 of milisec
};
//^#======================================================= Scalar Thread
class ScalarThread : public QThread {
Q_OBJECT
public:
ScalarThread(QObject * parent = 0 ) : QThread(parent){
waitTime = 20; // 10 x 100 milisec
stop = false;
}
void Stop() { this->stop = true;}
void SetWaitTimeinSec(float sec) {waitTime = sec * 10 ;}
unsigned int GetWaitTimeinSec() const {return waitTime/10;}
void run(){
unsigned int count = 0;

View File

@ -182,8 +182,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
lbLastUpdateTime = nullptr;
lbScalarACQStatus = nullptr;
scalarThread = new TimingThread();
connect(scalarThread, &TimingThread::updataScalar, this, &MainWindow::UpdateScalar);
scalarThread = new ScalarThread();
//connect(scalarThread, &ScalarThread::updataScalar, this, &MainWindow::UpdateScalar);
}
@ -199,14 +199,6 @@ MainWindow::~MainWindow(){
if( scope ) delete scope;
if( scalar ) {
CleanUpScalar();
scalarThread->Stop();
scalarThread->quit();
scalarThread->exit();
delete scalarThread;
}
}
@ -530,18 +522,7 @@ void MainWindow::OpenScalar(){
}
void MainWindow::UpdateScalar(){
if( digi == nullptr ) return;
lbLastUpdateTime->setText("Last update: " + QDateTime::currentDateTime().toString("MM.dd hh:mm:ss"));
for( unsigned int iDigi = 0; iDigi < nDigi; iDigi++){
Data * data = digi[iDigi]->GetData();
for( int i = 0; i < digi[iDigi]->GetNChannels(); i++){
leTrigger[iDigi][i]->setText(QString::number(data->TriggerRate[i]));
leAccept[iDigi][i]->setText(QString::number(data->NonPileUpRate[i]));
}
}
}
@ -551,38 +532,27 @@ void MainWindow::UpdateScalar(){
void MainWindow::StartACQ(){
if( digi == nullptr ) return;
bool commentResult = true;
if( chkSaveData->isChecked() ) commentResult = CommentDialog(true);
if( commentResult == false) return;
if( CommentDialog(true) == false) return;
for( unsigned int i = 0; i < nDigi ; i++){
digi[i]->GetData()->OpenSaveFile((rawDataPath + "/" + prefix).toStdString());
digi[i]->StartACQ();
readDataThread[i]->SetSaveData(chkSaveData->isChecked());
readDataThread[i]->SetSaveData(true);
readDataThread[i]->start();
}
if( chkSaveData->isChecked() ) SaveLastRunFile();
scalarThread->start();
if( !scalar->isVisible() ) {
scalar->show();
}else{
scalar->activateWindow();
}
lbScalarACQStatus->setText("<font style=\"color: green;\"><b>ACQ On</b></font>");
SaveLastRunFile();
}
void MainWindow::StopACQ(){
if( digi == nullptr ) return;
bool commentResult = true;
if( chkSaveData->isChecked() ) commentResult = CommentDialog(true);
if( commentResult == false) return;
if( CommentDialog(false) == false) return;
for( unsigned int i = 0; i < nDigi; i++){
digi[i]->StopACQ();
if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile();
digi[i]->GetData()->CloseSaveFile();
if( readDataThread[i]->isRunning() ) {
readDataThread[i]->quit();
@ -590,13 +560,6 @@ void MainWindow::StopACQ(){
}
}
if( scalarThread->isRunning()){
scalarThread->Stop();
scalarThread->quit();
scalarThread->wait();
}
lbScalarACQStatus->setText("<font style=\"color: red;\"><b>ACQ Off</b></font>");
}
void MainWindow::AutoRun(){

View File

@ -92,7 +92,7 @@ private:
//@----- Scalar
QMainWindow * scalar;
QGridLayout * scalarLayout;
TimingThread * scalarThread;
ScalarThread * scalarThread;
QLineEdit *** leTrigger; // need to delete manually
QLineEdit *** leAccept; // need to delete manually
QLabel * lbLastUpdateTime;

View File

@ -48,9 +48,7 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
xaxis->setLabelFormat("%.0f");
xaxis->setTitleText("Time [ns]");
updateTraceThread = new TimingThread();
updateTraceThread->SetWaitTimeinSec(0.5);
updateTraceThread = new UpdateTraceThread();
//connect(updateTraceThread, &UpdateTraceThread::updateTrace, this, &Scope::UpdateScope);
//*================================== UI
@ -77,33 +75,26 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
for( int i = 0; i < digi[0]->GetNChannels(); i++) cbScopeCh->addItem("Ch-" + QString::number(i));
ch2ns = digi[ID]->GetCh2ns();
connect(cbScopeDigi, &RComboBox::currentIndexChanged, this, [=](int index){
connect(cbScopeCh, &RComboBox::currentIndexChanged, this, [=](int index){
if( !enableSignalSlot ) return;
ID = index;
ch2ns = digi[ID]->GetCh2ns();
//---setup cbScopeCh
cbScopeCh->clear();
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();
}
});
//================ Trace settings
rowID ++;
{
settingGroup = new QGroupBox("Trace Settings",this);
QGroupBox * settingGroup = new QGroupBox("Trace Settings",this);
layout->addWidget(settingGroup, rowID, 0, 1, 6);
settingLayout = new QGridLayout(settingGroup);
settingLayout->setSpacing(0);
QGridLayout * bLayout = new QGridLayout(settingGroup);
bLayout->setSpacing(0);
SetUpSpinBox(sbReordLength, "Record Length", bLayout, 0, 0, Register::DPP::RecordLength_G);
if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) SetUpPHAPanel();
}
//================ Plot view
@ -117,7 +108,7 @@ Scope::Scope(Digitizer ** digi, unsigned int nDigi, ReadDataThread ** readDataTh
QLabel * lbhints = new QLabel("Type 'r' to restore view, '+/-' Zoom in/out, arrow key to pan.", this);
layout->addWidget(lbhints, rowID, 0, 1, 4);
QLabel * lbinfo = new QLabel("Trace update every " + QString::number(updateTraceThread->GetWaitTimeinSec()) + " sec.", this);
QLabel * lbinfo = new QLabel("Trace update every " + QString::number(updateTraceThread->GetWaitTimeSec()) + " sec.", this);
lbinfo->setAlignment(Qt::AlignRight);
layout->addWidget(lbinfo, rowID, 5);
@ -187,29 +178,28 @@ void Scope::StopScope(){
//*=======================================================
//*=======================================================
void Scope::SetUpComboBox(RComboBox * &cb, QString str, int row, int col, const Register::Reg para){
QLabel * lb = new QLabel(str, settingGroup);
void Scope::SetUpComboBox(RComboBox * &cb, QString str, QGridLayout * layout, int row, int col, const Register::Reg para){
QLabel * lb = new QLabel(str, this);
lb->setAlignment(Qt::AlignRight | Qt::AlignCenter);
settingLayout->addWidget(lb, row, col);
layout->addWidget(lb, row, col);
cb = new RComboBox(settingGroup);
settingLayout->addWidget(cb, row, col + 1);
cb = new RComboBox(this);
layout->addWidget(cb, row, col + 1);
}
void Scope::SetUpSpinBox(RSpinBox * &sb, QString str, int row, int col, const Register::Reg para){
QLabel * lb = new QLabel(str, settingGroup);
void Scope::SetUpSpinBox(RSpinBox * &sb, QString str, QGridLayout * layout, int row, int col, const Register::Reg para){
QLabel * lb = new QLabel(str, this);
lb->setAlignment(Qt::AlignRight | Qt::AlignCenter);
settingLayout->addWidget(lb, row, col);
layout->addWidget(lb, row, col);
sb = new RSpinBox(settingGroup);
sb = new RSpinBox(this);
if( para.GetPartialStep() != 0 ){
sb->setMinimum(0);
sb->setMaximum(para.GetMax() * para.GetPartialStep() * ch2ns);
if( para.GetPartialStep() > 0 ) sb->setSingleStep(para.GetPartialStep() * ch2ns);
if( para.GetPartialStep() == -1 ) sb->setSingleStep(1);
}
settingLayout->addWidget(sb, row, col + 1);
layout->addWidget(sb, row, col + 1);
connect(sb, &RSpinBox::valueChanged, this, [=](){
if( !enableSignalSlot ) return;
sb->setStyleSheet("color:blue");
@ -239,42 +229,5 @@ void Scope::SetUpSpinBox(RSpinBox * &sb, QString str, int row, int col, const Re
// sb->setStyleSheet("color:red;");
// }
});
}
void Scope::CleanUpSettingsGroupBox(){
printf("-- %s\n", __func__);
QList<QLabel *> labelChildren1 = settingGroup->findChildren<QLabel *>();
for( int i = 0; i < labelChildren1.size(); i++) delete labelChildren1[i];
QList<RComboBox *> labelChildren2 = settingGroup->findChildren<RComboBox *>();
for( int i = 0; i < labelChildren2.size(); i++) delete labelChildren2[i];
QList<RSpinBox *> labelChildren3 = settingGroup->findChildren<RSpinBox *>();
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);
SetUpSpinBox(sbDCOffset, "DC offset", 0, 4, Register::DPP::ChannelDCOffset);
SetUpSpinBox(sbInputRiseTime, "Input Rise Time [ns]", 1, 0, Register::DPP::PHA::InputRiseTime);
SetUpSpinBox(sbThreshold, "Threshold [LSB]", 1, 2, Register::DPP::PHA::TriggerThreshold);
SetUpSpinBox(sbThreshold, "Trigger HoldOff [ns]", 1, 4, Register::DPP::PHA::TriggerHoldOffWidth);
SetUpSpinBox(sbTrapRiseTime, "Trap. Rise Time [ns]", 2, 0, Register::DPP::PHA::TrapezoidRiseTime);
SetUpSpinBox(sbTrapFlatTop, "Trap. FlatTop [ns]", 2, 2, Register::DPP::PHA::TrapezoidFlatTop);
SetUpSpinBox(sbDecayTime, "Decay Time [ns]", 2, 4, Register::DPP::PHA::DecayTime);
SetUpSpinBox(sbPeakingTime, "Peaking Time [ns]", 2, 6, Register::DPP::PHA::PeakingTime);
}

30
Scope.h
View File

@ -11,7 +11,6 @@
#include <QLineEdit>
#include <QComboBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QLineSeries>
#include <QRubberBand>
#include <QMouseEvent>
@ -37,11 +36,8 @@ private slots:
void StartScope();
void StopScope();
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();
void SetUpComboBox(RComboBox * &cb, QString str, QGridLayout * layout, int row, int col, const Register::Reg para);
void SetUpSpinBox(RSpinBox * &sb, QString str, QGridLayout * layout, int row, int col, const Register::Reg para);
signals:
@ -53,7 +49,7 @@ private:
int ch2ns;
ReadDataThread ** readDataThread;
TimingThread * updateTraceThread;
UpdateTraceThread * updateTraceThread;
bool enableSignalSlot;
@ -68,29 +64,11 @@ private:
QLineEdit * leTriggerRate;
QGroupBox * settingGroup;
QGridLayout * settingLayout;
/// common to PSD and PHA
RSpinBox * sbReordLength;
RSpinBox * sbPreTrigger;
//RSpinBox * sbPreTrigger;
RSpinBox * sbDCOffset;
//RComboBox * cbDynamicRange;
/// PHA
RSpinBox * sbInputRiseTime;
RSpinBox * sbTriggerHoldOff;
RSpinBox * sbThreshold;
//RComboBox * cbSmoothingFactor;
RSpinBox * sbTrapRiseTime;
RSpinBox * sbTrapFlatTop;
RSpinBox * sbDecayTime;
RSpinBox * sbPeakingTime;
};