killed many bugs

This commit is contained in:
carina@hades 2023-10-12 16:27:56 -04:00
parent c51bd7e662
commit 674f3bdd77
8 changed files with 88 additions and 69 deletions

View File

@ -434,7 +434,7 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
///printf("nw : %d ,x 4 = %d, nByte : %d \n", nw, 4*nw, nByte);
}while(4*nw < nByte);
///Calculate trigger rate and first and last Timestamp
///^===================Calculate trigger rate and first and last Timestamp
for(int ch = 0; ch < MaxNChannels; ch++){
if( ch > numInputCh ) continue;
@ -442,6 +442,8 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
// printf("%s | ch %d | %d %d \n", __func__, ch, LoopIndex[ch], DataIndex[ch]);
IsNotRollOverFakeAgg = true;
}else{
TriggerRate[ch] = 0;
NonPileUpRate[ch] = 0;
continue;
}

View File

@ -226,9 +226,9 @@ int Digitizer::CloseDigitizer(){
if( !isConnected ) return 0;
isConnected = false;
ret = CAEN_DGTZ_SWStopAcquisition(handle);
printf("-------- Closing Digtizer Board : %d Port : %d \n", boardID, portID);
printf(" Model %s with handle %d using %s\n", BoardInfo.ModelName, handle, LinkType == CAEN_DGTZ_USB ? "USB" : "Optical Link");
ret = CAEN_DGTZ_SWStopAcquisition(handle);
ret |= CAEN_DGTZ_CloseDigitizer(handle);
return ret;
@ -388,36 +388,23 @@ int Digitizer::ProgramBoard_QDC(){
int ret = 0;
WriteRegister(DPP::QDC::RecordLength, 6000/16, -1);
WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x100, -1);
WriteRegister(DPP::QDC::RecordLength, 4000/16, -1);
WriteRegister(DPP::QDC::PreTrigger, 1000/16, -1);
WriteRegister(DPP::QDC::GateWidth, 100/16, -1);
WriteRegister(DPP::QDC::GateOffset, 0, -1);
WriteRegister(DPP::QDC::FixedBaseline, 0, -1);
WriteRegister(DPP::QDC::PreTrigger, 1000/16, -1);
//WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300112); // with test pulse
WriteRegister(DPP::QDC::DPPAlgorithmControl, 0x300102); // No test pulse
WriteRegister(DPP::QDC::TriggerHoldOffWidth, 100/16, -1);
WriteRegister(DPP::QDC::TRGOUTWidth, 100/16, -1);
//WriteRegister(DPP::QDC::OverThresholdWidth, 100/16, -1);
//WriteRegister(DPP::QDC::DCOffset, 100/16, -1);
WriteRegister(DPP::QDC::SubChannelMask, 0xFF, -1);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x0, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x1, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x2, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x3, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x4, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x5, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x6, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x7, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x8, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0x9, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xA, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xB, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xC, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xD, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xE, 0xAAAA);
ret |= CAEN_DGTZ_SetChannelDCOffset(handle, 0xF, 0xAAAA);
WriteRegister(DPP::QDC::DCOffset, 0xAAAA, -1);
WriteRegister(DPP::QDC::TriggerThreshold_sub0, 100, -1);
WriteRegister(DPP::QDC::TriggerThreshold_sub1, 100, -1);
@ -430,7 +417,6 @@ int Digitizer::ProgramBoard_QDC(){
WriteRegister(DPP::BoardConfiguration, 0xC0110);
WriteRegister(DPP::AggregateOrganization, 0x0);
WriteRegister(DPP::QDC::NumberEventsPerAggregate, 0x100);
WriteRegister(DPP::AcquisitionControl, 0x0);
WriteRegister(DPP::GlobalTriggerMask, 0x0);
WriteRegister(DPP::FrontPanelTRGOUTEnableMask, 0x0);
@ -438,8 +424,6 @@ int Digitizer::ProgramBoard_QDC(){
WriteRegister(DPP::QDC::GroupEnableMask, 0xFF);
WriteRegister(DPP::MaxAggregatePerBlockTransfer, 0x4);
if( ret != 0 ) { printf("!!!!!!!! set channels error.\n");}
isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard();
usleep(1000*300);

View File

@ -74,7 +74,7 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
SetUpInfo( "S/N No. ", std::to_string(digi[ID]->GetSerialNumber()), infoLayout[ID], 1, 0);
SetUpInfo("No. Input Ch. ", std::to_string(digi[ID]->GetNumInputCh()), infoLayout[ID], 1, 2);
SetUpInfo("Sampling Rate ", std::to_string((int) digi[ID]->GetTick2ns()) + " ns = " + std::to_string( (1000/digi[ID]->GetTick2ns())) + " MHz" , infoLayout[ID], 1, 4);
SetUpInfo("Sampling Rate ", std::to_string((int) digi[ID]->GetTick2ns()) + " ns = " + QString::number( (1000/digi[ID]->GetTick2ns()), 'f', 1).toStdString() + " MHz" , infoLayout[ID], 1, 4);
SetUpInfo("ADC bit ", std::to_string(digi[ID]->GetADCBits()), infoLayout[ID], 2, 0);
SetUpInfo("ROC version ", digi[ID]->GetROCVersion(), infoLayout[ID], 2, 2);
@ -2382,8 +2382,6 @@ void DigiSettingsPanel::SetUpBoard_QDC(){
SetUpComboBoxBit(cbAnaProbe1[ID], "Ana. Probe ", bdCfgLayout[ID], 3, 0, DPP::Bit_BoardConfig::ListAnaProbe_QDC, DPP::BoardConfiguration, DPP::Bit_BoardConfig::AnalogProbe1, 1, 0);
SetUpComboBoxBit(cbExtTriggerMode[ID], "Ext. Trig. Mode ", bdCfgLayout[ID], 4, 0, DPP::Bit_BoardConfig::ListExtTriggerMode_QDC, DPP::BoardConfiguration, DPP::Bit_BoardConfig::ExtTriggerMode_QDC, 1, 0);
SetUpSpinBox(sbEventPreAgg_QDC[ID], "Event pre Agg. ", bdCfgLayout[ID], 6, 0, DPP::QDC::NumberEventsPerAggregate, -1, true);
}
void DigiSettingsPanel::SetUpChannel_QDC(){
@ -3322,12 +3320,6 @@ void DigiSettingsPanel::UpdatePanelFromMemory(){
}
}
//*======================================== QDC only
if( digi[ID]->GetDPPType() == V1740_DPP_QDC_CODE ){
uint32_t eventPreAgg = digi[ID]->GetSettingFromMemory(DPP::QDC::NumberEventsPerAggregate);
sbEventPreAgg_QDC[ID]->setValue(eventPreAgg & 0x3FF);
}
//*======================================== update channels/group setting
if( digi[ID]->GetDPPType() == V1730_DPP_PHA_CODE ) UpdateSettings_PHA();
if( digi[ID]->GetDPPType() == V1730_DPP_PSD_CODE ) UpdateSettings_PSD();

View File

@ -321,24 +321,33 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
MainWindow::~MainWindow(){
if( scalar ) {
scalarThread->Stop();
scalarThread->quit();
scalarThread->exit();
CleanUpScalar();
delete scalar;
}
if( digi ) CloseDigitizers();
SaveProgramSettings();
if( scope ) delete scope;
if( histThread){
histThread->Stop();
histThread->quit();
histThread->wait();
delete histThread;
}
if( canvas ) delete canvas;
if( onlineAnalyzer ) delete onlineAnalyzer;
if( digiSettings ) delete digiSettings;
if( scalar ) {
CleanUpScalar();
scalarThread->Stop();
scalarThread->quit();
scalarThread->exit();
delete scalarThread;
}
delete influx;
@ -688,8 +697,11 @@ void MainWindow::OpenDigitizers(){
void MainWindow::CloseDigitizers(){
LogMsg("Closing Digitizer(s)....");
LogMsg("MainWindow::Closing Digitizer(s)....");
scalarThread->Stop();
scalarThread->quit();
scalarThread->exit();
CleanUpScalar();
if( scope ) {
@ -698,6 +710,16 @@ void MainWindow::CloseDigitizers(){
scope = nullptr;
}
if( histThread){
histThread->Stop();
histThread->quit();
histThread->wait();
delete histThread;
histThread = nullptr;
}
if( canvas ){
canvas->close();
delete canvas;
@ -713,23 +735,23 @@ void MainWindow::CloseDigitizers(){
if( digi == nullptr ) return;
for(unsigned int i = 0; i < nDigi; i ++){
digi[i]->CloseDigitizer();
delete digi[i];
if(readDataThread[i]->isRunning()){
readDataThread[i]->Stop();
readDataThread[i]->quit();
readDataThread[i]->wait();
}
readDataThread[i]->Stop();
readDataThread[i]->quit();
readDataThread[i]->wait();
delete readDataThread[i];
printf(" readDataThread[%d] is deleted.\n", i);
}
delete [] digi;
digi = nullptr;
delete [] readDataThread;
readDataThread = nullptr;
for(unsigned int i = 0; i < nDigi; i ++){
digi[i]->CloseDigitizer();
delete digi[i];
}
delete [] digi;
digi = nullptr;
LogMsg("Done. Closed " + QString::number(nDigi) + " Digitizer(s).");
nDigi = 0;
@ -737,6 +759,8 @@ void MainWindow::CloseDigitizers(){
bnStartACQ->setStyleSheet("");
bnStopACQ->setStyleSheet("");
printf("End of MainWindow::%s\n", __func__);
}
void MainWindow::WaitForDigitizersOpen(bool onOff){
@ -785,7 +809,7 @@ void MainWindow::SetupScalar(){
lbLastUpdateTime = nullptr;
lbScalarACQStatus = nullptr;
scalarThread = new TimingThread();
scalarThread = new TimingThread(scalar);
connect(scalarThread, &TimingThread::timeUp, this, &MainWindow::UpdateScalar);
unsigned short maxNChannel = 0;
@ -1051,11 +1075,9 @@ void MainWindow::StopACQ(){
}
for( unsigned int i = 0; i < nDigi; i++){
if( readDataThread[i]->isRunning() ) {
readDataThread[i]->Stop();
readDataThread[i]->quit();
readDataThread[i]->wait();
}
readDataThread[i]->Stop();
readDataThread[i]->quit();
readDataThread[i]->wait();
digiMTX[i].lock();
digi[i]->StopACQ();
digiMTX[i].unlock();

View File

@ -8,12 +8,12 @@ INCLUDEPATH += .
QT += core widgets charts printsupport
#QMAKE_CXXFLAGS += -g `root-config --cflags --glibs`
#LIBS += -lCAENDigitizer -lcurl `root-config --cflags --glibs`
QMAKE_CXXFLAGS += -g
LIBS += -lCAENDigitizer -lcurl
QMAKE_CXXFLAGS_RELEASE = -O0
QMAKE_CFLAGS_RELEASE = -O0
# You can make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# Please consult the documentation of the deprecated API in order to know

View File

@ -786,6 +786,7 @@ namespace DPP {
}
namespace QDC { // Register already grouped in channel. and there no control for indiviual channel except the Fine DC offset and threshold, so it is like no group
const Reg NumberEventsPerAggregate ("Number of Events per Aggregate", 0x1020, RW::ReadWrite, false, 0x3FF, -1); /// R/W
const Reg RecordLength ("Record Length" , 0x1024, RW::ReadWrite, false, 0x1FFF, 1); /// R/W
const Reg GateWidth ("GateWidth" , 0x1030, RW::ReadWrite, false, 0xFFF, 1); /// R/W
const Reg GateOffset ("GateOfset" , 0x1034, RW::ReadWrite, false, 0xFF, 1); /// R/W
@ -811,7 +812,6 @@ namespace DPP {
const Reg TriggerThreshold_sub7 ("Trigger Threshold sub7" , 0x10EC, RW::ReadWrite, false, 0xFFF, -1); /// R/W
const Reg NumberEventsPerAggregate ("Number of Events per Aggregate", 0x8020, RW::ReadWrite, false, 0x3FF, -1); /// R/W
const Reg GroupEnableMask ("Group Enable Mask" , 0x8120, RW::ReadWrite, false, 0xFF, -1); /// R/W
namespace Bit_DPPAlgorithmControl {

View File

@ -680,6 +680,8 @@ void Scope::SetUpPanel_PHA(){
dataTrace[3]->setName(cbDigiProbe2->currentText());
cbDigiProbe2->setEnabled(false);
dataTrace[4]->setVisible(false);
enableSignalSlot = true;
}
@ -751,6 +753,8 @@ void Scope::SetUpPanel_PSD(){
dataTrace[3]->setName(cbDigiProbe2->currentText());
});
dataTrace[4]->setVisible(false);
enableSignalSlot = true;
}
@ -846,10 +850,15 @@ void Scope::SetUpPanel_QDC() {
connect(cbAnaProbe1, &RComboBox::currentIndexChanged, this, [=](){
if( !enableSignalSlot ) return;
digi[ID]->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::AnalogProbe1, cbAnaProbe1->currentData().toInt(), cbScopeCh->currentIndex());
//dataTrace[0]->setName(cbAnaProbe1->currentText());
dataTrace[0]->setName(cbAnaProbe1->currentText());
});
dataTrace[1]->setVisible(true); dataTrace[1]->setName("Gate");
dataTrace[2]->setVisible(true); dataTrace[2]->setName("Trigger");
dataTrace[3]->setVisible(true); dataTrace[3]->setName("Trigger HoldOff");
dataTrace[4]->setVisible(true); dataTrace[4]->setName("OverThreshold");
enableSignalSlot = true;
}

View File

@ -26,20 +26,30 @@ int getch(void);
//^======================================
int main(int argc, char* argv[]){
Digitizer * digi = new Digitizer(0, 0, false, true);
Digitizer * digi = new Digitizer(0, 2, false, true);
Reg reg("test", 0x1020, RW::ReadWrite, false, 0xFFF, -1);
digi->WriteRegister(reg, 0x13, -1);
digi->ReadAllSettingsFromBoard();
digi->GetSettingFromMemory(DPP::QDC::NumberEventsPerAggregate);
// digi->Reset();
// digi->ProgramBoard_PHA();
digi->Reset();
digi->ProgramBoard_PHA();
for( int ch = 0; ch < 16; ch++){
printf("%2d | 0x%X \n", ch, digi->GetSettingFromMemory(DPP::ChannelDCOffset, ch));
printf("%2d | 0x%X \n", ch, digi->GetSettingFromMemory(reg, ch));
}
//digi->SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, 1, -1);
// Data * data = digi->GetData();
// digi->StartACQ();
//digi->StartACQ();
// for( int i = 0; i < 4; i ++ ){
// usleep(1000*1000);