76 lines
2.1 KiB
C++
76 lines
2.1 KiB
C++
#ifndef DATA_H
|
|
#define DATA_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"
|
|
|
|
class Data{
|
|
|
|
public:
|
|
|
|
int nByte; /// number of byte
|
|
char *buffer; /// readout buffer
|
|
uint32_t NumEvents[MaxNChannels];
|
|
uint32_t AllocatedSize;
|
|
uint32_t BufferSize;
|
|
CAEN_DGTZ_DPP_PHA_Event_t *Events[MaxNChannels]; /// events buffer
|
|
CAEN_DGTZ_DPP_PHA_Waveforms_t *Waveform[MaxNChannels]; /// waveforms buffer
|
|
|
|
public:
|
|
Data(){
|
|
nByte = 0;
|
|
buffer = NULL;
|
|
AllocatedSize = 0;
|
|
BufferSize = 0;
|
|
for( int i = 0 ; i < MaxNChannels; i++){
|
|
NumEvents[i] = 0;
|
|
Events[i] = NULL;
|
|
Waveform[i] = NULL;
|
|
}
|
|
}
|
|
|
|
~Data(){
|
|
for( int i = 0 ; i < MaxNChannels; i++){
|
|
delete Events [i];
|
|
delete Waveform [i];
|
|
}
|
|
}
|
|
|
|
void AllocateMemory(int handle){
|
|
int ret = CAEN_DGTZ_MallocReadoutBuffer(handle, &buffer, &AllocatedSize); /// output: buffer and allocatedSize
|
|
ret |= CAEN_DGTZ_MallocDPPEvents(handle, reinterpret_cast<void**>(&Events), &AllocatedSize) ;
|
|
for( int i = 0 ; i < MaxNChannels; i++){
|
|
ret |= CAEN_DGTZ_MallocDPPWaveforms(handle, reinterpret_cast<void**>(&Waveform[i]), &AllocatedSize);
|
|
}
|
|
if (ret != 0) {
|
|
printf("Can't allocate memory buffers\n");
|
|
CAEN_DGTZ_SWStopAcquisition(handle);
|
|
CAEN_DGTZ_CloseDigitizer(handle);
|
|
CAEN_DGTZ_FreeReadoutBuffer(&buffer);
|
|
CAEN_DGTZ_FreeDPPEvents(handle, reinterpret_cast<void**>(&Events));
|
|
}else{
|
|
printf("====== Allocated %d byte memory for data buffer.\n", AllocatedSize);
|
|
}
|
|
}
|
|
|
|
void FreeMemory(int handle){
|
|
printf("======= Free memory \n");
|
|
CAEN_DGTZ_FreeReadoutBuffer(&buffer);
|
|
CAEN_DGTZ_FreeDPPEvents(handle, reinterpret_cast<void**>(&Events));
|
|
CAEN_DGTZ_FreeDPPWaveforms(handle, Waveform);
|
|
}
|
|
};
|
|
|
|
|
|
#endif
|