FSUDAQ_Qt6/ClassDigitizer.h

143 lines
6.4 KiB
C
Raw Normal View History

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
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;
2023-04-14 16:12:52 -04:00
//^----- adjustable parameters
2023-04-11 11:13:23 -04:00
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; /// 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; ///
bool settingFileExist; ///
bool isSettingFilledinMemeory; /// false for disabled ReadAllSettingFromBoard()
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 = "");
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
void SetChannelMask (uint32_t mask);
void SetChannelOnOff (unsigned short ch, bool onOff);
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
void PrintBoard() ;
2023-04-14 16:12:52 -04:00
virtual int ProgramBoard() ; /// program a generic board, no program channel
2023-04-11 11:13:23 -04:00
int ProgramPHABoard() ; /// program a default PHA board
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;}
void PrintACQStatue();
unsigned int CalByteForBuffer();
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
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),
/// for board setting, ignore ch
uint32_t ReadRegister (Reg registerAddress, unsigned short ch = 0, bool isSave2MemAndFile = true, std::string str = "" );
uint32_t PrintRegister(uint32_t address, std::string msg);
2023-04-14 16:12:52 -04:00
//^================ Get Board info
2023-04-11 11:13:23 -04:00
std::string GetModelName() const {return BoardInfo.ModelName;}
int GetSerialNumber() const {return BoardInfo.SerialNumber;}
int GetChannelMask() const {return channelMask;}
bool GetChannelOnOff(unsigned ch) const {return (channelMask & ( 1 << ch) );}
float GetCh2ns() const {return ch2ns;}
2023-04-17 15:17:25 -04:00
int GetNChannels() const {return NChannel;}
2023-04-11 11:13:23 -04:00
int GetHandle() const {return handle;}
int GetDPPType() const {return DPPType;}
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-14 16:12:52 -04:00
//^================ Setting
2023-04-11 11:13:23 -04:00
Reg FindRegister(uint32_t address);
/// board <--> memory functions
void ReadAllSettingsFromBoard (bool force = false);
void ProgramSettingsToBoard ();
/// simply read settings from memory
void SetSettingToMemory (Reg registerAddress, unsigned int value, unsigned short ch = 0);
unsigned int GetSettingFromMemory (Reg registerAddress, unsigned short ch = 0);
void PrintSettingFromMemory ();
unsigned int * GetSettings() {return setting;};
/// memory <--> file
void SaveAllSettingsAsText (std::string fileName);
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);
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
};
#endif