#ifndef DIGITIZER_H #define DIGITIZER_H #include #include #include #include #include ///memset #include ///cout #include #include "CAENDigitizer.h" #include "CAENDigitizerType.h" #include "macro.h" #include "ClassData.h" #include "RegisterAddress.h" using namespace std; //################################################################ class Digitizer{ public: Digitizer(); Digitizer(int boardID, int portID = 0, bool verbose = false); ~Digitizer(); 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 void WriteRegister(uint32_t address, uint32_t value, int ch = -1); uint32_t ReadRegister(uint32_t address, int ch = -1, string str = ""); ///common for PHA and PSD digitizers 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(uint32_t 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;} CAEN_DGTZ_ConnectionType GetLinkType() {return LinkType;} int GetADCBits() {return BoardInfo.ADC_NBits;} std::string GetROCVersion() {return BoardInfo.ROC_FirmwareRel;} std::string GetAMCVersion() {return BoardInfo.AMC_FirmwareRel;} 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(uint32_t address, unsigned int bitLength, unsigned int bitSmallestPos, int ch = -1 ); unsigned int GetDPPAlgorithmControl(int ch = -1) {return ReadRegister(Register::DPP::DPPAlgorithmControl, ch);} 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(); ///================ Setting void OpenSettingBinary(string fileName); //TODO void LoadSettingBinary(string fileName); void CreateAndSaveSettingBinary(string fileName); void EditByte(unsigned int value, uint32_t filePos); void EditByteByRegister(uint32_t registerAddress, int ch = -1); unsigned long ReadSettingBinary(uint32_t filePos, int ch = -1); /// read from setting binary protected: Data * data; ///---- fixed parameter 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 int NChannel; /// number of channel int ADCbits; /// ADC bit int DPPType; /// DPP verion unsigned int ADCFullSize; /// pow(2, ADCbits) - 1 float ch2ns; /// channel to ns CAEN_DGTZ_BoardInfo_t BoardInfo; ///----- adjustable parameters uint32_t channelMask ; /// the channel mask from NChannel uint32_t VMEBaseAddress; /// For direct USB or Optical-link connection, VMEBaseAddress must be 0 CAEN_DGTZ_ConnectionType LinkType; 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; ///------- other parameters int ret; /// return value, refer to CAEN_DGTZ_ErrorCode bool isConnected; bool AcqRun; /// ------- setting string settingFileName; FILE * settingFile; bool settingFileExist; ///========== virtual int ProgramBoard(); void ErrorMsg(string header = ""); }; #endif