working on test_indep.cpp for most simplifiest DAQ

This commit is contained in:
Ryan Tang 2022-12-02 17:33:02 -05:00
commit 2b3b48bc77
7 changed files with 996 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
test
test_indep
*.o

341
ClassDigitizer2Gen.cpp Normal file
View File

@ -0,0 +1,341 @@
#include "ClassDigitizer2Gen.h"
Digitizer2Gen::Digitizer2Gen(){
printf("======== %s \n",__func__);
Initialization();
}
Digitizer2Gen::~Digitizer2Gen(){
printf("======== %s \n",__func__);
if(isConnected ) CloseDigitizer();
}
void Digitizer2Gen::Initialization(){
printf("======== %s \n",__func__);
handle = 0;
ret = 0;
isConnected = false;
modelName = "";
cupVersion = "";
DPPVersion = "";
DPPType = "";
serialNumber = 0;
adcBits = 0;
nChannels = 0;
adcRate = 0;
ch2ns = 0;
IPAddress = "";
netMask = "";
gateway = "";
}
//########################## 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
std::string Digitizer2Gen::ReadValue(const char * parameter){
if( !isConnected ) return "not connected";
printf(" %s|%s \n", __func__, parameter);
ret = CAEN_FELib_GetValue(handle, parameter, retValue);
if (ret != CAEN_FELib_Success) return ErrorMsg(__func__);
return retValue;
}
void Digitizer2Gen::WriteValue(const char * parameter, std::string value){
if( !isConnected );
printf(" %s| %-45s : %s\n", __func__, parameter, value.c_str());
ret = CAEN_FELib_SetValue(handle, parameter, value.c_str());
if (ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return;
}
}
void Digitizer2Gen::SendCommand(const char * parameter){
if( !isConnected );
printf("Send Command : %s \n", parameter);
ret = CAEN_FELib_SendCommand(handle, parameter);
if (ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return;
}
}
//############################## Open digitizer
int Digitizer2Gen::OpenDigitizer(const char * url){
printf("======== %s \n",__func__);
ret = CAEN_FELib_Open(url, &handle);
printf("=== ret : %d | %d \n", ret, CAEN_FELib_Success);
if (ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return -1;
}
isConnected = true;
modelName = ReadValue("/par/ModelName");
cupVersion = ReadValue("/par/cupver");
DPPVersion = ReadValue("/par/FPGA_FwVer");
DPPType = ReadValue("/par/FwType");
serialNumber = atoi(ReadValue("/par/SerialNum").c_str());
nChannels = atoi(ReadValue("/par/NumCh").c_str());
adcBits = atoi(ReadValue("/par/ADC_Nbit").c_str());
adcRate = atoi(ReadValue("/par/ADC_SamplRate").c_str());
ch2ns = 1000/adcRate;
IPAddress = ReadValue("/par/IPAddress");
netMask = ReadValue("/par/Netmask");
gateway = ReadValue("/par/Gateway");
printf(" IP address : %s\n", IPAddress.c_str());
printf(" Net Mask : %s\n", netMask.c_str());
printf(" Gateway : %s\n", gateway.c_str());
printf(" Model name : %s\n", modelName.c_str());
printf(" CUP version : %s\n", cupVersion.c_str());
printf(" DPP Type : %s\n", DPPType.c_str());
printf(" DPP Version : %s\n", DPPVersion.c_str());
printf("Serial number : %d\n", serialNumber);
printf(" ADC bits : %d\n", adcBits);
printf(" ADC rate : %d Msps, ch2ns : %d ns\n", adcRate, ch2ns);
printf(" Channels : %d\n", nChannels);
///========== get endpoint and endpoint folder handle
ret = CAEN_FELib_GetHandle(handle, "/endpoint/dpppha", &ep_handle);
if (ret != CAEN_FELib_Success) {
ErrorMsg("Get Handle");
return -2;
}
ret = CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle);
if (ret != CAEN_FELib_Success) {
ErrorMsg("GetParentHandle");
return -3;
}
///SendCommand("/cmd/reset");
return 0;
}
int Digitizer2Gen::CloseDigitizer(){
printf("======== %s \n",__func__);
ret = CAEN_FELib_Close(handle);
if (ret != CAEN_FELib_Success) {
ErrorMsg(__func__);
return 0;
}
isConnected = false;
return 0;
}
//################################## DAQ
void Digitizer2Gen::StartACQ(){
SendCommand("/cmd/armacquisition");
SendCommand("/cmd/swstartacquisition");
}
void Digitizer2Gen::StopACQ(){
SendCommand("/cmd/disarmacquisition");
}
void Digitizer2Gen::SetPHADataFormat(){
ret = CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "dpppha");
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set active endpoint");
return;
}
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\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
] \
");
if (ret != CAEN_FELib_Success) {
ErrorMsg("Set Read Data Format");
return;
}
}
struct event {
uint8_t channel;
uint64_t timestamp;
double timestamp_us;
uint16_t fine_timestamp;
uint16_t energy;
uint16_t flags_low_priority;
uint16_t flags_high_priority;
size_t event_size;
int32_t* analog_probes[2];
uint8_t* digital_probes[4];
uint8_t analog_probes_type[2];
uint8_t digital_probes_type[4];
size_t n_allocated_samples;
size_t n_samples;
};
void Digitizer2Gen::ReadData(){
printf("========= %s \n", __func__);
event evt;
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.n_samples,
evt.flags_low_priority,
evt.flags_high_priority,
evt.event_size
);
if( ret != CAEN_FELib_Success) {
ErrorMsg("Set Read Data");
return;
}
}
//##########################################
void Digitizer2Gen::ProgramPHA(){
if( !isConnected ) return ;
// Channel enable
WriteValue("/ch/0..63/par/ChEnable" , "true");
// Global trigger configuration
///WriteValue("/par/GlobalTriggerSource", "SwTrg");
WriteValue("/par/GlobalTriggerSource", "SwTrg | TestPulse");
WriteValue("/par/TestPulsePeriod" , "100000000");
WriteValue("/par/TestPulseWidth" , "16");
// Wave configuration
WriteValue("/ch/0..63/par/WaveTriggerSource" , "GlobalTriggerSource");
WriteValue("/ch/0..63/par/ChRecordLengthS" , "512");
WriteValue("/ch/0..63/par/ChPreTriggerS" , "100");
WriteValue("/ch/0..63/par/WaveResolution" , "RES8"); /// 8 ns
WriteValue("/ch/0..63/par/WaveAnalogProbe0" , "ADCInput");
WriteValue("/ch/0..63/par/WaveAnalogProbe1" , "TimeFilter");
WriteValue("/ch/0..63/par/WaveDigitalProbe0" , "Trigger");
WriteValue("/ch/0..63/par/WaveDigitalProbe1" , "TimeFilterArmed");
WriteValue("/ch/0..63/par/WaveDigitalProbe2" , "EnergyFilterBaselineFreeze");
WriteValue("/ch/0..63/par/WaveDigitalProbe3" , "EnergyFilterPeakReady");
// Event configuration
WriteValue("/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
// Filter parameters
WriteValue("/ch/0..63/par/TimeFilterRiseTimeS" , "10");
WriteValue("/ch/0..63/par/TriggerThr" , "3");
WriteValue("/ch/0..63/par/PulsePolarity" , "Positive");
WriteValue("/ch/0..63/par/EnergyFilterBaselineAvg" , "Medium");
WriteValue("/ch/0..63/par/EnergyFilterFineGain" , "1.0");
WriteValue("/ch/0..63/par/EnergyFilterRiseTimeS" , "100");
WriteValue("/ch/0..63/par/EnergyFilterFlatTopS" , "100");
WriteValue("/ch/0..63/par/EnergyFilterPoleZeroS" , "1000");
WriteValue("/ch/0..63/par/EnergyFilterPeakingPosition" , "80");
WriteValue("/ch/0..63/par/TimeFilterRetriggerGuardS" , "10");
WriteValue("/ch/0..63/par/EnergyFilterPileupGuardT" , "10");
WriteValue("/ch/0..63/par/EnergyFilterBaselineGuardS" , "100");
WriteValue("/ch/0..63/par/EnergyFilterLFLimitation" , "Off");
}
std::string Digitizer2Gen::ErrorMsg(const char * funcName){
printf("======== %s | %s\n",__func__, funcName);
char msg[1024];
int ec = CAEN_FELib_GetLastError(msg);
if (ec != CAEN_FELib_Success) {
std::string errMsg = __func__;
errMsg += " failed";
printf("%s failed\n", __func__);
return errMsg;
}
printf("last error: %s\n", msg);
return msg;
}

70
ClassDigitizer2Gen.h Normal file
View File

@ -0,0 +1,70 @@
#ifndef DIGITIZER_CLASS_H
#define DIGITIZER_CLASS_H
#include <CAEN_FELib.h>
#include <cstdlib>
#include <string>
//#include "Parameter.h"
class Digitizer2Gen {
private:
uint64_t handle;
uint64_t ep_handle; ///end point handle
uint64_t ep_folder_handle; ///end point folder handle
bool isConnected;
int ret;
char retValue[256];
std::string modelName;
std::string cupVersion;
std::string DPPVersion;
std::string DPPType;
unsigned short serialNumber;
unsigned short adcBits;
unsigned short nChannels;
unsigned short adcRate;
unsigned short ch2ns;
std::string IPAddress;
std::string netMask;
std::string gateway;
void Initialization();
std::string ErrorMsg(const char * funcName);
public:
Digitizer2Gen();
~Digitizer2Gen();
int OpenDigitizer(const char * url);
int CloseDigitizer();
std::string ReadValue(const char * parameter);
void WriteValue(const char * parameter, std::string value);
void SendCommand(const char * parameter);
uint64_t GetHandle(const char * parameter);
uint64_t GetParentHandle(uint64_t handle);
std::string GetPath(uint64_t handle);
void StartACQ();
void StopACQ();
void SetPHADataFormat();
void ReadData();
void ProgramPHA();
unsigned short GetNChannels() {return nChannels;}
unsigned short GetCh2ns() {return ch2ns;}
uint64_t GetHandle() {return handle;}
};
#endif

13
Makefile Normal file
View File

@ -0,0 +1,13 @@
CC = g++
COPTS = -fPIC -DLINUX -O2 -std=c++17 -lpthread
CAENLIBS = -lCAEN_FELib
test_indep : test_indep.cpp
$(CC) $(COPTS) -o test_indep test_indep.cpp $(CAENLIBS)
test : test.cpp ClassDigitizer2Gen.o
$(CC) $(COPTS) -o test test.cpp ClassDigitizer2Gen.o $(CAENLIBS)
ClassDigitizer2Gen.o : ClassDigitizer2Gen.cpp ClassDigitizer2Gen.h Parameter.h
$(CC) $(COPTS) -c ClassDigitizer2Gen.cpp $(CAENLIBS)

207
Parameter.h Normal file
View File

@ -0,0 +1,207 @@
#ifndef PARAMETER_H
#define PARAMETER_H
enum Type { DIG = 0, CH = 1, LVDS = 2, VGA = 3};
enum RW { ReadWrite = 0, ReadONLY = 1, WriteONLY = 2};
class Par{
public:
Par( const char * string, unsigned short type, unsigned short readWrite = RW::ReadWrite){
this->str = string;
this->type = type;
this->ReadWrite = readWrite;
}
~Par(){};
operator const char * () const {return this->str;}
unsigned short IsReadWrtie() const {return this->ReadWrite;}
unsigned short GetType() const {return this->type;}
private:
const char * str; /// 32bits
unsigned short type;
unsigned short ReadWrite;
};
namespace Parameter{
//######### PHA
///======= board settings
const Par CUPVersion ("CupVer" , Type::DIG, RW::ReadONLY);
const Par FPGAVersion ("FPGA_FwVer" , Type::DIG, RW::ReadONLY);
const Par DPPType ("FwType" , Type::DIG, RW::ReadONLY);
const Par ModelCode ("ModelCode" , Type::DIG, RW::ReadONLY);
const Par PiggyBackCode ("PBCode" , Type::DIG, RW::ReadONLY);
const Par ModelName ("ModelName" , Type::DIG, RW::ReadONLY);
const Par FormFactor ("FormFactor" , Type::DIG, RW::ReadONLY);
const Par FamilyCode ("FamilyCode" , Type::DIG, RW::ReadONLY);
const Par SerialNumber ("SerialNum" , Type::DIG, RW::ReadONLY);
const Par PCBrevision_MB ("PCBrev_MB" , Type::DIG, RW::ReadONLY); /// mother board
const Par PCBrevision_PB ("PCBrev_PB" , Type::DIG, RW::ReadONLY); /// piggy back
const Par Licence ("License" , Type::DIG, RW::ReadONLY);
const Par LicenceStatus ("LicenseStatus" , Type::DIG, RW::ReadONLY);
const Par LicenceRemainingTime ("LicenseRemainingTime" , Type::DIG, RW::ReadONLY);
const Par NumCh ("NumCh" , Type::DIG, RW::ReadONLY);
const Par ADC_Nbit ("ADC_Nbit" , Type::DIG, RW::ReadONLY);
const Par ADC_SampleRate ("ADC_SamplRate" , Type::DIG, RW::ReadONLY);
const Par InputRange ("InputRate" , Type::DIG, RW::ReadONLY); /// input dynamic range
const Par Inputtype ("InputType" , Type::DIG, RW::ReadONLY);
const Par InputImpedance ("Zin" , Type::DIG, RW::ReadONLY);
const Par IPAddress ("IPAddress" , Type::DIG, RW::ReadONLY);
const Par Netmask ("Netmask" , Type::DIG, RW::ReadONLY);
const Par Gateway ("Gateway" , Type::DIG, RW::ReadONLY);
const Par ClockSource ("ClockSource" , Type::DIG, RW::ReadWrite);
const Par EnableClockOutputP0 ("EnClockOutP0" , Type::DIG, RW::ReadWrite); /// P0 connector, backplane
const Par EnableClockOutputFP ("EnClockOutFP" , Type::DIG, RW::ReadWrite); /// front panel
///======= Acquistion, trigger and VETO
const Par StartSource ("StartSource" , Type::DIG, RW::ReadWrite);
const Par GlobalTriggerSource ("GlobalTriggerSource" , Type::DIG, RW::ReadWrite);
const Par WaveTriggerSource ("WaveTriggerSource" , Type::CH , RW::ReadWrite);
const Par EventTriggerSource ("EventTriggerSource" , Type::CH , RW::ReadWrite);
const Par ChannelsTriggerSource ("ChannelsTriggerSource" , Type::CH , RW::ReadWrite);
const Par WaveSaving ("WaveSaving" , Type::CH , RW::ReadWrite);
const Par TrgOutMode ("TrgOutMode" , Type::DIG, RW::ReadWrite);
const Par GPIOMode ("GPIOtMode" , Type::DIG, RW::ReadWrite);
const Par BusyInSource ("BusyInSource" , Type::DIG, RW::ReadWrite);
const Par SyncOutMode ("SyncOutMode" , Type::DIG, RW::ReadWrite);
const Par BoardVetoSource ("BoardVetoSource" , Type::DIG, RW::ReadWrite);
const Par BoardVetoWidth ("BoardVetoWidth" , Type::DIG, RW::ReadWrite);
const Par BoardVetoPolarity ("BoardVetoPolarity" , Type::DIG, RW::ReadWrite);
const Par ChannelsVetoSource ("ChannelsVetoSource" , Type::CH , RW::ReadWrite);
const Par ADCVetoWidth ("ADCVetoWidth" , Type::CH , RW::ReadWrite);
const Par EnableAutoDisarmACQ ("EnAutoDisarmAcq" , Type::DIG, RW::ReadWrite);
const Par LedStatus ("LedStatus" , Type::DIG, RW::ReadONLY);
const Par AcquistionStatus ("AcquistionStatus" , Type::DIG, RW::ReadONLY);
const Par EnableDataReduction ("EnDataReduction" , Type::DIG, RW::ReadWrite);
const Par EnableStatEvents ("EnStatEvents" , Type::DIG, RW::ReadWrite);
const Par VolatileClockOutDelay ("VolatileClockOutDelay" , Type::DIG, RW::ReadWrite);
const Par PermanentClockOutDelay("PermanentClockOutDelay" , Type::DIG, RW::ReadWrite);
///======= Waveform parameters
const Par WaveDataSource ("WaveDataSource" , Type::CH, RW::ReadWrite);
const Par ChRecordLengthS ("ChRecordLengthS" , Type::CH, RW::ReadWrite); /// in sample
const Par ChRecordLengthT ("ChRecordLengthT" , Type::CH, RW::ReadWrite); /// in time [ns]
const Par WaveResolution ("WaveResolution" , Type::CH, RW::ReadWrite);
const Par WaveAnalogProbes0 ("WaveAnalogProbes0" , Type::CH, RW::ReadWrite);
const Par WaveAnalogProbes1 ("WaveAnalogProbes1" , Type::CH, RW::ReadWrite);
const Par WaveDigitalProbes0 ("WaveDigitalProbes0" , Type::CH, RW::ReadWrite);
const Par WaveDigitalProbes1 ("WaveDigitalProbes1" , Type::CH, RW::ReadWrite);
const Par WaveDigitalProbes2 ("WaveDigitalProbes2" , Type::CH, RW::ReadWrite);
const Par WaveDigitalProbes3 ("WaveDigitalProbes3" , Type::CH, RW::ReadWrite);
const Par ChPreTriggerS ("ChPreTriggerS" , Type::CH, RW::ReadWrite);
const Par ChPreTriggerT ("ChPreTriggerT" , Type::CH, RW::ReadWrite);
///======= Service parameters
const Par TestPulsePeriod ("TestPulsePeriod" , Type::DIG, RW::ReadWrite);
const Par TestPulseWdith ("TestPulseWidth" , Type::DIG, RW::ReadWrite);
const Par TestPulseLowLevel ("TestPulseLowLevel" , Type::DIG, RW::ReadWrite);
const Par TestPulseHighLevel ("TestPulseHighLevel" , Type::DIG, RW::ReadWrite);
const Par IOlevel ("IOlevel" , Type::DIG, RW::ReadWrite);
const Par TempSensAirIn ("TempSensAirIn" , Type::DIG, RW::ReadONLY);
const Par TempSensAirOut ("TempSensAirOut" , Type::DIG, RW::ReadONLY);
const Par TempSensCore ("TempSensCore" , Type::DIG, RW::ReadONLY);
const Par TempSensFirstADC ("TempSensFirstADC" , Type::DIG, RW::ReadONLY);
const Par TempSensLastADC ("TempSensLastADC" , Type::DIG, RW::ReadONLY);
const Par TempSensHottestADC ("TempSensHottestADC" , Type::DIG, RW::ReadONLY);
const Par TempSensADC0 ("TempSensADC0" , Type::DIG, RW::ReadONLY);
const Par TempSensADC1 ("TempSensADC1" , Type::DIG, RW::ReadONLY);
const Par TempSensADC2 ("TempSensADC2" , Type::DIG, RW::ReadONLY);
const Par TempSensADC3 ("TempSensADC3" , Type::DIG, RW::ReadONLY);
const Par TempSensADC4 ("TempSensADC4" , Type::DIG, RW::ReadONLY);
const Par TempSensADC5 ("TempSensADC5" , Type::DIG, RW::ReadONLY);
const Par TempSensADC6 ("TempSensADC6" , Type::DIG, RW::ReadONLY);
const Par TempSensADC7 ("TempSensADC7" , Type::DIG, RW::ReadONLY);
const Par TempSensDCDC ("TempSensDCDC" , Type::DIG, RW::ReadONLY);
const Par VInSensDCDC ("VInSensDCDC" , Type::DIG, RW::ReadONLY);
const Par VOutSensDCDC ("VOutSensDCDC" , Type::DIG, RW::ReadONLY);
const Par IOutSensDCDC ("IOutSensDCDC" , Type::DIG, RW::ReadONLY);
const Par FreqSensCore ("FreqSensCore" , Type::DIG, RW::ReadONLY);
const Par DutyCycleSensDCDC ("DutyCycleSensDCDC" , Type::DIG, RW::ReadONLY);
const Par SpeedSensFan1 ("SpeedSensFan1" , Type::DIG, RW::ReadONLY);
const Par SpeedSensFan2 ("SpeedSensFan2" , Type::DIG, RW::ReadONLY);
const Par ErrorFlagMask ("ErrorFlagMask" , Type::DIG, RW::ReadONLY);
const Par ErrorFlagDataMask ("ErrorFlagDataMask" , Type::DIG, RW::ReadONLY);
const Par ErrorFlags ("ErrorFlags" , Type::DIG, RW::ReadONLY);
const Par BoardReady ("BoardReady" , Type::DIG, RW::ReadONLY);
///======= Indiviual trigger parameters
const Par ITLAMainLogic ("ITLAMainLogic" , Type::DIG, RW::ReadWrite);
const Par ITLAMajorityLev ("ITLAMajorityLev" , Type::DIG, RW::ReadWrite);
const Par ITLAPairLogic ("ITLAPairLogic" , Type::DIG, RW::ReadWrite);
const Par ITLAPolarity ("ITLAPolarity" , Type::DIG, RW::ReadWrite);
const Par ITLAMask ("ITLAMask" , Type::DIG, RW::ReadWrite);
const Par ITLAGateWdith ("ITLAGateWidth" , Type::DIG, RW::ReadWrite);
const Par ITLConnect ("ITLConnect" , Type::CH, RW::ReadWrite);
const Par ITLBMainLogic ("ITLBMainLogic" , Type::DIG, RW::ReadWrite);
const Par ITLBMajorityLev ("ITLBMajorityLev" , Type::DIG, RW::ReadWrite);
const Par ITLBPairLogic ("ITLBPairLogic" , Type::DIG, RW::ReadWrite);
const Par ITLBPolarity ("ITLBPolarity" , Type::DIG, RW::ReadWrite);
const Par ITLBMask ("ITLBMask" , Type::DIG, RW::ReadWrite);
const Par ITLBGateWdith ("ITLBGateWidth" , Type::DIG, RW::ReadWrite);
///======== Front Panel LEMO
///======== Input signal conditioning
const Par VGAGain ("VGAGain" , Type::VGA, RW::ReadWrite); /// 2745 only
const Par EnableOffsetCalibration ("EnOffsetCalibration" , Type::DIG, RW::ReadWrite);
const Par ChannelEnable ("ChEnable" , Type::CH , RW::ReadWrite);
const Par SelfTrgRate ("SelfTrgRate" , Type::CH , RW::ReadONLY);
const Par ChannelStatus ("ChStatus" , Type::CH , RW::ReadONLY);
const Par DCOffset ("DCOffset" , Type::CH , RW::ReadWrite);
const Par GainFactor ("GainFactor" , Type::CH , RW::ReadONLY);
const Par ADCToVolts ("ADCToVolts" , Type::CH , RW::ReadONLY);
const Par TriggerThreshold ("TriggerThr" , Type::CH , RW::ReadWrite);
const Par PulsePolarity ("PulsePolarity" , Type::CH , RW::ReadWrite);
///======= Event Selection
///======== PHA parameters
const Par TimeFilterRiseTimeS ("TimeFilterRiseTimeS" , Type::CH , RW::ReadWrite);
const Par TimeFilterRetriggerGuardS ("TimeFilterRetriggerGuardS" , Type::CH , RW::ReadWrite);
const Par EnergyFilterRiseTimeS ("EnergyFilterRiseTimeS" , Type::CH , RW::ReadWrite);
const Par EnergyFilterFlatTopS ("EnergyFilterFlatTopS" , Type::CH , RW::ReadWrite);
const Par EnergyFilterPoleZeroS ("EnergyFilterPoleZeroS" , Type::CH , RW::ReadWrite);
const Par EnergyFilterBaselineGuardS ("EnergyFilterBaselineGuardS" , Type::CH , RW::ReadWrite);
const Par EnergyFilterPileUpGuardS ("EnergyFilterPileUpGuardS" , Type::CH , RW::ReadWrite);
const Par TimeFilterRiseTimeT ("TimeFilterRiseTimeT" , Type::CH , RW::ReadWrite);
const Par TimeFilterRetriggerGuardT ("TimeFilterRetriggerGuardT" , Type::CH , RW::ReadWrite);
const Par EnergyFilterRiseTimeT ("EnergyFilterRiseTimeT" , Type::CH , RW::ReadWrite);
const Par EnergyFilterFlatTopT ("EnergyFilterFlatTopT" , Type::CH , RW::ReadWrite);
const Par EnergyFilterPoleZeroT ("EnergyFilterPoleZeroT" , Type::CH , RW::ReadWrite);
const Par EnergyFilterBaselineGuardT ("EnergyFilterBaselineGuardT" , Type::CH , RW::ReadWrite);
const Par EnergyFilterPileUpGuardT ("EnergyFilterPileUpGuardT" , Type::CH , RW::ReadWrite);
const Par EnergyFilterPeakingPosition ("EnergyFilterPeakingPosition" , Type::CH , RW::ReadWrite);
const Par EnergyFilterPeakingAvg ("EnergyFilterPeakingAvg" , Type::CH , RW::ReadWrite);
const Par EnergyFilterFineGain ("EnergyFilterFineGain" , Type::CH , RW::ReadWrite);
const Par EnergyFilterLowPassFilter ("EnergyFilterLFLimitation" , Type::CH , RW::ReadWrite);
const Par EnergyFilterBaselineAvg ("EnergyFilterBaselineAvg" , Type::CH , RW::ReadWrite);
const Par Energy_Nbit ("Energy_Nbit" , Type::CH , RW::ReadONLY);
const Par ChRealtimeMonitor ("ChRealtimeMonitor" , Type::CH , RW::ReadONLY);
const Par ChDeadtimeMonitor ("ChDeadtimeMonitor" , Type::CH , RW::ReadONLY);
const Par ChTriggerCnt ("ChTriggerCnt" , Type::CH , RW::ReadONLY);
const Par ChSavedEventCnt ("ChSavedEventCnt" , Type::CH , RW::ReadONLY);
const Par ChWaveCnt ("ChWaveCnt" , Type::CH , RW::ReadONLY);
///====== Command
const Par Reset ("Reset" , Type::CH , RW::WriteONLY);
const Par ClearData ("ClearData" , Type::CH , RW::WriteONLY);
const Par ArmAcquisition ("ArmAcquisition" , Type::CH , RW::WriteONLY);
const Par DisarmAcquisition ("DisarmAcquisition" , Type::CH , RW::WriteONLY);
const Par SwStartAcquisition ("SwStartAcquisition" , Type::CH , RW::WriteONLY);
const Par SwStopAcquisition ("SwStopAcquisition" , Type::CH , RW::WriteONLY);
const Par SendSWTrigger ("SendSWTrigger" , Type::CH , RW::WriteONLY);
const Par ReloadCalibration ("ReloadCalibration" , Type::CH , RW::WriteONLY);
}
#endif

66
test.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <cstdlib>
#include <string>
#include <vector>
#include <unistd.h>
#include "ClassDigitizer2Gen.h"
int main(int argc, char* argv[]){
printf("##########################################\n");
printf("\t CAEN firmware DPP-PHA testing \n");
printf("##########################################\n");
const char * url = "dig2://192.168.0.100/";
Digitizer2Gen * digi = new Digitizer2Gen();
digi->OpenDigitizer(url);
digi->ProgramPHA();
//printf("%s \n", digi->ReadValue("/ch/0/par/ChRealtimeMonitor").c_str());
//printf("%s \n", digi->ReadValue("/ch/0/par/Energy_Nbit").c_str());
//printf("%s \n", digi->ReadValue("/par/MaxRawDataSize").c_str());
/*///======================= Play with handle
uint64_t parHandle;
parHandle = digi->GetHandle("/ch/0/par/ChRealtimeMonitor"); printf("%lu|%lX\n", parHandle, parHandle);
parHandle = digi->GetHandle("/ch/1/par/ChRealtimeMonitor"); printf("%lu|%lX\n", parHandle, parHandle);
printf("%s\n", digi->GetPath(parHandle).c_str());
parHandle = digi->GetParentHandle(parHandle); printf("%lu|%lX\n", parHandle, parHandle);
printf("%s\n", digi->GetPath(parHandle).c_str());
parHandle = digi->GetParentHandle(parHandle); printf("%lu|%lX\n", parHandle, parHandle);
printf("%s\n", digi->GetPath(parHandle).c_str());
parHandle = digi->GetParentHandle(parHandle); printf("%lu|%lX\n", parHandle, parHandle);
printf("%s\n", digi->GetPath(parHandle).c_str());
parHandle = digi->GetParentHandle(parHandle); printf("%lu|%lX\n", parHandle, parHandle);
printf("%s\n", digi->GetPath(parHandle).c_str());
*/
digi->SetPHADataFormat();
digi->StartACQ();
usleep(1e6);
//digi->ReadData();
digi->StopACQ();
digi->CloseDigitizer();
delete digi;
}

295
test_indep.cpp Normal file
View File

@ -0,0 +1,295 @@
#include <CAEN_FELib.h>
#include <cstdlib>
#include <cstdio>
#include <unistd.h>
#include <cmath>
int main(){
int ret;
//#################################### Open digitizer
uint64_t dev_handle;
ret = CAEN_FELib_Open("dig2://192.168.0.100", &dev_handle);
//#################################### Get some values
char value[256];
ret = CAEN_FELib_GetValue(dev_handle, "/par/ModelName", value);
printf("Model name:\t%s\n", value);
ret = CAEN_FELib_GetValue(dev_handle, "/par/NumCh", value);
short NChannel = atoi(value);
printf("Channels:\t%u\n", NChannel);
//#################################### Reset
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/reset");
//#################################### Program digitizer
/// Channel enable
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChEnable", "true");
/// Global trigger configuration
ret = CAEN_FELib_SetValue(dev_handle, "/par/GlobalTriggerSource", "SwTrg | TestPulse"); // use test Pulse
ret = CAEN_FELib_SetValue(dev_handle, "/par/TestPulsePeriod", "100000000"); /// ns
ret = CAEN_FELib_SetValue(dev_handle, "/par/TestPulseWidth", "16"); ///ns
/// Wave configuration
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChRecordLengthS", "512");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveTriggerSource", "GlobalTriggerSource");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveResolution", "RES8");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveAnalogProbe0", "ADCInput");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveAnalogProbe1", "TimeFilter");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe0", "Trigger");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe1", "TimeFilterArmed");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe2", "EnergyFilterBaselineFreeze");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/WaveDigitalProbe3", "EnergyFilterPeakReady");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/ChPreTriggerS", "200");
/// Event configuration
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EventTriggerSource", "GlobalTriggerSource");
/// Filter parameters
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/TimeFilterRiseTimeS", "10");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterRiseTimeS", "100");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterFlatTopS", "100");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/TriggerThr", "3");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterPeakingPosition", "80");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterPoleZeroS", "1000");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/TimeFilterRetriggerGuardS", "10");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterPileupGuardT", "10");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterBaselineGuardS", "100");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/PulsePolarity", "Positive");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterLFLimitation", "Off");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterBaselineAvg", "Medium");
ret = CAEN_FELib_SetValue(dev_handle, "/ch/0..63/par/EnergyFilterFineGain", "1.0");
//#################################### Set the end point for data
{//----------------------- RAW
uint64_t ep_handle;
ret = CAEN_FELib_GetHandle(dev_handle, "/endpoint/raw", &ep_handle);
//---------- configure endpoint
uint64_t ep_folder_handle;
ret = CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle);
ret = CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "raw");
ret = CAEN_FELib_SetReadDataFormat(ep_handle,
" [ \
{ \"name\": \"DATA\", \"type\": \"U8\", \"dim\": 1 }, \
{ \"name\": \"SIZE\", \"type\": \"SIZE_T\" }, \
{ \"name\": \"N_EVENTS\", \"type\": \"U32\" }, \
]"
);
uint8_t* data = new uint8_t[200000];
size_t size; /// number of byte of the data
uint32_t n_events;
printf("Starting ACQ\n");
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/armacquisition");
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/swstartacquisition");
int count = 0;
for( int i = 0; i < 2; i++){
usleep(10000);
ret = CAEN_FELib_ReadData(ep_handle, 100, data, &size, &n_events );
count ++;
if( ret == CAEN_FELib_Success ) {
printf("================= %u, %ld, %d \n", n_events, size, count);
uint64_t haha ;
unsigned short dataType;
int word = 0;
for( int i =0 ; i < std::min((int)size / 8, 100) ; i++){
///the data is array of 1 byte.
/// by get the point of the data[8*i]
/// cast it into uint64_t pointer, that will get 8 bytes all togteher
/// get this point value, and bit swap it.
haha = __builtin_bswap64(*(uint64_t *)&(data[8*i]));
printf("%7d | 0x%016lX \n", i, haha);
if ( word == 0 ){ /// aggregation header, or start header, or end header
dataType = ( haha >> 55 ) & 0xFF ;
if ( dataType == 0x30 ){ /// start Run data
}
if ( dataType == 0x32 ){ /// stop Run data
}
if ( (dataType >> 4) == 0x2 ){ /// data aggregation
}
}
if ( word == 1 ){
unsigned short channel = ((haha >> 56) & 0x7F);
unsigned short SE = ((haha >> 55) & 0x1);
uint64_t timestamp = (haha & 0xFFFFFFFFFFFF);
printf("ch %u, SE %u, %llu \n", channel, SE, timestamp);
}
if ( word == 2 ){
unsigned short W = ((haha >> 62) & 0x1);
unsigned short fl = (( haha >> 50) & 0x1FFF);
unsigned short fh = (( haha >> 41) & 0xFF);
unsigned short energy = (haha & 0xFFFF);
unsigned short fTime = ((haha >> 15) & 7FF);
printf("energy %u, fTiem %u, fl %u, fh %u, W %u\n", energy, fTime, fl, fh, W);
}*/
word++;
}
}
}
printf("Stop ACQ\n");
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/disarmacquisition");
}
/**
{//------------------------ DPPPHA
uint64_t ep_handle;
ret = CAEN_FELib_GetHandle(dev_handle, "/endpoint/dpppha", &ep_handle);
//---------- configure endpoint
uint64_t ep_folder_handle;
ret = CAEN_FELib_GetParentHandle(ep_handle, NULL, &ep_folder_handle);
ret = CAEN_FELib_SetValue(ep_folder_handle, "/par/activeendpoint", "dpppha");
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\" : \"EVENT_SIZE\", \"type\" : \"SIZE_T\" } \
] \
"
);
uint8_t channel;
uint64_t timestamp;
uint16_t fine_timestamp;
uint16_t energy;
int32_t* analog_probes[2];
uint8_t* digital_probes[4];
analog_probes[0] = new int32_t[512];
analog_probes[1] = new int32_t[512];
digital_probes[0] = new uint8_t[512];
digital_probes[1] = new uint8_t[512];
digital_probes[2] = new uint8_t[512];
digital_probes[3] = new uint8_t[512];
uint8_t analog_probes_type[2];
uint8_t digital_probes_type[4];
size_t n_samples;
uint16_t flags_low_priority;
uint16_t flags_high_priority;
size_t event_size;
//#################################### Read data loop
printf("Starting ACQ\n");
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/armacquisition");
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/swstartacquisition");
int count = 0;
for( int i = 0; i < 10; i++){
usleep(10000);
ret = CAEN_FELib_ReadData(ep_handle, 100,
&channel,
&timestamp,
&fine_timestamp,
&energy,
analog_probes[0],
analog_probes[1],
digital_probes[0],
digital_probes[1],
digital_probes[2],
digital_probes[3],
&analog_probes_type[0],
&analog_probes_type[1],
&digital_probes_type[0],
&digital_probes_type[1],
&digital_probes_type[2],
&digital_probes_type[3],
&n_samples,
&flags_low_priority,
&flags_high_priority,
&event_size
);
count ++;
if( ret == CAEN_FELib_Success ) {
printf("================= %ld, %d \n", event_size, count);
printf("ch : %u, energy : %u, time : %lu, fTime : %u \n", channel, energy, timestamp, fine_timestamp);
printf("nSample: %ld, Flag low: %u, Flag high : %u\n", n_samples, flags_low_priority, flags_high_priority);
printf("Ana prob type: %u, %u, Digi : %u %u %u %u\n", analog_probes_type[0],
analog_probes_type[1],
digital_probes_type[0],
digital_probes_type[1],
digital_probes_type[2],
digital_probes_type[3] );
for( int i = 0; i < n_samples; i++){
if( i % 100 == 0 ) printf("%3d | %d, %d, %u, %u, %u, %u \n", i, analog_probes[0][i],
analog_probes[1][i],
digital_probes[0][i],
digital_probes[1][i],
digital_probes[2][i],
digital_probes[3][i]);
}
}
}
printf("Stop ACQ\n");
ret = CAEN_FELib_SendCommand(dev_handle, "/cmd/disarmacquisition");
}/**/
//#################################### Close digitizer
ret = CAEN_FELib_Close(dev_handle);
}