finished the save/load of setting file while offline

This commit is contained in:
carina@hades 2022-10-17 14:42:00 -04:00
parent d6a29e1b8f
commit c851da2f3c
8 changed files with 166 additions and 85 deletions

View File

@ -13,7 +13,7 @@
#include "CAENDigitizerType.h" #include "CAENDigitizerType.h"
#include "macro.h" #include "macro.h"
#define MaxNData 10000 /// for timestamp 8 byte = 80kB #define MaxNData 10000 /// 10k events per channels
class Data{ class Data{

View File

@ -23,11 +23,12 @@ void Digitizer::Initalization(){
NChannel = 16; NChannel = 16;
ADCbits = 1; ADCbits = 1;
DPPType = 0; DPPType = 0;
DPPTypeStr = "";
ADCFullSize = 0; ADCFullSize = 0;
ch2ns = 0; ch2ns = 0;
BoardInfo = {}; BoardInfo = {};
isDummy = true;
VMEBaseAddress = 0; VMEBaseAddress = 0;
LinkType = CAEN_DGTZ_USB; /// default USB LinkType = CAEN_DGTZ_USB; /// default USB
IOlev = CAEN_DGTZ_IOLevel_NIM; ///default NIM IOlev = CAEN_DGTZ_IOLevel_NIM; ///default NIM
@ -63,7 +64,7 @@ void Digitizer::PrintBoard (){
printf("Sampling rate : %.0f MHz = %.1f ns \n", 1000/ch2ns, ch2ns); printf("Sampling rate : %.0f MHz = %.1f ns \n", 1000/ch2ns, ch2ns);
printf("Number of Channels : %d = 0x%X\n", NChannel, channelMask); printf("Number of Channels : %d = 0x%X\n", NChannel, channelMask);
printf("SerialNumber :\e[1m\e[33m %d\e[0m\n", BoardInfo.SerialNumber); printf("SerialNumber :\e[1m\e[33m %d\e[0m\n", BoardInfo.SerialNumber);
printf("DPPType : %d (%s)\n", DPPType, DPPTypeStr.c_str()); printf("DPPType : %d (%s)\n", DPPType, GetDPPString().c_str());
printf("ADC bit is \e[33m%d\e[0m, %d = 0x%X\n", ADCbits, ADCFullSize, ADCFullSize); printf("ADC bit is \e[33m%d\e[0m, %d = 0x%X\n", ADCbits, ADCFullSize, ADCFullSize);
printf("ROC FPGA Release is %s\n", BoardInfo.ROC_FirmwareRel); printf("ROC FPGA Release is %s\n", BoardInfo.ROC_FirmwareRel);
printf("AMC FPGA Release is %s\n", BoardInfo.AMC_FirmwareRel); printf("AMC FPGA Release is %s\n", BoardInfo.AMC_FirmwareRel);
@ -110,36 +111,20 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose
ADCbits = BoardInfo.ADC_NBits; ADCbits = BoardInfo.ADC_NBits;
ADCFullSize = (unsigned int)( pow(2, ADCbits) -1 ); ADCFullSize = (unsigned int)( pow(2, ADCbits) -1 );
//SetBoardID(BoardInfo.SerialNumber); //SetBoardID(BoardInfo.SerialNumber);
} }
} }
///====================== Check DPP firmware revision ///====================== Check DPP firmware revision
sscanf(BoardInfo.AMC_FirmwareRel, "%d", &DPPType); sscanf(BoardInfo.AMC_FirmwareRel, "%d", &DPPType);
data->DPPType = DPPType; data->DPPType = DPPType;
switch (DPPType){
case V1724_DPP_PHA_CODE: DPPTypeStr = "DPP-PHA x724"; break; /// 0x80
case V1720_DPP_CI_CODE : DPPTypeStr = "DPP-CI x720"; break; /// 0x82
case V1720_DPP_PSD_CODE: DPPTypeStr = "DPP-PSD x720"; break; /// 0x83
case V1751_DPP_PSD_CODE: DPPTypeStr = "DPP-PSD x751"; break; /// 0x84
case V1751_DPP_ZLE_CODE: DPPTypeStr = "DPP-ZLE x751"; break; /// 0x85
case V1743_DPP_CI_CODE: DPPTypeStr = "DPP-PSD x743"; break; /// 0x86
case V1740_DPP_QDC_CODE: DPPTypeStr = "DPP-QDC x740"; break; /// 0x87
case V1730_DPP_PSD_CODE: DPPTypeStr = "DPP-PSD x730"; break; /// 0x88
case V1730_DPP_PHA_CODE: DPPTypeStr = "DPP-PHA x730"; break; /// 0x8B
case V1730_DPP_ZLE_CODE: DPPTypeStr = "DPP-ZLE x730"; break; /// 0x8C
case V1730_DPP_DAW_CODE: DPPTypeStr = "DPP-DAW x730"; break; /// 0x8D
}
if ( verbose ){ if ( verbose ){
PrintBoard(); PrintBoard();
if (DPPType < 0x80 ) { if (DPPType < 0x80 ) {
printf("This digitizer does not have DPP-PHA firmware\n"); printf("This digitizer does not have DPP-PHA firmware\n");
}else { }else {
printf("\t==== This digitizer has a DPP firmware!\n"); printf("\t==== This digitizer has a DPP firmware!\n");
printf("\e[32m\t %s \e[0m", DPPTypeStr.c_str()); printf("\e[32m\t %s \e[0m", GetDPPString().c_str());
} }
} }
@ -190,6 +175,7 @@ int Digitizer::OpenDigitizer(int boardID, int portID, bool program, bool verbose
ErrorMsg("end of OpenDigitizer"); ErrorMsg("end of OpenDigitizer");
if( isConnected && program) { if( isConnected && program) {
isDummy = false;
ProgramBoard(); ProgramBoard();
} }
@ -375,13 +361,13 @@ unsigned int Digitizer::CalByteForBuffer(){
} }
} }
//printf(" Channel Mask : %04X \n", chMask); printf(" Channel Mask : %04X \n", chMask);
//printf("Max number of Agg per Readout : %u \n", numAggBLT); printf("Max number of Agg per Readout : %u \n", numAggBLT);
//printf(" is Extra2 enabed : %u \n", ((boardCfg >> 17) & 0x1) ); printf(" is Extra2 enabed : %u \n", ((boardCfg >> 17) & 0x1) );
//
//for( int pCh = 0; pCh < NChannel/2; pCh++){ for( int pCh = 0; pCh < NChannel/2; pCh++){
// printf("Paied Ch : %d, RecordLength (bit value): %u, Event per Agg. : %u \n", pCh, recordLength[pCh], eventAgg[pCh]); printf("Paied Ch : %d, RecordLength (bit value): %u, Event per Agg. : %u \n", pCh, recordLength[pCh], eventAgg[pCh]);
//} }
unsigned int bufferSize = 4; /// Board Agg. header unsigned int bufferSize = 4; /// Board Agg. header
/// Cal size for each dual channel aggregation /// Cal size for each dual channel aggregation
@ -415,11 +401,19 @@ void Digitizer::ReadData(){
//=========================================================== //===========================================================
//=========================================================== //===========================================================
void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){ void Digitizer::WriteRegister (Reg registerAddress, uint32_t value, int ch, bool isSave2MemAndFile){
if( !isConnected ) return;
//printf("0x%X, ch:%02d, 0x%X=%u\n", registerAddress, ch, value, value); printf("%s[0x%04X](ch-%02d): %u \n", registerAddress.GetNameChar(), registerAddress.GetAddress(),ch, value);
if( !isConnected ) {
SetSettingToMemory(registerAddress, value, ch);
SaveSettingToFile(registerAddress, value, ch);
return;
}
if( registerAddress.GetType() == 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) { if( ret == 0 && isSave2MemAndFile && registerAddress.GetType() == RW::ReadWrite) {
SetSettingToMemory(registerAddress, value, ch); SetSettingToMemory(registerAddress, value, ch);
SaveSettingToFile(registerAddress, value, ch); SaveSettingToFile(registerAddress, value, ch);
} }
@ -429,6 +423,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;
uint32_t data[1]; uint32_t data[1];
ret = CAEN_DGTZ_ReadRegister(handle, registerAddress.ActualAddress(ch), data); ret = CAEN_DGTZ_ReadRegister(handle, registerAddress.ActualAddress(ch), data);
@ -475,17 +470,21 @@ Reg Digitizer::FindRegister(uint32_t address){
if( tempReg.GetName() == ""){ if( tempReg.GetName() == ""){
if( DPPType == V1730_DPP_PHA_CODE ){ if( DPPType == V1730_DPP_PHA_CODE ){
for( int p = 0; p < (int) RegisterPHAList[p]; p++){ for( int p = 0; p < (int) RegisterPHAList[p]; p++){
if( address == RegisterPHAList[p].GetAddress() ) tempReg = RegisterPHAList[p]; if( address == RegisterPHAList[p].GetAddress() ) {
tempReg = RegisterPHAList[p];
break; break;
} }
} }
}
if( DPPType == V1730_DPP_PSD_CODE ){ if( DPPType == V1730_DPP_PSD_CODE ){
for( int p = 0; p < (int) RegisterPSDList[p]; p++){ for( int p = 0; p < (int) RegisterPSDList[p]; p++){
if( address == RegisterPSDList[p].GetAddress() ) tempReg = RegisterPSDList[p]; if( address == RegisterPSDList[p].GetAddress() ) {
tempReg = RegisterPSDList[p];
break; break;
} }
} }
} }
}
return tempReg; return tempReg;
} }
@ -557,7 +556,7 @@ void Digitizer::PrintSettingFromMemory(){
for( int i = 0; i < SETTINGSIZE; i++) printf("%4d | 0x%04X |0x%08X = %u \n", i, i*4, setting[i], setting[i]); for( int i = 0; i < SETTINGSIZE; i++) printf("%4d | 0x%04X |0x%08X = %u \n", i, i*4, setting[i], setting[i]);
} }
void Digitizer::OpenSettingBinary(std::string fileName){ int Digitizer::OpenSettingBinary(std::string fileName){
if( settingFile != NULL ) delete settingFile; if( settingFile != NULL ) delete settingFile;
settingFile = fopen(fileName.c_str(), "r+"); settingFile = fopen(fileName.c_str(), "r+");
@ -576,30 +575,50 @@ void Digitizer::OpenSettingBinary(std::string fileName){
printf("Created file : %s. file size : %d Byte\n", settingFileName.c_str(), inFileSize); printf("Created file : %s. file size : %d Byte\n", settingFileName.c_str(), inFileSize);
fclose (settingFile); fclose (settingFile);
settingFileExist = true; settingFileExist = true;
return 0;
}else{ }else{
this->settingFileName = fileName; this->settingFileName = fileName;
settingFileExist = true; settingFileExist = true;
printf("setting file already exist. do nothing. Should program the digitizer\n"); printf("setting file already exist. do nothing. Should program the digitizer\n");
return -1;
} }
} }
void Digitizer::LoadSettingBinary(std::string fileName){ int Digitizer::LoadSettingBinary(std::string fileName){
settingFile = fopen(fileName.c_str(), "r+"); settingFile = fopen(fileName.c_str(), "r+");
if( settingFile == NULL ) { if( settingFile == NULL ) {
printf(" %s does not exist.\n", fileName.c_str()); printf(" %s does not exist or cannot load.\n", fileName.c_str());
settingFileExist = false; settingFileExist = false;
return; return -1;
}else{ }else{
settingFileExist = true; settingFileExist = true;
settingFileName = fileName; settingFileName = fileName;
fclose (settingFile);
uint32_t fileDPP = ((ReadSettingFromFile(Register::DPP::AMCFirmwareRevision_R, 0) >> 8) & 0xFF);
/// compare seeting DPP version;
if( isConnected && DPPType != fileDPP ){
printf("DPPType in the file is %s(0x%X), but the dgitizer DPPType is %s(0x%X). \n", GetDPPString(fileDPP).c_str(), fileDPP, GetDPPString().c_str(), DPPType);
return -1;
}else{
/// load binary to memoery /// load binary to memoery
DPPType = fileDPP;
printf("DPPType in the file is %s(0x%X). \n", GetDPPString(fileDPP).c_str(), fileDPP);
settingFile = fopen(fileName.c_str(), "r+");
size_t dummy = fread( setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile); size_t dummy = fread( setting, SETTINGSIZE * sizeof(unsigned int), 1, settingFile);
fclose (settingFile);
ProgramSettingsToBoard(); uint32_t boardInfo = GetSettingFromMemory(Register::DPP::BoardInfo_R);
if( (boardInfo & 0xFF) == 0x0E ) ch2ns = 4.0;
if( (boardInfo & 0xFF) == 0x0B ) ch2ns = 2.0;
ProgramSettingsToBoard(); /// do nothing if not connected.
return 0;
}
} }
} }
@ -678,6 +697,25 @@ void Digitizer::SaveSettingAsText(std::string fileName){
} }
} }
std::string Digitizer::GetDPPString(int DPPType){
std::string DPPTypeStr = "";
if( DPPType == 0 ) DPPType = this->DPPType;
switch (DPPType){
case V1724_DPP_PHA_CODE: DPPTypeStr = "DPP-PHA x724"; break; /// 0x80
case V1720_DPP_CI_CODE : DPPTypeStr = "DPP-CI x720"; break; /// 0x82
case V1720_DPP_PSD_CODE: DPPTypeStr = "DPP-PSD x720"; break; /// 0x83
case V1751_DPP_PSD_CODE: DPPTypeStr = "DPP-PSD x751"; break; /// 0x84
case V1751_DPP_ZLE_CODE: DPPTypeStr = "DPP-ZLE x751"; break; /// 0x85
case V1743_DPP_CI_CODE: DPPTypeStr = "DPP-PSD x743"; break; /// 0x86
case V1740_DPP_QDC_CODE: DPPTypeStr = "DPP-QDC x740"; break; /// 0x87
case V1730_DPP_PSD_CODE: DPPTypeStr = "DPP-PSD x730"; break; /// 0x88
case V1730_DPP_PHA_CODE: DPPTypeStr = "DPP-PHA x730"; break; /// 0x8B
case V1730_DPP_ZLE_CODE: DPPTypeStr = "DPP-ZLE x730"; break; /// 0x8C
case V1730_DPP_DAW_CODE: DPPTypeStr = "DPP-DAW x730"; break; /// 0x8D
}
return DPPTypeStr;
}
void Digitizer::ErrorMsg(std::string header){ void Digitizer::ErrorMsg(std::string header){
switch (ret){ switch (ret){
///case CAEN_DGTZ_Success : /** 0 */ printf("%s | Operation completed successfully.\n", header.c_str()); break; ///case CAEN_DGTZ_Success : /** 0 */ printf("%s | Operation completed successfully.\n", header.c_str()); break;

View File

@ -30,7 +30,6 @@ class Digitizer{
int NChannel; /// number of channel int NChannel; /// number of channel
int ADCbits; /// ADC bit int ADCbits; /// ADC bit
int DPPType; /// DPP verion int DPPType; /// DPP verion
std::string DPPTypeStr; /// DPP type in string
unsigned int ADCFullSize; /// pow(2, ADCbits) - 1 unsigned int ADCFullSize; /// pow(2, ADCbits) - 1
float ch2ns; /// channel to ns float ch2ns; /// channel to ns
CAEN_DGTZ_BoardInfo_t BoardInfo; CAEN_DGTZ_BoardInfo_t BoardInfo;
@ -46,6 +45,7 @@ class Digitizer{
int ret; /// return value, refer to CAEN_DGTZ_ErrorCode int ret; /// return value, refer to CAEN_DGTZ_ErrorCode
bool isConnected; /// true for digitizer communication estabished. bool isConnected; /// true for digitizer communication estabished.
bool AcqRun; /// true when digitizer is taking data bool AcqRun; /// true when digitizer is taking data
bool isDummy; /// true for a dummy digitizer.
/// ------- setting /// ------- setting
std::string settingFileName; /// std::string settingFileName; ///
@ -55,6 +55,7 @@ class Digitizer{
unsigned int setting[SETTINGSIZE]; /// Setting, 4bytes x 2048 = 8192 bytes unsigned int setting[SETTINGSIZE]; /// Setting, 4bytes x 2048 = 8192 bytes
///---------- protected functions ///---------- protected functions
void ErrorMsg(std::string header = ""); void ErrorMsg(std::string header = "");
public: public:
@ -69,6 +70,7 @@ class Digitizer{
int CloseDigitizer(); int CloseDigitizer();
void Initalization(); void Initalization();
void Reset(); void Reset();
bool IsDummy() {return isDummy;};
void PrintBoard() ; void PrintBoard() ;
virtual int ProgramBoard() ; /// program a generic board, no program channel virtual int ProgramBoard() ; /// program a generic board, no program channel
@ -86,14 +88,15 @@ class Digitizer{
///=================Settings ///=================Settings
/// write value to digitizer, memory, and settingFile (if exist) /// write value to digitizer, memory, and settingFile (if exist)
/// ONLY WriteRegister can have ch = -1, for writting all channels
/// for board setting, ignore ch
void WriteRegister (Reg registerAddress, uint32_t value, int ch = -1, bool isSave2MemAndFile = true); void WriteRegister (Reg registerAddress, uint32_t value, int ch = -1, bool isSave2MemAndFile = true);
/// read value from digitizer and memory, and save to memory, and settingFile(if exist), /// read value from digitizer and memory, and save to memory, and settingFile(if exist),
/// ch must be >= 0,
/// for board setting, ignore ch /// for board setting, ignore ch
uint32_t ReadRegister (Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, std::string str = "" ); uint32_t ReadRegister (Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, std::string str = "" );
uint32_t PrintRegister(uint32_t address, std::string msg); uint32_t PrintRegister(uint32_t address, std::string msg);
///================ Get Settings ///================ Get Board info
std::string GetModelName() const {return BoardInfo.ModelName;} std::string GetModelName() const {return BoardInfo.ModelName;}
int GetSerialNumber() const {return BoardInfo.SerialNumber;} int GetSerialNumber() const {return BoardInfo.SerialNumber;}
int GetChannelMask() const {return channelMask;} int GetChannelMask() const {return channelMask;}
@ -103,7 +106,7 @@ class Digitizer{
int GetHandle() const {return handle;} int GetHandle() const {return handle;}
bool GetConnectionStatus() const {return isConnected;} bool GetConnectionStatus() const {return isConnected;}
int GetDPPType() const {return DPPType;} int GetDPPType() const {return DPPType;}
std::string GetDPPTypeString() const {return DPPTypeStr;} std::string GetDPPString(int DPPType = 0); /// if no input, use digitizer DPPType
int GetADCBits() const {return BoardInfo.ADC_NBits;} int GetADCBits() const {return BoardInfo.ADC_NBits;}
std::string GetROCVersion() const {return BoardInfo.ROC_FirmwareRel;} std::string GetROCVersion() const {return BoardInfo.ROC_FirmwareRel;}
std::string GetAMCVersion() const {return BoardInfo.AMC_FirmwareRel;} std::string GetAMCVersion() const {return BoardInfo.AMC_FirmwareRel;}
@ -116,16 +119,22 @@ class Digitizer{
void ProgramSettingsToBoard (); void ProgramSettingsToBoard ();
/// simply read settings from memory /// simply read settings from memory
void SetSettingToMemory (Reg registerAddress, unsigned int value, unsigned short ch = -1); void SetSettingToMemory (Reg registerAddress, unsigned int value, unsigned short ch = 0);
unsigned int GetSettingFromMemory (Reg registerAddress, unsigned short ch = -1); unsigned int GetSettingFromMemory (Reg registerAddress, unsigned short ch = 0);
void PrintSettingFromMemory (); void PrintSettingFromMemory ();
unsigned int * GetSetting() {return setting;}; unsigned int * GetSetting() {return setting;};
/// memory <--> file /// memory <--> file
void SaveSettingAsText (std::string fileName); void SaveSettingAsText (std::string fileName);
std::string GetSettingFileName() {return settingFileName;} std::string GetSettingFileName() {return settingFileName;}
void OpenSettingBinary (std::string fileName); /// Open setting file, if file not exist, call create and save settings, if file exit set the settignFileName but not overwrite /// Open setting file, if file not exist, call create and save settings, return 0
void LoadSettingBinary (std::string fileName); /// load settign file to memory, if digitizer connected, program digitizer /// if file exit, set the settignFileName but not overwrite, return -1;
int OpenSettingBinary (std::string fileName);
/// load setting file to memory
/// if connected and DPPtype match, program digitizer
/// else assumed not connected and save settings to memory;
/// if problem, return -1; load without problem, return 0;
int LoadSettingBinary (std::string fileName);
void SaveSettingToFile (Reg registerAddress, unsigned int value, unsigned short ch = 0); /// also save to memory void SaveSettingToFile (Reg registerAddress, unsigned int value, unsigned short ch = 0); /// also save to memory
unsigned int ReadSettingFromFile (Reg registerAddress, unsigned short ch = 0); /// read from setting binary unsigned int ReadSettingFromFile (Reg registerAddress, unsigned short ch = 0); /// read from setting binary

View File

@ -19,7 +19,6 @@
#include "FSUDAQ.h" #include "FSUDAQ.h"
enum MenuIdentifiers{ enum MenuIdentifiers{
M_DIGITIZER_OPEN, M_DIGITIZER_OPEN,
@ -94,7 +93,7 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
fMenuDigitizers = new TGPopupMenu(gClient->GetRoot()); fMenuDigitizers = new TGPopupMenu(gClient->GetRoot());
fMenuDigitizers->AddEntry("&Open Digitizers", M_DIGITIZER_OPEN); fMenuDigitizers->AddEntry("&Open Digitizers", M_DIGITIZER_OPEN);
fMenuDigitizers->AddEntry("&Load Settings", M_LOAD_SETTINGS); fMenuDigitizers->AddEntry("&Load Setting (Offline)", M_LOAD_SETTINGS);
fMenuDigitizers->AddEntry("&Trigger Summary", M_TRIGGER_SUMMARY); fMenuDigitizers->AddEntry("&Trigger Summary", M_TRIGGER_SUMMARY);
fMenuDigitizers->AddSeparator(); fMenuDigitizers->AddSeparator();
fMenuDigitizers->AddEntry("Digitizer &Settings", M_BOARD_SETTINGS); fMenuDigitizers->AddEntry("Digitizer &Settings", M_BOARD_SETTINGS);
@ -106,6 +105,10 @@ MainWindow::MainWindow(const TGWindow *p,UInt_t w,UInt_t h) {
fMenuDigitizers->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)"); fMenuDigitizers->Connect("Activated(Int_t)", "MainWindow", this, "HandleMenu(Int_t)");
fMenuBar->AddPopup("&Digitizers", fMenuDigitizers, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0)); fMenuBar->AddPopup("&Digitizers", fMenuDigitizers, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
fMenuDigitizers->DisableEntry( M_TRIGGER_SUMMARY);
fMenuDigitizers->DisableEntry( M_BOARD_SETTINGS);
fMenuDigitizers->DisableEntry( M_CH_SETTING_PHA);
fMenuDigitizers->DisableEntry( M_CH_SETTING_PSD);
fMenuDigitizers->DisableEntry( M_REGISTER_SETTING); fMenuDigitizers->DisableEntry( M_REGISTER_SETTING);
fMenuUtility = new TGPopupMenu(gClient->GetRoot()); fMenuUtility = new TGPopupMenu(gClient->GetRoot());
@ -404,14 +407,14 @@ void MainWindow::OpenDigitizers(){
printf("------------ %d \n", i); printf("------------ %d \n", i);
digi[i] = new Digitizer(boardID[i], portID[i], false, false); digi[i] = new Digitizer(boardID[i], portID[i], false, false);
LogMsg(Form("%2d, Serial number : %3d opened (%s, %s)", i, digi[i]->GetSerialNumber(), LogMsg(Form("%2d, Serial number : %3d opened (%s, %s)", i, digi[i]->GetSerialNumber(),
digi[i]->GetDPPTypeString().c_str(), digi[i]->GetDPPString().c_str(),
digi[i]->GetModelName().c_str())); digi[i]->GetModelName().c_str()));
digi[i]->OpenSettingBinary("./setting_" + std::to_string(digi[i]->GetSerialNumber()) + ".bin"); digi[i]->OpenSettingBinary("./setting_" + std::to_string(digi[i]->GetSerialNumber()) + ".bin");
} }
fMenuDigitizers->DisableEntry( M_DIGITIZER_OPEN); fMenuDigitizers->DisableEntry( M_DIGITIZER_OPEN);
fMenuDigitizers->EnableEntry( M_LOAD_SETTINGS); fMenuDigitizers->DisableEntry( M_LOAD_SETTINGS);
fMenuDigitizers->EnableEntry( M_TRIGGER_SUMMARY); fMenuDigitizers->EnableEntry( M_TRIGGER_SUMMARY);
fMenuDigitizers->EnableEntry( M_REGISTER_SETTING); fMenuDigitizers->EnableEntry( M_REGISTER_SETTING);
bOpenDigitizers->SetEnabled(false); bOpenDigitizers->SetEnabled(false);
@ -454,19 +457,29 @@ void MainWindow::LoadSettingFromFile(){
printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir); printf("Open file: %s (dir: %s)\n", fi.fFilename, fi.fIniDir);
dir = fi.fIniDir; dir = fi.fIniDir;
LogMsg((char *)"This is not implement yet. Should Load and Program all digitizers"); if( fi.fFilename == NULL) return;
int loadStatus = -1;
/// if no digitize open /// if no digitize open
if( digi == NULL ) { if( digi == NULL ) {
LogMsg((char *)"No Digitizer is connected. Create a dummy digitizer.");
digi = new Digitizer *[1];
nDigi = 1;
digi[0] = new Digitizer();
loadStatus = digi[0]->LoadSettingBinary( fi.fFilename );
boardIDEntry->SetNumber(0, false);
}else{ }else{
loadStatus = digi[0]->LoadSettingBinary( fi.fFilename ); /// still dummy digitizer
} }
if( boardSetting != NULL ) boardSetting->CloseWindow();
if( channelSettingPHA != NULL ) channelSettingPHA->CloseWindow();
if( channelSettingPSD != NULL ) channelSettingPSD->CloseWindow();
HandleMenu(M_BOARD_SETTINGS);
OpenChannelSetting(0);
} }
void MainWindow::ChangeBoard(){ void MainWindow::ChangeBoard(){

View File

@ -43,6 +43,7 @@ class Reg{
uint32_t GetAddress() const {return this->address; } uint32_t GetAddress() const {return this->address; }
char GetType() const {return this->type;} char GetType() const {return this->type;}
bool GetGroup() const {return this->group;} bool GetGroup() const {return this->group;}
void Print() const ;
uint32_t ActualAddress(int ch = -1){ uint32_t ActualAddress(int ch = -1){
if( address == 0x8180 ) return (ch < 0 ? address : (address + 4*(ch/2))); if( address == 0x8180 ) return (ch < 0 ? address : (address + 4*(ch/2)));
@ -63,6 +64,13 @@ class Reg{
bool group; bool group;
}; };
inline void Reg::Print() const{
printf(" Name: %s\n", name.c_str());
printf("Address: 0x%04X\n", address);
printf(" Type: %s\n", type == RW::ReadWrite ? "Read/Write" : (type == RW::ReadONLY ? "Read-Only" : "Write-Only") );
printf(" Group: %s\n", group ? "True" : "False");
}
inline unsigned short Reg::Index (unsigned short ch){ inline unsigned short Reg::Index (unsigned short ch){
unsigned short index; unsigned short index;
if( address == 0x8180){ if( address == 0x8180){

View File

@ -75,6 +75,7 @@ BoardSetting::BoardSetting(const TGWindow *p, UInt_t w, UInt_t h, Digitizer ** d
TGTextButton * bProgramBoardFromFile = new TGTextButton(hframe1, "Load File"); hframe1->AddFrame(bProgramBoardFromFile, new TGLayoutHints( kLHintsLeft | kLHintsCenterY, 5,5,3,3)); TGTextButton * bProgramBoardFromFile = new TGTextButton(hframe1, "Load File"); hframe1->AddFrame(bProgramBoardFromFile, new TGLayoutHints( kLHintsLeft | kLHintsCenterY, 5,5,3,3));
bProgramBoardFromFile->Connect("Clicked()", "BoardSetting", this, "ProgramBoardFromFile()"); bProgramBoardFromFile->Connect("Clicked()", "BoardSetting", this, "ProgramBoardFromFile()");
if( nDigi == 1 && digi[0]->IsDummy() ) bProgramBoardFromFile->SetEnabled(false);
TGTextButton * bSaveFile = new TGTextButton(hframe1, "Save As"); hframe1->AddFrame(bSaveFile, new TGLayoutHints( kLHintsLeft | kLHintsCenterY, 5,5,3,3)); TGTextButton * bSaveFile = new TGTextButton(hframe1, "Save As"); hframe1->AddFrame(bSaveFile, new TGLayoutHints( kLHintsLeft | kLHintsCenterY, 5,5,3,3));
bSaveFile->Connect("Clicked()", "BoardSetting", this, "SaveSettingFile()"); bSaveFile->Connect("Clicked()", "BoardSetting", this, "SaveSettingFile()");
@ -738,6 +739,11 @@ void BoardSetting::ReadStatus(){
if( digi == NULL) return; if( digi == NULL) return;
int boardID = boardIDEntry->GetNumber(); int boardID = boardIDEntry->GetNumber();
if( digi[boardID]->IsDummy() ) {
txtACQBoardReady->SetText("No Digitizer is opened!");
txtACQBoardReady->SetTextColor(red);
return;
}
/// ACQ Status /// ACQ Status
///digi[boardID]->PrintRegister(Register::DPP::AcquisitionStatus, "ACQ Status"); ///digi[boardID]->PrintRegister(Register::DPP::AcquisitionStatus, "ACQ Status");
@ -783,7 +789,7 @@ void BoardSetting::ReadStatus(){
///================ Board Failure Status ///================ Board Failure Status
///digi[boardID]->PrintRegister(Register::DPP::BoardFailureStatus, "Board Fail"); ///digi[boardID]->PrintRegister(Register::DPP::BoardFailureStatus, "Board Fail");
temp = digi[boardID]->GetSettingFromMemory(Register::DPP::BoardFailureStatus_R); temp = digi[boardID]->ReadRegister(Register::DPP::BoardFailureStatus_R);
if( ((temp >> 4) & 0x1) == 0 ) { if( ((temp >> 4) & 0x1) == 0 ) {
enPLLStatus->SetText( "OK" , false); enPLLStatus->SetTextColor(1); enPLLStatus->SetText( "OK" , false); enPLLStatus->SetTextColor(1);
}else{ }else{
@ -1411,15 +1417,20 @@ void BoardSetting::ProgramBoardFromFile(){
txtSettingFile->SetText(fi.fFilename); txtSettingFile->SetText(fi.fFilename);
int loadStatus = -1;
if( digi == NULL ) { if( digi == NULL ) {
///digi = new Digitizer *[1];
///nDigi = 1;
///digi[0] = new Digitizer();
///loadStatus = digi[0]->LoadSettingBinary( fi.fFilename );
}else{ }else{
int boardID = boardIDEntry->GetNumber(); int boardID = boardIDEntry->GetNumber();
digi[boardID]->LoadSettingBinary( fi.fFilename ); loadStatus = digi[boardID]->LoadSettingBinary( fi.fFilename );
ChangeBoard();
} }
if( loadStatus == 0 ) ChangeBoard();
} }
void BoardSetting::SaveSettingFile(){ void BoardSetting::SaveSettingFile(){

View File

@ -264,7 +264,7 @@ ChannelSettingPHA::ChannelSettingPHA(const TGWindow *p, UInt_t w, UInt_t h, Digi
TGLabel * lbTrapScale = new TGLabel(vfDPPCtrl11, "Trap. Scaling [bit] :"); vfDPPCtrl11->AddFrame(lbTrapScale, haha); TGLabel * lbTrapScale = new TGLabel(vfDPPCtrl11, "Trap. Scaling [bit] :"); vfDPPCtrl11->AddFrame(lbTrapScale, haha);
numTrapScale = new TGNumberEntry(vfDPPCtrl12, 14, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative ); vfDPPCtrl12->AddFrame(numTrapScale); numTrapScale = new TGNumberEntry(vfDPPCtrl12, 14, 0, 0, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative ); vfDPPCtrl12->AddFrame(numTrapScale);
numTrapScale->Resize(width, 20); numTrapScale->Resize(width, 20);
numTrapScale->Connect("Changed()", "ChannelSettingPHA", this, "SetDPPAlgorithm1()"); numTrapScale->Connect("Modified()", "ChannelSettingPHA", this, "SetDPPAlgorithm1()");
TGLabel * lbDecimation = new TGLabel(vfDPPCtrl11, "Decimation :"); vfDPPCtrl11->AddFrame(lbDecimation, haha); TGLabel * lbDecimation = new TGLabel(vfDPPCtrl11, "Decimation :"); vfDPPCtrl11->AddFrame(lbDecimation, haha);
cbDecimation = new TGComboBox(vfDPPCtrl12); vfDPPCtrl12->AddFrame(cbDecimation); cbDecimation = new TGComboBox(vfDPPCtrl12); vfDPPCtrl12->AddFrame(cbDecimation);
@ -545,7 +545,6 @@ void ChannelSettingPHA::ChangeCh(){
cbBaselineOptimize->Select( ( (temp >> 29) & 0x1), false); cbBaselineOptimize->Select( ( (temp >> 29) & 0x1), false);
cbExtra2WordOption->Select( ( (temp >> 8) & 0x7), false); cbExtra2WordOption->Select( ( (temp >> 8) & 0x7), false);
} }
void ChannelSettingPHA::SetAllChannels(){ void ChannelSettingPHA::SetAllChannels(){
@ -557,7 +556,7 @@ void ChannelSettingPHA::SetAllChannels(){
short ch = chIDEntry->GetNumber(); short ch = chIDEntry->GetNumber();
///use memory from this channel and set to all other channal ///use memory from this channel and set to all other channal
for( int p = 0; (int) RegisterPHAList.size(); p++){ for( int p = 0; p < (int) RegisterPHAList.size(); p++){
unsigned short temp = digi[boardID]->GetSettingFromMemory(RegisterPHAList[p], ch); unsigned short temp = digi[boardID]->GetSettingFromMemory(RegisterPHAList[p], ch);
for( int i = 0; i < digi[boardID]->GetNChannel() ; i++){ for( int i = 0; i < digi[boardID]->GetNChannel() ; i++){

View File

@ -79,29 +79,32 @@ long get_time(){
int main(int argc, char* argv[]){ int main(int argc, char* argv[]){
//for( int p = 0; p < (int) RegisterDPPList.size(); p++){ //##################### Demo for loading and change setting without open a digitizer
// printf("0x%04X , %s\n", (uint32_t) RegisterDPPList[p], RegisterDPPList[p].GetNameChar()); Digitizer dig;
//} dig.LoadSettingBinary("setting_323.bin");
Digitizer * dig = new Digitizer; //dig.PrintSettingFromMemory();
dig->SetDPPType (V1730_DPP_PHA_CODE); ///dig.SaveSettingAsText("haha.txt");
//dig->OpenSettingBinary("setting_323.bin"); printf("ch2ns = %f \n", dig.GetCh2ns());
dig->LoadSettingBinary("setting_323.bin");
//dig->PrintSettingFromMemory();
//printf("##############################################################\n");
//dig->SaveSettingAsText("haha.txt");
//for( int i = 0; i < dig->GetNChannel(); i++){
// dig->SaveSettingToFile(Register::DPP::NumberEventsPerAggregate_G, 10, i);
//}
dig->SaveSettingToFile(Register::DPP::MaxAggregatePerBlockTransfer, 200, 0); ///for( int i = 0; i < dig->GetNChannel(); i++){
/// dig.SaveSettingToFile(Register::DPP::NumberEventsPerAggregate_G, 10, i);
unsigned int bSize = dig->CalByteForBuffer(); ///}
///dig.SaveSettingToFile(Register::DPP::MaxAggregatePerBlockTransfer, 200, 0);
///
unsigned int bSize = dig.CalByteForBuffer();
printf("Buffer Size : %u byte = %.2f MB \n", bSize, bSize/1024./1024.); printf("Buffer Size : %u byte = %.2f MB \n", bSize, bSize/1024./1024.);
Reg haha = dig.FindRegister(Register::DPP::RecordLength_G);
haha.Print();
//#####################
/* /*
const int nBoard = 2; const int nBoard = 2;
Digitizer **dig = new Digitizer *[nBoard]; Digitizer **dig = new Digitizer *[nBoard];