Make ClassData.h and event builder independent of CAEN Library, some improvement of DAQ UI

This commit is contained in:
carina@hades 2023-09-08 17:21:05 -04:00
parent fc87d4f92b
commit 66484b6003
6 changed files with 44 additions and 37 deletions

View File

@ -11,11 +11,16 @@
#include <vector> #include <vector>
#include <sys/stat.h> #include <sys/stat.h>
#include "CAENDigitizerType.h" //#include "CAENDigitizerType.h"
#include "macro.h" #include "macro.h"
#define MaxNData 10000 /// store 10k events per channels #define MaxNData 10000 /// store 10k events per channels
enum DPPType{
DPP_PHA_CODE = 0x8B,
DPP_PSD_CODE = 0x88
};
class Data{ class Data{
public: public:
@ -115,7 +120,7 @@ class Data{
inline Data::Data(){ inline Data::Data(){
tick2ns = 2.0; tick2ns = 2.0;
boardSN = 0; boardSN = 0;
DPPType = V1730_DPP_PHA_CODE; DPPType = DPPType::DPP_PHA_CODE;
DPPTypeStr = ""; DPPTypeStr = "";
IsNotRollOverFakeAgg = false; IsNotRollOverFakeAgg = false;
buffer = NULL; buffer = NULL;
@ -309,8 +314,8 @@ inline void Data::PrintAllData(bool tableMode, unsigned int maxRowDisplay) const
if( DataIndex[ch] < 0 ) continue; if( DataIndex[ch] < 0 ) continue;
printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]); printf("------------ ch : %d, DataIndex : %d, loop : %d\n", ch, DataIndex[ch], LoopIndex[ch]);
for( int ev = 0; ev <= (LoopIndex[ch] > 0 ? MaxNData : DataIndex[ch]) ; ev++){ 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 == DPPType::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( DPPType == DPPType::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; if( maxRowDisplay > 0 && (unsigned int) ev > maxRowDisplay ) break;
} }
} }
@ -362,8 +367,8 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
if( BoardID > 0 ) { if( BoardID > 0 ) {
switch(BoardID){ switch(BoardID){
case 0x8 : DPPType = V1730_DPP_PSD_CODE; break; case 0x8 : DPPType = DPPType::DPP_PSD_CODE; break;
case 0xB : DPPType = V1730_DPP_PHA_CODE; break; case 0xB : DPPType = DPPType::DPP_PHA_CODE; break;
} }
} }
@ -384,10 +389,10 @@ inline void Data::DecodeBuffer(bool fastDecode, int verbose){
if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue; if( ((ChannelMask >> chMask) & 0x1 ) == 0 ) continue;
if( verbose >= 2 ) printf("==================== Dual Channel Block, ch Mask : %d, nw : %d\n", chMask *2, nw); if( verbose >= 2 ) printf("==================== Dual Channel Block, ch Mask : %d, nw : %d\n", chMask *2, nw);
if( DPPType == V1730_DPP_PHA_CODE ) { if( DPPType == DPPType::DPP_PHA_CODE ) {
if ( DecodePHADualChannelBlock(chMask, fastDecode, verbose) < 0 ) break; if ( DecodePHADualChannelBlock(chMask, fastDecode, verbose) < 0 ) break;
} }
if( DPPType == V1730_DPP_PSD_CODE ) { if( DPPType == DPPType::DPP_PSD_CODE ) {
if ( DecodePSDDualChannelBlock(chMask, fastDecode, verbose) < 0 ) break; if ( DecodePSDDualChannelBlock(chMask, fastDecode, verbose) < 0 ) break;
} }
} }

View File

@ -542,11 +542,11 @@ void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool
return; return;
} }
if( registerAddress.GetType() == RW::ReadONLY ) return; if( registerAddress.GetRWType() == RW::ReadONLY ) return;
ret = CAEN_DGTZ_WriteRegister(handle, registerAddress.ActualAddress(ch), value); ret = CAEN_DGTZ_WriteRegister(handle, registerAddress.ActualAddress(ch), value);
if( ret == 0 && isSave2MemAndFile && registerAddress.GetType() == RW::ReadWrite) { if( ret == 0 && isSave2MemAndFile && registerAddress.GetRWType() == RW::ReadWrite) {
if( ch < 0 ) { if( ch < 0 ) {
for(int i = 0; i < NChannel; i++){ for(int i = 0; i < NChannel; i++){
SetSettingToMemory(registerAddress, value, i); SetSettingToMemory(registerAddress, value, i);
@ -567,7 +567,7 @@ void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool
uint32_t Digitizer::ReadRegister(Reg registerAddress, unsigned short ch, bool isSave2MemAndFile, std::string str ){ uint32_t Digitizer::ReadRegister(Reg registerAddress, unsigned short ch, bool isSave2MemAndFile, std::string str ){
if( !isConnected ) return 0; if( !isConnected ) return 0;
if( registerAddress.GetType() == RW::WriteONLY ) return 0; if( registerAddress.GetRWType() == RW::WriteONLY ) return 0;
ret = CAEN_DGTZ_ReadRegister(handle, registerAddress.ActualAddress(ch), &returnData); ret = CAEN_DGTZ_ReadRegister(handle, registerAddress.ActualAddress(ch), &returnData);
@ -640,7 +640,7 @@ void Digitizer::ReadAllSettingsFromBoard(bool force){
/// board setting /// board setting
for( int p = 0; p < (int) RegisterDPPList.size(); p++){ for( int p = 0; p < (int) RegisterDPPList.size(); p++){
if( RegisterDPPList[p].GetType() == RW::WriteONLY) continue; if( RegisterDPPList[p].GetRWType() == RW::WriteONLY) continue;
ReadRegister(RegisterDPPList[p]); ReadRegister(RegisterDPPList[p]);
} }
@ -650,13 +650,13 @@ void Digitizer::ReadAllSettingsFromBoard(bool force){
for( int ch = 0; ch < NChannel; ch ++){ for( int ch = 0; ch < NChannel; ch ++){
if( DPPType == V1730_DPP_PHA_CODE ){ if( DPPType == V1730_DPP_PHA_CODE ){
for( int p = 0; p < (int) RegisterPHAList.size(); p++){ for( int p = 0; p < (int) RegisterPHAList.size(); p++){
if( RegisterPHAList[p].GetType() == RW::WriteONLY) continue; if( RegisterPHAList[p].GetRWType() == RW::WriteONLY) continue;
ReadRegister(RegisterPHAList[p], ch); ReadRegister(RegisterPHAList[p], ch);
} }
} }
if( DPPType == V1730_DPP_PSD_CODE ){ if( DPPType == V1730_DPP_PSD_CODE ){
for( int p = 0; p < (int) RegisterPSDList.size(); p++){ for( int p = 0; p < (int) RegisterPSDList.size(); p++){
if( RegisterPSDList[p].GetType() == RW::WriteONLY) continue; if( RegisterPSDList[p].GetRWType() == RW::WriteONLY) continue;
ReadRegister(RegisterPSDList[p], ch); ReadRegister(RegisterPSDList[p], ch);
} }
} }
@ -674,7 +674,7 @@ void Digitizer::ProgramSettingsToBoard(){
/// board setting /// board setting
for( int p = 0; p < (int) RegisterDPPList.size(); p++){ for( int p = 0; p < (int) RegisterDPPList.size(); p++){
if( RegisterDPPList[p].GetType() == RW::ReadWrite) { if( RegisterDPPList[p].GetRWType() == RW::ReadWrite) {
haha = RegisterDPPList[p]; haha = RegisterDPPList[p];
WriteRegister(haha, GetSettingFromMemory(haha), -1, false); WriteRegister(haha, GetSettingFromMemory(haha), -1, false);
usleep(1 * 1000); usleep(1 * 1000);
@ -684,7 +684,7 @@ void Digitizer::ProgramSettingsToBoard(){
for( int ch = 0; ch < NChannel; ch ++){ for( int ch = 0; ch < NChannel; ch ++){
if( DPPType == V1730_DPP_PHA_CODE ){ if( DPPType == V1730_DPP_PHA_CODE ){
for( int p = 0; p < (int) RegisterPHAList.size(); p++){ for( int p = 0; p < (int) RegisterPHAList.size(); p++){
if( RegisterPHAList[p].GetType() == RW::ReadWrite ){ if( RegisterPHAList[p].GetRWType() == RW::ReadWrite ){
haha = RegisterPHAList[p]; haha = RegisterPHAList[p];
WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false); WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false);
usleep(1 * 1000); usleep(1 * 1000);
@ -693,7 +693,7 @@ void Digitizer::ProgramSettingsToBoard(){
} }
if( DPPType == V1730_DPP_PSD_CODE ){ if( DPPType == V1730_DPP_PSD_CODE ){
for( int p = 0; p < (int) RegisterPSDList.size(); p++){ for( int p = 0; p < (int) RegisterPSDList.size(); p++){
if( RegisterPSDList[p].GetType() == RW::ReadWrite){ if( RegisterPSDList[p].GetRWType() == RW::ReadWrite){
haha = RegisterPSDList[p]; haha = RegisterPSDList[p];
WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false); WriteRegister(haha, GetSettingFromMemory(haha, ch), ch, false);
usleep(1 * 1000); usleep(1 * 1000);
@ -865,9 +865,9 @@ void Digitizer::SaveAllSettingsAsText(std::string fileName){
} }
if( haha.GetName() != "" ) { if( haha.GetName() != "" ) {
std::string typeStr ; std::string typeStr ;
if( haha.GetType() == RW::ReadWrite ) typeStr = "R/W"; if( haha.GetRWType() == RW::ReadWrite ) typeStr = "R/W";
if( haha.GetType() == RW::ReadONLY ) typeStr = "R "; if( haha.GetRWType() == RW::ReadONLY ) typeStr = "R ";
if( haha.GetType() == RW::WriteONLY ) typeStr = " W"; if( haha.GetRWType() == RW::WriteONLY ) typeStr = " W";
fprintf( txtFile, "0x%04X %30s 0x%08X %s %u\n", actualAddress, fprintf( txtFile, "0x%04X %30s 0x%08X %s %u\n", actualAddress,
haha.GetNameChar(), haha.GetNameChar(),
setting[i], setting[i],

View File

@ -48,6 +48,7 @@ public:
// digi->StartACQ(); // digi->StartACQ();
// usleep(1000); // wait for some data; // usleep(1000); // wait for some data;
printf("ReadDataThread for digi-%d running.\n", digi->GetSerialNumber());
do{ do{
if( stop) break; if( stop) break;
@ -84,6 +85,7 @@ public:
clock_gettime(CLOCK_REALTIME, &tb); clock_gettime(CLOCK_REALTIME, &tb);
if( tb.tv_sec - ta.tv_sec > 2 ) { if( tb.tv_sec - ta.tv_sec > 2 ) {
digiMTX[ID].lock(); digiMTX[ID].lock();
emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetData()->GetTotalFileSize()/1024./1024., 'f', 4) + " MB [" + QString::number(tb.tv_sec-t0.tv_sec) + " sec]"); emit sendMsg("FileSize ("+ QString::number(digi->GetSerialNumber()) +"): " + QString::number(digi->GetData()->GetTotalFileSize()/1024./1024., 'f', 4) + " MB [" + QString::number(tb.tv_sec-t0.tv_sec) + " sec]");
//digi->GetData()->PrintStat(); //digi->GetData()->PrintStat();
digiMTX[ID].unlock(); digiMTX[ID].unlock();
@ -92,7 +94,7 @@ public:
} }
}while(!stop); }while(!stop);
printf("ReadDataThread stopped.\n"); printf("ReadDataThread for digi-%d stopped.\n", digi->GetSerialNumber());
} }
signals: signals:
void sendMsg(const QString &msg); void sendMsg(const QString &msg);

View File

@ -379,7 +379,7 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
connect(cbBdReg, &RComboBox::currentIndexChanged, this, [=](int index){ connect(cbBdReg, &RComboBox::currentIndexChanged, this, [=](int index){
if( !enableSignalSlot ) return; if( !enableSignalSlot ) return;
if( RegisterDPPList[index].GetType() == RW::WriteONLY ) { if( RegisterDPPList[index].GetRWType() == RW::WriteONLY ) {
leBdRegRW->setText("Write ONLY" ); leBdRegRW->setText("Write ONLY" );
leBdRegValue->setText(""); leBdRegValue->setText("");
leBdRegSet->setEnabled(true); leBdRegSet->setEnabled(true);
@ -389,13 +389,13 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
uint32_t value = digi[ cbDigi->currentIndex() ] ->ReadRegister(RegisterDPPList[index]); uint32_t value = digi[ cbDigi->currentIndex() ] ->ReadRegister(RegisterDPPList[index]);
leBdRegValue->setText( "0x" + QString::number(value, 16).toUpper()); leBdRegValue->setText( "0x" + QString::number(value, 16).toUpper());
if( RegisterDPPList[index].GetType() == RW::ReadONLY ) { if( RegisterDPPList[index].GetRWType() == RW::ReadONLY ) {
leBdRegRW->setText("Read ONLY" ); leBdRegRW->setText("Read ONLY" );
leBdRegSet->setEnabled(false); leBdRegSet->setEnabled(false);
return; return;
} }
if( RegisterDPPList[index].GetType() == RW::ReadWrite ) { if( RegisterDPPList[index].GetRWType() == RW::ReadWrite ) {
leBdRegRW->setText("Read/Write" ); leBdRegRW->setText("Read/Write" );
leBdRegSet->setEnabled(true); leBdRegSet->setEnabled(true);
} }
@ -414,7 +414,7 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
connect(cbChReg, &RComboBox::currentIndexChanged, this, [=](int index){ connect(cbChReg, &RComboBox::currentIndexChanged, this, [=](int index){
if( !enableSignalSlot ) return; if( !enableSignalSlot ) return;
if( chRegList[index].GetType() == RW::WriteONLY ) { if( chRegList[index].GetRWType() == RW::WriteONLY ) {
leChRegRW->setText("Write ONLY" ); leChRegRW->setText("Write ONLY" );
leChRegValue->setText(""); leChRegValue->setText("");
leChRegSet->setEnabled(true); leChRegSet->setEnabled(true);
@ -424,13 +424,13 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
uint32_t value = digi[ cbDigi->currentIndex() ] ->ReadRegister(chRegList[index], cbCh->currentIndex()); uint32_t value = digi[ cbDigi->currentIndex() ] ->ReadRegister(chRegList[index], cbCh->currentIndex());
leChRegValue->setText( "0x" + QString::number(value, 16).toUpper()); leChRegValue->setText( "0x" + QString::number(value, 16).toUpper());
if( chRegList[index].GetType() == RW::ReadONLY ) { if( chRegList[index].GetRWType() == RW::ReadONLY ) {
leChRegRW->setText("Read ONLY" ); leChRegRW->setText("Read ONLY" );
leChRegSet->setEnabled(false); leChRegSet->setEnabled(false);
return; return;
} }
if( chRegList[index].GetType() == RW::ReadWrite ) { if( chRegList[index].GetRWType() == RW::ReadWrite ) {
leChRegRW->setText("Read/Write" ); leChRegRW->setText("Read/Write" );
leChRegSet->setEnabled(true); leChRegSet->setEnabled(true);
} }
@ -554,6 +554,7 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
//Copy Board Setting //Copy Board Setting
for( int i = 0; i < (int) RegisterDPPList.size(); i++){ for( int i = 0; i < (int) RegisterDPPList.size(); i++){
if( RegisterDPPList[i].GetRWType() != RW::WriteONLY ) continue;
uint32_t value = digi[fromIndex]->GetSettingFromMemory(RegisterDPPList[i]); uint32_t value = digi[fromIndex]->GetSettingFromMemory(RegisterDPPList[i]);
digi[toIndex]->WriteRegister(RegisterDPPList[i], value); digi[toIndex]->WriteRegister(RegisterDPPList[i], value);
} }
@ -565,7 +566,7 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
for( int i = 0; i < MaxNChannels; i++){ for( int i = 0; i < MaxNChannels; i++){
//Copy setting //Copy setting
for( int k = 0; k < (int) regList.size(); k ++){ for( int k = 0; k < (int) regList.size(); k ++){
if( regList[k].GetType() != RW::ReadWrite ) continue; if( regList[k].GetRWType() != RW::ReadWrite ) continue;
uint32_t value = digi[fromIndex]->GetSettingFromMemory(regList[k], i); uint32_t value = digi[fromIndex]->GetSettingFromMemory(regList[k], i);
digi[toIndex]->WriteRegister(regList[k], value, i); digi[toIndex]->WriteRegister(regList[k], value, i);
@ -600,7 +601,7 @@ DigiSettingsPanel::DigiSettingsPanel(Digitizer ** digi, unsigned int nDigi, QStr
if( ! chkCh[i]->isChecked() ) return; if( ! chkCh[i]->isChecked() ) return;
//Copy setting //Copy setting
for( int k = 0; k < (int) regList.size(); k ++){ for( int k = 0; k < (int) regList.size(); k ++){
if( regList[k].GetType() != RW::ReadWrite ) continue; if( regList[k].GetRWType() != RW::ReadWrite ) continue;
uint32_t value = digi[fromIndex]->GetSettingFromMemory(regList[k], fromCh); uint32_t value = digi[fromIndex]->GetSettingFromMemory(regList[k], fromCh);
digi[toIndex]->WriteRegister(regList[k], value, i); digi[toIndex]->WriteRegister(regList[k], value, i);

View File

@ -1030,8 +1030,6 @@ void MainWindow::StopACQ(){
} }
for( unsigned int i = 0; i < nDigi; i++){ for( unsigned int i = 0; i < nDigi; i++){
LogMsg("Digi-" + QString::number(digi[i]->GetSerialNumber()) + " is stoping ACQ." );
if( readDataThread[i]->isRunning() ) { if( readDataThread[i]->isRunning() ) {
readDataThread[i]->Stop(); readDataThread[i]->Stop();
readDataThread[i]->quit(); readDataThread[i]->quit();
@ -1041,6 +1039,7 @@ void MainWindow::StopACQ(){
digi[i]->StopACQ(); digi[i]->StopACQ();
digiMTX[i].unlock(); digiMTX[i].unlock();
if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile(); if( chkSaveData->isChecked() ) digi[i]->GetData()->CloseSaveFile();
LogMsg("Digi-" + QString::number(digi[i]->GetSerialNumber()) + " ACQ is stopped." );
} }
if( scalarThread->isRunning()){ if( scalarThread->isRunning()){

View File

@ -27,7 +27,7 @@ class Reg{
Reg(){ Reg(){
name = ""; name = "";
address = 0; address = 0;
type = RW::ReadWrite; rwType = RW::ReadWrite;
group = 0; group = 0;
maxBit = 0; maxBit = 0;
partialStep = 0; partialStep = 0;
@ -36,7 +36,7 @@ class Reg{
Reg(std::string name, uint32_t address, RW type = RW::ReadWrite, bool group = false, unsigned int max = 0, int pStep = 0){ Reg(std::string name, uint32_t address, RW type = RW::ReadWrite, bool group = false, unsigned int max = 0, int pStep = 0){
this->name = name; this->name = name;
this->address = address; this->address = address;
this->type = type; this->rwType = type;
this->group = group; this->group = group;
this->maxBit = max; this->maxBit = max;
this->partialStep = pStep; this->partialStep = pStep;
@ -46,7 +46,7 @@ class Reg{
Reg(std::string name, uint32_t address, RW type = RW::ReadWrite, bool group = false, std::vector<std::pair<std::string, unsigned int>> list = {}){ Reg(std::string name, uint32_t address, RW type = RW::ReadWrite, bool group = false, std::vector<std::pair<std::string, unsigned int>> list = {}){
this->name = name; this->name = name;
this->address = address; this->address = address;
this->type = type; this->rwType = type;
this->group = group; this->group = group;
this->maxBit = 0; this->maxBit = 0;
this->partialStep = 0; this->partialStep = 0;
@ -60,7 +60,7 @@ class Reg{
std::string GetName() const {return name;} std::string GetName() const {return name;}
const char * GetNameChar() const {return name.c_str();} const char * GetNameChar() const {return name.c_str();}
uint32_t GetAddress() const {return address; } uint32_t GetAddress() const {return address; }
RW GetType() const {return type;} RW GetRWType() const {return rwType;}
bool IsCoupled() const {return group;} bool IsCoupled() const {return group;}
unsigned int GetMaxBit() const {return maxBit;} unsigned int GetMaxBit() const {return maxBit;}
int GetPartialStep() const {return partialStep;} /// step = partialStep * tick2ns, -1 : step = 1 int GetPartialStep() const {return partialStep;} /// step = partialStep * tick2ns, -1 : step = 1
@ -90,7 +90,7 @@ class Reg{
std::string name; std::string name;
uint32_t address; /// This is the table of register, the actual address should call ActualAddress(); uint32_t address; /// This is the table of register, the actual address should call ActualAddress();
RW type; /// read/write = 0; read = 1; write = 2 RW rwType; /// read/write = 0; read = 1; write = 2
bool group; bool group;
unsigned int maxBit ; unsigned int maxBit ;
int partialStep; int partialStep;
@ -100,7 +100,7 @@ class Reg{
inline void Reg::Print() const{ inline void Reg::Print() const{
printf(" Name: %s\n", name.c_str()); printf(" Name: %s\n", name.c_str());
printf(" Re.Address: 0x%04X\n", address); printf(" Re.Address: 0x%04X\n", address);
printf(" Type: %s\n", type == RW::ReadWrite ? "Read/Write" : (type == RW::ReadONLY ? "Read-Only" : "Write-Only") ); printf(" Type: %s\n", rwType == RW::ReadWrite ? "Read/Write" : (rwType == RW::ReadONLY ? "Read-Only" : "Write-Only") );
printf(" Group: %s\n", group ? "True" : "False"); printf(" Group: %s\n", group ? "True" : "False");
printf(" Max Value : 0x%X = %d \n", maxBit, maxBit); printf(" Max Value : 0x%X = %d \n", maxBit, maxBit);
} }