SOLARIS_QT6_DAQ/ClassDigitizer2Gen.cpp

1285 lines
47 KiB
C++
Raw Normal View History

2023-01-25 14:59:48 -05:00
#include "ClassDigitizer2Gen.h"
#include <cstring>
#include <algorithm>
2023-03-15 19:10:17 -04:00
#include <sys/stat.h>
2023-01-25 14:59:48 -05:00
Digitizer2Gen::Digitizer2Gen(){
//printf("======== %s \n",__func__);
2023-01-25 14:59:48 -05:00
Initialization();
}
Digitizer2Gen::~Digitizer2Gen(){
2023-02-13 15:22:24 -05:00
printf("========Digitizer2Gen::%s (%d)\n",__func__, serialNumber);
2023-01-25 14:59:48 -05:00
if(isConnected ) CloseDigitizer();
}
void Digitizer2Gen::Initialization(){
//printf("======== %s \n",__func__);
2023-01-25 14:59:48 -05:00
handle = 0;
ret = 0;
isConnected = false;
isDummy = false;
2023-02-28 17:49:33 -05:00
2023-01-25 14:59:48 -05:00
serialNumber = 0;
FPGAType = "";
2023-01-25 14:59:48 -05:00
nChannels = 0;
ch2ns = 0;
outFileIndex = 0;
FinishedOutFilesSize = 0;
2023-01-25 14:59:48 -05:00
dataStartIndetifier = 0xAAA0;
outFile = NULL;
outFileSize = 0;
evt = NULL;
acqON = false;
2023-02-23 16:08:47 -05:00
settingFileName = "";
2023-03-14 16:17:22 -04:00
boardSettings = PHA::DIG::AllSettings;
for( int ch = 0; ch < MaxNumberOfChannel ; ch ++) chSettings[ch] = PHA::CH::AllSettings;
for( int index = 0 ; index < 4; index ++) {
VGASetting[index] = PHA::VGA::VGAGain;
LVDSSettings[index] = PHA::LVDS::AllSettings;
}
2023-02-23 12:24:39 -05:00
//build map
2023-03-14 16:17:22 -04:00
for( int i = 0; i < (int) PHA::DIG::AllSettings.size(); i++) boardMap[PHA::DIG::AllSettings[i].GetPara()] = i;
for( int i = 0; i < (int) PHA::LVDS::AllSettings.size(); i++) LVDSMap[PHA::LVDS::AllSettings[i].GetPara()] = i;
2023-03-14 16:17:22 -04:00
for( int i = 0; i < (int) PHA::CH::AllSettings.size(); i++) chMap[PHA::CH::AllSettings[i].GetPara()] = i;
2023-01-25 14:59:48 -05:00
}
2023-02-13 15:22:24 -05:00
void Digitizer2Gen::SetDummy(unsigned short sn){
isDummy = true;
2023-02-13 15:22:24 -05:00
serialNumber = sn;
nChannels = 64;
FPGAType = "DPP_PHA";
}
2023-01-25 14:59:48 -05:00
//########################################### Handles functions
uint64_t Digitizer2Gen::GetHandle(const char * parameter){
uint64_t par_handle;
ret = CAEN_FELib_GetHandle(handle, parameter, &par_handle);
if(ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return 0;
}
return par_handle;
}
uint64_t Digitizer2Gen::GetParentHandle(uint64_t handle){
uint64_t par_handle;
ret = CAEN_FELib_GetParentHandle(handle, NULL, &par_handle);
if(ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return 0;
}
return par_handle;
}
std::string Digitizer2Gen::GetPath(uint64_t handle){
char path[256];
ret = CAEN_FELib_GetPath(handle, path);
if(ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return "Error";
}
return path;
}
//########################################### Read Write
int Digitizer2Gen::FindIndex(const Reg para){
switch (para.GetType() ){
case TYPE::CH: return chMap[para.GetPara()];
case TYPE::DIG: return boardMap[para.GetPara()];
case TYPE::VGA: return 0;
case TYPE::LVDS: return LVDSMap[para.GetPara()];
}
return -1;
}
2023-01-25 14:59:48 -05:00
std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose){
if( !isConnected ) return "not connected";
//printf(" %s|%s \n", __func__, parameter);
ret = CAEN_FELib_GetValue(handle, parameter, retValue);
if (ret != CAEN_FELib_Success) {
2023-04-03 18:20:36 -04:00
printf(" %s|%d|%-45s| read fail\n", __func__, serialNumber, parameter);
2023-01-25 14:59:48 -05:00
return ErrorMsg(__func__);
}else{
2023-04-03 18:20:36 -04:00
if( verbose ) printf(" %s|%d|%-45s:%s\n", __func__, serialNumber, parameter, retValue);
2023-01-25 14:59:48 -05:00
}
return retValue;
}
std::string Digitizer2Gen::ReadValue(const Reg para, int ch_index, bool verbose){
std:: string ans = ReadValue(para.GetFullPara(ch_index).c_str(), verbose);
2023-02-23 12:24:39 -05:00
int index = FindIndex(para);
switch( para.GetType()){
case TYPE::CH : chSettings[ch_index][index].SetValue(ans); break;
case TYPE::DIG : boardSettings[index].SetValue(ans); break;
case TYPE::VGA : VGASetting[ch_index].SetValue(ans); break;
case TYPE::LVDS: LVDSSettings[ch_index][index].SetValue(ans);break;
2023-02-23 16:08:47 -05:00
}
//printf("%s | %s | index %d | %s \n", para.GetFullPara(ch_index).c_str(), ans.c_str(), index, chSettings[ch_index][index].GetValue().c_str());
2023-02-23 16:08:47 -05:00
return ans;
2023-02-23 16:08:47 -05:00
}
bool Digitizer2Gen::WriteValue(const char * parameter, std::string value, bool verbose){
if( !isConnected ) return false;
2023-04-03 18:20:36 -04:00
//ReadValue(parameter, 1);
if( verbose) printf(" %s|%d|%-45s|%s|\n", __func__, serialNumber, parameter, value.c_str());
2023-01-25 14:59:48 -05:00
ret = CAEN_FELib_SetValue(handle, parameter, value.c_str());
if (ret != CAEN_FELib_Success) {
printf("WriteError|%s||%s|\n", parameter, value.c_str());
2023-01-25 14:59:48 -05:00
ErrorMsg(__func__);
2023-02-23 12:24:39 -05:00
return false;
2023-01-25 14:59:48 -05:00
}
2023-02-23 12:24:39 -05:00
return true;
2023-01-25 14:59:48 -05:00
}
bool Digitizer2Gen::WriteValue(const Reg para, std::string value, int ch_index){
if( WriteValue(para.GetFullPara(ch_index).c_str(), value) || isDummy){
int index = FindIndex(para);
if( index != -1 ){
switch(para.GetType()){
case TYPE::CH :{
if( ch_index >= 0 ){
chSettings[ch_index][index].SetValue(value);
}else{
for( int ch = 0; ch < nChannels; ch++ ) chSettings[ch][index].SetValue(value);
}
//if( ch_index < 0 ) ch_index = 0;
//printf("%s %s %s |%s|\n", __func__, para.GetPara().c_str(),
// chSettings[ch_index][index].GetFullPara(ch_index).c_str(),
// chSettings[ch_index][index].GetValue().c_str());
}break;
case TYPE::VGA : {
VGASetting[ch_index].SetValue(value);
//printf("%s %s %s |%s|\n", __func__, para.GetPara().c_str(),
// VGASetting[ch_index].GetFullPara(ch_index).c_str(),
// VGASetting[ch_index].GetValue().c_str());
}break;
case TYPE::DIG : {
boardSettings[index].SetValue(value);
//printf("%s %s %s |%s|\n", __func__, para.GetPara().c_str(),
// boardSettings[index].GetFullPara(ch_index).c_str(),
// boardSettings[index].GetValue().c_str());
}break;
case TYPE::LVDS : break;
}
}
2023-02-23 12:24:39 -05:00
return true;
}else{
return false;
}
}
2023-01-25 14:59:48 -05:00
void Digitizer2Gen::SendCommand(const char * parameter){
if( !isConnected ) return;
printf(" %s|%d|Send Command : %s \n", __func__, serialNumber, parameter);
2023-01-25 14:59:48 -05:00
ret = CAEN_FELib_SendCommand(handle, parameter);
if (ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return;
}
}
2023-02-08 17:35:04 -05:00
void Digitizer2Gen::SendCommand(std::string shortPara){
std::string haha = "/cmd/" + shortPara;
SendCommand(haha.c_str());
}
2023-01-25 14:59:48 -05:00
//########################################### Open digitizer
int Digitizer2Gen::OpenDigitizer(const char * url){
//printf("======== %s \n",__func__);
2023-01-25 14:59:48 -05:00
ret = CAEN_FELib_Open(url, &handle);
//printf("=== ret : %d | %d \n", ret, CAEN_FELib_Success);
2023-01-25 14:59:48 -05:00
if (ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return -1;
}
isConnected = true;
2023-03-16 16:05:55 -04:00
printf("#################################################\n");
2023-01-25 14:59:48 -05:00
//========== PHA and PSD are the same
serialNumber = atoi(ReadValue(PHA::DIG::SerialNumber).c_str());
FPGAType = ReadValue(PHA::DIG::FirmwareType);
FPGAVer = atoi(ReadValue(PHA::DIG::CupVer).c_str());
nChannels = atoi(ReadValue(PHA::DIG::NumberOfChannel).c_str());
ModelName = ReadValue(PHA::DIG::ModelName);
int adcRate = atoi(ReadValue(PHA::DIG::ADC_SampleRate).c_str());
2023-01-25 14:59:48 -05:00
ch2ns = 1000/adcRate;
printf(" IP address : %s\n", ReadValue(PHA::DIG::IPAddress).c_str());
printf(" Net Mask : %s\n", ReadValue(PHA::DIG::NetMask).c_str());
printf(" Gateway : %s\n", ReadValue(PHA::DIG::Gateway).c_str());
2023-03-16 16:05:55 -04:00
printf(" Model name : %s\n", ModelName.c_str());
printf(" DPP Type : %s (%d)\n", FPGAType.c_str(), FPGAVer);
2023-01-25 14:59:48 -05:00
printf("Serial number : %d\n", serialNumber);
printf(" ADC bits : %s\n", ReadValue(PHA::DIG::ADC_bit).c_str());
2023-01-25 14:59:48 -05:00
printf(" ADC rate : %d Msps, ch2ns : %d ns\n", adcRate, ch2ns);
printf(" Channels : %d\n", nChannels);
if( FPGAType == DPPType::PHA) {
printf("========== defining setting arrays for %s \n", FPGAType.c_str());
boardSettings = PHA::DIG::AllSettings;
for( int ch = 0; ch < MaxNumberOfChannel ; ch ++) chSettings[ch] = PHA::CH::AllSettings;
for( int index = 0 ; index < 4; index ++) {
VGASetting[index] = PHA::VGA::VGAGain;
LVDSSettings[index] = PHA::LVDS::AllSettings;
}
//build map
for( int i = 0; i < (int) PHA::DIG::AllSettings.size(); i++) boardMap[PHA::DIG::AllSettings[i].GetPara()] = i;
for( int i = 0; i < (int) PHA::LVDS::AllSettings.size(); i++) LVDSMap[PHA::LVDS::AllSettings[i].GetPara()] = i;
for( int i = 0; i < (int) PHA::CH::AllSettings.size(); i++) chMap[PHA::CH::AllSettings[i].GetPara()] = i;
}else if (FPGAType == DPPType::PSD){
printf("========== defining setting arrays for %s \n", FPGAType.c_str());
boardSettings = PSD::DIG::AllSettings;
for( int ch = 0; ch < MaxNumberOfChannel ; ch ++) chSettings[ch] = PSD::CH::AllSettings;
for( int index = 0 ; index < 4; index ++) {
VGASetting[index] = PSD::VGA::VGAGain;
LVDSSettings[index] = PSD::LVDS::AllSettings;
}
//build map
for( int i = 0; i < (int) PSD::DIG::AllSettings.size(); i++) boardMap[PSD::DIG::AllSettings[i].GetPara()] = i;
for( int i = 0; i < (int) PSD::LVDS::AllSettings.size(); i++) LVDSMap[PSD::LVDS::AllSettings[i].GetPara()] = i;
for( int i = 0; i < (int) PSD::CH::AllSettings.size(); i++) chMap[PSD::CH::AllSettings[i].GetPara()] = i;
}else{
printf(" DPP Type %s is not supported.\n", FPGAType.c_str());
return -303;
}
ReadAllSettings();
2023-02-23 16:08:47 -05:00
//------ set default setting file name
settingFileName = "settings_"+ std::to_string(serialNumber) + ".dat";
2023-02-08 17:35:04 -05:00
printf("====================== \n");
2023-01-25 14:59:48 -05:00
return 0;
}
int Digitizer2Gen::CloseDigitizer(){
printf("========Digitizer2Gen::%s \n",__func__);
if( isConnected == true ){
ret = CAEN_FELib_Close(handle);
if (ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return 0;
}
isConnected = false;
2023-01-25 14:59:48 -05:00
}
return 0;
}
//########################################### DAQ
void Digitizer2Gen::StartACQ(){
SendCommand("/cmd/armacquisition"); // this will also clear data
SendCommand("/cmd/swstartacquisition");
outFileIndex = 0;
outFileSize = 0;
FinishedOutFilesSize = 0;
2023-01-25 14:59:48 -05:00
acqON = true;
}
void Digitizer2Gen::StopACQ(){
SendCommand("/cmd/SwStopAcquisition");
SendCommand("/cmd/disarmacquisition");
acqON = false;
}
void Digitizer2Gen::SetDataFormat(unsigned short dataFormat){
2023-01-25 14:59:48 -05:00
2023-02-08 17:35:04 -05:00
printf("%s : %d\n", __func__, dataFormat);
2023-01-25 14:59:48 -05:00
///========== get endpoint and endpoint folder handle
if( dataFormat != DataFormat::RAW ){
if( FPGAType == DPPType::PHA ){
ret = CAEN_FELib_GetHandle(handle, "/endpoint/dpppha", &ep_handle);
ret |= CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle);
ret |= CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "dpppha");
}else if(FPGAType == DPPType::PSD) {
ret = CAEN_FELib_GetHandle(handle, "/endpoint/dpppsd", &ep_handle);
ret |= CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle);
ret |= CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "dpppsd");
}else{
ErrorMsg("DPP-Type not supported.");
return;
}
2023-01-25 14:59:48 -05:00
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set active endpoint");
return;
}
}else{
ret = CAEN_FELib_GetHandle(handle, "/endpoint/raw", &ep_handle);
ret |= CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle);
ret |= CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "raw");
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set active endpoint");
return;
}
}
2023-02-06 19:18:21 -05:00
if( evt ) delete evt;
2023-01-25 14:59:48 -05:00
evt = new Event();
evt->SetDataType(dataFormat, FPGAType);
dataStartIndetifier = 0xAA00 + dataFormat;
if(FPGAType == DPPType::PSD ) dataStartIndetifier += 0x0010;
if( FPGAType == DPPType::PHA) {
if( dataFormat == DataFormat::ALL ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_2\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_1\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_2\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_3\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_4\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"ANALOG_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_3_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_4_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"WAVEFORM_SIZE\", \"type\" : \"SIZE_T\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"TRIGGER_THR\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIME_RESOLUTION\", \"type\" : \"U8\" }, \
{ \"name\" : \"BOARD_FAIL\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"FLUSH\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"AGGREGATE_COUNTER\", \"type\" : \"U32\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
]");
}
2023-01-25 14:59:48 -05:00
if( dataFormat == DataFormat::OneTrace ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"WAVEFORM_SIZE\", \"type\" : \"SIZE_T\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"TRIGGER_THR\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIME_RESOLUTION\", \"type\" : \"U8\" }, \
{ \"name\" : \"BOARD_FAIL\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"FLUSH\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"AGGREGATE_COUNTER\", \"type\" : \"U32\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
]");
}
2023-01-25 14:59:48 -05:00
if( dataFormat == DataFormat::NoTrace ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"TRIGGER_THR\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIME_RESOLUTION\", \"type\" : \"U8\" }, \
{ \"name\" : \"BOARD_FAIL\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"FLUSH\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"AGGREGATE_COUNTER\", \"type\" : \"U32\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
]");
}
2023-01-25 14:59:48 -05:00
if( dataFormat == DataFormat::Minimum ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" } \
]");
}
}else if ( FPGAType == DPPType::PSD ){
if( dataFormat == DataFormat::ALL ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY_SHORT\", \"type\" : \"U16\" }, \
{ \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_2\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_1\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_2\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_3\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"DIGITAL_PROBE_4\", \"type\" : \"U8\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"ANALOG_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_2_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_3_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"DIGITAL_PROBE_4_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"WAVEFORM_SIZE\", \"type\" : \"SIZE_T\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"TRIGGER_THR\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIME_RESOLUTION\", \"type\" : \"U8\" }, \
{ \"name\" : \"BOARD_FAIL\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"FLUSH\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"AGGREGATE_COUNTER\", \"type\" : \"U32\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
]");
}
if( dataFormat == DataFormat::OneTrace ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY_SHORT\", \"type\" : \"U16\" }, \
{ \"name\" : \"ANALOG_PROBE_1\", \"type\" : \"I32\", \"dim\" : 1 }, \
{ \"name\" : \"ANALOG_PROBE_1_TYPE\", \"type\" : \"U8\" }, \
{ \"name\" : \"WAVEFORM_SIZE\", \"type\" : \"SIZE_T\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"TRIGGER_THR\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIME_RESOLUTION\", \"type\" : \"U8\" }, \
{ \"name\" : \"BOARD_FAIL\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"FLUSH\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"AGGREGATE_COUNTER\", \"type\" : \"U32\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
]");
}
if( dataFormat == DataFormat::NoTrace ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"FINE_TIMESTAMP\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY_SHORT\", \"type\" : \"U16\" }, \
{ \"name\" : \"FLAGS_LOW_PRIORITY\", \"type\" : \"U16\"}, \
{ \"name\" : \"FLAGS_HIGH_PRIORITY\", \"type\" : \"U16\" }, \
{ \"name\" : \"TRIGGER_THR\", \"type\" : \"U16\" }, \
{ \"name\" : \"TIME_RESOLUTION\", \"type\" : \"U8\" }, \
{ \"name\" : \"BOARD_FAIL\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"FLUSH\", \"type\" : \"BOOL\" }, \
{ \"name\" : \"AGGREGATE_COUNTER\", \"type\" : \"U32\" }, \
{ \"name\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
]");
}
if( dataFormat == DataFormat::Minimum ){
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
"[ \
{ \"name\" : \"CHANNEL\", \"type\" : \"U8\" }, \
{ \"name\" : \"TIMESTAMP\", \"type\" : \"U64\" }, \
{ \"name\" : \"ENERGY\", \"type\" : \"U16\" }, \
{ \"name\" : \"ENERGY_SHORT\", \"type\" : \"U16\" }, \
]");
}
2023-01-25 14:59:48 -05:00
}
if( dataFormat == DataFormat::RAW ){
2023-01-25 14:59:48 -05:00
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
" [ \
{ \"name\": \"DATA\", \"type\": \"U8\", \"dim\": 1 }, \
{ \"name\": \"SIZE\", \"type\": \"SIZE_T\" }, \
{ \"name\": \"N_EVENTS\", \"type\": \"U32\" } \
]"
);
}
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set Read Data Format");
return;
}
//TODO Statistic handle and endpoint
ret = CAEN_FELib_GetHandle(handle, "/endpoint/dpppha/stats", &stat_handle);
ret |= CAEN_FELib_SetReadDataFormat(stat_handle,
" [ \
{ \"name\": \"REAL_TIME_NS\", \"type\": \"U64\", \"dim\": 1 }, \
{ \"name\": \"DEAD_TIME_NS\", \"type\": \"U64\", \"dim\": 1 }, \
{ \"name\": \"LIVE_TIME_NS\", \"type\": \"U64\", \"dim\": 1 }, \
{ \"name\": \"TRIGGER_CNT\", \"type\": \"U32\", \"dim\": 1 }, \
{ \"name\": \"SAVED_EVENT_CNT\", \"type\": \"U32\", \"dim\": 1 } \
]"
);
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set Statistics");
return;
}
}
int Digitizer2Gen::ReadStat(){
ret = CAEN_FELib_ReadData(stat_handle, 100,
realTime,
deadTime,
liveTime,
triggerCount,
savedEventCount
);
if (ret != CAEN_FELib_Success) ErrorMsg("Read Statistics");
return ret;
}
void Digitizer2Gen::PrintStat(){
printf("ch | Real Time[ns] | Dead Time[ns] | Live Time[ns] | Trigger | Saved | Rate[Hz] \n");
for( int i = 0; i < MaxNumberOfChannel; i++){
if( triggerCount[i] == 0 ) continue;
printf("%02d | %13lu | %13lu | %13lu | %7u | %7u | %.3f\n",
i, realTime[i], deadTime[i], liveTime[i], triggerCount[i], savedEventCount[i], triggerCount[i]*1e9*1.0/realTime[i]);
}
}
int Digitizer2Gen::ReadData(){
//printf("========= %s \n", __func__);
if( FPGAType != DPPType::PHA || FPGAType != DPPType::PSD ) return -404;
if( evt->dataType == DataFormat::ALL ){
if( FPGAType == DPPType::PHA ){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->fine_timestamp,
&evt->energy,
evt->analog_probes[0],
evt->analog_probes[1],
evt->digital_probes[0],
evt->digital_probes[1],
evt->digital_probes[2],
evt->digital_probes[3],
&evt->analog_probes_type[0],
&evt->analog_probes_type[1],
&evt->digital_probes_type[0],
&evt->digital_probes_type[1],
&evt->digital_probes_type[2],
&evt->digital_probes_type[3],
&evt->traceLenght,
&evt->flags_low_priority,
&evt->flags_high_priority,
&evt->trigger_threashold,
&evt->downSampling,
&evt->board_fail,
&evt->flush,
&evt->aggCounter,
&evt->event_size
);
}else{
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->fine_timestamp,
&evt->energy,
&evt->energy_short,
evt->analog_probes[0],
evt->analog_probes[1],
evt->digital_probes[0],
evt->digital_probes[1],
evt->digital_probes[2],
evt->digital_probes[3],
&evt->analog_probes_type[0],
&evt->analog_probes_type[1],
&evt->digital_probes_type[0],
&evt->digital_probes_type[1],
&evt->digital_probes_type[2],
&evt->digital_probes_type[3],
&evt->traceLenght,
&evt->flags_low_priority,
&evt->flags_high_priority,
&evt->trigger_threashold,
&evt->downSampling,
&evt->board_fail,
&evt->flush,
&evt->aggCounter,
&evt->event_size
);
}
evt->isTraceAllZero = false;
}else if( evt->dataType == DataFormat::OneTrace){
if( FPGAType == DPPType::PHA ){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->fine_timestamp,
&evt->energy,
evt->analog_probes[0],
&evt->analog_probes_type[0],
&evt->traceLenght,
&evt->flags_low_priority,
&evt->flags_high_priority,
&evt->trigger_threashold,
&evt->downSampling,
&evt->board_fail,
&evt->flush,
&evt->aggCounter,
&evt->event_size
);
}else{
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->fine_timestamp,
&evt->energy,
&evt->energy_short,
evt->analog_probes[0],
&evt->analog_probes_type[0],
&evt->traceLenght,
&evt->flags_low_priority,
&evt->flags_high_priority,
&evt->trigger_threashold,
&evt->downSampling,
&evt->board_fail,
&evt->flush,
&evt->aggCounter,
&evt->event_size
);
}
evt->isTraceAllZero = false;
}else if( evt->dataType == DataFormat::NoTrace){
if( FPGAType == DPPType::PHA ){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->fine_timestamp,
&evt->energy,
&evt->flags_low_priority,
&evt->flags_high_priority,
&evt->trigger_threashold,
&evt->downSampling,
&evt->board_fail,
&evt->flush,
&evt->aggCounter,
&evt->event_size
);
}else{
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->fine_timestamp,
&evt->energy,
&evt->energy_short,
&evt->flags_low_priority,
&evt->flags_high_priority,
&evt->trigger_threashold,
&evt->downSampling,
&evt->board_fail,
&evt->flush,
&evt->aggCounter,
&evt->event_size
);
}
evt->isTraceAllZero = true;
}else if( evt->dataType == DataFormat::Minimum){
if( FPGAType == DPPType::PHA ){
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->energy
);
}else{
ret = CAEN_FELib_ReadData(ep_handle, 100,
&evt->channel,
&evt->timestamp,
&evt->energy,
&evt->energy_short
);
}
evt->isTraceAllZero = true;
}else if( evt->dataType == DataFormat::RAW){
2023-01-25 14:59:48 -05:00
ret = CAEN_FELib_ReadData(ep_handle, 100, evt->data, &evt->dataSize, &evt->n_events );
//printf("data size: %lu byte\n", evt.dataSize);
evt->isTraceAllZero = true; //assume no trace, as the trace need to be extracted.
2023-01-25 14:59:48 -05:00
}else{
return CAEN_FELib_UNKNOWN;
}
if( ret != CAEN_FELib_Success) {
//ErrorMsg("ReadData()");
return ret;
}
return ret;
}
//###########################################
2023-02-14 17:39:49 -05:00
void Digitizer2Gen::OpenOutFile(std::string fileName, const char * mode){
2023-01-25 14:59:48 -05:00
outFileNameBase = fileName;
sprintf(outFileName, "%s_%03d.sol", fileName.c_str(), outFileIndex);
2023-02-14 17:39:49 -05:00
outFile = fopen(outFileName, mode);
2023-01-25 14:59:48 -05:00
fseek(outFile, 0L, SEEK_END);
outFileSize = ftell(outFile); // unsigned int = Max ~4GB
}
void Digitizer2Gen::CloseOutFile(){
2023-03-15 19:10:17 -04:00
if( outFile != NULL ) {
fclose(outFile);
int result = chmod(outFileName, S_IRUSR | S_IRGRP | S_IROTH);
if( result != 0 ) printf("somewrong when set file (%s) to read only.", outFileName);
}
2023-01-25 14:59:48 -05:00
}
void Digitizer2Gen::SaveDataToFile(){
if( outFileSize > (unsigned int) MaxOutFileSize){
FinishedOutFilesSize += ftell(outFile);
2023-03-15 19:10:17 -04:00
CloseOutFile();
2023-01-25 14:59:48 -05:00
outFileIndex ++;
sprintf(outFileName, "%s_%03d.sol", outFileNameBase.c_str(), outFileIndex);
2023-04-04 11:46:02 -04:00
outFile = fopen(outFileName, "wb"); //overwrite binary
2023-01-25 14:59:48 -05:00
}
if( evt->dataType == DataFormat::ALL){
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt->channel, 1, 1, outFile);
fwrite(&evt->energy, 2, 1, outFile);
if( FPGAType == DPPType::PSD ) fwrite(&evt->energy_short, 2, 1, outFile);
fwrite(&evt->timestamp, 6, 1, outFile);
fwrite(&evt->fine_timestamp, 2, 1, outFile);
2023-01-25 14:59:48 -05:00
fwrite(&evt->flags_high_priority, 1, 1, outFile);
fwrite(&evt->flags_low_priority, 2, 1, outFile);
fwrite(&evt->downSampling, 1, 1, outFile);
fwrite(&evt->board_fail, 1, 1, outFile);
fwrite(&evt->flush, 1, 1, outFile);
fwrite(&evt->trigger_threashold, 2, 1, outFile);
fwrite(&evt->event_size, 8, 1, outFile);
fwrite(&evt->aggCounter, 4, 1, outFile);
fwrite(&evt->traceLenght, 8, 1, outFile);
fwrite(evt->analog_probes_type, 2, 1, outFile);
fwrite(evt->digital_probes_type, 4, 1, outFile);
2023-01-25 14:59:48 -05:00
fwrite(evt->analog_probes[0], evt->traceLenght*4, 1, outFile);
fwrite(evt->analog_probes[1], evt->traceLenght*4, 1, outFile);
fwrite(evt->digital_probes[0], evt->traceLenght, 1, outFile);
fwrite(evt->digital_probes[1], evt->traceLenght, 1, outFile);
fwrite(evt->digital_probes[2], evt->traceLenght, 1, outFile);
fwrite(evt->digital_probes[3], evt->traceLenght, 1, outFile);
}else if( evt->dataType == DataFormat::OneTrace){
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt->channel, 1, 1, outFile);
fwrite(&evt->energy, 2, 1, outFile);
if( FPGAType == DPPType::PSD ) fwrite(&evt->energy_short, 2, 1, outFile);
fwrite(&evt->timestamp, 6, 1, outFile);
fwrite(&evt->fine_timestamp, 2, 1, outFile);
fwrite(&evt->flags_high_priority, 1, 1, outFile);
fwrite(&evt->flags_low_priority, 2, 1, outFile);
fwrite(&evt->traceLenght, 8, 1, outFile);
2023-01-25 14:59:48 -05:00
fwrite(&evt->analog_probes_type[0], 1, 1, outFile);
fwrite(evt->analog_probes[0], evt->traceLenght*4, 1, outFile);
}else if( evt->dataType == DataFormat::NoTrace ){
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt->channel, 1, 1, outFile);
fwrite(&evt->energy, 2, 1, outFile);
if( FPGAType == DPPType::PSD ) fwrite(&evt->energy_short, 2, 1, outFile);
fwrite(&evt->timestamp, 6, 1, outFile);
fwrite(&evt->fine_timestamp, 2, 1, outFile);
2023-01-25 14:59:48 -05:00
fwrite(&evt->flags_high_priority, 1, 1, outFile);
fwrite(&evt->flags_low_priority, 2, 1, outFile);
}else if( evt->dataType == DataFormat::Minimum ){
2023-01-25 14:59:48 -05:00
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt->channel, 1, 1, outFile);
fwrite(&evt->energy, 2, 1, outFile);
if( FPGAType == DPPType::PSD ) fwrite(&evt->energy_short, 2, 1, outFile);
fwrite(&evt->timestamp, 6, 1, outFile);
}else if( evt->dataType == DataFormat::RAW){
fwrite(&dataStartIndetifier, 2, 1, outFile);
fwrite(&evt->dataSize, 8, 1, outFile);
2023-01-25 14:59:48 -05:00
fwrite(evt->data, evt->dataSize, 1, outFile);
}
outFileSize = ftell(outFile); // unsigned int = Max ~4GB
}
//###########################################
void Digitizer2Gen::Reset(){ SendCommand("/cmd/Reset"); }
2023-09-21 19:00:48 -04:00
void Digitizer2Gen::ProgramDPPBoard(){
2023-01-25 14:59:48 -05:00
if( !isConnected ) return ;
//============= Board
WriteValue("/par/ClockSource" , "Internal");
WriteValue("/par/EnClockOutFP" , "True");
WriteValue("/par/StartSource" , "SWcmd");
WriteValue("/par/GlobalTriggerSource" , "TrgIn");
WriteValue("/par/TrgOutMode" , "Disabled");
WriteValue("/par/GPIOMode" , "Disabled");
WriteValue("/par/BusyInSource" , "Disabled");
WriteValue("/par/SyncOutMode" , "Disabled");
WriteValue("/par/BoardVetoSource" , "Disabled");
WriteValue("/par/RunDelay" , "0"); // ns, that is for sync time with multi board
WriteValue("/par/IOlevel" , "NIM");
WriteValue("/par/EnAutoDisarmAcq" , "true");
WriteValue("/par/EnStatEvents" , "true");
2023-01-25 14:59:48 -05:00
WriteValue("/par/BoardVetoWidth" , "0");
WriteValue("/par/VolatileClockOutDelay" , "0");
WriteValue("/par/PermanentClockOutDelay" , "0");
WriteValue("/par/DACoutMode" , "ChInput");
WriteValue("/par/DACoutStaticLevel" , "8192");
WriteValue("/par/DACoutChSelect" , "0");
//============== Test pulse
//WriteValue("/par/TestPulsePeriod" , "1000000"); // 1.0 msec = 1000Hz, tested, 1 trace recording
//WriteValue("/par/TestPulseWidth" , "1000"); // nsec
//WriteValue("/par/TestPulseLowLevel" , "0");
//WriteValue("/par/TestPulseHighLevel" , "10000");
//============== ITL
WriteValue("/par/ITLAMainLogic" , "OR");
WriteValue("/par/ITLAMajorityLev" , "2");
WriteValue("/par/ITLAPairLogic" , "NONE");
WriteValue("/par/ITLAPolarity" , "Direct");
WriteValue("/par/ITLAGateWidth" , "100");
WriteValue("/par/ITLBMainLogic" , "OR");
WriteValue("/par/ITLBMajorityLev" , "2");
WriteValue("/par/ITLBPairLogic" , "NONE");
WriteValue("/par/ITLBPolarity" , "Direct");
WriteValue("/par/ITLBGateWidth" , "100");
}
void Digitizer2Gen::ProgramPHAChannels(bool testPulse){
2023-01-25 14:59:48 -05:00
// Channel setting
if( testPulse){
WriteValue("/ch/0..63/par/ChEnable" , "false");
2023-09-21 19:00:48 -04:00
WriteValue("/ch/0..63/par/ChEnable" , "true");
2023-01-25 14:59:48 -05:00
WriteValue("/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
WriteValue("/ch/0..63/par/WaveTriggerSource" , "GlobalTriggerSource"); // EventTriggerSource enought
WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse");
WriteValue("/par/TestPulsePeriod" , "1000000"); // 1.0 msec = 1000Hz, tested, 1 trace recording
WriteValue("/par/TestPulseWidth" , "1000"); // nsec
WriteValue("/par/TestPulseLowLevel" , "0");
WriteValue("/par/TestPulseHighLevel" , "10000");
2023-01-25 14:59:48 -05:00
}else{
//======== Self trigger for each channel
WriteValue("/ch/0..63/par/ChEnable" , "true");
2023-09-21 19:00:48 -04:00
WriteValue("/ch/0..63/par/WaveDaatSource" , "ADC_DATA");
WriteValue("/ch/0..63/par/WaveResolution" , "RES8"); /// 8 ns
WriteValue("/ch/0..63/par/WaveSaving" , "OnRequest");
WriteValue("/ch/0..63/par/PulsePolarity" , "Positive");
WriteValue("/ch/0..63/par/EnergyFilterLFLimitation" , "Off");
WriteValue("/ch/0..63/par/DCOffset" , "10"); /// 10%
WriteValue("/ch/0..63/par/TriggerThr" , "1000");
WriteValue("/ch/0..63/par/TimeFilterRiseTimeS" , "10"); // 80 ns
WriteValue("/ch/0..63/par/TimeFilterRetriggerGuardS" , "10"); // 80 ns
WriteValue("/ch/0..63/par/ChRecordLengthT" , "4096"); /// 4096 ns, S and T are not Sync
WriteValue("/ch/0..63/par/ChPreTriggerT" , "1000"); /// 1000 ns
//======== Trapezoid setting
WriteValue("/ch/0..63/par/EnergyFilterRiseTimeS" , "62"); // 496 ns
WriteValue("/ch/0..63/par/EnergyFilterFlatTopS" , "200"); // 1600 ns
WriteValue("/ch/0..63/par/EnergyFilterPoleZeroS" , "6250"); // 50 us
WriteValue("/ch/0..63/par/EnergyFilterPeakingPosition" , "20"); // 20 % = Flatup * 20% = 320 ns
WriteValue("/ch/0..63/par/EnergyFilterBaselineGuardS" , "100"); // 800 ns
WriteValue("/ch/0..63/par/EnergyFilterPileupGuardS" , "10"); // 80 ns
WriteValue("/ch/0..63/par/EnergyFilterBaselineAvg" , "Medium"); // 1024 sample
WriteValue("/ch/0..63/par/EnergyFilterFineGain" , "1.0");
WriteValue("/ch/0..63/par/EnergyFilterPeakingAvg" , "LowAVG");
//======== Probe Setting
WriteValue("/ch/0..63/par/WaveAnalogProbe0" , "ADCInput");
WriteValue("/ch/0..63/par/WaveAnalogProbe1" , "EnergyFilterMinusBaseline");
WriteValue("/ch/0..63/par/WaveDigitalProbe0" , "Trigger");
WriteValue("/ch/0..63/par/WaveDigitalProbe1" , "EnergyFilterPeaking");
WriteValue("/ch/0..63/par/WaveDigitalProbe2" , "TimeFilterArmed");
WriteValue("/ch/0..63/par/WaveDigitalProbe3" , "EnergyFilterPeakReady");
//======== Trigger setting
WriteValue("/ch/0..63/par/EventTriggerSource" , "ChSelfTrigger");
WriteValue("/ch/0..63/par/WaveTriggerSource" , "Disabled");
WriteValue("/ch/0..63/par/ChannelVetoSource" , "Disabled");
WriteValue("/ch/0..63/par/ChannelsTriggerMask" , "0x0");
WriteValue("/ch/0..63/par/CoincidenceMask" , "Disabled");
WriteValue("/ch/0..63/par/AntiCoincidenceMask" , "Disabled");
WriteValue("/ch/0..63/par/CoincidenceLengthT" , "0");
WriteValue("/ch/0..63/par/ADCVetoWidth" , "0");
//======== Other Setting
WriteValue("/ch/0..63/par/EventSelector" , "All");
WriteValue("/ch/0..63/par/WaveSelector" , "All");
WriteValue("/ch/0..63/par/EnergySkimLowDiscriminator" , "0");
WriteValue("/ch/0..63/par/EnergySkimHighDiscriminator" , "0");
WriteValue("/ch/0..63/par/ITLConnect" , "Disabled");
2023-01-25 14:59:48 -05:00
}
2023-09-21 19:00:48 -04:00
}
void Digitizer2Gen::ProgramPSDChannels(bool testPulse){
if( testPulse){
WriteValue("/ch/0..63/par/ChEnable" , "false");
WriteValue("/ch/0..63/par/ChEnable" , "true");
WriteValue("/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
WriteValue("/ch/0..63/par/WaveTriggerSource" , "GlobalTriggerSource"); // EventTriggerSource enought
WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse");
WriteValue("/par/TestPulsePeriod" , "1000000"); // 1.0 msec = 1000Hz, tested, 1 trace recording
WriteValue("/par/TestPulseWidth" , "1000"); // nsec
WriteValue("/par/TestPulseLowLevel" , "0");
WriteValue("/par/TestPulseHighLevel" , "10000");
}else{
//TODO not finished.
//======== Self trigger for each channel
WriteValue("/ch/0..63/par/ChEnable" , "true");
WriteValue("/ch/0..63/par/WaveDaatSource" , "ADC_DATA");
WriteValue("/ch/0..63/par/WaveResolution" , "RES8"); /// 8 ns
WriteValue("/ch/0..63/par/WaveSaving" , "OnRequest");
WriteValue("/ch/0..63/par/PulsePolarity" , "Positive");
WriteValue("/ch/0..63/par/DCOffset" , "20"); /// 20%
WriteValue("/ch/0..63/par/TriggerThr" , "1000");
WriteValue("/ch/0..63/par/EventNeutronReject", "Disabled");
WriteValue("/ch/0..63/par/WaveNeutronReject", "Disabled");
WriteValue("/ch/0..63/par/WaveAnalogProbe0" , "ADCInput");
WriteValue("/ch/0..63/par/ChRecordLengthT" , "4096"); /// 4096 ns, S and T are not Sync
WriteValue("/ch/0..63/par/ChPreTriggerT" , "1000"); /// 1000 ns
}
2023-01-25 14:59:48 -05:00
}
std::string Digitizer2Gen::ErrorMsg(const char * funcName){
2023-03-16 16:05:55 -04:00
printf("======== %s | %5d | %s\n",__func__, serialNumber, funcName);
2023-01-25 14:59:48 -05:00
char msg[1024];
int ec = CAEN_FELib_GetErrorDescription((CAEN_FELib_ErrorCode) ret, msg);
if (ec != CAEN_FELib_Success) {
std::string errMsg = __func__;
errMsg += " failed";
printf("%s failed\n", __func__);
return errMsg;
}
if( ret != CAEN_FELib_Stop ) printf("Error msg (%d): %s\n", ret, msg);
2023-01-25 14:59:48 -05:00
return msg;
}
2023-02-23 12:24:39 -05:00
//^===================================================== Settings
void Digitizer2Gen::ReadAllSettings(){
2023-02-23 16:08:47 -05:00
if( !isConnected ) return;
printf("Digitizer2Gen::%s | %s \n", __func__, FPGAType.c_str());
2023-02-23 12:24:39 -05:00
for(int i = 0; i < (int) boardSettings.size(); i++){
if( boardSettings[i].ReadWrite() == RW::WriteOnly) continue;
// here TempSens is same for PHA and PSD
if( !(ModelName == "VX2745") &&
(boardSettings[i].GetPara() == PHA::DIG::TempSensADC1.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC2.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC3.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC4.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC5.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC6.GetPara()
)
) continue;
2023-02-23 12:24:39 -05:00
ReadValue(boardSettings[i]);
}
if( ModelName == "VX2745") for(int i = 0; i < 4 ; i ++) ReadValue(VGASetting[i], i);
2023-02-23 12:24:39 -05:00
for( int index = 0; index < 4; index++){
for( int i = 0; i < (int) LVDSSettings[index].size(); i++){
if( LVDSSettings[index][i].ReadWrite() == RW::WriteOnly) continue;
ReadValue(LVDSSettings[index][i], index, false);
//printf("%d %d | %s | %s \n", index, i, LVDSSettings[index][i].GetPara().c_str(), LVDSSettings[index][i].GetValue().c_str());
}
}
2023-02-23 12:24:39 -05:00
for(int ch = 0; ch < nChannels ; ch++ ){
for( int i = 0; i < (int) chSettings[ch].size(); i++){
if( chSettings[ch][i].ReadWrite() == RW::WriteOnly) continue;
ReadValue(chSettings[ch][i], ch);
2023-02-23 12:24:39 -05:00
}
}
2023-02-23 12:24:39 -05:00
}
int Digitizer2Gen::SaveSettingsToFile(const char * saveFileName, bool setReadOnly){
2023-02-23 16:08:47 -05:00
if( saveFileName != NULL) settingFileName = saveFileName;
2023-03-02 15:00:59 -05:00
int totCount = 0;
int count = 0;
2023-02-23 16:08:47 -05:00
FILE * saveFile = fopen(settingFileName.c_str(), "w");
if( saveFile ){
2023-02-23 12:24:39 -05:00
for(int i = 0; i < (int) boardSettings.size(); i++){
if( boardSettings[i].ReadWrite() == RW::WriteOnly) continue;
2023-03-02 15:00:59 -05:00
totCount ++;
//--- exclude Gateway
if( boardSettings[i].GetPara() == PHA::DIG::Gateway.GetPara()) {
totCount --;
continue;
}
//--- exclude some TempSens for Not VX2745
if( ModelName != "VX2745" &&
( boardSettings[i].GetPara() == PHA::DIG::TempSensADC1.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC2.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC3.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC4.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC5.GetPara() ||
boardSettings[i].GetPara() == PHA::DIG::TempSensADC6.GetPara() ) ) {
totCount --;
continue;
}
if( boardSettings[i].GetValue() == "") {
printf(" No value for %s \n", boardSettings[i].GetPara().c_str());
continue;
}
2023-04-03 18:20:36 -04:00
fprintf(saveFile, "%-45s!%d!%4d!%s\n", boardSettings[i].GetFullPara().c_str(),
2023-02-23 12:24:39 -05:00
boardSettings[i].ReadWrite(),
8000 + i,
boardSettings[i].GetValue().c_str());
2023-03-02 15:00:59 -05:00
count ++;
}
if( ModelName == "VX2745" && FPGAType == DPPType::PHA) {
for(int i = 0; i < 4 ; i ++){
totCount ++;
if( VGASetting[i].GetValue() == "" ) {
printf(" No value for %s \n", VGASetting[i].GetPara().c_str());
continue;
}
fprintf(saveFile, "%-45s!%d!%4d!%s\n", VGASetting[i].GetFullPara(i).c_str(),
VGASetting[i].ReadWrite(),
9000 + i,
VGASetting[i].GetValue().c_str());
count ++;
}
}
for( int i = 0; i < (int) LVDSSettings[0].size(); i++){
for( int index = 0; index < 4; index++){
if( LVDSSettings[index][i].ReadWrite() == RW::WriteOnly) continue;
totCount ++;
if( LVDSSettings[index][i].GetValue() == "") {
printf(" No value for %s \n", LVDSSettings[index][i].GetPara().c_str());
continue;
}
fprintf(saveFile, "%-45s!%d!%4d!%s\n", LVDSSettings[index][i].GetFullPara(index).c_str(),
LVDSSettings[index][i].ReadWrite(),
7000 + 4 * index + i,
LVDSSettings[index][i].GetValue().c_str());
count ++;
}
}
for( int i = 0; i < (int) chSettings[0].size(); i++){
for(int ch = 0; ch < nChannels ; ch++ ){
2023-02-23 12:24:39 -05:00
if( chSettings[ch][i].ReadWrite() == RW::WriteOnly) continue;
2023-03-02 15:00:59 -05:00
totCount ++;
if( chSettings[ch][i].GetValue() == "") {
printf("[%i] No value for %s , ch-%02d\n", i, chSettings[ch][i].GetPara().c_str(), ch);
continue;
}
2023-04-03 18:20:36 -04:00
fprintf(saveFile, "%-45s!%d!%4d!%s\n", chSettings[ch][i].GetFullPara(ch).c_str(),
2023-02-23 12:24:39 -05:00
chSettings[ch][i].ReadWrite(),
ch*100 + i,
chSettings[ch][i].GetValue().c_str());
2023-03-02 15:00:59 -05:00
count ++;
}
2023-03-02 15:00:59 -05:00
}
fclose(saveFile);
2023-03-02 15:00:59 -05:00
if( count != totCount ) {
printf("!!!!! some setting is empty. !!!!!! ");
2023-03-02 15:00:59 -05:00
return -1;
}
if( setReadOnly ){
int result = chmod(saveFileName, S_IRUSR | S_IRGRP | S_IROTH);
if( result != 0 ) printf("somewrong when set file (%s) to read only.", saveFileName);
}
2023-02-23 12:24:39 -05:00
//printf("Saved setting files to %s\n", saveFileName);
2023-03-02 15:00:59 -05:00
return 1;
}else{
2023-02-23 12:24:39 -05:00
//printf("Save file accessing error.");
}
2023-02-23 12:24:39 -05:00
2023-03-02 15:00:59 -05:00
return 0;
}
int Digitizer2Gen::ReadAndSaveSettingsToFile(const char *saveFileName){
ReadAllSettings();
return SaveSettingsToFile(saveFileName);
}
2023-02-23 12:24:39 -05:00
bool Digitizer2Gen::LoadSettingsFromFile(const char * loadFileName){
2023-02-23 16:08:47 -05:00
if( loadFileName != NULL) settingFileName = loadFileName;
2023-02-23 12:24:39 -05:00
2023-02-23 16:08:47 -05:00
FILE * loadFile = fopen(settingFileName.c_str(), "r");
if( loadFile ){
2023-02-23 12:24:39 -05:00
char * para = new char[100];
char * readWrite = new char[100];
char * idStr = new char[100];
char * value = new char[100];
char line[100];
while(fgets(line, sizeof(line), loadFile) != NULL){
//printf("%s", line);
2023-04-03 18:20:36 -04:00
char* token = std::strtok(line, "!");
int count = 0;
while( token != nullptr){
char * end = std::remove_if(token, token + std::strlen(token), [](char c) {
return std::isspace(c);
});
*end = '\0';
size_t len = std::strcspn(token, "\n");
if( len > 0 ) token[len] = '\0';
if( count == 0 ) std::strcpy(para, token);
if( count == 1 ) std::strcpy(readWrite, token);
2023-02-23 12:24:39 -05:00
if( count == 2 ) std::strcpy(idStr, token);
if( count == 3 ) std::strcpy(value, token);
if( count > 3) break;
count ++;
2023-04-03 18:20:36 -04:00
token = std::strtok(nullptr, "!");
}
2023-02-23 12:24:39 -05:00
int id = atoi(idStr);
if( id < 7000){ // channel
2023-02-23 12:24:39 -05:00
int ch = id / 100;
int index = id - ch * 100;
chSettings[ch][index].SetValue(value);
//printf("-------id : %d, ch: %d, index : %d\n", id, ch, index);
//printf("%s|%d|%d|%s|\n", chSettings[ch][index].GetFullPara(ch).c_str(),
// chSettings[ch][index].ReadWrite(), id,
// chSettings[ch][index].GetValue().c_str());
}else if ( 7000 <= id && id < 8000){ // LVDS
int index = (id-7000)/4;
int ch = id - 7000 - index * 4;
LVDSSettings[index][ch].SetValue(value);
2023-02-23 12:24:39 -05:00
}else if ( 8000 <= id && id < 9000){ // board
boardSettings[id - 8000].SetValue(value);
//printf("%s|%d|%d|%s\n", boardSettings[id-8000].GetFullPara().c_str(),
// boardSettings[id-8000].ReadWrite(), id,
// boardSettings[id-8000].GetValue().c_str());
}else{ // vga
VGASetting[id - 9000].SetValue(value);
}
//printf("%s|%s|%d|%s|\n", para, readWrite, id, value);
if( std::strcmp(readWrite, "2") == 0 && isConnected) WriteValue(para, value, false);
}
2023-02-23 12:24:39 -05:00
delete [] para;
delete [] readWrite;
delete [] idStr;
delete [] value;
return true;
}else{
2023-02-23 12:24:39 -05:00
//printf("Fail to load file %s\n", loadFileName);
}
2023-02-23 12:24:39 -05:00
return false;
}
std::string Digitizer2Gen::GetSettingValue(const Reg para, unsigned int ch_index) {
int index = FindIndex(para);
switch (para.GetType()){
case TYPE::DIG: return boardSettings[index].GetValue();
case TYPE::CH: return chSettings[ch_index][index].GetValue();
case TYPE::VGA: return VGASetting[ch_index].GetValue();
case TYPE::LVDS: return LVDSSettings[ch_index][index].GetValue();
default : return "invalid";
}
return "no such parameter";
}