2023-04-11 11:13:23 -04:00
|
|
|
#ifndef DIGITIZER_H
|
|
|
|
#define DIGITIZER_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstring> ///memset
|
|
|
|
#include <iostream> ///cout
|
|
|
|
#include <bitset>
|
|
|
|
|
|
|
|
#include "CAENDigitizer.h"
|
|
|
|
#include "CAENDigitizerType.h"
|
|
|
|
|
|
|
|
#include "macro.h"
|
|
|
|
#include "ClassData.h"
|
|
|
|
#include "RegisterAddress.h"
|
|
|
|
|
|
|
|
//################################################################
|
|
|
|
class Digitizer{
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Data * data;
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^---- fixed parameter
|
2023-04-11 11:13:23 -04:00
|
|
|
int portID; /// port ID for optical link for using PCIe card, from 0, 1, 2, 3
|
|
|
|
int boardID; /// board identity
|
|
|
|
int handle; /// i don't know why, but better separete the handle from boardID
|
2023-10-09 17:46:32 -04:00
|
|
|
int NumInputCh; /// number of physical input channel
|
|
|
|
int NumRegChannel; /// number of Register channel
|
|
|
|
bool isInputChEqRegCh; /// is number of physical input channel = Register channel
|
2023-10-05 12:26:17 -04:00
|
|
|
int NCoupledCh; /// number of Coupled channel
|
2023-04-11 11:13:23 -04:00
|
|
|
int ADCbits; /// ADC bit
|
|
|
|
int DPPType; /// DPP verion
|
2024-03-02 00:33:08 -05:00
|
|
|
int ModelType; /// VME or DT
|
2023-04-11 11:13:23 -04:00
|
|
|
unsigned int ADCFullSize; /// pow(2, ADCbits) - 1
|
2023-06-20 11:57:39 -04:00
|
|
|
float tick2ns; /// channel to ns
|
2024-03-19 20:20:33 -04:00
|
|
|
unsigned int MemorySizekSample; /// channel Memory size in kSample
|
|
|
|
std::string familyName;
|
|
|
|
|
2023-04-11 11:13:23 -04:00
|
|
|
CAEN_DGTZ_BoardInfo_t BoardInfo;
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^----- adjustable parameters
|
2023-11-06 17:59:16 -05:00
|
|
|
bool softwareDisable; /// not using the whole board
|
2023-10-09 17:46:32 -04:00
|
|
|
uint32_t regChannelMask ; /// the channel mask from NumInputCh
|
2023-04-11 11:13:23 -04:00
|
|
|
uint32_t VMEBaseAddress; /// For direct USB or Optical-link connection, VMEBaseAddress must be 0
|
|
|
|
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)
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^------- other parameters
|
2023-04-11 11:13:23 -04:00
|
|
|
int ret; /// return value, refer to CAEN_DGTZ_ErrorCode
|
|
|
|
bool isConnected; /// true for digitizer communication estabished.
|
|
|
|
bool AcqRun; /// true when digitizer is taking data
|
|
|
|
bool isDummy; /// true for a dummy digitizer.
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^-------- setting
|
2023-04-11 11:13:23 -04:00
|
|
|
std::string settingFileName; ///
|
|
|
|
FILE * settingFile; ///
|
2024-01-18 23:41:18 -05:00
|
|
|
bool isSettingFileExist; ///
|
2024-01-19 14:15:37 -05:00
|
|
|
bool isSettingFileUpdate;
|
2023-04-11 11:13:23 -04:00
|
|
|
bool isSettingFilledinMemeory; /// false for disabled ReadAllSettingFromBoard()
|
2024-11-21 18:21:32 -05:00
|
|
|
bool hasOverThresholdWidth; /// for QDC
|
2023-04-11 11:13:23 -04:00
|
|
|
unsigned int setting[SETTINGSIZE]; /// Setting, 4bytes x 2048 = 8192 bytes
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^-------- other protected functions
|
2023-04-11 11:13:23 -04:00
|
|
|
void ErrorMsg(std::string header = "");
|
|
|
|
|
2023-04-19 13:41:43 -04:00
|
|
|
uint32_t returnData;
|
|
|
|
|
2023-11-07 15:24:28 -05:00
|
|
|
uint32_t acqStatus;
|
|
|
|
|
2024-01-18 23:09:50 -05:00
|
|
|
int ProgramBoard_PHA() ; /// program a default PHA board with dual trace
|
|
|
|
int ProgramBoard_PSD() ;
|
|
|
|
int ProgramBoard_QDC() ;
|
|
|
|
|
2024-11-01 16:42:31 -04:00
|
|
|
int ProgramChannel_PHA(short ch) ; /// program a default PHA Channel for Si-detector, ch = -1 for all channel
|
|
|
|
int ProgramChannel_PSD(short ch) ; /// program a default PSD Channel for Si-detector, ch = -1 for all channel
|
|
|
|
int ProgramChannel_QDC(short group) ; /// program a default QDC group for Si-detector, ch = -1 for all group
|
|
|
|
|
2023-04-11 11:13:23 -04:00
|
|
|
public:
|
|
|
|
Digitizer(); /// no digitizer open
|
|
|
|
Digitizer(int boardID, int portID = 0, bool program = false, bool verbose = false);
|
2023-04-14 16:12:52 -04:00
|
|
|
virtual ~Digitizer();
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^------ portID is for optical link for using PCIe card, from 0, 1, 2, 3
|
2023-04-11 11:13:23 -04:00
|
|
|
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
|
2023-10-09 13:12:48 -04:00
|
|
|
void SetRegChannelMask (uint32_t mask);
|
|
|
|
void SetRegChannelOnOff (unsigned short ch, bool onOff);
|
2023-04-11 11:13:23 -04:00
|
|
|
int CloseDigitizer();
|
|
|
|
void Initalization();
|
|
|
|
void Reset();
|
2023-04-11 14:23:38 -04:00
|
|
|
bool IsDummy() {return isDummy;}
|
|
|
|
bool IsConnected() {return isConnected;}
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-11-06 17:59:16 -05:00
|
|
|
void DisableBoard() {softwareDisable = true;}
|
2024-04-09 15:18:48 -04:00
|
|
|
void EnableBoard() {softwareDisable = false;}
|
2023-11-06 17:59:16 -05:00
|
|
|
bool IsBoardDisabled() const {return softwareDisable;}
|
|
|
|
|
2024-01-18 23:09:50 -05:00
|
|
|
void PrintBoard();
|
|
|
|
void ProgramBoard();
|
2024-11-01 17:03:10 -04:00
|
|
|
void ProgramChannel(short chOrGroup);
|
2024-10-28 15:12:26 -04:00
|
|
|
|
|
|
|
void AutoSetDPPEventAggregation();
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^================ ACQ control
|
2023-04-11 11:13:23 -04:00
|
|
|
void StopACQ();
|
|
|
|
void StartACQ();
|
2023-04-14 16:12:52 -04:00
|
|
|
int ReadData();
|
2023-04-11 11:13:23 -04:00
|
|
|
bool IsRunning() const {return AcqRun;}
|
|
|
|
Data * GetData() const {return data;}
|
2023-11-21 15:34:29 -05:00
|
|
|
uint32_t GetACQStatusFromMemory() const {return acqStatus;}
|
2023-11-07 15:24:28 -05:00
|
|
|
void ReadAndPrintACQStatue();
|
2024-03-22 17:20:07 -04:00
|
|
|
void ReadACQStatus() { // Only use when ACQ is running;
|
2024-03-19 16:13:44 -04:00
|
|
|
// printf("%s\n", __func__);
|
2024-03-22 17:20:07 -04:00
|
|
|
//acqStatus = ReadRegister(DPP::AcquisitionStatus_R);
|
|
|
|
CAEN_DGTZ_ReadRegister(handle, DPP::AcquisitionStatus_R, &acqStatus);
|
2024-03-19 16:13:44 -04:00
|
|
|
}
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2024-03-06 20:10:33 -05:00
|
|
|
unsigned int CalByteForBuffer(bool verbose = false);
|
|
|
|
unsigned int CalByteForBufferCAEN();
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^================= Settings
|
2023-04-11 11:13:23 -04:00
|
|
|
/// write value to digitizer, memory, and settingFile (if exist)
|
|
|
|
/// ONLY WriteRegister can have ch = -1, for writting all channels
|
|
|
|
/// for board setting, ignore ch
|
2023-05-01 16:20:16 -04:00
|
|
|
void WriteRegister (Reg registerAddress, uint32_t value, int ch = -1, bool isSave2MemAndFile = true);
|
2023-04-11 11:13:23 -04:00
|
|
|
/// read value from digitizer and memory, and save to memory, and settingFile(if exist),
|
|
|
|
/// for board setting, ignore ch
|
2023-05-01 16:20:16 -04:00
|
|
|
uint32_t ReadRegister (Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, std::string str = "" );
|
2023-04-11 11:13:23 -04:00
|
|
|
uint32_t PrintRegister(uint32_t address, std::string msg);
|
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^================ Get Board info
|
2023-04-24 17:37:03 -04:00
|
|
|
CAEN_DGTZ_BoardInfo_t GetBoardInfo() const {return BoardInfo;}
|
2023-04-11 11:13:23 -04:00
|
|
|
std::string GetModelName() const {return BoardInfo.ModelName;}
|
|
|
|
int GetSerialNumber() const {return BoardInfo.SerialNumber;}
|
2023-10-09 17:46:32 -04:00
|
|
|
int GetRegChannelMask() { regChannelMask = GetSettingFromMemory(DPP::RegChannelEnableMask); return regChannelMask;}
|
|
|
|
bool GetInputChannelOnOff(unsigned ch) ;
|
|
|
|
float GetTick2ns() const {return tick2ns;}
|
|
|
|
int GetNumInputCh() const {return NumInputCh;}
|
|
|
|
int GetNumRegChannels() const {return NumRegChannel;}
|
|
|
|
bool IsInputChEqRegCh() const {return isInputChEqRegCh;}
|
2023-10-09 13:12:48 -04:00
|
|
|
int GetCoupledChannels() const {return NCoupledCh;}
|
2023-04-11 11:13:23 -04:00
|
|
|
int GetHandle() const {return handle;}
|
|
|
|
int GetDPPType() const {return DPPType;}
|
2024-03-02 00:33:08 -05:00
|
|
|
int GetModelType() const {return ModelType;}
|
2023-04-11 11:13:23 -04:00
|
|
|
std::string GetDPPString(int DPPType = 0); /// if no input, use digitizer DPPType
|
|
|
|
int GetADCBits() const {return BoardInfo.ADC_NBits;}
|
|
|
|
std::string GetROCVersion() const {return BoardInfo.ROC_FirmwareRel;}
|
|
|
|
std::string GetAMCVersion() const {return BoardInfo.AMC_FirmwareRel;}
|
|
|
|
CAEN_DGTZ_ConnectionType GetLinkType() const {return LinkType;}
|
2023-04-20 18:15:30 -04:00
|
|
|
int GetErrorCode() const {return ret;}
|
2024-03-19 20:20:33 -04:00
|
|
|
unsigned int GetChMemSizekSample() const {return MemorySizekSample;}
|
|
|
|
std::string GetFamilyName() const {return familyName;}
|
2024-11-21 18:21:32 -05:00
|
|
|
bool HasOverThresholdWidth_QDC() const {return hasOverThresholdWidth;}
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-14 16:12:52 -04:00
|
|
|
//^================ Setting
|
2023-05-01 16:20:16 -04:00
|
|
|
Reg FindRegister(uint32_t address);
|
2023-04-11 11:13:23 -04:00
|
|
|
/// board <--> memory functions
|
|
|
|
void ReadAllSettingsFromBoard (bool force = false);
|
|
|
|
void ProgramSettingsToBoard ();
|
|
|
|
|
|
|
|
/// simply read settings from memory
|
2023-05-01 16:20:16 -04:00
|
|
|
void SetSettingToMemory (Reg registerAddress, unsigned int value, unsigned short ch = 0);
|
|
|
|
unsigned int GetSettingFromMemory (Reg registerAddress, unsigned short ch = 0);
|
2024-01-18 23:41:18 -05:00
|
|
|
unsigned int * GetSettings() {return setting;}
|
|
|
|
void PrintSettingFromMemory();
|
2024-01-19 14:15:37 -05:00
|
|
|
void SetSettingFileUpdate(bool onOff) {isSettingFileUpdate = onOff;}
|
|
|
|
bool IsSettingFileUpdate() const {return isSettingFileUpdate;}
|
|
|
|
bool IsSettingFileExist() const {return isSettingFileExist;}
|
2023-04-11 11:13:23 -04:00
|
|
|
|
|
|
|
/// memory <--> file
|
|
|
|
void SaveAllSettingsAsText (std::string fileName);
|
2024-02-26 16:17:41 -05:00
|
|
|
void SaveAllSettingsAsTextForRun (std::string fileName);
|
2023-04-11 11:13:23 -04:00
|
|
|
void SaveAllSettingsAsBin (std::string fileName);
|
|
|
|
std::string GetSettingFileName() {return settingFileName;}
|
|
|
|
/// tell the digitizer where to look at the setting file.
|
|
|
|
/// if not exist, call SaveAllSettinsAsBin();
|
|
|
|
void SetSettingBinaryPath (std::string fileName);
|
|
|
|
/// load setting file to memory
|
|
|
|
/// if problem, return -1; load without problem, return 0;
|
|
|
|
int LoadSettingBinaryToMemory (std::string fileName);
|
2023-05-01 16:20:16 -04:00
|
|
|
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
|
2023-04-11 11:13:23 -04:00
|
|
|
|
2023-04-19 18:08:20 -04:00
|
|
|
//============ old methods, that only manipulate digitizer register, not setting in memory
|
2023-04-24 15:27:05 -04:00
|
|
|
void SetDPPAlgorithmControl(uint32_t bit, int ch);
|
2023-05-01 16:20:16 -04:00
|
|
|
unsigned int ReadBits(Reg address, unsigned int bitLength, unsigned int bitSmallestPos, int ch );
|
|
|
|
void SetBits(Reg address, unsigned int bitValue, unsigned int bitLength, unsigned int bitSmallestPos, int ch);
|
|
|
|
void SetBits(Reg address, std::pair<unsigned short, unsigned short> bit, unsigned int bitValue, int ch){ SetBits(address, bitValue, bit.first, bit.second, ch);}
|
2023-04-25 17:04:46 -04:00
|
|
|
static unsigned int ExtractBits(uint32_t value, std::pair<unsigned short, unsigned short> bit){ return ((value >> bit.second) & uint(pow(2, bit.first)-1) ); }
|
2023-04-19 18:08:20 -04:00
|
|
|
|
2023-04-20 18:15:30 -04:00
|
|
|
//====== Board Config breakDown
|
2023-05-23 17:02:39 -04:00
|
|
|
bool IsDualTrace_PHA() {return ( (GetSettingFromMemory(DPP::BoardConfiguration) >> 11) & 0x1 );}
|
|
|
|
bool IsRecordTrace() {return ( (GetSettingFromMemory(DPP::BoardConfiguration) >> 16) & 0x1 );}
|
2023-04-20 18:15:30 -04:00
|
|
|
|
2024-03-19 18:36:49 -04:00
|
|
|
//QDC read recordLength
|
2024-10-28 15:12:26 -04:00
|
|
|
uint32_t ReadQDCRecordLength();
|
|
|
|
void SetQDCOptimialAggOrg();
|
2024-03-19 18:36:49 -04:00
|
|
|
|
2024-09-06 18:16:18 -04:00
|
|
|
void SetTrace(bool onOff){
|
|
|
|
SetBits(DPP::BoardConfiguration, DPP::Bit_BoardConfig::RecordTrace, onOff, -1);
|
|
|
|
}
|
|
|
|
|
2023-04-11 11:13:23 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|