clean up again

This commit is contained in:
carina@hades 2022-10-13 18:37:13 -04:00
parent 12d54d2e3b
commit 9f7182673e
2 changed files with 345 additions and 357 deletions

View File

@ -210,46 +210,15 @@ int Digitizer::CloseDigitizer(){
return ret; return ret;
} }
void Digitizer::ErrorMsg(string header){
switch (ret){ void Digitizer::SetChannelMask(uint32_t mask){
///case CAEN_DGTZ_Success : /** 0 */ printf("%s | Operation completed successfully.\n", header.c_str()); break; if( !isConnected ) return;
case CAEN_DGTZ_CommError : /** -1 */ printf("%s | Communication Error.\n", header.c_str()); break; channelMask = mask;
case CAEN_DGTZ_GenericError : /** -2 */ printf("%s | Unspecified error.\n", header.c_str()); break; ret |= CAEN_DGTZ_SetChannelEnableMask(handle, channelMask);
case CAEN_DGTZ_InvalidParam : /** -3 */ printf("%s | Invalid parameter.\n", header.c_str()); break; SaveSettingToFile(Register::DPP::ChannelEnableMask, mask);
case CAEN_DGTZ_InvalidLinkType : /** -4 */ printf("%s | Invalid Link Type.\n", header.c_str()); break; ErrorMsg(__func__);
case CAEN_DGTZ_InvalidHandle : /** -5 */ printf("%s | Invalid device handler.\n", header.c_str()); break;
case CAEN_DGTZ_MaxDevicesError : /** -6 */ printf("%s | Maximum number of devices exceeded.\n", header.c_str()); break;
case CAEN_DGTZ_BadBoardType : /** -7 */ printf("%s | Operation not allowed on this type of board.\n", header.c_str()); break;
case CAEN_DGTZ_BadInterruptLev : /** -8 */ printf("%s | The interrupt level is not allowed.\n", header.c_str()); break;
case CAEN_DGTZ_BadEventNumber : /** -9 */ printf("%s | The event number is bad.\n", header.c_str()); break;
case CAEN_DGTZ_ReadDeviceRegisterFail : /** -10 */ printf("%s | Unable to read the registry.\n", header.c_str()); break;
case CAEN_DGTZ_WriteDeviceRegisterFail : /** -11 */ printf("%s | Unable to write the registry.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidChannelNumber : /** -13 */ printf("%s | The channel number is invalid.\n", header.c_str()); break;
case CAEN_DGTZ_ChannelBusy : /** -14 */ printf("%s | The channel is busy.\n", header.c_str()); break;
case CAEN_DGTZ_FPIOModeInvalid : /** -15 */ printf("%s | Invalid FPIO mode.\n", header.c_str()); break;
case CAEN_DGTZ_WrongAcqMode : /** -16 */ printf("%s | Wrong Acquistion mode.\n", header.c_str()); break;
case CAEN_DGTZ_FunctionNotAllowed : /** -17 */ printf("%s | This function is not allowed on this module.\n", header.c_str()); break;
case CAEN_DGTZ_Timeout : /** -18 */ printf("%s | Communication Timeout.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidBuffer : /** -19 */ printf("%s | The buffer is invalid.\n", header.c_str()); break;
case CAEN_DGTZ_EventNotFound : /** -20 */ printf("%s | The event is not found.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidEvent : /** -21 */ printf("%s | The event is invalid.\n", header.c_str()); break;
case CAEN_DGTZ_OutOfMemory : /** -22 */ printf("%s | Out of memory.\n", header.c_str()); break;
case CAEN_DGTZ_CalibrationError : /** -23 */ printf("%s | Unable to calibrate the board.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerNotFound : /** -24 */ printf("%s | Unbale to open the digitizer.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerAlreadyOpen : /** -25 */ printf("%s | The digitizer is already open.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerNotReady : /** -26 */ printf("%s | The digitizer is not ready.\n", header.c_str()); break;
case CAEN_DGTZ_InterruptNotConfigured : /** -27 */ printf("%s | The digitizer has no IRQ configured.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerMemoryCorrupted: /** -28 */ printf("%s | The digitizer flash memory is corrupted.\n", header.c_str()); break;
case CAEN_DGTZ_DPPFirmwareNotSupported : /** -29 */ printf("%s | The digitier DPP firmware is not supported in this lib version.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidLicense : /** -30 */ printf("%s | Invalid firmware licence.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidDigitizerStatus : /** -31 */ printf("%s | The digitizer is found in a corrupted status.\n", header.c_str()); break;
case CAEN_DGTZ_UnsupportedTrace : /** -32 */ printf("%s | The given trace is not supported.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidProbe : /** -33 */ printf("%s | The given probe is not supported.\n", header.c_str()); break;
case CAEN_DGTZ_UnsupportedBaseAddress : /** -34 */ printf("%s | The base address is not supported.\n", header.c_str()); break;
case CAEN_DGTZ_NotYetImplemented : /** -99 */ printf("%s | The function is not yet implemented.\n", header.c_str()); break;
} }
}
int Digitizer::ProgramBoard(){ int Digitizer::ProgramBoard(){
@ -274,7 +243,7 @@ int Digitizer::ProgramBoard(){
ret |= CAEN_DGTZ_SetChannelEnableMask(handle, channelMask); ret |= CAEN_DGTZ_SetChannelEnableMask(handle, channelMask);
/// Set the number of samples for each waveform /// Set the number of samples for each waveform
SetRecordLength(2000); /// ns ret |= CAEN_DGTZ_SetRecordLength(handle, 2000);
/// Set Extras 2 to enable, this override Accusition mode, focring list mode /// Set Extras 2 to enable, this override Accusition mode, focring list mode
ret |= CAEN_DGTZ_WriteRegister(handle, Register::BoardConfiguration , 0x00E8114 ); ret |= CAEN_DGTZ_WriteRegister(handle, Register::BoardConfiguration , 0x00E8114 );
@ -304,6 +273,61 @@ int Digitizer::ProgramBoard(){
} }
int Digitizer::ProgramPHABoard(){
ret = CAEN_DGTZ_Reset(handle);
printf("======== program board PHA\n");
ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::RecordLength_G + 0x7000, 250);
ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x0F8115);
//TODO change to write register
ret = CAEN_DGTZ_SetAcquisitionMode(handle, CAEN_DGTZ_SW_CONTROLLED); /// software command
ret |= CAEN_DGTZ_SetIOLevel(handle, CAEN_DGTZ_IOLevel_NIM);
ret |= CAEN_DGTZ_SetExtTriggerInputMode(handle, CAEN_DGTZ_TRGMODE_ACQ_ONLY);
ret = CAEN_DGTZ_SetChannelEnableMask(handle, 0xFFFF);
//ret = CAEN_DGTZ_SetNumEventsPerAggregate(handle, 0);
ret = CAEN_DGTZ_SetRunSynchronizationMode(handle, CAEN_DGTZ_RUN_SYNC_Disabled);
if( ret != 0 ) { printf("==== set board error.\n"); return 0;}
printf("======== program Channels PHA\n");
uint32_t address;
address = Register::DPP::PHA::DecayTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 5000 );
address = Register::DPP::PHA::TrapezoidFlatTop; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x62 );
address = Register::DPP::PHA::TrapezoidRiseTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 6 );
address = Register::DPP::PHA::PeakingTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 6 );
address = Register::DPP::PHA::RCCR2SmoothingFactor; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 4 );
address = Register::DPP::PHA::InputRiseTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 6 );
address = Register::DPP::PHA::TriggerThreshold; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 1000 );
address = Register::DPP::PHA::PeakHoldOff; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x3E );
address = Register::DPP::PHA::TriggerHoldOffWidth; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x3E );
address = Register::DPP::PHA::RiseTimeValidationWindow;ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x0 );
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::ChannelDCOffset) + 0x7000 , 0xEEEE );
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::PreTrigger) + 0x7000 , 124 );
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::InputDynamicRange) + 0x7000 , 0x0 );
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::NumberEventsPerAggregate_G) + 0x7000, 511);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::AggregateOrganization), 0);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::MaxAggregatePerBlockTransfer), 40);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::DPPAlgorithmControl) + 0x7000, 0xe30200f);
if( ret != 0 ) { printf("==== set channels error.\n"); return 0;}
printf("End of program board and channels\n");
isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard();
ReadAllSettingsFromBoard();
return ret;
}
//========================================================= ACQ control //========================================================= ACQ control
void Digitizer::StartACQ(){ void Digitizer::StartACQ(){
if ( AcqRun ) return; if ( AcqRun ) return;
@ -387,142 +411,6 @@ uint32_t Digitizer::ReadRegister(Reg registerAddress, unsigned short ch, bool is
} }
void Digitizer::SetChannelMask(uint32_t mask){
if( !isConnected ) return;
channelMask = mask;
ret |= CAEN_DGTZ_SetChannelEnableMask(handle, channelMask);
SaveSettingToFile(Register::DPP::ChannelEnableMask, mask);
ErrorMsg(__func__);
}
void Digitizer::SetRecordLength(unsigned int ns, int ch){
WriteRegister( Register::DPP::RecordLength_G, ns / ch2ns / 8 , ch);
if( ch >= 0 ) WriteRegister( Register::DPP::RecordLength_G, ns / ch2ns / 8 , ch + int(pow(-1, ch)));
ErrorMsg(__func__);
}
void Digitizer::SetAggregateOrganization(unsigned int bit){
WriteRegister(Register::DPP::AggregateOrganization, bit & 0x7);
ErrorMsg(__func__);
}
void Digitizer::SetEventAggregation(unsigned int numEvent, int ch){
WriteRegister( Register::DPP::NumberEventsPerAggregate_G,numEvent, ch);
if( ch >= 0 ) WriteRegister( Register::DPP::NumberEventsPerAggregate_G,numEvent, ch + int(pow(-1, ch)));
ErrorMsg(__func__);
}
void Digitizer::SetMaxAggregatePerBlockTransfer(unsigned int numEvent){
WriteRegister( Register::DPP::MaxAggregatePerBlockTransfer,numEvent);
ErrorMsg(__func__);
}
void Digitizer::SetACQControl(uint32_t bit){
WriteRegister( Register::DPP::AcquisitionControl, bit);
ErrorMsg(__func__);
}
void Digitizer::SetGlobalTriggerMask(uint32_t bit){
WriteRegister( Register::DPP::GlobalTriggerMask, bit);
ErrorMsg(__func__);
}
void Digitizer::SetFrontPanelTRGOUTMask(uint32_t bit){
WriteRegister( Register::DPP::FrontPanelTRGOUTEnableMask, bit);
ErrorMsg(__func__);
}
void Digitizer::SetFrontPanelIOControl(uint32_t bit){
WriteRegister( Register::DPP::FrontPanelIOControl, bit);
ErrorMsg(__func__);
}
void Digitizer::SetTriggerValidationMask(uint32_t bit){
WriteRegister( Register::DPP::TriggerValidationMask_G, bit);
ErrorMsg(__func__);
}
void Digitizer::SetInputDynamicRange(unsigned int TwoVol_0_or_halfVol_1, int ch){ WriteRegister( Register::DPP::InputDynamicRange, TwoVol_0_or_halfVol_1, ch); ErrorMsg(__func__);}
void Digitizer::SetPreTriggerSample(unsigned int nSample, int ch) { WriteRegister( Register::DPP::PreTrigger, nSample / 4, ch); ErrorMsg(__func__);}
void Digitizer::SetPreTriggerDuration(unsigned int ns, int ch) { WriteRegister( Register::DPP::PreTrigger, ns / ch2ns / 4, ch); ErrorMsg(__func__);}
void Digitizer::SetDCOffset(float offsetPrecentage, int ch) { WriteRegister( Register::DPP::ChannelDCOffset, uint( 0xFFFF * (1.0-offsetPrecentage)), ch ); ErrorMsg(__func__);}
void Digitizer::SetVetoWidth(uint32_t bit, int ch) { WriteRegister( Register::DPP::VetoWidth, bit, ch); ErrorMsg(__func__);}
void Digitizer::SetTriggerPolarity(bool RiseingIsZero, int ch ){
if( !isConnected ) return;
if ( DPPType >= 128 ) return; /// do thing for DPP firmware
if( ch < 0 ) {
ret = 0;
for (int i = 0; i < NChannel; i++){
ret |= CAEN_DGTZ_SetTriggerPolarity(handle, i, CAEN_DGTZ_TriggerPolarity_t(RiseingIsZero));
}
}else{
ret = CAEN_DGTZ_SetTriggerPolarity(handle, ch, CAEN_DGTZ_TriggerPolarity_t(RiseingIsZero));
}
if( ret != 0 ) ErrorMsg(__func__);
}
//============================== DPP-Alpgorthm Control
void Digitizer::SetDPPAlgorithmControl(uint32_t bit, int ch){
WriteRegister( Register::DPP::DPPAlgorithmControl, bit, ch);
if( ret != 0 ) ErrorMsg(__func__);
}
unsigned int Digitizer::ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch ){
int tempCh = ch;
if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0
uint32_t bit = ReadRegister(address, tempCh);
bit = (bit >> bitSmallestPos ) & uint(pow(2, bitLength)-1);
return bit;
}
void Digitizer::SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch){
///printf("address : 0x%X, value : 0x%X, len : %d, pos : %d, ch : %d \n", address, bitValue, bitLength, bitSmallestPos, ch);
uint32_t bit ;
uint32_t bitmask = (uint(pow(2, bitLength)-1) << bitSmallestPos);
int tempCh = ch;
if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0
bit = ReadRegister(address, tempCh);
///printf("bit : 0x%X, bitmask : 0x%X \n", bit, bitmask);
bit = (bit & ~bitmask) | (bitValue << bitSmallestPos);
///printf("bit : 0x%X, ch : %d \n", bit, ch);
WriteRegister(address, bit, ch);
if( ret != 0 ) ErrorMsg(__func__);
}
int Digitizer::GetChTemperature(int ch){
if( !isConnected ) return -404;
if( BoardInfo.Model != CAEN_DGTZ_V1730 &&
BoardInfo.Model != CAEN_DGTZ_V1725 &&
BoardInfo.Model != CAEN_DGTZ_V1751 ) return -404;
uint32_t * temp;
ret |= CAEN_DGTZ_ReadTemperature(handle, ch, temp);
if( ret != 0 ) ErrorMsg(__func__);
return temp[0];
}
uint32_t Digitizer::PrintRegister(uint32_t address, std::string msg){
if( !isConnected ) return 0 ;
printf("\e[33m----------------------------------------------------\n");
printf("------------ %s = 0x%X \n", msg.c_str(), address);
printf("----------------------------------------------------\e[0m\n");
uint32_t * value = new uint32_t[1];
CAEN_DGTZ_ReadRegister(handle, address, value);
printf(" %*s 32 28 24 20 16 12 8 4 0\n", (int) msg.length(), "");
printf(" %*s | | | | | | | | |\n", (int) msg.length(), "");
printf(" %*s", (int) msg.length(), "");
cout << " : 0b" << bitset<32>(value[0]) << endl;
printf(" %*s : 0x%X\n", (int) msg.length(), msg.c_str(), value[0]);
return value[0];
}
void Digitizer::PrintACQStatue(){ void Digitizer::PrintACQStatue(){
if( !isConnected ) return; if( !isConnected ) return;
unsigned int status = ReadRegister(Register::DPP::AcquisitionStatus_R); unsigned int status = ReadRegister(Register::DPP::AcquisitionStatus_R);
@ -542,63 +430,6 @@ void Digitizer::PrintACQStatue(){
} }
//=====================================================
int Digitizer::ProgramPHABoard(){
ret = CAEN_DGTZ_Reset(handle);
printf("======== program board PHA\n");
ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::RecordLength_G + 0x7000, 250);
ret = CAEN_DGTZ_WriteRegister(handle, Register::DPP::BoardConfiguration, 0x0F8115);
//TODO change to write register
ret = CAEN_DGTZ_SetAcquisitionMode(handle, CAEN_DGTZ_SW_CONTROLLED); /// software command
ret |= CAEN_DGTZ_SetIOLevel(handle, CAEN_DGTZ_IOLevel_NIM);
ret |= CAEN_DGTZ_SetExtTriggerInputMode(handle, CAEN_DGTZ_TRGMODE_ACQ_ONLY);
ret = CAEN_DGTZ_SetChannelEnableMask(handle, 0xFFFF);
//ret = CAEN_DGTZ_SetNumEventsPerAggregate(handle, 0);
ret = CAEN_DGTZ_SetRunSynchronizationMode(handle, CAEN_DGTZ_RUN_SYNC_Disabled);
if( ret != 0 ) { printf("==== set board error.\n"); return 0;}
printf("======== program Channels PHA\n");
uint32_t address;
address = Register::DPP::PHA::DecayTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 5000 );
address = Register::DPP::PHA::TrapezoidFlatTop; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x62 );
address = Register::DPP::PHA::TrapezoidRiseTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 6 );
address = Register::DPP::PHA::PeakingTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 6 );
address = Register::DPP::PHA::RCCR2SmoothingFactor; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 4 );
address = Register::DPP::PHA::InputRiseTime; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 6 );
address = Register::DPP::PHA::TriggerThreshold; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 1000 );
address = Register::DPP::PHA::PeakHoldOff; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x3E );
address = Register::DPP::PHA::TriggerHoldOffWidth; ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x3E );
address = Register::DPP::PHA::RiseTimeValidationWindow;ret |= CAEN_DGTZ_WriteRegister(handle, address + 0x7000 , 0x0 );
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::ChannelDCOffset) + 0x7000 , 0xEEEE );
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::PreTrigger) + 0x7000 , 124 );
ret |= CAEN_DGTZ_WriteRegister(handle, (uint32_t)(Register::DPP::InputDynamicRange) + 0x7000 , 0x0 );
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::NumberEventsPerAggregate_G) + 0x7000, 511);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::AggregateOrganization), 0);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::MaxAggregatePerBlockTransfer), 40);
ret |= CAEN_DGTZ_WriteRegister(handle, (int32_t)(Register::DPP::DPPAlgorithmControl) + 0x7000, 0xe30200f);
if( ret != 0 ) { printf("==== set channels error.\n"); return 0;}
printf("End of program board and channels\n");
isSettingFilledinMemeory = false; /// unlock the ReadAllSettingsFromBoard();
ReadAllSettingsFromBoard();
return ret;
}
//========================================== setting file IO //========================================== setting file IO
void Digitizer::ReadAllSettingsFromBoard(){ void Digitizer::ReadAllSettingsFromBoard(){
if( !isConnected ) return; if( !isConnected ) return;
@ -791,3 +622,172 @@ void Digitizer::SaveSettingAsText(string fileName){
delete haha; delete haha;
} }
void Digitizer::ErrorMsg(string header){
switch (ret){
///case CAEN_DGTZ_Success : /** 0 */ printf("%s | Operation completed successfully.\n", header.c_str()); break;
case CAEN_DGTZ_CommError : /** -1 */ printf("%s | Communication Error.\n", header.c_str()); break;
case CAEN_DGTZ_GenericError : /** -2 */ printf("%s | Unspecified error.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidParam : /** -3 */ printf("%s | Invalid parameter.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidLinkType : /** -4 */ printf("%s | Invalid Link Type.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidHandle : /** -5 */ printf("%s | Invalid device handler.\n", header.c_str()); break;
case CAEN_DGTZ_MaxDevicesError : /** -6 */ printf("%s | Maximum number of devices exceeded.\n", header.c_str()); break;
case CAEN_DGTZ_BadBoardType : /** -7 */ printf("%s | Operation not allowed on this type of board.\n", header.c_str()); break;
case CAEN_DGTZ_BadInterruptLev : /** -8 */ printf("%s | The interrupt level is not allowed.\n", header.c_str()); break;
case CAEN_DGTZ_BadEventNumber : /** -9 */ printf("%s | The event number is bad.\n", header.c_str()); break;
case CAEN_DGTZ_ReadDeviceRegisterFail : /** -10 */ printf("%s | Unable to read the registry.\n", header.c_str()); break;
case CAEN_DGTZ_WriteDeviceRegisterFail : /** -11 */ printf("%s | Unable to write the registry.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidChannelNumber : /** -13 */ printf("%s | The channel number is invalid.\n", header.c_str()); break;
case CAEN_DGTZ_ChannelBusy : /** -14 */ printf("%s | The channel is busy.\n", header.c_str()); break;
case CAEN_DGTZ_FPIOModeInvalid : /** -15 */ printf("%s | Invalid FPIO mode.\n", header.c_str()); break;
case CAEN_DGTZ_WrongAcqMode : /** -16 */ printf("%s | Wrong Acquistion mode.\n", header.c_str()); break;
case CAEN_DGTZ_FunctionNotAllowed : /** -17 */ printf("%s | This function is not allowed on this module.\n", header.c_str()); break;
case CAEN_DGTZ_Timeout : /** -18 */ printf("%s | Communication Timeout.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidBuffer : /** -19 */ printf("%s | The buffer is invalid.\n", header.c_str()); break;
case CAEN_DGTZ_EventNotFound : /** -20 */ printf("%s | The event is not found.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidEvent : /** -21 */ printf("%s | The event is invalid.\n", header.c_str()); break;
case CAEN_DGTZ_OutOfMemory : /** -22 */ printf("%s | Out of memory.\n", header.c_str()); break;
case CAEN_DGTZ_CalibrationError : /** -23 */ printf("%s | Unable to calibrate the board.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerNotFound : /** -24 */ printf("%s | Unbale to open the digitizer.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerAlreadyOpen : /** -25 */ printf("%s | The digitizer is already open.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerNotReady : /** -26 */ printf("%s | The digitizer is not ready.\n", header.c_str()); break;
case CAEN_DGTZ_InterruptNotConfigured : /** -27 */ printf("%s | The digitizer has no IRQ configured.\n", header.c_str()); break;
case CAEN_DGTZ_DigitizerMemoryCorrupted: /** -28 */ printf("%s | The digitizer flash memory is corrupted.\n", header.c_str()); break;
case CAEN_DGTZ_DPPFirmwareNotSupported : /** -29 */ printf("%s | The digitier DPP firmware is not supported in this lib version.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidLicense : /** -30 */ printf("%s | Invalid firmware licence.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidDigitizerStatus : /** -31 */ printf("%s | The digitizer is found in a corrupted status.\n", header.c_str()); break;
case CAEN_DGTZ_UnsupportedTrace : /** -32 */ printf("%s | The given trace is not supported.\n", header.c_str()); break;
case CAEN_DGTZ_InvalidProbe : /** -33 */ printf("%s | The given probe is not supported.\n", header.c_str()); break;
case CAEN_DGTZ_UnsupportedBaseAddress : /** -34 */ printf("%s | The base address is not supported.\n", header.c_str()); break;
case CAEN_DGTZ_NotYetImplemented : /** -99 */ printf("%s | The function is not yet implemented.\n", header.c_str()); break;
}
}
/**
void Digitizer::SetRecordLength(unsigned int ns, int ch){
WriteRegister( Register::DPP::RecordLength_G, ns / ch2ns / 8 , ch);
if( ch >= 0 ) WriteRegister( Register::DPP::RecordLength_G, ns / ch2ns / 8 , ch + int(pow(-1, ch)));
ErrorMsg(__func__);
}
void Digitizer::SetAggregateOrganization(unsigned int bit){
WriteRegister(Register::DPP::AggregateOrganization, bit & 0x7);
ErrorMsg(__func__);
}
void Digitizer::SetEventAggregation(unsigned int numEvent, int ch){
WriteRegister( Register::DPP::NumberEventsPerAggregate_G,numEvent, ch);
if( ch >= 0 ) WriteRegister( Register::DPP::NumberEventsPerAggregate_G,numEvent, ch + int(pow(-1, ch)));
ErrorMsg(__func__);
}
void Digitizer::SetMaxAggregatePerBlockTransfer(unsigned int numEvent){
WriteRegister( Register::DPP::MaxAggregatePerBlockTransfer,numEvent);
ErrorMsg(__func__);
}
void Digitizer::SetACQControl(uint32_t bit){
WriteRegister( Register::DPP::AcquisitionControl, bit);
ErrorMsg(__func__);
}
void Digitizer::SetGlobalTriggerMask(uint32_t bit){
WriteRegister( Register::DPP::GlobalTriggerMask, bit);
ErrorMsg(__func__);
}
void Digitizer::SetFrontPanelTRGOUTMask(uint32_t bit){
WriteRegister( Register::DPP::FrontPanelTRGOUTEnableMask, bit);
ErrorMsg(__func__);
}
void Digitizer::SetFrontPanelIOControl(uint32_t bit){
WriteRegister( Register::DPP::FrontPanelIOControl, bit);
ErrorMsg(__func__);
}
void Digitizer::SetTriggerValidationMask(uint32_t bit){
WriteRegister( Register::DPP::TriggerValidationMask_G, bit);
ErrorMsg(__func__);
}
void Digitizer::SetInputDynamicRange(unsigned int TwoVol_0_or_halfVol_1, int ch){ WriteRegister( Register::DPP::InputDynamicRange, TwoVol_0_or_halfVol_1, ch); ErrorMsg(__func__);}
void Digitizer::SetPreTriggerSample(unsigned int nSample, int ch) { WriteRegister( Register::DPP::PreTrigger, nSample / 4, ch); ErrorMsg(__func__);}
void Digitizer::SetPreTriggerDuration(unsigned int ns, int ch) { WriteRegister( Register::DPP::PreTrigger, ns / ch2ns / 4, ch); ErrorMsg(__func__);}
void Digitizer::SetDCOffset(float offsetPrecentage, int ch) { WriteRegister( Register::DPP::ChannelDCOffset, uint( 0xFFFF * (1.0-offsetPrecentage)), ch ); ErrorMsg(__func__);}
void Digitizer::SetVetoWidth(uint32_t bit, int ch) { WriteRegister( Register::DPP::VetoWidth, bit, ch); ErrorMsg(__func__);}
void Digitizer::SetTriggerPolarity(bool RiseingIsZero, int ch ){
if( !isConnected ) return;
if ( DPPType >= 128 ) return; /// do thing for DPP firmware
if( ch < 0 ) {
ret = 0;
for (int i = 0; i < NChannel; i++){
ret |= CAEN_DGTZ_SetTriggerPolarity(handle, i, CAEN_DGTZ_TriggerPolarity_t(RiseingIsZero));
}
}else{
ret = CAEN_DGTZ_SetTriggerPolarity(handle, ch, CAEN_DGTZ_TriggerPolarity_t(RiseingIsZero));
}
if( ret != 0 ) ErrorMsg(__func__);
}
//============================== DPP-Alpgorthm Control
void Digitizer::SetDPPAlgorithmControl(uint32_t bit, int ch){
WriteRegister( Register::DPP::DPPAlgorithmControl, bit, ch);
if( ret != 0 ) ErrorMsg(__func__);
}
unsigned int Digitizer::ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch ){
int tempCh = ch;
if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0
uint32_t bit = ReadRegister(address, tempCh);
bit = (bit >> bitSmallestPos ) & uint(pow(2, bitLength)-1);
return bit;
}
void Digitizer::SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch){
///printf("address : 0x%X, value : 0x%X, len : %d, pos : %d, ch : %d \n", address, bitValue, bitLength, bitSmallestPos, ch);
uint32_t bit ;
uint32_t bitmask = (uint(pow(2, bitLength)-1) << bitSmallestPos);
int tempCh = ch;
if (ch < 0 && address < 0x8000 ) tempCh = 0; /// take ch-0
bit = ReadRegister(address, tempCh);
///printf("bit : 0x%X, bitmask : 0x%X \n", bit, bitmask);
bit = (bit & ~bitmask) | (bitValue << bitSmallestPos);
///printf("bit : 0x%X, ch : %d \n", bit, ch);
WriteRegister(address, bit, ch);
if( ret != 0 ) ErrorMsg(__func__);
}
int Digitizer::GetChTemperature(int ch){
if( !isConnected ) return -404;
if( BoardInfo.Model != CAEN_DGTZ_V1730 &&
BoardInfo.Model != CAEN_DGTZ_V1725 &&
BoardInfo.Model != CAEN_DGTZ_V1751 ) return -404;
uint32_t * temp;
ret |= CAEN_DGTZ_ReadTemperature(handle, ch, temp);
if( ret != 0 ) ErrorMsg(__func__);
return temp[0];
}
uint32_t Digitizer::PrintRegister(uint32_t address, std::string msg){
if( !isConnected ) return 0 ;
printf("\e[33m----------------------------------------------------\n");
printf("------------ %s = 0x%X \n", msg.c_str(), address);
printf("----------------------------------------------------\e[0m\n");
uint32_t * value = new uint32_t[1];
CAEN_DGTZ_ReadRegister(handle, address, value);
printf(" %*s 32 28 24 20 16 12 8 4 0\n", (int) msg.length(), "");
printf(" %*s | | | | | | | | |\n", (int) msg.length(), "");
printf(" %*s", (int) msg.length(), "");
cout << " : 0b" << bitset<32>(value[0]) << endl;
printf(" %*s : 0x%X\n", (int) msg.length(), msg.c_str(), value[0]);
return value[0];
}
*/

View File

@ -21,126 +21,6 @@ using namespace std;
//################################################################ //################################################################
class Digitizer{ class Digitizer{
public:
Digitizer(); /// no digitizer open
Digitizer(int boardID, int portID = 0, bool program = false, bool verbose = false);
~Digitizer();
void Initalization();
void Reset();
int OpenDigitizer(int boardID, int portID = 0, bool program = false, bool verbose = false);/// portID is for optical link for using PCIe card, from 0, 1, 2, 3
int CloseDigitizer();
///=================Settings
/// write value to digitizer, memory, and settingFile (if exist)
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),
/// ch must be >= 0,
/// for board setting, ignore ch
uint32_t ReadRegister(Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, string str = "" );
///common for PHA and PSD digitizers
void SetDPPType (int type) { this->DPPType = type;} /// for manual override, or, digitizer does not open
void SetChannelMask (uint32_t mask);
void SetRecordLength (unsigned int ns, int ch = -1); /// when ch == -1, mean set all channels
void SetInputDynamicRange (unsigned int TwoVol_0_or_halfVol_1, int ch = -1);
void SetPreTriggerSample (unsigned int nSample, int ch = -1 );
void SetPreTriggerDuration (unsigned int ns, int ch = -1 );
void SetDCOffset (float offsetPrecentage, int ch = -1);
void SetVetoWidth (uint32_t bit, int ch = -1); /// See manual
void SetTriggerPolarity (bool RiseingIsZero, int ch = -1); ///not used for DPP firmware
void SetEventAggregation (unsigned int numEvent, int ch = -1);
void SetAggregateOrganization (unsigned int bit);
void SetMaxAggregatePerBlockTransfer (unsigned int numEvent);
void SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1);
void SetDPPAlgorithmControl(uint32_t bit, int ch = -1);
void SetACQControl(uint32_t bit);
void SetGlobalTriggerMask(uint32_t bit);
void SetFrontPanelTRGOUTMask(uint32_t bit);
void SetFrontPanelIOControl(uint32_t bit);
void SetTriggerValidationMask(uint32_t bit);
//void SetBoardID(unsigned int ID) {WriteRegister(Register::DPP::BoardID, ID));
///================ Get Settings
std::string GetModelName() {return BoardInfo.ModelName;}
int GetSerialNumber() {return BoardInfo.SerialNumber;}
int GetChannelMask() {return channelMask;}
bool GetChannelOnOff(unsigned ch) {return (channelMask & ( 1 << ch) );}
float GetCh2ns() {return ch2ns;}
int GetNChannel() {return NChannel;}
int GetHandle() {return handle;}
bool GetConnectionStatus() {return isConnected;}
int GetDPPType() {return DPPType;}
std::string GetDPPTypeString() {return DPPTypeStr;}
int GetADCBits() {return BoardInfo.ADC_NBits;}
std::string GetROCVersion() {return BoardInfo.ROC_FirmwareRel;}
std::string GetAMCVersion() {return BoardInfo.AMC_FirmwareRel;}
CAEN_DGTZ_ConnectionType GetLinkType() {return LinkType;}
int GetChTemperature(int ch) ;
unsigned int GetRecordLengthSample(int ch) {return ReadRegister(Register::DPP::RecordLength_G, ch) * 8;}
unsigned int GetInputDynamicRange(int ch) {return ReadRegister(Register::DPP::InputDynamicRange, ch);}
unsigned int GetPreTriggerSample(int ch) {return ReadRegister(Register::DPP::PreTrigger, ch) * 4;}
float GetDCOffset(int ch) {return 100.0 - ReadRegister(Register::DPP::ChannelDCOffset, ch) * 100. / 0xFFFFF; }
unsigned int GetVetoWidth(int ch) {return ReadRegister(Register::DPP::VetoWidth, ch);}
unsigned int GetEventAggregation(int ch = -1) {return ReadRegister(Register::DPP::NumberEventsPerAggregate_G, ch);}
unsigned int GetAggregateOrganization() {return ReadRegister(Register::DPP::AggregateOrganization);}
unsigned int GetMaxNumberOfAggregatePerBlockTransfer() {return ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer);}
unsigned int ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1 );
unsigned int GetDPPAlgorithmControl(int ch = -1) {return ReadRegister(Register::DPP::DPPAlgorithmControl, ch);}
bool IsRunning() {return AcqRun;}
uint32_t PrintRegister(uint32_t address, std::string msg);
void PrintBoard();
void PrintACQStatue();
///================ ACQ control
void StopACQ();
void StartACQ();
void ReadData();
Data * GetData(){ return data;}
unsigned int CalByteForBuffer();
int ProgramPHABoard();
///================ Setting
//unsigned short CalSettingIndex (uint32_t registerAddress, int ch = -1); /// real address is CalSettingIndex() * 4
//void FillSetting (Reg registerAddress, int ch = -1); /// Read DIgitizer Setting and save to memory and binary
/// board <--> memory functions
void ReadAllSettingsFromBoard ();
void SetSettingFromMemory (Reg registerAddress, int ch = -1); /// write to digitizer
void ProgramSettingsToBoard ();
/// simply read settings from memory
void SetSettingToMemory (Reg registerAddress, unsigned int value, int ch = -1);
unsigned int GetSettingFromMemory (Reg registerAddress, int ch = -1);
void PrintSettingFromMemory ();
unsigned int * GetSetting() {return setting;};
/// memory <--> file
void OpenSettingBinary (string fileName); /// Open setting file, if file not exist, call CreateAndSaveSetiingFile, if file exit simple set the settignFileName
void LoadSettingBinary (string fileName); /// load settign file to memory, if digitizer connected, program digitizer
void SaveSettingToFile (Reg registerAddress, unsigned int value, int ch = -1);
unsigned int ReadSettingFromFile (Reg registerAddress, int ch = -1); /// read from setting binary
void SaveSettingAsText (string fileName);
string GetSettingFileName() {return settingFileName;}
virtual int ProgramBoard();
protected: protected:
Data * data; Data * data;
@ -160,25 +40,133 @@ class Digitizer{
///----- adjustable parameters ///----- adjustable parameters
uint32_t channelMask ; /// the channel mask from NChannel uint32_t channelMask ; /// the channel mask from NChannel
uint32_t VMEBaseAddress; /// For direct USB or Optical-link connection, VMEBaseAddress must be 0 uint32_t VMEBaseAddress; /// For direct USB or Optical-link connection, VMEBaseAddress must be 0
CAEN_DGTZ_ConnectionType LinkType; CAEN_DGTZ_ConnectionType LinkType; /// USB or Optic
CAEN_DGTZ_IOLevel_t IOlev; /// TTL signal (1 = 1.5 to 5V, 0 = 0 to 0.7V ) or NIM signal (1 = -1 to -0.8V, 0 = 0V) CAEN_DGTZ_IOLevel_t IOlev; /// TTL signal (1 = 1.5 to 5V, 0 = 0 to 0.7V ) or NIM signal (1 = -1 to -0.8V, 0 = 0V)
CAEN_DGTZ_DPP_AcqMode_t AcqMode; CAEN_DGTZ_DPP_AcqMode_t AcqMode;
///------- other parameters ///------- other parameters
int ret; /// return value, refer to CAEN_DGTZ_ErrorCode int ret; /// return value, refer to CAEN_DGTZ_ErrorCode
bool isConnected; bool isConnected; /// true for digitizer communication estabished.
bool AcqRun; bool AcqRun; /// true when digitizer is taking data
/// ------- setting /// ------- setting
string settingFileName; string settingFileName; ///
FILE * settingFile; FILE * settingFile; ///
bool settingFileExist; bool settingFileExist; ///
bool isSettingFilledinMemeory; /// false for disabled ReadAllSettingFromBoard()
unsigned int setting[SETTINGSIZE]; /// Setting, 4bytes x 2048 = 8192 bytes unsigned int setting[SETTINGSIZE]; /// Setting, 4bytes x 2048 = 8192 bytes
bool isSettingFilledinMemeory;
///========== ///---------- protected functions
void ErrorMsg(string header = ""); void ErrorMsg(string header = "");
public:
Digitizer(); /// no digitizer open
Digitizer(int boardID, int portID = 0, bool program = false, bool verbose = false);
~Digitizer();
/// portID is for optical link for using PCIe card, from 0, 1, 2, 3
int OpenDigitizer(int boardID, int portID = 0, bool program = false, bool verbose = false);
void SetDPPType (int type) { this->DPPType = type;} /// for manual override, or, digitizer does not open
void SetChannelMask (uint32_t mask);
int CloseDigitizer();
void Initalization();
void Reset();
void PrintBoard();
virtual int ProgramBoard(); /// program a generic board, no program channel
int ProgramPHABoard(); /// program a default PHA board
///================ ACQ control
void StopACQ();
void StartACQ();
void ReadData();
bool IsRunning() {return AcqRun;}
Data * GetData(){ return data;}
void PrintACQStatue();
unsigned int CalByteForBuffer();
///=================Settings
/// write value to digitizer, memory, and settingFile (if exist)
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),
/// ch must be >= 0,
/// for board setting, ignore ch
uint32_t ReadRegister(Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, string str = "" );
uint32_t PrintRegister(uint32_t address, std::string msg);
///================ Get Settings
std::string GetModelName() {return BoardInfo.ModelName;}
int GetSerialNumber() {return BoardInfo.SerialNumber;}
int GetChannelMask() {return channelMask;}
bool GetChannelOnOff(unsigned ch) {return (channelMask & ( 1 << ch) );}
float GetCh2ns() {return ch2ns;}
int GetNChannel() {return NChannel;}
int GetHandle() {return handle;}
bool GetConnectionStatus() {return isConnected;}
int GetDPPType() {return DPPType;}
std::string GetDPPTypeString() {return DPPTypeStr;}
int GetADCBits() {return BoardInfo.ADC_NBits;}
std::string GetROCVersion() {return BoardInfo.ROC_FirmwareRel;}
std::string GetAMCVersion() {return BoardInfo.AMC_FirmwareRel;}
CAEN_DGTZ_ConnectionType GetLinkType() {return LinkType;}
///================ Setting
/// board <--> memory functions
void ReadAllSettingsFromBoard ();
void SetSettingFromMemory (Reg registerAddress, int ch = -1); /// write to digitizer
void ProgramSettingsToBoard ();
/// simply read settings from memory
void SetSettingToMemory (Reg registerAddress, unsigned int value, int ch = -1);
unsigned int GetSettingFromMemory (Reg registerAddress, int ch = -1);
void PrintSettingFromMemory ();
unsigned int * GetSetting() {return setting;};
/// memory <--> file
string GetSettingFileName() {return settingFileName;}
void OpenSettingBinary (string fileName); /// Open setting file, if file not exist, call CreateAndSaveSetiingFile, if file exit simple set the settignFileName
void LoadSettingBinary (string fileName); /// load settign file to memory, if digitizer connected, program digitizer
void SaveSettingToFile (Reg registerAddress, unsigned int value, int ch = -1);
unsigned int ReadSettingFromFile (Reg registerAddress, int ch = -1); /// read from setting binary
void SaveSettingAsText (string fileName);
///=================== Relic methods
///void SetRecordLength (unsigned int ns, int ch = -1); /// when ch == -1, mean set all channels
///void SetInputDynamicRange (unsigned int TwoVol_0_or_halfVol_1, int ch = -1);
///void SetPreTriggerSample (unsigned int nSample, int ch = -1 );
///void SetPreTriggerDuration (unsigned int ns, int ch = -1 );
///void SetDCOffset (float offsetPrecentage, int ch = -1);
///void SetVetoWidth (uint32_t bit, int ch = -1); /// See manual
///void SetTriggerPolarity (bool RiseingIsZero, int ch = -1); ///not used for DPP firmware
///
///void SetEventAggregation (unsigned int numEvent, int ch = -1);
///void SetAggregateOrganization (unsigned int bit);
///void SetMaxAggregatePerBlockTransfer (unsigned int numEvent);
///
///void SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1);
///void SetDPPAlgorithmControl(uint32_t bit, int ch = -1);
///
///void SetACQControl(uint32_t bit);
///void SetGlobalTriggerMask(uint32_t bit);
///void SetFrontPanelTRGOUTMask(uint32_t bit);
///void SetFrontPanelIOControl(uint32_t bit);
///void SetTriggerValidationMask(uint32_t bit);
///void SetBoardID(unsigned int ID) {WriteRegister(Register::DPP::BoardID, ID));
///unsigned int GetRecordLengthSample(int ch) {return ReadRegister(Register::DPP::RecordLength_G, ch) * 8;}
///unsigned int GetInputDynamicRange(int ch) {return ReadRegister(Register::DPP::InputDynamicRange, ch);}
///unsigned int GetPreTriggerSample(int ch) {return ReadRegister(Register::DPP::PreTrigger, ch) * 4;}
///float GetDCOffset(int ch) {return 100.0 - ReadRegister(Register::DPP::ChannelDCOffset, ch) * 100. / 0xFFFFF; }
///unsigned int GetVetoWidth(int ch) {return ReadRegister(Register::DPP::VetoWidth, ch);}
///unsigned int GetEventAggregation(int ch = -1) {return ReadRegister(Register::DPP::NumberEventsPerAggregate_G, ch);}
///unsigned int GetAggregateOrganization() {return ReadRegister(Register::DPP::AggregateOrganization);}
///unsigned int GetMaxNumberOfAggregatePerBlockTransfer() {return ReadRegister(Register::DPP::MaxAggregatePerBlockTransfer);}
///
///unsigned int ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1 );
///unsigned int GetDPPAlgorithmControl(int ch = -1) {return ReadRegister(Register::DPP::DPPAlgorithmControl, ch);}
///
///int GetChTemperature(int ch) ;
}; };